Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cache_url_async_fetcher.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #ifndef NET_INSTAWEB_HTTP_PUBLIC_CACHE_URL_ASYNC_FETCHER_H_
20 #define NET_INSTAWEB_HTTP_PUBLIC_CACHE_URL_ASYNC_FETCHER_H_
21 
22 #include "base/logging.h"
26 
27 namespace net_instaweb {
28 
29 class AsyncFetch;
30 class Hasher;
31 class Histogram;
32 class HTTPCache;
33 class MessageHandler;
34 class NamedLockManager;
35 class Sequence;
36 class Variable;
37 
62  public:
65  class AsyncOpHooks {
66  public:
67  AsyncOpHooks() {}
68  virtual ~AsyncOpHooks();
69 
71  virtual void StartAsyncOp() = 0;
73  virtual void FinishAsyncOp() = 0;
74  };
75 
77  CacheUrlAsyncFetcher(const Hasher* lock_hasher,
78  NamedLockManager* lock_manager,
79  HTTPCache* cache,
80  const GoogleString& fragment,
81  AsyncOpHooks* async_op_hooks,
82  UrlAsyncFetcher* fetcher);
83  virtual ~CacheUrlAsyncFetcher();
84 
85  virtual bool SupportsHttps() const { return fetcher_->SupportsHttps(); }
86 
87  virtual void Fetch(const GoogleString& url,
88  MessageHandler* message_handler,
89  AsyncFetch* base_fetch);
90 
93  static const int kNotInCacheStatus;
94 
95  HTTPCache* http_cache() const { return http_cache_; }
96  UrlAsyncFetcher* fetcher() const { return fetcher_; }
97 
98  void set_backend_first_byte_latency_histogram(Histogram* x) {
99  backend_first_byte_latency_ = x;
100  }
101 
102  Histogram* backend_first_byte_latency_histogram() const {
103  return backend_first_byte_latency_;
104  }
105 
106  void set_fallback_responses_served(Variable* x) {
107  fallback_responses_served_ = x;
108  }
109 
110  Variable* fallback_responses_served() const {
111  return fallback_responses_served_;
112  }
113 
114  void set_fallback_responses_served_while_revalidate(Variable* x) {
115  fallback_responses_served_while_revalidate_ = x;
116  }
117 
118  Variable* fallback_responses_served_while_revalidate() const {
119  return fallback_responses_served_while_revalidate_;
120  }
121 
122  void set_num_conditional_refreshes(Variable* x) {
123  num_conditional_refreshes_ = x;
124  }
125 
126  Variable* num_conditional_refreshes() const {
127  return num_conditional_refreshes_;
128  }
129 
130  void set_num_proactively_freshen_user_facing_request(Variable* x) {
131  num_proactively_freshen_user_facing_request_ = x;
132  }
133 
134  Variable* num_proactively_freshen_user_facing_request() const {
135  return num_proactively_freshen_user_facing_request_;
136  }
137 
138  void set_respect_vary(bool x) { respect_vary_ = x; }
139  bool respect_vary() const { return respect_vary_; }
140 
141  void set_ignore_recent_fetch_failed(bool x) {
142  ignore_recent_fetch_failed_ = x;
143  }
144  bool ignore_recent_fetch_failed() const {
145  return ignore_recent_fetch_failed_;
146  }
147 
148  void set_serve_stale_if_fetch_error(bool x) {
149  serve_stale_if_fetch_error_ = x;
150  }
151 
152  bool serve_stale_if_fetch_error() const {
153  return serve_stale_if_fetch_error_;
154  }
155 
156  void set_serve_stale_while_revalidate_threshold_sec(int64 x) {
157  serve_stale_while_revalidate_threshold_sec_ = x;
158  }
159 
160  int64 serve_stale_while_revalidate_threshold_sec() const {
161  return serve_stale_while_revalidate_threshold_sec_;
162  }
163 
164  void set_default_cache_html(bool x) { default_cache_html_ = x; }
165  bool default_cache_html() const { return default_cache_html_; }
166 
167  void set_proactively_freshen_user_facing_request(bool x) {
168  proactively_freshen_user_facing_request_ = x;
169  }
170  bool proactively_freshen_user_facing_request() const {
171  return proactively_freshen_user_facing_request_;
172  }
173 
174  void set_own_fetcher(bool x) { own_fetcher_ = x; }
175 
189  CHECK(fetcher_ == NULL);
190  response_sequence_ = x;
191  }
192 
193  private:
195  const Hasher* lock_hasher_;
196  NamedLockManager* lock_manager_;
197  HTTPCache* http_cache_;
198  GoogleString fragment_;
199  UrlAsyncFetcher* fetcher_;
200  AsyncOpHooks* async_op_hooks_;
201 
202  Histogram* backend_first_byte_latency_;
203  Variable* fallback_responses_served_;
204  Variable* fallback_responses_served_while_revalidate_;
205  Variable* num_conditional_refreshes_;
206  Variable* num_proactively_freshen_user_facing_request_;
207 
208  bool respect_vary_;
209  bool ignore_recent_fetch_failed_;
210  bool serve_stale_if_fetch_error_;
211  bool default_cache_html_;
212  bool proactively_freshen_user_facing_request_;
213  bool own_fetcher_;
214  int64 serve_stale_while_revalidate_threshold_sec_;
215  Sequence* response_sequence_;
216 
217 
218 };
219 
220 }
221 
222 #endif
Definition: statistics.h:43
virtual void FinishAsyncOp()=0
Called when async operation is ended.
Definition: named_lock_manager.h:82
Definition: sequence.h:33
virtual void StartAsyncOp()=0
Called when CacheUrlAsyncFetcher is about to start async operation.
virtual bool SupportsHttps() const
Definition: cache_url_async_fetcher.h:85
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
CacheUrlAsyncFetcher(const Hasher *lock_hasher, NamedLockManager *lock_manager, HTTPCache *cache, const GoogleString &fragment, AsyncOpHooks *async_op_hooks, UrlAsyncFetcher *fetcher)
None of these are owned by CacheUrlAsyncFetcher.
Definition: async_fetch.h:53
Definition: cache_url_async_fetcher.h:61
Definition: cache_url_async_fetcher.h:65
Definition: statistics.h:138
Definition: message_handler.h:39
void set_response_sequence(Sequence *x)
Definition: cache_url_async_fetcher.h:188
virtual void Fetch(const GoogleString &url, MessageHandler *message_handler, AsyncFetch *base_fetch)
virtual bool SupportsHttps() const
Definition: url_async_fetcher.h:54
Definition: hasher.h:30
Definition: url_async_fetcher.h:33
static const int kNotInCacheStatus
Definition: cache_url_async_fetcher.h:93
Definition: http_cache.h:67