net_instaweb::RewriteDriver Class Reference

#include "rewrite_driver.h"

Inheritance diagram for net_instaweb::RewriteDriver:
net_instaweb::HtmlParse

List of all members.

Public Types

enum  CssResolutionStatus { kWriteFailed, kNoResolutionNeeded, kSuccess }
 

Status return-code for ResolveCssUrls.


enum  WaitMode { kNoWait, kWaitForCompletion, kWaitForCachedRender, kWaitForShutDown }
 

Mode for BoundedWaitForCompletion.

More...
enum  LazyBool { kNotSet = -1, kFalse = 0, kTrue = 1 }
 

Lazily-initialized boolean value.


Public Member Functions

 RewriteDriver (MessageHandler *message_handler, FileSystem *file_system, UrlAsyncFetcher *url_async_fetcher)
virtual ~RewriteDriver ()
RewriteDriverClone ()
 Returns a fresh instance using the same options we do.
void Clear ()
void SetResourceManager (ResourceManager *resource_manager)
bool ShouldNotRewriteImages () const
bool MayCacheExtendCss () const
 Returns true if we may cache extend Css, Images or Scripts respectively.
bool MayCacheExtendImages () const
bool MayCacheExtendScripts () const
void RememberResource (const StringPiece &url, const ResourcePtr &resource)
const GoogleStringuser_agent () const
void set_user_agent (const StringPiece &user_agent_string)
bool using_spdy () const
 Returns true if the request we're rewriting was made using SPDY.
void set_using_spdy (bool x)
ResponseHeadersmutable_response_headers ()
const ResponseHeadersresponse_headers ()
void set_response_headers_ptr (ResponseHeaders *headers)
void set_request_headers (const RequestHeaders *headers)
const RequestHeadersrequest_headers () const
const UserAgentMatcheruser_agent_matcher () const
bool UserAgentSupportsImageInlining () const
bool UserAgentSupportsJsDefer () const
bool UserAgentSupportsWebp () const
bool IsMobileUserAgent () const
void AddFilters ()
void AddOwnedEarlyPreRenderFilter (HtmlFilter *filter)
void PrependOwnedPreRenderFilter (HtmlFilter *filter)
 Adds a filter to the beginning of the pre-render chain, taking ownership.
void AppendOwnedPreRenderFilter (HtmlFilter *filter)
 Adds a filter to the end of the pre-render chain, taking ownership.
void AddOwnedPostRenderFilter (HtmlFilter *filter)
 Adds a filter to the end of the post-render chain, taking ownership.
void AddUnownedPostRenderFilter (HtmlFilter *filter)
 Same, without taking ownership.
void AppendRewriteFilter (RewriteFilter *filter)
void PrependRewriteFilter (RewriteFilter *filter)
void SetWriter (Writer *writer)
Writerwriter () const
bool FetchResource (const StringPiece &url, AsyncFetch *fetch)
bool FetchOutputResource (const OutputResourcePtr &output_resource, RewriteFilter *filter, AsyncFetch *async_fetch)
OutputResourcePtr DecodeOutputResource (const GoogleUrl &url, RewriteFilter **filter) const
bool DecodeOutputResourceName (const GoogleUrl &url, ResourceNamer *name_out, OutputResourceKind *kind_out, RewriteFilter **filter_out) const
bool DecodeUrl (const GoogleUrl &url, StringVector *decoded_urls) const
 Decodes the incoming pagespeed url to original url(s).
FileSystemfile_system ()
UrlAsyncFetcherasync_fetcher ()
void SetSessionFetcher (UrlAsyncFetcher *f)
CacheUrlAsyncFetcherCreateCacheFetcher ()
ResourceManagerresource_manager () const
Statisticsstatistics () const
AddInstrumentationFilteradd_instrumentation_filter ()
void set_custom_options (RewriteOptions *options)
 Takes ownership of 'options'.
void set_options (bool is_custom, RewriteOptions *options)
 Takes ownership of 'options'.
bool has_custom_options () const
 Determines whether this RewriteDriver was built with custom options.
const RewriteOptionsoptions () const
 Return the options used for this RewriteDriver.
