Page Speed Optimization Libraries  1.7.30.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions
net_instaweb::RewriteDriverFactory Class Reference

#include "rewrite_driver_factory.h"

Inheritance diagram for net_instaweb::RewriteDriverFactory:
net_instaweb::FileRewriter net_instaweb::SystemRewriteDriverFactory net_instaweb::TestRewriteDriverFactory net_instaweb::ApacheRewriteDriverFactory net_instaweb::CustomRewriteTestBase< OptionsClass >::CustomTestRewriteDriverFactory

List of all members.

Classes

class  Deleter

Public Types

enum  WorkerPoolCategory { kHtmlWorkers, kRewriteWorkers, kLowPriorityRewriteWorkers, kNumWorkerPools }

Public Member Functions

 RewriteDriverFactory (const ProcessContext &process_context, ThreadSystem *thread_system)
 Takes ownership of thread_system.
void InitializeDefaultOptions ()
void set_html_parse_message_handler (MessageHandler *message_handler)
void set_message_handler (MessageHandler *message_handler)
void set_file_system (FileSystem *file_system)
void set_hasher (Hasher *hasher)
void set_filename_encoder (FilenameEncoder *filename_encoder)
void set_nonce_generator (NonceGenerator *nonce_generator)
void set_url_namer (UrlNamer *url_namer)
void set_timer (Timer *timer)
void set_usage_data_reporter (UsageDataReporter *reporter)
void set_slurp_directory (const StringPiece &directory)
void set_slurp_read_only (bool read_only)
void set_slurp_print_urls (bool read_only)
void set_force_caching (bool u)
void set_base_url_async_fetcher (UrlAsyncFetcher *url_fetcher)
void set_base_distributed_async_fetcher (UrlAsyncFetcher *distributed_fetcher)
 Takes ownership of distributed_fetcher.
bool set_filename_prefix (StringPiece p)
bool slurping_enabled () const
 Determines whether Slurping is enabled.
MessageHandler * html_parse_message_handler ()
MessageHandler * message_handler ()
FileSystem * file_system ()
NonceGenerator * nonce_generator ()
Hasher * hasher ()
FilenameEncoder * filename_encoder ()
UrlNamerurl_namer ()
UserAgentMatcher * user_agent_matcher ()
StaticAssetManagerstatic_asset_manager ()
RewriteOptionsdefault_options ()
virtual RewriteOptionsManagerNewRewriteOptionsManager ()
Timer * timer ()
NamedLockManager * lock_manager ()
QueuedWorkerPool * WorkerPool (WorkerPoolCategory pool)
Scheduler * scheduler ()
UsageDataReporterusage_data_reporter ()
const
pagespeed::js::JsTokenizerPatterns * 
js_tokenizer_patterns () const
const std::vector< const
UserAgentNormalizer * > & 
user_agent_normalizers ()
virtual UrlAsyncFetcherComputeUrlAsyncFetcher ()
virtual UrlAsyncFetcherComputeDistributedFetcher ()
ServerContextCreateServerContext ()
void InitServerContext (ServerContext *server_context)
virtual void SetupCaches (ServerContext *server_context)=0
virtual bool UseBeaconResultsInFilters () const =0
virtual void AddPlatformSpecificRewritePasses (RewriteDriver *driver)
virtual void AddPlatformSpecificDecodingPasses (RewriteDriver *driver)
virtual void ApplyPlatformSpecificConfiguration (RewriteDriver *driver)
ThreadSystem * thread_system ()
const StringSet & created_directories () const
bool async_rewrites ()
RewriteStatsrewrite_stats ()
Statistics * statistics ()
void SetStatistics (Statistics *stats)
 Does *not* take ownership of Statistics.
virtual void ShutDown ()
void AddCreatedDirectory (const GoogleString &dir)
 Registers the directory as having been created by us.
virtual RewriteOptionsNewRewriteOptions ()
virtual RewriteOptionsNewRewriteOptionsForQuery ()
const GoogleString & version_string () const
 get/set the version placed into the X-[Mod-]Page(s|-S)peed header.
void set_version_string (const StringPiece &version_string)
void defer_cleanup (Function *f)
template<class T >
void TakeOwnership (T *obj)
virtual bool IsDebugClient (const GoogleString &ip) const
 Base method that returns true if the given ip is a debug ip.
