Page Speed Optimization Libraries
1.5.27.2
|
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 00049 class CacheUrlAsyncFetcher : public UrlAsyncFetcher { 00050 public: 00051 CacheUrlAsyncFetcher(HTTPCache* cache, UrlAsyncFetcher* fetcher) 00052 : http_cache_(cache), 00053 fetcher_(fetcher), 00054 backend_first_byte_latency_(NULL), 00055 fallback_responses_served_(NULL), 00056 num_conditional_refreshes_(NULL), 00057 respect_vary_(false), 00058 ignore_recent_fetch_failed_(false), 00059 serve_stale_if_fetch_error_(false), 00060 default_cache_html_(false) { 00061 } 00062 virtual ~CacheUrlAsyncFetcher(); 00063 00064 virtual bool SupportsHttps() const { return fetcher_->SupportsHttps(); } 00065 00066 virtual void Fetch(const GoogleString& url, 00067 MessageHandler* message_handler, 00068 AsyncFetch* base_fetch); 00069 00072 static const int kNotInCacheStatus; 00073 00074 HTTPCache* http_cache() const { return http_cache_; } 00075 UrlAsyncFetcher* fetcher() const { return fetcher_; } 00076 00077 void set_backend_first_byte_latency_histogram(Histogram* x) { 00078 backend_first_byte_latency_ = x; 00079 } 00080 00081 Histogram* backend_first_byte_latency_histogram() const { 00082 return backend_first_byte_latency_; 00083 } 00084 00085 void set_fallback_responses_served(Variable* x) { 00086 fallback_responses_served_ = x; 00087 } 00088 00089 Variable* fallback_responses_served() const { 00090 return fallback_responses_served_; 00091 } 00092 00093 void set_num_conditional_refreshes(Variable* x) { 00094 num_conditional_refreshes_ = x; 00095 } 00096 00097 Variable* num_conditional_refreshes() const { 00098 return num_conditional_refreshes_; 00099 } 00100 00101 void set_respect_vary(bool x) { respect_vary_ = x; } 00102 bool respect_vary() const { return respect_vary_; } 00103 00104 void set_ignore_recent_fetch_failed(bool x) { 00105 ignore_recent_fetch_failed_ = x; 00106 } 00107 bool ignore_recent_fetch_failed() const { 00108 return ignore_recent_fetch_failed_; 00109 } 00110 00111 void set_serve_stale_if_fetch_error(bool x) { 00112 serve_stale_if_fetch_error_ = x; 00113 } 00114 00115 bool serve_stale_if_fetch_error() const { 00116 return serve_stale_if_fetch_error_; 00117 } 00118 00119 void set_default_cache_html(bool x) { default_cache_html_ = x; } 00120 bool default_cache_html() const { return default_cache_html_; } 00121 00122 private: 00124 HTTPCache* http_cache_; 00125 UrlAsyncFetcher* fetcher_; 00126 00127 Histogram* backend_first_byte_latency_; 00128 Variable* fallback_responses_served_; 00129 Variable* num_conditional_refreshes_; 00130 00131 bool respect_vary_; 00132 bool ignore_recent_fetch_failed_; 00133 bool serve_stale_if_fetch_error_; 00134 bool default_cache_html_; 00135 00136 DISALLOW_COPY_AND_ASSIGN(CacheUrlAsyncFetcher); 00137 }; 00138 00139 } 00140 00141 #endif ///< NET_INSTAWEB_HTTP_PUBLIC_CACHE_URL_ASYNC_FETCHER_H_