23 #ifndef NET_INSTAWEB_AUTOMATIC_PUBLIC_PROXY_FETCH_H_
24 #define NET_INSTAWEB_AUTOMATIC_PUBLIC_PROXY_FETCH_H_
32 #include "net/instaweb/http/public/meta_data.h"
34 #include "net/instaweb/http/public/user_agent_matcher.h"
35 #include "net/instaweb/util/public/queued_worker_pool.h"
38 #include "net/instaweb/util/public/gtest_prod.h"
44 namespace net_instaweb {
47 class CacheUrlAsyncFetcher;
52 class ProxyFetchPropertyCallbackCollector;
55 class ResponseHeaders;
70 const GoogleString& url,
86 const GoogleString& url,
95 bool is_resource_fetch,
96 const GoogleUrl& request_url,
100 const bool requires_blink_cohort,
101 bool* added_page_property_callback);
103 MessageHandler* message_handler()
const {
return handler_; }
112 void RegisterNewFetch(
ProxyFetch* proxy_fetch);
113 void RegisterFinishedFetch(
ProxyFetch* proxy_fetch);
117 MessageHandler* handler_;
119 scoped_ptr<AbstractMutex> outstanding_proxy_fetches_mutex_;
120 std::set<ProxyFetch*> outstanding_proxy_fetches_;
137 const StringPiece& url,
138 const StringPiece& options_signature_hash,
139 UserAgentMatcher::DeviceType device_type,
141 AbstractMutex* mutex);
143 PageType page_type()
const {
return page_type_; }
146 virtual bool IsCacheValid(int64 write_timestamp_ms)
const;
148 virtual void Done(
bool success);
152 UserAgentMatcher::DeviceType device_type_;
181 const StringPiece& url,
182 const RequestContextPtr& req_ctx,
209 void Detach(HttpStatus::Code status_code);
213 return fallback_property_page_ == NULL ?
214 NULL : fallback_property_page_->actual_property_page();
219 return fallback_property_page_.get();
229 return fallback_property_page_.release();
252 const RequestContextPtr& request_context() {
return request_context_; }
255 UserAgentMatcher::DeviceType
device_type() {
return device_type_; }
258 friend class ProxyFetchPropertyCallbackCollectorTest;
260 void ExecuteAddPostLookupTask(Function* func);
261 void ExecuteConnectProxyFetch(
ProxyFetch* proxy_fetch);
262 void ExecuteDetach(HttpStatus::Code status_code);
263 void ExecuteRequestHeadersComplete();
265 void RunPostLookupsAndCleanupIfSafe();
268 void UpdateStatusCodeInPropertyCache();
270 std::set<ProxyFetchPropertyCallback*> pending_callbacks_;
271 std::map<ProxyFetchPropertyCallback::PageType, PropertyPage*>
273 scoped_ptr<AbstractMutex> mutex_;
275 QueuedWorkerPool::Sequence*
const sequence_;
276 const GoogleString url_;
277 const RequestContextPtr request_context_;
278 const UserAgentMatcher::DeviceType device_type_;
279 bool is_options_valid_;
284 bool request_headers_ok_;
286 std::vector<Function*> post_lookup_task_vector_;
288 HttpStatus::Code status_code_;
289 scoped_ptr<FallbackPropertyPage> fallback_property_page_;
319 static const char kCollectorDetachFinish[];
320 static const char kCollectorDoneFinish[];
321 static const char kCollectorFinish[];
322 static const char kCollectorDetachStart[];
323 static const char kCollectorRequestHeadersCompleteFinish[];
328 static const char kHeadersSetupRaceDone[];
329 static const char kHeadersSetupRaceFlush[];
330 static const char kHeadersSetupRacePrefix[];
331 static const char kHeadersSetupRaceWait[];
344 virtual bool HandleWrite(
const StringPiece& content, MessageHandler* handler);
345 virtual bool HandleFlush(MessageHandler* handler);
346 virtual void HandleDone(
bool success);
352 friend class MockProxyFetch;
353 FRIEND_TEST(ProxyFetchTest, TestInhibitParsing);
357 virtual void PropertyCacheComplete(
379 void AddPagespeedHeader();
391 void DoFetch(
bool prepare_success);
395 void ExecuteQueued();
399 void ScheduleQueueExecutionIfNeeded();
405 void Finish(
bool success);
408 void CompleteFinishParse(
bool success);
418 void CancelIdleAlarm();
421 void QueueIdleAlarm();
424 void HandleIdleAlarm();
430 scoped_ptr<CacheUrlAsyncFetcher> cache_fetcher_;
444 bool parse_text_called_;
468 bool queue_run_job_created_;
481 scoped_ptr<AbstractMutex> mutex_;
482 StringStarVector text_queue_;
483 bool network_flush_outstanding_;
484 QueuedWorkerPool::Sequence* sequence_;
488 bool done_outstanding_;
501 bool waiting_for_flush_to_finish_;
505 QueuedAlarm* idle_alarm_;
510 bool distributed_fetch_;
static ProxyFetchPropertyCallbackCollector * InitiatePropertyCacheLookup(bool is_resource_fetch, const GoogleUrl &request_url, ServerContext *server_context, RewriteOptions *options, AsyncFetch *async_fetch, const bool requires_blink_cohort, bool *added_page_property_callback)
void RequestHeadersComplete()
Definition: html_detector.h:54
Definition: proxy_fetch.h:314
static const int kTestSignalTimeoutMs
Definition: proxy_fetch.h:339
void AddCallback(ProxyFetchPropertyCallback *callback)
UserAgentMatcher::DeviceType device_type()
Returns DeviceType from device property page.
Definition: proxy_fetch.h:255
Adds property-semantics to a raw cache API.
Definition: property_cache.h:180
FallbackPropertyPage * fallback_property_page()
Returns the fallback property page.
Definition: proxy_fetch.h:218
static const char kCollectorConnectProxyFetchFinish[]
Definition: proxy_fetch.h:318
virtual bool IsCacheValid(int64 write_timestamp_ms) const
Delegates to collector_'s IsCacheValid.
void Detach(HttpStatus::Code status_code)
void AddPostLookupTask(Function *func)
static const char kHeadersSetupRaceAlarmQueued[]
Definition: proxy_fetch.h:327
virtual void HandleHeadersComplete()
protected interface from AsyncFetch.
Definition: property_cache.h:323
virtual void Done(bool success)
Called as a result of PropertyCache::Read when the data is available.
Definition: proxy_fetch.h:133
void ConnectProxyFetch(ProxyFetch *proxy_fetch)
PageType
The cache type associated with this callback.
Definition: property_cache.h:326
Definition: async_fetch.h:267
FallbackPropertyPage * ReleaseFallbackPropertyPage()
Releases the ownership of fallback property page.
Definition: proxy_fetch.h:228
Definition: proxy_fetch.h:178
Definition: async_fetch.h:53
PropertyPage * ReleasePropertyPage(ProxyFetchPropertyCallback::PageType page_type)
bool IsCacheValid(int64 write_timestamp_ms) const
Definition: rewrite_driver.h:98
Definition: server_context.h:100
PropertyPage * property_page()
Returns the actual property page.
Definition: proxy_fetch.h:212
ProxyFetch * CreateNewProxyFetch(const GoogleString &url, AsyncFetch *async_fetch, RewriteDriver *driver, ProxyFetchPropertyCallbackCollector *property_callback, AsyncFetch *original_content_fetch)
Definition: proxy_fetch.h:62
virtual bool IsCachedResultValid(const ResponseHeaders &headers)
Definition: rewrite_options.h:81
void Done(ProxyFetchPropertyCallback *callback)
Called by a ProxyFetchPropertyCallback when the former is complete.
Definition: fallback_property_page.h:38
void StartNewProxyFetch(const GoogleString &url, AsyncFetch *async_fetch, RewriteDriver *driver, ProxyFetchPropertyCallbackCollector *property_callback, AsyncFetch *original_content_fetch)