virtual ExperimentMatcherNewExperimentMatcher ()
const std::vector< int > * preferred_webp_qualities ()
 Returns the preferred webp image quality vector for client options.
const std::vector< int > * preferred_jpeg_qualities ()
 Returns the preferred jpeg image quality vector for client options.
bool SetPreferredWebpQualities (const StringPiece &qualities)
 Returns true if the correct number of WebP qualities are parsed and set.
bool SetPreferredJpegQualities (const StringPiece &qualities)
 Returns true if the correct number of JPEG qualities are parsed and set.

Static Public Member Functions

static void InitStats (Statistics *statistics)
static void Initialize ()
 Initializes static variables. Initialize/Terminate calls must be paired.
static void Terminate ()

Protected Member Functions

bool FetchersComputed () const
virtual void StopCacheActivity ()
StringPiece filename_prefix ()
bool TerminateServerContext (ServerContext *server_context)
virtual UrlAsyncFetcherDefaultAsyncUrlFetcher ()=0
virtual MessageHandler * DefaultHtmlParseMessageHandler ()=0
virtual MessageHandler * DefaultMessageHandler ()=0
virtual FileSystem * DefaultFileSystem ()=0
virtual NonceGenerator * DefaultNonceGenerator ()
virtual Timer * DefaultTimer ()
virtual Hasher * NewHasher ()=0
virtual ServerContextNewServerContext ()=0
virtual ServerContextNewDecodingServerContext ()=0
virtual UrlAsyncFetcherDefaultDistributedUrlFetcher ()
virtual CriticalCssFinderDefaultCriticalCssFinder ()
virtual CriticalImagesFinderDefaultCriticalImagesFinder (ServerContext *server_context)
virtual CriticalSelectorFinderDefaultCriticalSelectorFinder (ServerContext *server_context)
virtual CacheHtmlInfoFinderDefaultCacheHtmlInfoFinder (PropertyCache *cache, ServerContext *server_context)
 Default implementation returns NULL.
virtual FlushEarlyInfoFinderDefaultFlushEarlyInfoFinder ()
 Default implementation returns NULL.
virtual CriticalLineInfoFinderDefaultCriticalLineInfoFinder (ServerContext *server_context)
 Default implementation returns a valid CriticalSelectorFinder.
virtual NamedLockManager * DefaultLockManager ()
virtual UrlNamerDefaultUrlNamer ()
virtual UserAgentMatcher * DefaultUserAgentMatcher ()
virtual UsageDataReporterDefaultUsageDataReporter ()
virtual void AddPlatformSpecificUserAgentNormalizers (std::vector< const UserAgentNormalizer * > *out)
virtual QueuedWorkerPool * CreateWorkerPool (WorkerPoolCategory pool, StringPiece name)
virtual int LowPriorityLoadSheddingThreshold () const
virtual Scheduler * CreateScheduler ()
virtual void FetcherSetupHooks ()
 Called before creating the url fetchers.
virtual StringPiece LockFilePrefix ()
virtual void InitStaticAssetManager (StaticAssetManager *static_asset_manager)
 Initializes the StaticAssetManager.
void InitStubDecodingServerContext (ServerContext *context)
void RebuildDecodingDriverForTests (ServerContext *server_context)
 For use in tests.

Detailed Description

Manages the construction and ownership of most objects needed to create RewriteDrivers. If you have your own versions of these classes (specific implementations of UrlAsyncFetcher, Hasher, etc.) you can make your own subclass of RewriteDriverFactory to use these by default.


Member Enumeration Documentation

Enumerator:
kNumWorkerPools 

Make sure to insert new values above this line.


Member Function Documentation

Provides an optional hook for adding rewriters to the .pagespeed. resource decoding chain. This should be used for rewriters that are specific to a particular RewriteDriverFactory implementation. The caller should only use the resulting driver for reconstructing a .pagespeed. resource, not for transforming HTML. Therefore, implementations should add any platform-specific rewriter whose id might appear in a .pagespeed. URL. This should be done independent of RewriteOptions, since we only store a single decoding driver globally to save memory.

Reimplemented in net_instaweb::TestRewriteDriverFactory.

Provides an optional hook for adding rewrite passes to the HTML filter chain. This should be used for filters that are specific to a particular RewriteDriverFactory implementation.

Reimplemented in net_instaweb::TestRewriteDriverFactory.

