Page Speed Optimization Libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Friends | List of all members
net_instaweb::ProxyFetchPropertyCallbackCollector Class Reference

#include "proxy_fetch.h"

Public Member Functions

 ProxyFetchPropertyCallbackCollector (ServerContext *server_context, const StringPiece &url, const RequestContextPtr &req_ctx, const RewriteOptions *options, UserAgentMatcher::DeviceType device_type)
void AddCallback (ProxyFetchPropertyCallback *callback)
void RequestHeadersComplete ()
void ConnectProxyFetch (ProxyFetch *proxy_fetch)
void Detach (HttpStatus::Code status_code)
PropertyPageproperty_page ()
 Returns the actual property page.
FallbackPropertyPagefallback_property_page ()
 Returns the fallback property page.
PropertyPageReleasePropertyPage (ProxyFetchPropertyCallback::PageType page_type)
FallbackPropertyPageReleaseFallbackPropertyPage ()
 Releases the ownership of fallback property page.
PropertyPageReleaseOriginPropertyPage ()
 Releases the ownership of origin property page.
void AddPostLookupTask (Function *func)
bool IsCacheValid (int64 write_timestamp_ms) const
void Done (ProxyFetchPropertyCallback *callback)
 Called by a ProxyFetchPropertyCallback when the former is complete.
const RequestContextPtrrequest_context ()
UserAgentMatcher::DeviceType device_type ()
 Returns DeviceType from device property page.


class ProxyFetchPropertyCallbackCollectorTest

Detailed Description

Tracks a collection of property-cache lookups occurring in parallel. Sequence is used to execute various functions in an orderly fashion to avoid any kind of race between Done(), ConnectProxyFetch(), Detach() and AddPostLookupTask(). When any function is called, it is added to the sequence and added function will be executed immediately if sequence is free, otherwise it will wait for its turn.

Order of events: InitiatePropertyCacheLookup–>AddPostLookupTask–>Initiate Html Fetch | (Added to Sequence) | | Fetch Done Lookup Done() | (Added to Sequence) ----------------— is html | !html | ConnectProxyFetch() Detach() (Added to Sequence)

This will also wait for RequestHeadersComplete() to be called before invoking any post-completion callbacks (but not before canceling them due to Detach).

Member Function Documentation

void net_instaweb::ProxyFetchPropertyCallbackCollector::AddCallback ( ProxyFetchPropertyCallback callback)

Add a callback to be handled by this collector. Transfers ownership of the callback to the collector.

void net_instaweb::ProxyFetchPropertyCallbackCollector::AddPostLookupTask ( Function func)

In our flow, property-page will be available via RewriteDriver only after ProxyFetch is set. But there may be instances where the result may be required even before proxy-fetch is created. Any task that depends on the PropertyCache result will be executed as soon as PropertyCache lookup is done and RequestHeadersComplete() has been called.

func is guaranteed to execute after PropertyCache lookup has completed, as long as ProxyFetch is not set before PropertyCache lookup is done. One should use PropertyCache result via RewriteDriver if some other thread can initiate SetProxyFetch().

void net_instaweb::ProxyFetchPropertyCallbackCollector::ConnectProxyFetch ( ProxyFetch proxy_fetch)

In our flow, we initiate the property-cache lookup prior to creating a proxy-fetch, so that RewriteOptions lookup can proceed in parallel. If/when we determine that ProxyFetch is associated with HTML content, we connect it to this callback. Note that if the property cache lookups have completed, this will result in a direct call into proxy_fetch->PropertyCacheComplete.

void net_instaweb::ProxyFetchPropertyCallbackCollector::Detach ( HttpStatus::Code  status_code)

If for any reason we decide not to initiate a ProxyFetch for a request, then we need to 'detach' this request so that we can delete it once it completes, rather than waiting for a ProxyFetch to be inserted. The status code of the response is passed from ProxyFetch to the Collector. In case the status code is unknown then pass RewriteDriver::kStatusCodeUnknown.

bool net_instaweb::ProxyFetchPropertyCallbackCollector::IsCacheValid ( int64  write_timestamp_ms) const

If options_ is NULL returns true. Else, returns true if (url_, write_timestamp_ms) is valid as per URL cache invalidation entries is options_.

PropertyPage* net_instaweb::ProxyFetchPropertyCallbackCollector::ReleasePropertyPage ( ProxyFetchPropertyCallback::PageType  page_type)

Returns the collected PropertyPage with the corresponding page_type. Ownership of the object is transferred to the caller.

void net_instaweb::ProxyFetchPropertyCallbackCollector::RequestHeadersComplete ( )

Must be called once request headers have been resolved from configuration, Gates successful post-lookup callback invocation.

The documentation for this class was generated from the following file: