Page Speed Optimization Libraries  1.8.31.3
net/instaweb/rewriter/public/output_resource.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http:///www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00021 
00022 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_OUTPUT_RESOURCE_H_
00023 #define NET_INSTAWEB_REWRITER_PUBLIC_OUTPUT_RESOURCE_H_
00024 
00025 #include "base/logging.h"
00026 #include "net/instaweb/http/public/request_context.h"
00027 #include "net/instaweb/rewriter/public/output_resource_kind.h"
00028 #include "net/instaweb/rewriter/public/resource.h"
00029 #include "net/instaweb/rewriter/public/resource_namer.h"
00030 #include "net/instaweb/util/public/basictypes.h"
00031 #include "net/instaweb/util/public/ref_counted_ptr.h"
00032 #include "net/instaweb/util/public/string.h"
00033 #include "net/instaweb/util/public/string_util.h"
00034 
00035 namespace net_instaweb {
00036 
00037 class CachedResult;
00038 class MessageHandler;
00039 class RewriteOptions;
00040 class ServerContext;
00041 class Writer;
00042 struct ContentType;
00043 
00044 class OutputResource : public Resource {
00045  public:
00054   OutputResource(ServerContext* server_context,
00055                  const StringPiece& resolved_base,
00056                  const StringPiece& unmapped_base, 
00057                  const StringPiece& original_base, 
00058                  const ResourceNamer& resource_id,
00059                  const RewriteOptions* options,
00060                  OutputResourceKind kind);
00061 
00062   virtual void LoadAndCallback(NotCacheablePolicy not_cacheable_policy,
00063                                const RequestContextPtr& request_context,
00064                                AsyncCallback* callback);
00071   virtual GoogleString url() const;
00075   GoogleString UrlEvenIfHashNotSet();
00076 
00081   void DumpToDisk(MessageHandler* handler);
00082 
00085   void UpdateCachedResultPreservingInputInfo(CachedResult* to_update) const;
00086 
00100   virtual GoogleString name_key() const;
00101 
00111   GoogleString HttpCacheKey() const;
00112 
00114   const GoogleString& resolved_base() const { return resolved_base_; }
00115   const GoogleString& unmapped_base() const { return unmapped_base_; }
00116   const GoogleString& original_base() const { return original_base_; }
00117   const ResourceNamer& full_name() const { return full_name_; }
00118   ResourceNamer* mutable_full_name() { return &full_name_; }
00119   StringPiece name() const { return full_name_.name(); }
00120   StringPiece experiment() const { return full_name_.experiment(); }
00121   StringPiece suffix() const;
00122   StringPiece filter_prefix() const { return full_name_.id(); }
00123   StringPiece hash() const { return full_name_.hash(); }
00124   bool has_hash() const { return !hash().empty(); }
00125   void clear_hash() {
00126     full_name_.ClearHash();
00127     computed_url_.clear();
00128   }
00129 
00139   GoogleString decoded_base() const;
00140 
00148   bool IsWritten() const { return writing_complete_; }
00149 
00151   virtual void SetType(const ContentType* type);
00152 
00165   const CachedResult* cached_result() const { return cached_result_; }
00166 
00174   CachedResult* EnsureCachedResultCreated();
00175 
00176   void clear_cached_result();
00177 
00180   void set_cached_result(CachedResult* cached_result) {
00181     clear_cached_result();
00182     cached_result_ = cached_result;
00183   }
00184 
00185   OutputResourceKind kind() const { return kind_; }
00186 
00188   void SetWritten(bool written) { writing_complete_ = true; }
00189 
00190   virtual const RewriteOptions* rewrite_options() const {
00191     return rewrite_options_;
00192   }
00193 
00197   Writer* BeginWrite(MessageHandler* message_handler);
00198   void EndWrite(MessageHandler* message_handler);
00199 
00200   virtual bool UseHttpCache() const { return true; }
00201 
00205   const GoogleString& cache_control_suffix() const {
00206     return cache_control_suffix_;
00207   }
00208   void set_cache_control_suffix(const GoogleString& x) {
00209     DCHECK(cache_control_suffix_.empty());
00210     cache_control_suffix_ = x;
00211   }
00212 
00213  protected:
00214   virtual ~OutputResource();
00215   REFCOUNT_FRIEND_DECLARATION(OutputResource);
00216 
00217  private:
00218   friend class RewriteDriver;
00219   friend class ServerContext;
00220   friend class ServerContextTest;
00221 
00222   void SetHash(const StringPiece& hash);
00223   StringPiece extension() const { return full_name_.ext(); }
00224 
00226   GoogleString DumpFileName() const;
00227 
00228   bool writing_complete_;
00229 
00236   bool cached_result_owned_;
00237   CachedResult* cached_result_;
00238 
00257   GoogleString resolved_base_;
00258   GoogleString unmapped_base_;
00259   GoogleString original_base_;
00260 
00261   GoogleString cache_control_suffix_;
00262 
00263   ResourceNamer full_name_;
00264 
00266   mutable GoogleString computed_url_;
00267 
00268   const RewriteOptions* rewrite_options_;
00269 
00272   OutputResourceKind kind_;
00273 
00274   DISALLOW_COPY_AND_ASSIGN(OutputResource);
00275 };
00276 
00277 }  
00278 
00279 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_OUTPUT_RESOURCE_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines