Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
resource_combiner.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
22 
23 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_COMBINER_H_
24 #define NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_COMBINER_H_
25 
28 #include "net/instaweb/rewriter/public/url_partnership.h"
33 
34 namespace net_instaweb {
35 
36 struct ContentType;
37 class MessageHandler;
38 class OutputResource;
39 class RewriteDriver;
40 class RewriteFilter;
41 class Writer;
42 
44 struct TimedBool {
48  bool value;
49 };
50 
58  public:
67  static const int kUrlSlack = 100;
68 
70  ResourceCombiner(RewriteDriver* rewrite_driver,
71  const StringPiece& extension,
72  RewriteFilter* filter);
73 
74  virtual ~ResourceCombiner();
75 
79  void Reset();
80 
83  GoogleString UrlSafeId() const;
84 
86  int num_urls() const { return partnership_.num_urls(); }
87 
88  const ResourceVector& resources() const { return resources_; }
89 
91  GoogleString ResolvedBase() const { return partnership_.ResolvedBase(); }
92 
95  MessageHandler* handler);
96 
97  protected:
101  virtual void RemoveLastResource();
102 
108 
111  virtual bool WriteCombination(const ResourceVector& combine_resources,
112  const OutputResourcePtr& combination,
113  MessageHandler* handler);
114 
120  virtual bool WritePiece(int index, int num_pieces, const Resource* input,
121  OutputResource* combination, Writer* writer,
122  MessageHandler* handler);
123 
126  virtual void Clear();
127 
128  ServerContext* const server_context_;
129  RewriteDriver* const rewrite_driver_;
130 
131  private:
132  friend class AggregateCombiner;
133 
135  virtual const ContentType* CombinationContentType() = 0;
136 
138  void UpdateResolvedBase();
139 
141  void ComputeLeafSize();
142 
145  void AccumulateLeafSize(const StringPiece& url);
146 
149  bool UrlTooBig();
150 
153  virtual void AccumulateCombinedSize(const ResourcePtr& resource) {}
154 
157  virtual bool ContentSizeTooBig() const { return false; }
158 
164  virtual bool ResourceCombinable(Resource* resource,
165  GoogleString* failure_reason,
166  MessageHandler* handler);
167 
168  UrlPartnership partnership_;
169  ResourceVector resources_;
170  StringVector multipart_encoder_urls_;
171  int prev_num_components_;
172  int accumulated_leaf_size_;
173  GoogleString resolved_base_;
174  const int url_overhead_;
175  RewriteFilter* filter_;
176 
177  FRIEND_TEST(ResourceCombinerTest, TestRemove);
178  FRIEND_TEST(ResourceCombinerTest, TestRemoveFrom3);
179  FRIEND_TEST(ResourceCombinerTest, TestRebaseRemove);
180  FRIEND_TEST(ResourceCombinerTest, TestRebaseRemoveAdd);
181 
182 
183 };
184 
185 }
186 
187 #endif
int num_urls() const
Returns the number of URLs that have been successfully added.
Definition: url_partnership.h:55
GoogleString UrlSafeId() const
int num_urls() const
Returns the number of URLs that have been successfully added.
Definition: resource_combiner.h:86
virtual bool WritePiece(int index, int num_pieces, const Resource *input, OutputResource *combination, Writer *writer, MessageHandler *handler)
ResourceCombiner(RewriteDriver *rewrite_driver, const StringPiece &extension, RewriteFilter *filter)
Note: extension should not include the leading dot here.
Definition: resource.h:57
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
static const int kUrlSlack
Definition: resource_combiner.h:67
int64 expiration_ms
Definition: resource_combiner.h:47
GoogleString ResolvedBase() const
Base common to all URLs. Always has a trailing slash.
Definition: resource_combiner.h:91
Definition: rewrite_filter.h:35
Definition: resource_combiner.h:57
virtual bool WriteCombination(const ResourceVector &combine_resources, const OutputResourcePtr &combination, MessageHandler *handler)
Interface for writing bytes to an output stream.
Definition: writer.h:29
Definition: rewrite_driver.h:100
Definition: server_context.h:99
Definition: content_type.h:31
GoogleString ResolvedBase() const
Definition: message_handler.h:39
Definition: output_resource.h:44
OutputResourcePtr Combine(MessageHandler *handler)
A boolean with an expiration date.
Definition: resource_combiner.h:44
TimedBool AddResourceNoFetch(const ResourcePtr &resource, MessageHandler *handler)