Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
net_instaweb::ResourceCombiner Class Referenceabstract

#include "resource_combiner.h"

Inheritance diagram for net_instaweb::ResourceCombiner:
net_instaweb::CombiningFilter::Combiner

Public Member Functions

 ResourceCombiner (RewriteDriver *rewrite_driver, const StringPiece &extension, RewriteFilter *filter)
 Note: extension should not include the leading dot here.
 
void Reset ()
 
GoogleString UrlSafeId () const
 
int num_urls () const
 Returns the number of URLs that have been successfully added.
 
const ResourceVector & resources () const
 
GoogleString ResolvedBase () const
 Base common to all URLs. Always has a trailing slash.
 
TimedBool AddResourceNoFetch (const ResourcePtr &resource, MessageHandler *handler)
 

Static Public Attributes

static const int kUrlSlack = 100
 

Protected Member Functions

virtual void RemoveLastResource ()
 
OutputResourcePtr Combine (MessageHandler *handler)
 
virtual bool WriteCombination (const ResourceVector &combine_resources, const OutputResourcePtr &combination, MessageHandler *handler)
 
virtual bool WritePiece (int index, int num_pieces, const Resource *input, OutputResource *combination, Writer *writer, MessageHandler *handler)
 
virtual void Clear ()
 

Protected Attributes

ServerContext *const server_context_
 
RewriteDriver *const rewrite_driver_
 

Friends

class AggregateCombiner
 

Detailed Description

This class is a utility for filters that combine multiple resource files into one. It provides two major pieces of functionality to help out: 1) It keeps a ResourceVector and provides methods to keep track of resources and URLs that can be safely combined together while encoding the information on the pieces in the combined URL. 2) It implements Fetch, reconstructing combinations as needed.

Member Function Documentation

TimedBool net_instaweb::ResourceCombiner::AddResourceNoFetch ( const ResourcePtr resource,
MessageHandler handler 
)
Todo:
TODO(jmarantz): rename this to AddResource now that async flow is live.
virtual void net_instaweb::ResourceCombiner::Clear ( )
protectedvirtual

Override this if you need to remove some state whenever Reset() is called. Your implementation must call the superclass.

OutputResourcePtr net_instaweb::ResourceCombiner::Combine ( MessageHandler handler)
protected

Returns one resource containing the combination of all added resources, creating it if necessary. Caller takes ownership. Returns NULL if the combination does not exist and cannot be created. Will not combine fewer than 2 resources.

virtual void net_instaweb::ResourceCombiner::RemoveLastResource ( )
protectedvirtual

Removes the last resource that was added here, assuming the last call to AddResource was successful. If the last call to AddResource returned false, behavior is undefined.

void net_instaweb::ResourceCombiner::Reset ( )

Resets the current combiner to an empty state, incorporating the base URL. Make sure this gets called before documents — on a ::Flush() is enough. If a subclass needs to do some of its own reseting, see Clear().

GoogleString net_instaweb::ResourceCombiner::UrlSafeId ( ) const

Computes a name for the URL that meets all known character-set and size restrictions.

virtual bool net_instaweb::ResourceCombiner::WriteCombination ( const ResourceVector &  combine_resources,
const OutputResourcePtr combination,
MessageHandler handler 
)
protectedvirtual

Override this if your combination is not a matter of combining text pieces (perhaps adjusted by WritePiece).

virtual bool net_instaweb::ResourceCombiner::WritePiece ( int  index,
int  num_pieces,
const Resource input,
OutputResource combination,
Writer writer,
MessageHandler handler 
)
protectedvirtual

Override this to alter how pieces are processed when included inside a combination. Returns whether successful. The default implementation writes input->contents() to the writer without any alteration. 'index' is the position of this piece in the combination, while num_pieces is the total number of pieces.

Reimplemented in net_instaweb::CombiningFilter::Combiner.

Member Data Documentation

const int net_instaweb::ResourceCombiner::kUrlSlack = 100
static

Slack to leave in URL size, so that other filters running afterwards can expand the URLs without going over maximum allowed sizes.

Why 100? First example I saw, CssFilter expanded a CssCombined URL by 36 chars. So 100 seemed like a nice round number to allow two filters to run after this and then for there still be a little slack.

Todo:
TODO(sligocki): Set this more intelligently.

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