virtual void net_instaweb::RewriteDriverFactory::AddPlatformSpecificUserAgentNormalizers ( std::vector< const UserAgentNormalizer * > *  out) [protected, virtual]

Provides an optional hook to add user-agent normalizers specific to needs of a specific RewriteDriverFactory implementation. The new entries should be appended to the end of *out (without clearing it), and should still be owned by the RewriteDriverFactory subclass.

Default implementation does nothing.

Provides an optional hook for customizing the RewriteDriver object using the options set on it. This is called before RewriteDriver::AddFilters() and AddPlatformSpecificRewritePasses().

Reimplemented in net_instaweb::TestRewriteDriverFactory.

Computes URL fetchers using the base fetcher, and optionally, slurp_directory and slurp_read_only. These are not thread-safe; they must be called once prior to spawning threads, e.g. via CreateServerContext.

const StringSet& net_instaweb::RewriteDriverFactory::created_directories ( ) const [inline]

Returns the set of directories that we (our our subclasses) have created thus far.

virtual Scheduler* net_instaweb::RewriteDriverFactory::CreateScheduler ( ) [protected, virtual]

Subclasses can override this to create an appropriate Scheduler subclass if the default isn't acceptable.

Reimplemented in net_instaweb::TestRewriteDriverFactory.

Threadsafe mechanism to create a managed ServerContext. The ServerContext is owned by the factory, and should not be deleted directly. Currently it is not possible to delete a server context except by deleting the entire factory.

Implemented in terms of NewServerContext().

virtual QueuedWorkerPool* net_instaweb::RewriteDriverFactory::CreateWorkerPool ( WorkerPoolCategory  pool,
StringPiece  name 
) [protected, virtual]

Subclasses can override this to create an appropriately-sized thread pool for their environment. The default implementation will always make one with a single thread.

Reimplemented in net_instaweb::ApacheRewriteDriverFactory.

Implementors of RewriteDriverFactory must supply default definitions for each of these methods, although they may be overridden via set_ methods above. These methods all instantiate objects and transfer ownership to the caller.

Implemented in net_instaweb::TestRewriteDriverFactory, and net_instaweb::FileRewriter.

virtual NamedLockManager* net_instaweb::RewriteDriverFactory::DefaultLockManager ( ) [protected, virtual]

They may also supply a custom lock manager. The default implementation will use the file system.

Reimplemented in net_instaweb::SystemRewriteDriverFactory.

They may also supply a custom Url namer. The default implementation performs sharding and appends '.pagespeed.<filter>.<hash>.<extension>'.

Reimplemented in net_instaweb::TestRewriteDriverFactory.

void net_instaweb::RewriteDriverFactory::defer_cleanup ( Function *  f) [inline]

Causes the given function to be Run after all the threads are shutdown, in order to do any needed resource cleanups. The Deleter<T> template below may be useful for object deletion cleanups.

Todo:
TODO(sligocki): Remove hasher() and force people to make a NewHasher when they need one.

Initializes default options we want to hard-code into the base-class to get consistency across deployments. Subclasses that override NewRewriteOptions() should call this method from their constructor. It is safe to call this multiple times.

Initializes a ServerContext that has been new'd directly. This allows 2-phase initialization if required. There is no need to call this if you use CreateServerContext.

static void net_instaweb::RewriteDriverFactory::InitStats ( Statistics *  statistics) [static]

Initializes statistics variables. This must be done at process startup to enable shared memory segments in Apache to be set up.

Reimplemented in net_instaweb::SystemRewriteDriverFactory, net_instaweb::ApacheRewriteDriverFactory, and net_instaweb::TestRewriteDriverFactory.

Sets up enough of platform dependencies in 'context' to be able to use it for decoding URLs, based on this object's values and some stubs.

virtual StringPiece net_instaweb::RewriteDriverFactory::LockFilePrefix ( ) [protected, virtual]

Override this if you want to change what directory locks go into when using the default filesystem-based lock manager. The default is filename_prefix()

Subclasses can override this method to request load-shedding to happen if the low-priority work pool has too many inactive sequences queued up waiting (the returned value will be a threshold beyond which things will start getting dropped). The default implementation returns kNoLoadShedding, which disables the feature. See also QueuedWorkerPool::set_load_shedding_threshold

Create a new ServerContext used for decoding only. Unlike NewServerContext, the resulting ServerContext should not be fresh, but should have some of its platform dependencies injected --- but just enough for decoding URLs, and not full operation. At the time of writing it needs the timer, url namer, hasher, message handler, and stats; expensive stuff like cache backends is not needed, however.

You may find InitStubDecodingServerContext() useful for doing that, as it will inject all of these from what's available in 'this'.

Implemented in net_instaweb::TestRewriteDriverFactory, net_instaweb::ApacheRewriteDriverFactory, and net_instaweb::FileRewriter.

Creates an ExperimentMatcher, which is used to match clients or sessions to a specific experiment.

Creates a new empty RewriteOptions object, with no default settings. Generally configurations go factory's default_options() -> ServerContext::global_options() -> RewriteDriverFactory, but this method just provides a blank set of options.

Reimplemented in net_instaweb::TestRewriteDriverFactory, net_instaweb::ApacheRewriteDriverFactory, and net_instaweb::CustomRewriteTestBase< OptionsClass >::CustomTestRewriteDriverFactory.

Creates a new empty RewriteOptions object meant for use for custom options from queries or headers. Default implementation just forwards to NewRewriteOptions().

Reimplemented in net_instaweb::ApacheRewriteDriverFactory.

Creates a new ServerContext* object. ServerContext itself must be overridden per Factory as it has at least one pure virtual method.

Implemented in net_instaweb::TestRewriteDriverFactory, net_instaweb::SystemRewriteDriverFactory, and net_instaweb::FileRewriter.

Collection of global statistics objects. This is thread-unsafe: it must be called prior to spawning threads, and after any calls to SetStatistics. Failing that, it will be initialized in the first call to InitServerContext(), which is thread-safe.

You can call set_base_url_async_fetcher to set up real async fetching for real serving or for modeling of live traffic.

These fetchers may be used directly when serving traffic, or they may be aggregated with other fetchers (e.g. for slurping).

You cannot set the base URL fetcher once ComputeUrlAsyncFetcher has been called.

Setting HTTP caching on causes both the fetcher and the async fecher to return cached versions.

void net_instaweb::RewriteDriverFactory::set_html_parse_message_handler ( MessageHandler *  message_handler)

The RewriteDriverFactory will create objects of default type through the New* method from drived classes. Here are the objects that can be replaced before creating the RewriteDriver. Note: RewriteDriver takes ownership of these.

void net_instaweb::RewriteDriverFactory::set_slurp_directory ( const StringPiece &  directory)

Set up a directory for slurped files for HTML and resources. If read_only is true, then it will only read from these files, and this will eliminate the usage of any other url_fetcher. If read_only is false, then the existing url fetcher will be used as a fallback if the slurped file is not found, and slurped files will be subsequently written so they don't have to be fetched from the Internet again.

You must set the slurp directory prior to calling ComputeUrlAsyncFetcher.

virtual void net_instaweb::RewriteDriverFactory::SetupCaches ( ServerContext server_context) [pure virtual]

Called from InitServerContext, but virtualized separately as it is platform-specific. This method must call on the server context: set_http_cache, set_metadata_cache, set_filesystem_metadata_cache, and MakePropertyCaches.

Implemented in net_instaweb::TestRewriteDriverFactory, net_instaweb::SystemRewriteDriverFactory, net_instaweb::ApacheRewriteDriverFactory, and net_instaweb::FileRewriter.

Clean up all the factory-owned resources: fetchers, pools, Server Contexts, the Drivers owned by the Server Contexts, and worker threads.

Reimplemented in net_instaweb::SystemRewriteDriverFactory.

statistics (default is NullStatistics). This can be overridden by calling SetStatistics, either from subclasses or externally.

Reimplemented in net_instaweb::FileRewriter.

template<class T >
void net_instaweb::RewriteDriverFactory::TakeOwnership ( T *  obj) [inline]

Queues an object for deletion at the last phase of RewriteDriverFactory destruction.

Used by subclasses to indicate that a ServerContext has been terminated. Returns true if this was the last server context known to this factory.

These accessors are *not* thread-safe until after the first call, as they do unlocked lazy initialization, so they must be called at least once prior to starting threads. Normally this is done by CreateServerContext() or InitServerContext().

Returns true if this platform uses beacon-based measurements to make run-time decisions. This is used to determine how to configure various beacon-based filters.

Implemented in net_instaweb::TestRewriteDriverFactory, net_instaweb::ApacheRewriteDriverFactory, and net_instaweb::FileRewriter.


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