Page Speed Optimization Libraries  1.6.29.3
net/instaweb/rewriter/public/cacheable_resource_base.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 
00025 
00026 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_CACHEABLE_RESOURCE_BASE_H_
00027 #define NET_INSTAWEB_REWRITER_PUBLIC_CACHEABLE_RESOURCE_BASE_H_
00028 
00029 #include "net/instaweb/http/public/request_context.h"
00030 #include "net/instaweb/rewriter/public/resource.h"
00031 #include "net/instaweb/rewriter/public/server_context.h"
00032 #include "net/instaweb/util/public/basictypes.h"
00033 #include "net/instaweb/util/public/string_util.h"
00034 
00035 namespace net_instaweb {
00036 
00037 struct ContentType;
00038 class HTTPCache;
00039 class HTTPValue;
00040 class MessageHandler;
00041 class ResponseHeaders;
00042 class RewriteDriver;
00043 class RewriteOptions;
00044 class Statistics;
00045 class Timer;
00046 class Variable;
00047 
00048 class CacheableResourceBase : public Resource {
00049  public:
00051   virtual bool UseHttpCache() const { return true; }
00052 
00053   virtual bool IsValidAndCacheable() const;
00054 
00057   virtual void LoadAndCallback(NotCacheablePolicy not_cacheable_policy,
00058                                const RequestContextPtr& request_context,
00059                                AsyncCallback* callback);
00060 
00062   virtual void Freshen(FreshenCallback* callback, MessageHandler* handler);
00063 
00065   virtual void RefreshIfImminentlyExpiring();
00066 
00067  protected:
00069   CacheableResourceBase(StringPiece stat_prefix, RewriteDriver* rewrite_driver,
00070                         const ContentType* type);
00071   virtual ~CacheableResourceBase();
00072 
00073   static void InitStats(StringPiece stat_prefix, Statistics* statistics);
00074 
00076   virtual bool IsValidAndCacheableImpl(
00077       const ResponseHeaders& headers) const = 0;
00078 
00079   HTTPCache* http_cache() const { return server_context()->http_cache(); }
00080   RewriteDriver* rewrite_driver() const { return rewrite_driver_; }
00081   const RewriteOptions* rewrite_options() const;
00082 
00083  private:
00084   class FreshenHttpCacheCallback;
00085   class LoadHttpCacheCallback;
00086   class FetchCallbackBase;
00087   class FreshenFetchCallback;
00088   class LoadFetchCallback;
00089   friend class CacheableResourceBaseTest;
00090 
00094   bool UpdateInputInfoForFreshen(const ResponseHeaders& headers,
00095                                  const HTTPValue& value,
00096                                  Resource::FreshenCallback* callback);
00097 
00098 
00099   Timer* timer() const { return server_context()->timer(); }
00100   MessageHandler* message_handler() const {
00101     return server_context()->message_handler();
00102   }
00103 
00104   RewriteDriver* rewrite_driver_;
00105   Variable* hits_;
00106   Variable* recent_fetch_failures_;
00107   Variable* recent_uncacheables_treated_as_miss_;
00108   Variable* recent_uncacheables_treated_as_failure_;
00109   Variable* misses_;
00110 
00111   DISALLOW_COPY_AND_ASSIGN(CacheableResourceBase);
00112 };
00113 
00114 }  
00115 
00116 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_CACHEABLE_RESOURCE_BASE_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines