Page Speed Optimization Libraries  1.8.31.2
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 "net/instaweb/http/public/request_context.h"
00026 #include "net/instaweb/rewriter/public/output_resource_kind.h"
00027 #include "net/instaweb/rewriter/public/resource.h"
00028 #include "net/instaweb/rewriter/public/resource_namer.h"
00029 #include "net/instaweb/util/public/basictypes.h"
00030 #include "net/instaweb/util/public/ref_counted_ptr.h"
00031 #include "net/instaweb/util/public/string.h"
00032 #include "net/instaweb/util/public/string_util.h"
00033 
00034 namespace net_instaweb {
00035 
00036 class CachedResult;
00037 class MessageHandler;
00038 class RewriteOptions;
00039 class ServerContext;
00040 class Writer;
00041 struct ContentType;
00042 
00043 class OutputResource : public Resource {
00044  public:
00053   OutputResource(ServerContext* server_context,
00054                  const StringPiece& resolved_base,
00055                  const StringPiece& unmapped_base, 
00056                  const StringPiece& original_base, 
00057                  const ResourceNamer& resource_id,
00058                  const RewriteOptions* options,
00059                  OutputResourceKind kind);
00060 
00061   virtual void LoadAndCallback(NotCacheablePolicy not_cacheable_policy,
00062                                const RequestContextPtr& request_context,
00063                                AsyncCallback* callback);
00070   virtual GoogleString url() const;
00074   GoogleString UrlEvenIfHashNotSet();
00075 
00080   void DumpToDisk(MessageHandler* handler);
00081 
00084   void UpdateCachedResultPreservingInputInfo(CachedResult* to_update) const;
00085 
00099   virtual GoogleString name_key() const;
00100 
00110   GoogleString HttpCacheKey() const;
00111 
00113   const GoogleString& resolved_base() const { return resolved_base_; }
00114   const GoogleString& unmapped_base() const { return unmapped_base_; }
00115   const GoogleString& original_base() const { return original_base_; }
00116   const ResourceNamer& full_name() const { return full_name_; }
00117   ResourceNamer* mutable_full_name() { return &full_name_; }
00118   StringPiece name() const { return full_name_.name(); }
00119   StringPiece experiment() const { return full_name_.experiment(); }
00120   StringPiece suffix() const;
00121   StringPiece filter_prefix() const { return full_name_.id(); }
00122   StringPiece hash() const { return full_name_.hash(); }
00123   bool has_hash() const { return !hash().empty(); }
00124   void clear_hash() {
00125     full_name_.ClearHash();
00126     computed_url_.clear();
00127   }
00128 
00138   GoogleString decoded_base() const;
00139 
00147   bool IsWritten() const { return writing_complete_; }
00148 
00150   virtual void SetType(const ContentType* type);
00151 
00164   const CachedResult* cached_result() const { return cached_result_; }
00165 
00173   CachedResult* EnsureCachedResultCreated();
00174 
00175   void clear_cached_result();
00176 
00179   void set_cached_result(CachedResult* cached_result) {
00180     clear_cached_result();
00181     cached_result_ = cached_result;
00182   }
00183 
00184   OutputResourceKind kind() const { return kind_; }
00185 
00187   void SetWritten(bool written) { writing_complete_ = true; }
00188 
00189   virtual const RewriteOptions* rewrite_options() const {
00190     return rewrite_options_;
00191   }
00192 
00196   Writer* BeginWrite(MessageHandler* message_handler);
00197   void EndWrite(MessageHandler* message_handler);
00198 
00199   virtual bool UseHttpCache() const { return true; }
00200 
00201  protected:
00202   virtual ~OutputResource();
00203   REFCOUNT_FRIEND_DECLARATION(OutputResource);
00204 
00205  private:
00206   friend class RewriteDriver;
00207   friend class ServerContext;
00208   friend class ServerContextTest;
00209 
00210   void SetHash(const StringPiece& hash);
00211   StringPiece extension() const { return full_name_.ext(); }
00212 
00214   GoogleString DumpFileName() const;
00215 
00216   bool writing_complete_;
00217 
00224   bool cached_result_owned_;
00225   CachedResult* cached_result_;
00226 
00245   GoogleString resolved_base_;
00246   GoogleString unmapped_base_;
00247   GoogleString original_base_;
00248 
00249   ResourceNamer full_name_;
00250 
00252   mutable GoogleString computed_url_;
00253 
00254   const RewriteOptions* rewrite_options_;
00255 
00258   OutputResourceKind kind_;
00259 
00260   DISALLOW_COPY_AND_ASSIGN(OutputResource);
00261 };
00262 
00263 }  
00264 
00265 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_OUTPUT_RESOURCE_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines