23 #ifndef PAGESPEED_AUTOMATIC_PROXY_FETCH_H_
24 #define PAGESPEED_AUTOMATIC_PROXY_FETCH_H_
31 #include "net/instaweb/http/public/request_context.h"
32 #include "net/instaweb/util/public/fallback_property_page.h"
33 #include "net/instaweb/util/public/property_cache.h"
44 #include "pagespeed/kernel/http/user_agent_matcher.h"
47 namespace net_instaweb {
49 class CacheUrlAsyncFetcher;
53 class ProxyFetchPropertyCallbackCollector;
95 bool is_resource_fetch,
110 void RegisterNewFetch(
ProxyFetch* proxy_fetch);
111 void RegisterFinishedFetch(
ProxyFetch* proxy_fetch);
118 std::set<ProxyFetch*> outstanding_proxy_fetches_;
135 const StringPiece& url,
136 const StringPiece& options_signature_hash,
141 PageType page_type()
const {
return page_type_; }
144 virtual bool IsCacheValid(int64 write_timestamp_ms)
const;
146 virtual void Done(
bool success);
179 const StringPiece& url,
207 void Detach(HttpStatus::Code status_code);
211 return fallback_property_page_ == NULL ?
212 NULL : fallback_property_page_->actual_property_page();
217 return fallback_property_page_.get();
227 return fallback_property_page_.release();
232 return origin_property_page_.release();
261 friend class ProxyFetchPropertyCallbackCollectorTest;
263 void ExecuteAddPostLookupTask(
Function* func);
264 void ExecuteConnectProxyFetch(
ProxyFetch* proxy_fetch);
265 void ExecuteDetach(HttpStatus::Code status_code);
266 void ExecuteRequestHeadersComplete();
268 void RunPostLookupsAndCleanupIfSafe();
271 void UpdateStatusCodeInPropertyCache();
273 std::set<ProxyFetchPropertyCallback*> pending_callbacks_;
274 std::map<ProxyFetchPropertyCallback::PageType, PropertyPage*>
282 bool is_options_valid_;
287 bool request_headers_ok_;
289 std::vector<Function*> post_lookup_task_vector_;
291 HttpStatus::Code status_code_;
323 static const char kCollectorDetachFinish[];
324 static const char kCollectorDoneFinish[];
325 static const char kCollectorFinish[];
326 static const char kCollectorDetachStart[];
327 static const char kCollectorRequestHeadersCompleteFinish[];
332 static const char kHeadersSetupRaceDone[];
333 static const char kHeadersSetupRaceFlush[];
334 static const char kHeadersSetupRacePrefix[];
335 static const char kHeadersSetupRaceWait[];
345 void set_trusted_input(
bool trusted_input) { trusted_input_ = trusted_input; }
350 virtual bool HandleWrite(
const StringPiece& content,
MessageHandler* handler);
352 virtual void HandleDone(
bool success);
358 friend class MockProxyFetch;
359 FRIEND_TEST(ProxyFetchTest, TestInhibitParsing);
360 FRIEND_TEST(ProxyFetchTest, TestFollowFlushes);
364 virtual void PropertyCacheComplete(
386 void AddPagespeedHeader();
398 void DoFetch(
bool prepare_success);
402 void ExecuteQueued();
406 void ScheduleQueueExecutionIfNeeded();
412 void Finish(
bool success);
415 void CompleteFinishParse(
bool success);
425 void CancelIdleAlarm();
428 void QueueIdleAlarm();
431 void HandleIdleAlarm();
451 bool parse_text_called_;
475 bool queue_run_job_created_;
489 StringStarVector text_queue_;
490 bool network_flush_outstanding_;
495 bool done_outstanding_;
508 bool waiting_for_flush_to_finish_;
class GoogleUrl
Definition: google_url.h:58
void RequestHeadersComplete()
Definition: html_detector.h:54
Definition: proxy_fetch.h:318
static const int kTestSignalTimeoutMs
Definition: proxy_fetch.h:343
void AddCallback(ProxyFetchPropertyCallback *callback)
UserAgentMatcher::DeviceType device_type()
Returns DeviceType from device property page.
Definition: proxy_fetch.h:258
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:216
static const char kCollectorConnectProxyFetchFinish[]
Definition: proxy_fetch.h:322
virtual bool IsCacheValid(int64 write_timestamp_ms) const
Delegates to collector_'s IsCacheValid.
void Detach(HttpStatus::Code status_code)
void AddPostLookupTask(Function *func)
Abstract interface for implementing a mutex.
Definition: abstract_mutex.h:28
static const char kHeadersSetupRaceAlarmQueued[]
Definition: proxy_fetch.h:331
virtual void HandleHeadersComplete()
protected interface from AsyncFetch.
Definition: queued_alarm.h:32
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:131
Definition: scoped_ptr.h:30
Definition: function.h:47
void ConnectProxyFetch(ProxyFetch *proxy_fetch)
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
PageType
The cache type associated with this callback.
Definition: property_cache.h:326
static ProxyFetchPropertyCallbackCollector * InitiatePropertyCacheLookup(bool is_resource_fetch, const GoogleUrl &request_url, ServerContext *server_context, RewriteOptions *options, AsyncFetch *async_fetch)
Definition: async_fetch.h:278
FallbackPropertyPage * ReleaseFallbackPropertyPage()
Releases the ownership of fallback property page.
Definition: proxy_fetch.h:226
Definition: queued_worker_pool.h:65
Definition: proxy_fetch.h:176
Definition: async_fetch.h:53
PropertyPage * ReleasePropertyPage(ProxyFetchPropertyCallback::PageType page_type)
bool IsCacheValid(int64 write_timestamp_ms) const
Definition: rewrite_driver.h:100
Definition: server_context.h:99
PropertyPage * property_page()
Returns the actual property page.
Definition: proxy_fetch.h:210
Definition: message_handler.h:39
DeviceType
Definition: user_agent_matcher.h:49
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:84
Timer interface, made virtual so it can be mocked for tests.
Definition: timer.h:27
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)
PropertyPage * ReleaseOriginPropertyPage()
Releases the ownership of origin property page.
Definition: proxy_fetch.h:231