virtual bool StartParseId (const StringPiece &url, const StringPiece &id, const ContentType &content_type)
 Override HtmlParse's StartParseId to propagate any required options.
virtual void FinishParse ()
void FinishParseAsync (Function *callback)
void InhibitEndElement (const HtmlElement *element)
void UninhibitEndElement (const HtmlElement *element)
bool EndElementIsInhibited (const HtmlElement *element)
 Returns true if the EndElementEvent for element is inhibited from flushing.
bool EndElementIsStoppingFlush (const HtmlElement *element)
void InfoAt (const RewriteContext *context, const char *msg,...) INSTAWEB_PRINTF_FORMAT(3
void OutputResourcePtr CreateOutputResourceFromResource (const StringPiece &filter_prefix, const UrlSegmentEncoder *encoder, const ResourceContext *data, const ResourcePtr &input_resource, OutputResourceKind kind)
OutputResourcePtr CreateOutputResourceWithPath (const StringPiece &mapped_path, const StringPiece &unmapped_path, const StringPiece &base_url, const StringPiece &filter_id, const StringPiece &name, OutputResourceKind kind)
OutputResourcePtr CreateOutputResourceWithUnmappedPath (const StringPiece &path, const StringPiece &filter_id, const StringPiece &name, OutputResourceKind kind)
OutputResourcePtr CreateOutputResourceWithMappedPath (const StringPiece &mapped_path, const StringPiece &unmapped_path, const StringPiece &filter_id, const StringPiece &name, OutputResourceKind kind)
OutputResourcePtr CreateOutputResourceWithPath (const StringPiece &path, const StringPiece &filter_id, const StringPiece &name, OutputResourceKind kind)
ResourcePtr CreateInputResource (const GoogleUrl &input_url)
ResourcePtr CreateInputResourceAbsoluteUnchecked (const StringPiece &absolute_url)
bool MayRewriteUrl (const GoogleUrl &domain_url, const GoogleUrl &input_url) const
void ReadAsync (Resource::AsyncCallback *callback, MessageHandler *message_handler)
const GoogleUrlbase_url () const
const GoogleUrldecoded_base_url () const
StringPiece decoded_base () const
bool IsHttps () const
 Quick way to tell if the document url is https (ie was fetched via https).
const UrlSegmentEncoderdefault_encoder () const
RewriteFilterFindFilter (const StringPiece &id) const
 Finds a filter with the given ID, or returns NULL if none found.
bool refs_before_base ()
 Returns refs_before_base.
void set_refs_before_base ()
StringPiece containing_charset ()
void set_containing_charset (const StringPiece charset)
HtmlResourceSlotPtr GetSlot (const ResourcePtr &resource, HtmlElement *elt, HtmlElement::Attribute *attr)
 Establishes a HtmlElement slot for rewriting.
void InitiateRewrite (RewriteContext *rewrite_context)
void InitiateFetch (RewriteContext *rewrite_context)
void RewriteComplete (RewriteContext *rewrite_context)
void ReportSlowRewrites (int num)
void Cleanup ()
void WaitForCompletion ()
void WaitForShutDown ()
void BoundedWaitFor (WaitMode mode, int64 timeout_ms)
void set_fully_rewrite_on_flush (bool x)
void set_externally_managed (bool x)
void DetachFetch ()
void DetachedFetchComplete ()
void FetchComplete ()
void DeleteRewriteContext (RewriteContext *rewrite_context)
void set_rewrite_deadline_ms (int x)
int rewrite_deadline_ms ()
RewriteContextRegisterForPartitionKey (const GoogleString &partition_key, RewriteContext *candidate)
void DeregisterForPartitionKey (const GoogleString &partition_key, RewriteContext *candidate)
void RequestFlush ()
bool flush_requested () const
void ExecuteFlushIfRequested ()
void ExecuteFlushIfRequestedAsync (Function *callback)
virtual void Flush ()
void FlushAsync (Function *done)
void AddRewriteTask (Function *task)
 Queues up a task to run on the (high-priority) rewrite thread.
void AddLowPriorityRewriteTask (Function *task)
QueuedWorkerPool::Sequencehtml_worker ()
QueuedWorkerPool::Sequencerewrite_worker ()
QueuedWorkerPool::Sequencelow_priority_rewrite_worker ()
Schedulerscheduler ()
DomainRewriteFilterdomain_rewriter ()
UrlLeftTrimFilterurl_trim_filter ()
CssResolutionStatus ResolveCssUrls (const GoogleUrl &input_css_base, const StringPiece &output_css_base, const StringPiece &contents, Writer *writer, MessageHandler *handler)
bool ShouldAbsolutifyUrl (const GoogleUrl &input_base, const GoogleUrl &output_base, bool *proxy_mode) const
void set_client_state (AbstractClientState *client_state)
AbstractClientStateclient_state () const
void set_client_id (const StringPiece &id)
const GoogleStringclient_id () const
PropertyPageproperty_page () const
void set_property_page (PropertyPage *page)
 Takes ownership of page.
const StringSet * critical_images () const
 Used by ImageRewriteFilter for identifying critical images.
void set_critical_images (StringSet *critical_images)
int num_inline_preview_images () const
void increment_num_inline_preview_images ()
 We expect to this method to be called on the HTML parser thread.
void increment_async_events_count ()
void decrement_async_events_count ()
 Decrements the value of pending_async_events_.
bool need_furious_cookie () const
void set_need_furious_cookie (bool x)

Static Public Member Functions

static void Initialize (Statistics *statistics)
 Calls Initialize on all filters that need it.
static void Terminate ()
 Calls Terminate on all filters that need it.

Static Public Attributes

static const char * kPassThroughRequestAttributes [3]
static const char kDomCohort []

Friends

class ResourceManagerTestBase
class ResourceManagerTest
class ScanFilter

Detailed Description

Todo:
TODO(jmarantz): rename this class to RequestContext. This extends class HtmlParse (which should renamed HtmlContext) by providing context for rewriting resources (css, js, images).

Also note that ResourceManager should be renamed ServerContext, as it no longer contains much logic about resources.


Member Enumeration Documentation

Mode for BoundedWaitForCompletion.

Enumerator:
kNoWait 

Used internally. Do not pass in.

kWaitForCompletion 

wait for everything to complete (up to deadline)

kWaitForCachedRender 

wait for at least cached rewrites to complete, and anything else that finishes within deadline.

kWaitForShutDown 

Makes sure that all work, including any that's being done in background, finishes.


Constructor & Destructor Documentation

virtual net_instaweb::RewriteDriver::~RewriteDriver (  )  [virtual]

Need explicit destructors to allow destruction of scoped_ptr-controlled instances without propagating the include files.


Member Function Documentation

void net_instaweb::RewriteDriver::AddFilters (  ) 

Adds the filters from the options, specified by name in enabled_filters. This must be called explicitly after object construction to provide an opportunity to programatically add custom filters beyond those defined in RewriteOptions, via AddFilter(HtmlFilter* filter) (below).

void net_instaweb::RewriteDriver::AddLowPriorityRewriteTask ( Function task  ) 

Queues up a task to run on the low-priority rewrite thread. Such tasks are expected to be safely cancelable.

void net_instaweb::RewriteDriver::AddOwnedEarlyPreRenderFilter ( HtmlFilter filter  ) 

Adds a filter to the very beginning of the pre-render chain, taking ownership. This should only be used for filters that must run before any filter added via PrependOwnedPreRenderFilter.

void net_instaweb::RewriteDriver::AppendRewriteFilter ( RewriteFilter filter  ) 

Add a RewriteFilter to the end of the pre-render chain and take ownership of the filter. This differs from AppendOwnedPreRenderFilter in that it adds the filter's ID into a dispatch table for serving rewritten resources. E.g. if your filter->id == "xy" and FetchResource("NAME.pagespeed.xy.HASH.EXT"...) is called, then RewriteDriver will dispatch to filter->Fetch().

This is used when the filter being added is not part of the core set built into RewriteDriver and RewriteOptions, such as platform-specific or server-specific filters, or filters invented for unit-testing the framework.

const GoogleUrl& net_instaweb::RewriteDriver::base_url (  )  const [inline]

Returns the appropriate base gurl to be used for resolving hrefs in the document. Note that HtmlParse::google_url() is the URL for the HTML file and is used for printing html syntax errors.

void net_instaweb::RewriteDriver::BoundedWaitFor ( WaitMode  mode,
int64  timeout_ms 
)

As above, but with a time bound, and taking a mode parameter to decide between WaitForCompletion or WaitForShutDown behavior. If timeout_ms <= 0, no time bound will be used.

void net_instaweb::RewriteDriver::Cleanup (  ) 

If there are not outstanding references to this RewriteDriver, delete it or recycle it to a free pool in the ResourceManager. If this is a fetch, calling this also signals to the system that you are no longer interested in its results.

void net_instaweb::RewriteDriver::Clear (  ) 

Clears the current request cache of resources and base URL. The filter-chain is left intact so that a new request can be issued. Deletes all RewriteContexts.

WaitForCompletion must be called prior to Clear().

AbstractClientState* net_instaweb::RewriteDriver::client_state (  )  const [inline]

Return a pointer to the client state associated with this request. This may be NULL if the request does not have an associated client id, or if the retrieval of client state fails.

StringPiece net_instaweb::RewriteDriver::containing_charset (  )  [inline]

Get/set the charset of the containing HTML page. See scan_filter.cc for an explanation of how this is determined, but NOTE that the determined charset can change as more of the HTML is seen, in particular after a meta tag.

CacheUrlAsyncFetcher* net_instaweb::RewriteDriver::CreateCacheFetcher (  ) 

Creates a cache fetcher that uses the driver's fetcher and its options. Note: this means the driver's fetcher must survive as long as this does.

ResourcePtr net_instaweb::RewriteDriver::CreateInputResource ( const GoogleUrl input_url  ) 

Creates an input resource based on input_url. Returns NULL if the input resource url isn't valid, or can't legally be rewritten in the context of this page.

ResourcePtr net_instaweb::RewriteDriver::CreateInputResourceAbsoluteUnchecked ( const StringPiece &  absolute_url  ) 

Creates an input resource from the given absolute url. Requires that the provided url has been checked, and can legally be rewritten in the current page context.

void OutputResourcePtr net_instaweb::RewriteDriver::CreateOutputResourceFromResource ( const StringPiece &  filter_prefix,
const UrlSegmentEncoder encoder,
const ResourceContext *  data,
const ResourcePtr input_resource,
OutputResourceKind  kind 
)

Creates a reference-counted pointer to a new OutputResource object.

The content type is taken from the input_resource, but can be modified with SetType later if that is not correct (e.g. due to image transcoding). Constructs an output resource corresponding to the specified input resource and encoded using the provided encoder. Assumes permissions checking occurred when the input resource was constructed, and does not do it again. To avoid if-chains, tolerates a NULL input_resource (by returning NULL).

Todo:
TODO(jmaessen, jmarantz): Do we want to permit NULL input_resources here? jmarantz has evinced a distaste.
OutputResourcePtr net_instaweb::RewriteDriver::CreateOutputResourceWithMappedPath ( const StringPiece &  mapped_path,
const StringPiece &  unmapped_path,
const StringPiece &  filter_id,
const StringPiece &  name,
OutputResourceKind  kind 
) [inline]

Version of CreateOutputResourceWithPath where the unmapped and mapped paths are different and the base_url is this driver's base_url.

OutputResourcePtr net_instaweb::RewriteDriver::CreateOutputResourceWithPath ( const StringPiece &  path,
const StringPiece &  filter_id,
const StringPiece &  name,
OutputResourceKind  kind 
) [inline]

Version of CreateOutputResourceWithPath where the unmapped and mapped paths and the base url are all the same. FOR TESTS ONLY.

OutputResourcePtr net_instaweb::RewriteDriver::CreateOutputResourceWithPath ( const StringPiece &  mapped_path,
const StringPiece &  unmapped_path,
const StringPiece &  base_url,
const StringPiece &  filter_id,
const StringPiece &  name,
OutputResourceKind  kind 
)

Creates an output resource where the name is provided. The intent is to be able to derive the content from the name, for example, by encoding URLs and metadata.

This method succeeds unless the filename is too long.

This name is prepended with path for writing hrefs, and the resulting url is encoded and stored at file_prefix when working with the file system. So hrefs are: /usr/local/vnc32:/home/jmarantz/bin:/usr/local/vnc32:/home/jmarantz/bin/depot_tools:/home/jmarantz/local/bin:/usr/local/symlinks:/usr/local/scripts:/usr/local/buildtools/java/jdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/NX/bin:/usr/X11R6/bin/.pagespeed...

Could be private since you should use one of the versions below but put here with the rest like it and for documentation clarity.

OutputResourcePtr net_instaweb::RewriteDriver::CreateOutputResourceWithUnmappedPath ( const StringPiece &  path,
const StringPiece &  filter_id,
const StringPiece &  name,
OutputResourceKind  kind 
) [inline]

Version of CreateOutputResourceWithPath where the unmapped and mapped paths are the same and the base_url is this driver's base_url.

const GoogleUrl& net_instaweb::RewriteDriver::decoded_base_url (  )  const [inline]

Returns the decoded version of base_gurl() in case it was encoded by a non-default UrlNamer (for the default UrlNamer this returns the same value as base_url()). Required when fetching a resource by its encoded name.

OutputResourcePtr net_instaweb::RewriteDriver::DecodeOutputResource ( const GoogleUrl url,
RewriteFilter **  filter 
) const

Attempts to decode an output resource based on the URL pattern without actually rewriting it. No permission checks are performed on the url, though it is parsed to see if it looks like the url of a generated resource (which should mean checking the hash to ensure we generated it ourselves).

Todo:
TODO(jmaessen): add url hash & check thereof.
bool net_instaweb::RewriteDriver::DecodeOutputResourceName ( const GoogleUrl url,
ResourceNamer name_out,
OutputResourceKind kind_out,
RewriteFilter **  filter_out 
) const

As above, but does not actually create a resource object, and instead outputs the decoded information into the various out parameters. Returns whether decoding successful or not.

void net_instaweb::RewriteDriver::DeleteRewriteContext ( RewriteContext rewrite_context  ) 

Deletes the specified RewriteContext. If this is the last RewriteContext active on this Driver, and there is no other outstanding activity, then the RewriteDriver itself can be recycled, and WaitForCompletion can return.

We expect to this method to be called on the Rewrite thread.

void net_instaweb::RewriteDriver::DeregisterForPartitionKey ( const GoogleString partition_key,
RewriteContext candidate 
)

Must be called after all other rewrites that are currently relying on this one have had their RepeatedSuccess or RepeatedFailure methods called.

Must only be called from rewrite thread.

void net_instaweb::RewriteDriver::DetachedFetchComplete (  ) 

Called by RewriteContext when a detached async fetch is complete, allowing the RewriteDriver to be recycled if FetchComplete() got invoked as well.

void net_instaweb::RewriteDriver::DetachFetch (  ) 

Called by RewriteContext to let RewriteDriver know it will be continuing on the fetch in background, and so it should defer doing full cleanup sequences until DetachedFetchComplete() is called.

DomainRewriteFilter* net_instaweb::RewriteDriver::domain_rewriter (  )  [inline]

Used by CacheExtender, CssCombineFilter, etc. for rewriting domains of sub-resources in CSS.

bool net_instaweb::RewriteDriver::EndElementIsStoppingFlush ( const HtmlElement element  ) 

Will return true if the EndElementEvent of element is inhibited from flushing, and that event determined the size of the current flush. Will return false if a flush is not currently in progress.

void net_instaweb::RewriteDriver::ExecuteFlushIfRequested (  ) 

Executes an Flush() if RequestFlush() was called, e.g. from the Listener Filter (see set_event_listener below). Consider an HTML parse driven by a UrlAsyncFetcher. When the UrlAsyncFetcher temporarily runs out of bytes to read, it calls response_writer->Flush(). When that happens, we may want to consider flushing the outstanding HTML events through the system so that the browser can start fetching subresources and rendering. The event_listener (see set_event_listener below) helps determine whether enough "interesting" events have passed in the current flush window so that we should take this incoming network pause as an opportunity.

void net_instaweb::RewriteDriver::ExecuteFlushIfRequestedAsync ( Function callback  ) 

Asynchronous version of the above. Note that you should not attempt to write out any data until the callback is invoked. (If a flush is not needed, the callback will be invoked immediately).

void net_instaweb::RewriteDriver::FetchComplete (  ) 

Cleans up the driver and any fetch rewrite contexts, unless the fetch rewrite got detached by a call to DetachFetch(), in which case a call to DetachedFetchComplete() must also be performed.

bool net_instaweb::RewriteDriver::FetchOutputResource ( const OutputResourcePtr output_resource,
RewriteFilter filter,
AsyncFetch async_fetch 
)

See FetchResource. There are two differences: 1. It takes an OutputResource instead of a URL. 2. It returns whether a fetch was queued or not. This is safe to ignore because in either case the callback will be called. 3. If 'filter' is NULL then the request only checks cache and (if enabled) the file system.

bool net_instaweb::RewriteDriver::FetchResource ( const StringPiece &  url,
AsyncFetch fetch 
)

Initiates an async fetch for a rewritten resource with the specified name. If resource matches the pattern of what the driver is authorized to serve, then true is returned and the caller must listen on the callback for the completion of the request.

If the pattern does not match, then false is returned, and the request should be passed to another handler, and the callback will *not* be called. In other words there are four outcomes for this routine:

1. the request was handled immediately and the callback called before the method returns. true is returned. 2. the request looks good but was queued because some other resource fetch is needed to satisfy it. true is returned. 3. the request looks like one it belongs to Instaweb, but the resource could not be decoded. The callback is called immediately with 'false', but true is returned. 4. the request does not look like it belongs to Instaweb. The callback will not be called, and false will be returned.

In other words, if this routine returns 'false' then the callback will not be called. If the callback is called, then this should be the 'final word' on this request, whether it was called with success=true or success=false.

virtual void net_instaweb::RewriteDriver::FinishParse (  )  [virtual]

Override HtmlParse's FinishParse to ensure that the request-scoped cache is cleared immediately.

Note that the RewriteDriver can delete itself in this method, if it's not externally managed, and if all RewriteContexts have been completed.

Reimplemented from net_instaweb::HtmlParse.

void net_instaweb::RewriteDriver::FinishParseAsync ( Function callback  ) 

As above, but asynchronous. Note that the RewriteDriver may already be deleted at the point the callback is invoked.

virtual void net_instaweb::RewriteDriver::Flush (  )  [virtual]

Overrides HtmlParse::Flush so that it can happen in two phases: 1. Pre-render chain runs, resulting in async rewrite activity 2. async rewrite activity ends, calling callback, and post-render filters run. This API is used for unit-tests & Apache (which lacks a useful event model) and results in blocking behavior.

FlushAsync is prefered for event-driven servers.

Reimplemented from net_instaweb::HtmlParse.

void net_instaweb::RewriteDriver::FlushAsync ( Function done  ) 

Initiates an asynchronous Flush. done->Run() will be called when the flush is complete. The inhibits_mutex_ will be held while the callback is running, so the callback should not attempt to inhibit or uninhibit an element. Further calls to ParseText should be deferred until the callback is called.

void net_instaweb::RewriteDriver::increment_async_events_count (  ) 

Increments the value of pending_async_events_. pending_async_events_ will be incremented whenever an async event wants rewrite driver to be alive upon its completion.

void net_instaweb::RewriteDriver::InfoAt ( const RewriteContext context,
const char *  msg,
  ... 
)

Report error message with description of context's location (such as filenames and line numbers). context may be NULL, in which case the current parse position will be used.

void net_instaweb::RewriteDriver::InhibitEndElement ( const HtmlElement element  ) 

Prevent the EndElementEvent for element from flushing. If it has already flushed, this has no effect. Should only be called from an event listener. Useful for giving an active filter time to complete an RPC that provides data to append to element.

void net_instaweb::RewriteDriver::InitiateRewrite ( RewriteContext rewrite_context  ) 

Method to start a resource rewrite. This is called by a filter during parsing, although the Rewrite might continue after deadlines expire and the rewritten HTML must be flushed.

bool net_instaweb::RewriteDriver::MayRewriteUrl ( const GoogleUrl domain_url,
const GoogleUrl input_url 
) const

Checks to see if we can write the input_url resource in the domain_url taking into account domain authorization and wildcard allow/disallow from RewriteOptions.

ResponseHeaders* net_instaweb::RewriteDriver::mutable_response_headers (  )  [inline]

Return a mutable pointer to the response headers that filters can update before the first flush. Returns NULL after Flush has occurred.

int net_instaweb::RewriteDriver::num_inline_preview_images (  )  const [inline]

We expect to this method to be called on the HTML parser thread. Returns the number of images whose low quality images are inlined in the html page.

void net_instaweb::RewriteDriver::PrependRewriteFilter ( RewriteFilter filter  ) 

Like AppendRewriteFilter, but adds the filter to the beginning of the pre-render chain.

void net_instaweb::RewriteDriver::ReadAsync ( Resource::AsyncCallback callback,
MessageHandler message_handler 
)

Loads contents of resource asynchronously, calling callback when done. If the resource contents are cached, the callback will be called directly, rather than asynchronously. The resource will be passed to the callback, with its contents and headers filled in.

RewriteContext* net_instaweb::RewriteDriver::RegisterForPartitionKey ( const GoogleString partition_key,
RewriteContext candidate 
)

Tries to register the given rewrite context as working on its partition key. If this context is the first one to try to handle it, returns NULL. Otherwise returns the previous such context.

Must only be called from rewrite thread.

void net_instaweb::RewriteDriver::ReportSlowRewrites ( int  num  ) 

Provides a mechanism for a RewriteContext to notify a RewriteDriver that a certain number of rewrites have been discovered to need to take the slow path.

void net_instaweb::RewriteDriver::RequestFlush (  )  [inline]

Indicates that a Flush through the HTML parser chain should happen soon, e.g. once the network pauses its incoming byte stream.

CssResolutionStatus net_instaweb::RewriteDriver::ResolveCssUrls ( const GoogleUrl input_css_base,
const StringPiece &  output_css_base,
const StringPiece &  contents,
Writer writer,
MessageHandler handler 
)

Rewrites CSS content to absolutify any relative embedded URLs, streaming the results to the writer. Returns 'false' if the writer returns false or if the content was not rewritten because the domains of the gurl and resolved_base match.

input_css_base contains the path where the CSS text came from. output_css_base contains the path where the CSS will be written.

const ResponseHeaders* net_instaweb::RewriteDriver::response_headers (  )  [inline]

Returns a const version of the ResponseHeaders*, indepdendent of whether Flush has occurred. Note that ResponseHeaders* may still be NULL if no one has called set_response_headers_ptr.

Todo:
TODO(jmarantz): Change API to require response_headers in StartParse so we can guarantee this is non-null.
void net_instaweb::RewriteDriver::RewriteComplete ( RewriteContext rewrite_context  ) 

Provides a mechanism for a RewriteContext to notify a RewriteDriver that it is complete, to allow the RewriteDriver to delete itself or return it back to a free pool in the ResourceManager.

void net_instaweb::RewriteDriver::set_client_state ( AbstractClientState client_state  )  [inline]

Sets the pointer to the client state associated with this driver. RewriteDriver takes ownership of the provided AbstractClientState object.

void net_instaweb::RewriteDriver::set_critical_images ( StringSet *  critical_images  )  [inline]

Inserts the critical images present on the requested html page. It takes the ownership of critical_images.

void net_instaweb::RewriteDriver::set_externally_managed ( bool  x  )  [inline]

Indicate that this RewriteDriver will be explicitly deleted, and thus should not be auto-deleted at the end of the parse. This is primarily for tests.

Todo:
TODO(jmarantz): Consider phasing this out to make tests behave more like servers.
void net_instaweb::RewriteDriver::set_fully_rewrite_on_flush ( bool  x  )  [inline]

If this is set to true, during a Flush of HTML the system will wait for results of all rewrites rather than just waiting for cache lookups and a small deadline. Note, however, that in very rare circumstances some rewrites may still be dropped due to excessive load.

Note: reset every time the driver is recycled.

void net_instaweb::RewriteDriver::set_refs_before_base (  )  [inline]

Sets whether or not there were references to urls before the base tag (if there is a base tag). This variable has document-level scope. It is reset at the beginning of every document by ScanFilter.

void net_instaweb::RewriteDriver::set_response_headers_ptr ( ResponseHeaders headers  )  [inline]

Set the pointer to the response headers that filters can update before the first flush. RewriteDriver does NOT take ownership of this memory.

void net_instaweb::RewriteDriver::set_rewrite_deadline_ms ( int  x  )  [inline]

Explicitly sets the number of milliseconds to wait for Rewrites to complete while HTML parsing, overriding a default value which is dependent on whether the system is compiled for debug or release, or whether it's been detected as running on valgrind at runtime.

void net_instaweb::RewriteDriver::SetResourceManager ( ResourceManager resource_manager  ) 

Adds a resource manager enabling the rewriting of resources. This will replace any previous resource managers.

void net_instaweb::RewriteDriver::SetSessionFetcher ( UrlAsyncFetcher f  ) 

Set a fetcher that will be used by RewriteDriver for current request only (that is, until Clear()). RewriteDriver will take ownership of this fetcher, and will keep it around until Clear(), even if further calls to this method are made.

void net_instaweb::RewriteDriver::SetWriter ( Writer writer  ) 

Controls how HTML output is written. Be sure to call this last, after all other filters have been established.

Todo:
TODO(jmarantz): fix this in the implementation so that the caller can install filters in any order and the writer will always be last.
bool net_instaweb::RewriteDriver::ShouldAbsolutifyUrl ( const GoogleUrl input_base,
const GoogleUrl output_base,
bool *  proxy_mode 
) const

Determines if an URL relative to the given input_base needs to be absolutified given that it will end up under output_base:

  • If we are proxying and input_base isn't proxy encoded, then yes.
  • If we aren't proxying and input_base != output_base, then yes.
  • If we aren't proxying and the domain lawyer will shard or rewrite input_base, then yes. If not NULL also set *proxy_mode to whether proxy mode is active or not.
bool net_instaweb::RewriteDriver::ShouldNotRewriteImages (  )  const

Determines whether images should be rewritten.

Todo:
TODO(jmarantz): Another approach to allow rewriting to be friendly to image-search link rel=canonical, described in: http://googlewebmastercentral.blogspot.com/2011/06/ supporting-relcanonical-http-headers.html
void net_instaweb::RewriteDriver::UninhibitEndElement ( const HtmlElement element  ) 

Permits the EndElementEvent for element to flush. If it was not previously prevented from doing so by InhibitEndElement, this has no effect. Should only be called from an active filter, in coordination with an event listener that called InhibitEndElement. If we are currently flushing, another flush will be scheduled as soon as this one finishes. If we are not, another flush will be scheduled immediately.

void net_instaweb::RewriteDriver::WaitForCompletion (  ) 

Wait for outstanding Rewrite to complete. Once the rewrites are complete they can be rendered.

void net_instaweb::RewriteDriver::WaitForShutDown (  ) 

Wait for outstanding rewrite to complete, including any background work that may be ongoing even after results were reported.

Note: while this guarantees that the result of the computation is known, the thread that performed it may still be running for a little bit and accessing the driver.


Member Data Documentation

This string identifies, for the PropertyCache, a group of properties that are computed from the DOM, and thus can, if desired, be rewritten on every HTML request.

Todo:
TODO(jmarantz): The "DOM" cohort is here as a placeholder. There's no existing filter that needs this yet, although a pending test in proxy_interface_test.cc that will need it. If, by the time the PropertyCache comes into use in a product, the DOM cohort is not in use, we should remove it since its presence will cause an extra cache-lookup per HTML request.

A list of HTTP request headers. These are the headers which should be passed through from the client request into the ResponseHeaders request_headers sent to the rewrite driver. Headers not in this list will be ignored so there is no need to copy them over.

Todo:
TODO(sligocki): Use these in ProxyInterface flow.

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Tue May 29 16:34:04 2012 for Page Speed Optimization Libraries by  doxygen 1.6.3