00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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 respect_vary_(false),
00054 ignore_recent_fetch_failed_(false),
00055 serve_stale_if_fetch_error_(false),
00056 default_cache_html_(false) {
00057 }
00058 virtual ~CacheUrlAsyncFetcher();
00059
00060 virtual bool SupportsHttps() const { return fetcher_->SupportsHttps(); }
00061
00062 virtual bool Fetch(const GoogleString& url,
00063 MessageHandler* message_handler,
00064 AsyncFetch* base_fetch);
00065
00066 HTTPCache* http_cache() const { return http_cache_; }
00067 UrlAsyncFetcher* fetcher() const { return fetcher_; }
00068
00069 void set_backend_first_byte_latency_histogram(Histogram* x) {
00070 backend_first_byte_latency_ = x;
00071 }
00072
00073 Histogram* backend_first_byte_latency_histogram() const {
00074 return backend_first_byte_latency_;
00075 }
00076
00077 void set_fallback_responses_served(Variable* x) {
00078 fallback_responses_served_ = x;
00079 }
00080
00081 Variable* fallback_responses_served() const {
00082 return fallback_responses_served_;
00083 }
00084
00085 void set_num_conditional_refreshes(Variable* x) {
00086 num_conditional_refreshes_ = x;
00087 }
00088
00089 Variable* num_conditional_refreshes() const {
00090 return num_conditional_refreshes_;
00091 }
00092
00093 void set_respect_vary(bool x) { respect_vary_ = x; }
00094 bool respect_vary() const { return respect_vary_; }
00095
00096 void set_ignore_recent_fetch_failed(bool x) {
00097 ignore_recent_fetch_failed_ = x;
00098 }
00099 bool ignore_recent_fetch_failed() const {
00100 return ignore_recent_fetch_failed_;
00101 }
00102
00103 void set_serve_stale_if_fetch_error(bool x) {
00104 serve_stale_if_fetch_error_ = x;
00105 }
00106
00107 bool serve_stale_if_fetch_error() const {
00108 return serve_stale_if_fetch_error_;
00109 }
00110
00111 void set_default_cache_html(bool x) { default_cache_html_ = x; }
00112 bool default_cache_html() const { return default_cache_html_; }
00113
00114 private:
00116 HTTPCache* http_cache_;
00117 UrlAsyncFetcher* fetcher_;
00118
00119 Histogram* backend_first_byte_latency_;
00120 Variable* fallback_responses_served_;
00121 Variable* num_conditional_refreshes_;
00122
00123 bool respect_vary_;
00124 bool ignore_recent_fetch_failed_;
00125 bool serve_stale_if_fetch_error_;
00126 bool default_cache_html_;
00127
00128 DISALLOW_COPY_AND_ASSIGN(CacheUrlAsyncFetcher);
00129 };
00130
00131 }
00132
00133 #endif ///< NET_INSTAWEB_HTTP_PUBLIC_CACHE_URL_ASYNC_FETCHER_H_