Page Speed Optimization Libraries  1.2.24.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Protected Member Functions
net_instaweb::InlineRewriteContext Class Reference

#include "inline_rewrite_context.h"

Inheritance diagram for net_instaweb::InlineRewriteContext:
net_instaweb::RewriteContext

List of all members.

Public Member Functions

 InlineRewriteContext (CommonFilter *filter, HtmlElement *element, HtmlElement::Attribute *src)
 Note that you should also call StartInlining() to do the work.
bool StartInlining ()

Protected Member Functions

virtual bool ShouldInline (const ResourcePtr &resource) const =0
 Subclasses of InlineRewriteContext must override these:
virtual void RenderInline (const ResourcePtr &resource, const StringPiece &text, HtmlElement *element)=0
virtual bool Partition (OutputPartitions *partitions, OutputResourceVector *outputs)
 InlineRewriteContext takes care of these methods from RewriteContext;.
virtual void Rewrite (int partition_index, CachedResult *partition, const OutputResourcePtr &output)
virtual void Render ()
virtual OutputResourceKind kind () const
HtmlElementget_element () const

Detailed Description

Class that unifies tasks common to building rewriters for filters that inline resources.


Member Function Documentation

virtual OutputResourceKind net_instaweb::InlineRewriteContext::kind ( ) const [protected, virtual]

Rewrites come in three flavors, as described in output_resource_kind.h, so this method must be defined by subclasses to indicate which it is.

For example, we will avoid caching output_resource content in the HTTP cache for rewrites that are so quick to complete that it's fine to do the rewrite on every request. extend_cache is obviously in this category, and it's arguable we could treat js minification that way too (though we don't at the moment).

Implements net_instaweb::RewriteContext.

virtual void net_instaweb::InlineRewriteContext::Render ( ) [protected, virtual]

Performs rendering activities that span multiple HTML slots. For example, in a filter that combines N slots to 1, N-1 of the HTML elements might need to be removed. That can be performed in Render(). This method is optional; the base-class implementation is empty.

Note that unlike Harvest(), this method runs in the HTML thread (for top-level rewrites), and only runs if the rewrite completes prior to the rewrite-deadline. If the rewrite does make it by the deadline, RewriteContext::Render() will be invoked regardless of whether any slots were actually optimized successfully.

Reimplemented from net_instaweb::RewriteContext.

virtual void net_instaweb::InlineRewriteContext::Rewrite ( int  partition_index,
CachedResult *  partition,
const OutputResourcePtr output 
) [protected, virtual]

Takes a completed rewrite partition and rewrites it. When complete calls RewriteDone with kRewriteOk if successful. Note that a value of kTooBusy means that an HTML rewrite will skip this resource, but we should not cache it as "do not optimize".

During this phase, any nested contexts that are needed to complete the Rewrite process can be instantiated.

Todo:
TODO(jmarantz): check for resource completion from a different thread (while we were waiting for resource fetches) when Rewrite gets called.

Implements net_instaweb::RewriteContext.

Starts the actual inlining process, and takes over memory management of this object. Returns true if the process is started, false if it cannot be started because the input resource cannot be created, in which case 'this' is deleted and accordingly no rewriting callbacks are invoked.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines