Page Speed Optimization Libraries  1.2.24.1
net/instaweb/http/public/cache_url_async_fetcher.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2011 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 
00018 
00019 #ifndef NET_INSTAWEB_HTTP_PUBLIC_CACHE_URL_ASYNC_FETCHER_H_
00020 #define NET_INSTAWEB_HTTP_PUBLIC_CACHE_URL_ASYNC_FETCHER_H_
00021 
00022 #include "net/instaweb/http/public/url_async_fetcher.h"
00023 #include "net/instaweb/util/public/basictypes.h"
00024 #include "net/instaweb/util/public/string.h"
00025 
00026 namespace net_instaweb {
00027 
00028 class AsyncFetch;
00029 class Histogram;
00030 class HTTPCache;
00031 class MessageHandler;
00032 class Variable;
00033 
00046 class CacheUrlAsyncFetcher : public UrlAsyncFetcher {
00047  public:
00048   CacheUrlAsyncFetcher(HTTPCache* cache, UrlAsyncFetcher* fetcher)
00049       : http_cache_(cache),
00050         fetcher_(fetcher),
00051         backend_first_byte_latency_(NULL),
00052         fallback_responses_served_(NULL),
00053         num_conditional_refreshes_(NULL),
00054         respect_vary_(false),
00055         ignore_recent_fetch_failed_(false),
00056         serve_stale_if_fetch_error_(false),
00057         default_cache_html_(false) {
00058   }
00059   virtual ~CacheUrlAsyncFetcher();
00060 
00061   virtual bool SupportsHttps() const { return fetcher_->SupportsHttps(); }
00062 
00063   virtual void Fetch(const GoogleString& url,
00064                      MessageHandler* message_handler,
00065                      AsyncFetch* base_fetch);
00066 
00067   HTTPCache* http_cache() const { return http_cache_; }
00068   UrlAsyncFetcher* fetcher() const { return fetcher_; }
00069 
00070   void set_backend_first_byte_latency_histogram(Histogram* x) {
00071     backend_first_byte_latency_ = x;
00072   }
00073 
00074   Histogram* backend_first_byte_latency_histogram() const {
00075     return backend_first_byte_latency_;
00076   }
00077 
00078   void set_fallback_responses_served(Variable* x) {
00079     fallback_responses_served_ = x;
00080   }
00081 
00082   Variable* fallback_responses_served() const {
00083     return fallback_responses_served_;
00084   }
00085 
00086   void set_num_conditional_refreshes(Variable* x) {
00087     num_conditional_refreshes_ = x;
00088   }
00089 
00090   Variable* num_conditional_refreshes() const {
00091     return num_conditional_refreshes_;
00092   }
00093 
00094   void set_respect_vary(bool x) { respect_vary_ = x; }
00095   bool respect_vary() const { return respect_vary_; }
00096 
00097   void set_ignore_recent_fetch_failed(bool x) {
00098     ignore_recent_fetch_failed_ = x;
00099   }
00100   bool ignore_recent_fetch_failed() const {
00101     return ignore_recent_fetch_failed_;
00102   }
00103 
00104   void set_serve_stale_if_fetch_error(bool x) {
00105     serve_stale_if_fetch_error_ = x;
00106   }
00107 
00108   bool serve_stale_if_fetch_error() const {
00109     return serve_stale_if_fetch_error_;
00110   }
00111 
00112   void set_default_cache_html(bool x) { default_cache_html_ = x; }
00113   bool default_cache_html() const { return default_cache_html_; }
00114 
00115  private:
00117   HTTPCache* http_cache_;
00118   UrlAsyncFetcher* fetcher_;
00119 
00120   Histogram* backend_first_byte_latency_; 
00121   Variable* fallback_responses_served_; 
00122   Variable* num_conditional_refreshes_; 
00123 
00124   bool respect_vary_;
00125   bool ignore_recent_fetch_failed_;
00126   bool serve_stale_if_fetch_error_;
00127   bool default_cache_html_;
00128 
00129   DISALLOW_COPY_AND_ASSIGN(CacheUrlAsyncFetcher);
00130 };
00131 
00132 }  
00133 
00134 #endif  ///< NET_INSTAWEB_HTTP_PUBLIC_CACHE_URL_ASYNC_FETCHER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines