Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
output_resource.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 
21 
22 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_OUTPUT_RESOURCE_H_
23 #define NET_INSTAWEB_REWRITER_PUBLIC_OUTPUT_RESOURCE_H_
24 
25 #include "base/logging.h"
26 #include "net/instaweb/http/public/request_context.h"
34 
35 namespace net_instaweb {
36 
37 class CachedResult;
38 class MessageHandler;
39 class RewriteDriver;
40 class RewriteOptions;
41 class Writer;
42 struct ContentType;
43 
44 class OutputResource : public Resource {
45  public:
54  OutputResource(const RewriteDriver* driver,
55  StringPiece resolved_base,
56  StringPiece unmapped_base,
57  StringPiece original_base,
58  const ResourceNamer& resource_id,
59  OutputResourceKind kind);
60 
61  virtual void LoadAndCallback(NotCacheablePolicy not_cacheable_policy,
62  const RequestContextPtr& request_context,
63  AsyncCallback* callback);
70  virtual GoogleString url() const;
75 
80  void DumpToDisk(MessageHandler* handler);
81 
84  void UpdateCachedResultPreservingInputInfo(CachedResult* to_update) const;
85 
99  virtual GoogleString name_key() const;
100 
110  GoogleString HttpCacheKey() const;
111 
113  const GoogleString& resolved_base() const { return resolved_base_; }
114  const GoogleString& unmapped_base() const { return unmapped_base_; }
115  const GoogleString& original_base() const { return original_base_; }
116  const ResourceNamer& full_name() const { return full_name_; }
117  ResourceNamer* mutable_full_name() { return &full_name_; }
118  StringPiece name() const { return full_name_.name(); }
119  StringPiece experiment() const { return full_name_.experiment(); }
120  StringPiece suffix() const;
121  StringPiece filter_prefix() const { return full_name_.id(); }
122  StringPiece hash() const { return full_name_.hash(); }
123  StringPiece signature() const { return full_name_.signature(); }
124  bool has_hash() const { return !hash().empty(); }
125  void clear_hash() {
126  full_name_.ClearHash();
127  computed_url_.clear();
128  }
129 
139  GoogleString decoded_base() const;
140 
148  bool IsWritten() const { return writing_complete_; }
149 
151  virtual void SetType(const ContentType* type);
152 
165  const CachedResult* cached_result() const { return cached_result_; }
166 
174  CachedResult* EnsureCachedResultCreated();
175 
176  void clear_cached_result();
177 
180  void set_cached_result(CachedResult* cached_result) {
181  clear_cached_result();
182  cached_result_ = cached_result;
183  }
184 
185  OutputResourceKind kind() const { return kind_; }
186 
188  void SetWritten(bool written) { writing_complete_ = true; }
189 
190  virtual const RewriteOptions* rewrite_options() const {
191  return rewrite_options_;
192  }
193 
197  Writer* BeginWrite(MessageHandler* message_handler);
198  void EndWrite(MessageHandler* message_handler);
199 
200  virtual bool UseHttpCache() const { return true; }
201 
206  return cache_control_suffix_;
207  }
208  void set_cache_control_suffix(const GoogleString& x) {
209  DCHECK(cache_control_suffix_.empty());
210  cache_control_suffix_ = x;
211  }
212 
213  protected:
214  virtual ~OutputResource();
215  REFCOUNT_FRIEND_DECLARATION(OutputResource);
216 
217  private:
218  friend class RewriteDriver;
219  friend class ServerContext;
220  friend class ServerContextTest;
221 
222  void SetHash(StringPiece hash);
223  StringPiece extension() const { return full_name_.ext(); }
224  GoogleString ComputeSignature();
225  bool CheckSignature();
226 
228  GoogleString DumpFileName() const;
229 
230  bool writing_complete_;
231 
238  bool cached_result_owned_;
239  CachedResult* cached_result_;
240 
259  GoogleString resolved_base_;
260  GoogleString unmapped_base_;
261  GoogleString original_base_;
262 
263  GoogleString cache_control_suffix_;
264 
265  ResourceNamer full_name_;
266 
268  mutable GoogleString computed_url_;
269 
270  const RewriteOptions* rewrite_options_;
271 
274  OutputResourceKind kind_;
275 
276 
277 };
278 
279 }
280 
281 #endif
const GoogleString & resolved_base() const
output-specific
Definition: output_resource.h:113
virtual GoogleString name_key() const
Writer * BeginWrite(MessageHandler *message_handler)
void UpdateCachedResultPreservingInputInfo(CachedResult *to_update) const
CachedResult * EnsureCachedResultCreated()
void SetWritten(bool written)
This is called by CacheCallback::Done in rewrite_driver.cc.
Definition: output_resource.h:188
StringPiece id() const
Simple getters.
Definition: resource_namer.h:72
void set_cached_result(CachedResult *cached_result)
Definition: output_resource.h:180
Definition: resource.h:217
GoogleString UrlEvenIfHashNotSet()
virtual bool UseHttpCache() const
Definition: output_resource.h:200
Definition: resource.h:57
NotCacheablePolicy
Definition: resource.h:68
GoogleString decoded_base() const
virtual void SetType(const ContentType *type)
Sets the type of the output resource, and thus also its suffix.
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
virtual GoogleString url() const
OutputResource(const RewriteDriver *driver, StringPiece resolved_base, StringPiece unmapped_base, StringPiece original_base, const ResourceNamer &resource_id, OutputResourceKind kind)
GoogleString HttpCacheKey() const
Definition: rewrite_driver.h:100
Definition: content_type.h:31
void ClearHash()
Other setter-like operations.
Definition: resource_namer.h:98
void DumpToDisk(MessageHandler *handler)
Definition: message_handler.h:39
const GoogleString & cache_control_suffix() const
Definition: output_resource.h:205
Definition: output_resource.h:44
const CachedResult * cached_result() const
Definition: output_resource.h:165
bool IsWritten() const
Definition: output_resource.h:148
Definition: rewrite_options.h:84
virtual void LoadAndCallback(NotCacheablePolicy not_cacheable_policy, const RequestContextPtr &request_context, AsyncCallback *callback)
Definition: resource_namer.h:32
OutputResourceKind
Definition: output_resource_kind.h:26