Page Speed Optimization Libraries
1.8.31.3
|
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 Hasher; 00030 class Histogram; 00031 class HTTPCache; 00032 class MessageHandler; 00033 class NamedLockManager; 00034 class Variable; 00035 00057 class CacheUrlAsyncFetcher : public UrlAsyncFetcher { 00058 public: 00061 class AsyncOpHooks { 00062 public: 00063 AsyncOpHooks() {} 00064 virtual ~AsyncOpHooks(); 00065 00067 virtual void StartAsyncOp() = 0; 00069 virtual void FinishAsyncOp() = 0; 00070 }; 00071 00073 CacheUrlAsyncFetcher(const Hasher* lock_hasher, 00074 NamedLockManager* lock_manager, 00075 HTTPCache* cache, 00076 const GoogleString& fragment, 00077 AsyncOpHooks* async_op_hooks, 00078 UrlAsyncFetcher* fetcher) 00079 : lock_hasher_(lock_hasher), 00080 lock_manager_(lock_manager), 00081 http_cache_(cache), 00082 fragment_(fragment), 00083 fetcher_(fetcher), 00084 async_op_hooks_(async_op_hooks), 00085 backend_first_byte_latency_(NULL), 00086 fallback_responses_served_(NULL), 00087 fallback_responses_served_while_revalidate_(NULL), 00088 num_conditional_refreshes_(NULL), 00089 num_proactively_freshen_user_facing_request_(NULL), 00090 respect_vary_(false), 00091 ignore_recent_fetch_failed_(false), 00092 serve_stale_if_fetch_error_(false), 00093 default_cache_html_(false), 00094 proactively_freshen_user_facing_request_(false), 00095 serve_stale_while_revalidate_threshold_sec_(0) { 00096 } 00097 virtual ~CacheUrlAsyncFetcher(); 00098 00099 virtual bool SupportsHttps() const { return fetcher_->SupportsHttps(); } 00100 00101 virtual void Fetch(const GoogleString& url, 00102 MessageHandler* message_handler, 00103 AsyncFetch* base_fetch); 00104 00107 static const int kNotInCacheStatus; 00108 00109 HTTPCache* http_cache() const { return http_cache_; } 00110 UrlAsyncFetcher* fetcher() const { return fetcher_; } 00111 00112 void set_backend_first_byte_latency_histogram(Histogram* x) { 00113 backend_first_byte_latency_ = x; 00114 } 00115 00116 Histogram* backend_first_byte_latency_histogram() const { 00117 return backend_first_byte_latency_; 00118 } 00119 00120 void set_fallback_responses_served(Variable* x) { 00121 fallback_responses_served_ = x; 00122 } 00123 00124 Variable* fallback_responses_served() const { 00125 return fallback_responses_served_; 00126 } 00127 00128 void set_fallback_responses_served_while_revalidate(Variable* x) { 00129 fallback_responses_served_while_revalidate_ = x; 00130 } 00131 00132 Variable* fallback_responses_served_while_revalidate() const { 00133 return fallback_responses_served_while_revalidate_; 00134 } 00135 00136 void set_num_conditional_refreshes(Variable* x) { 00137 num_conditional_refreshes_ = x; 00138 } 00139 00140 Variable* num_conditional_refreshes() const { 00141 return num_conditional_refreshes_; 00142 } 00143 00144 void set_num_proactively_freshen_user_facing_request(Variable* x) { 00145 num_proactively_freshen_user_facing_request_ = x; 00146 } 00147 00148 Variable* num_proactively_freshen_user_facing_request() const { 00149 return num_proactively_freshen_user_facing_request_; 00150 } 00151 00152 void set_respect_vary(bool x) { respect_vary_ = x; } 00153 bool respect_vary() const { return respect_vary_; } 00154 00155 void set_ignore_recent_fetch_failed(bool x) { 00156 ignore_recent_fetch_failed_ = x; 00157 } 00158 bool ignore_recent_fetch_failed() const { 00159 return ignore_recent_fetch_failed_; 00160 } 00161 00162 void set_serve_stale_if_fetch_error(bool x) { 00163 serve_stale_if_fetch_error_ = x; 00164 } 00165 00166 bool serve_stale_if_fetch_error() const { 00167 return serve_stale_if_fetch_error_; 00168 } 00169 00170 void set_serve_stale_while_revalidate_threshold_sec(int64 x) { 00171 serve_stale_while_revalidate_threshold_sec_ = x; 00172 } 00173 00174 int64 serve_stale_while_revalidate_threshold_sec() const { 00175 return serve_stale_while_revalidate_threshold_sec_; 00176 } 00177 00178 void set_default_cache_html(bool x) { default_cache_html_ = x; } 00179 bool default_cache_html() const { return default_cache_html_; } 00180 00181 void set_proactively_freshen_user_facing_request(bool x) { 00182 proactively_freshen_user_facing_request_ = x; 00183 } 00184 bool proactively_freshen_user_facing_request() const { 00185 return proactively_freshen_user_facing_request_; 00186 } 00187 00188 private: 00190 const Hasher* lock_hasher_; 00191 NamedLockManager* lock_manager_; 00192 HTTPCache* http_cache_; 00193 GoogleString fragment_; 00194 UrlAsyncFetcher* fetcher_; 00195 AsyncOpHooks* async_op_hooks_; 00196 00197 Histogram* backend_first_byte_latency_; 00198 Variable* fallback_responses_served_; 00199 Variable* fallback_responses_served_while_revalidate_; 00200 Variable* num_conditional_refreshes_; 00201 Variable* num_proactively_freshen_user_facing_request_; 00202 00203 bool respect_vary_; 00204 bool ignore_recent_fetch_failed_; 00205 bool serve_stale_if_fetch_error_; 00206 bool default_cache_html_; 00207 bool proactively_freshen_user_facing_request_; 00208 int64 serve_stale_while_revalidate_threshold_sec_; 00209 00210 DISALLOW_COPY_AND_ASSIGN(CacheUrlAsyncFetcher); 00211 }; 00212 00213 } 00214 00215 #endif ///< NET_INSTAWEB_HTTP_PUBLIC_CACHE_URL_ASYNC_FETCHER_H_