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

#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

Classes

class  Deleter
 Helper for users of defer_cleanup; see below. More...
 

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_nonce_generator (NonceGenerator *nonce_generator)
 
void set_url_namer (UrlNamer *url_namer)
 
void set_signature (SHA1Signature *signature)
 
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)
 
bool set_filename_prefix (StringPiece p)
 
bool slurping_enabled () const
 Determines whether Slurping is enabled.
 
MessageHandlerhtml_parse_message_handler ()
 
MessageHandlermessage_handler ()
 
FileSystemfile_system ()
 
NonceGeneratornonce_generator ()
 
Hasherhasher ()
 
UrlNamerurl_namer ()
 
UserAgentMatcheruser_agent_matcher ()
 
StaticAssetManagerstatic_asset_manager ()
 
SHA1Signaturesignature ()
 
RewriteOptionsdefault_options ()
 
virtual RewriteOptionsManagerNewRewriteOptionsManager ()
 
Timertimer ()
 
NamedLockManagerlock_manager ()
 
QueuedWorkerPoolWorkerPool (WorkerPoolCategory pool)
 
Schedulerscheduler ()
 
UsageDataReporterusage_data_reporter ()
 
const
pagespeed::js::JsTokenizerPatterns
js_tokenizer_patterns () const
 
const std::vector< const
UserAgentNormalizer * > & 
user_agent_normalizers ()
 
virtual UrlAsyncFetcherComputeUrlAsyncFetcher ()
 
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)
 
ThreadSystemthread_system ()
 
const StringSet & created_directories () const
 
bool async_rewrites ()
 
RewriteStatsrewrite_stats ()
 
virtual bool HasWaveforms () const
 Returns true if the server supports waveforms in its status page.
 
Statisticsstatistics ()
 
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 GoogleStringversion_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 ()
 

Static Public Member Functions

static void InitializeDefaultOptions (RewriteOptions *options)
 
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 MessageHandlerDefaultHtmlParseMessageHandler ()=0
 
virtual MessageHandlerDefaultMessageHandler ()=0
 
virtual FileSystemDefaultFileSystem ()=0
 
virtual NonceGeneratorDefaultNonceGenerator ()
 
virtual TimerDefaultTimer ()
 
virtual SHA1SignatureDefaultSignature ()
 
virtual HasherNewHasher ()=0
 
virtual ServerContextNewServerContext ()=0
 
virtual ServerContextNewDecodingServerContext ()=0
 
virtual CriticalImagesFinderDefaultCriticalImagesFinder (ServerContext *server_context)
 
virtual CriticalSelectorFinderDefaultCriticalSelectorFinder (ServerContext *server_context)
 
virtual NamedLockManagerDefaultLockManager ()
 
virtual UrlNamerDefaultUrlNamer ()
 
virtual UserAgentMatcherDefaultUserAgentMatcher ()
 
virtual UsageDataReporterDefaultUsageDataReporter ()
 
virtual void AddPlatformSpecificUserAgentNormalizers (std::vector< const UserAgentNormalizer * > *out)
 
virtual QueuedWorkerPoolCreateWorkerPool (WorkerPoolCategory pool, StringPiece name)
 
virtual int LowPriorityLoadSheddingThreshold () const
 
virtual SchedulerCreateScheduler ()
 
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)
 
virtual std::shared_ptr
< CentralController
GetCentralController (NamedLockManager *lock_manager)
 
void RebuildDecodingDriverForTests (ServerContext *server_context)
 For use in tests.
 
void reset_default_options (RewriteOptions *new_defaults)
 

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

virtual void net_instaweb::RewriteDriverFactory::AddPlatformSpecificDecodingPasses ( RewriteDriver driver)
virtual

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.

virtual void net_instaweb::RewriteDriverFactory::AddPlatformSpecificRewritePasses ( RewriteDriver driver)
virtual

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)
protectedvirtual

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.

virtual void net_instaweb::RewriteDriverFactory::ApplyPlatformSpecificConfiguration ( RewriteDriver driver)
virtual

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.

virtual UrlAsyncFetcher* net_instaweb::RewriteDriverFactory::ComputeUrlAsyncFetcher ( )
virtual

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 ( )
protectedvirtual

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

Reimplemented in net_instaweb::TestRewriteDriverFactory.

ServerContext* net_instaweb::RewriteDriverFactory::CreateServerContext ( )

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().

Note that this is a convenience wrapper only. In particular, SystemServerContext creates ServerContexts by calling New and Init separately.

virtual QueuedWorkerPool* net_instaweb::RewriteDriverFactory::CreateWorkerPool ( WorkerPoolCategory  pool,
StringPiece  name 
)
protectedvirtual

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::SystemRewriteDriverFactory.

virtual UrlAsyncFetcher* net_instaweb::RewriteDriverFactory::DefaultAsyncUrlFetcher ( )
protectedpure virtual

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 ( )
protectedvirtual

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

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

virtual UrlNamer* net_instaweb::RewriteDriverFactory::DefaultUrlNamer ( )
protectedvirtual

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.

virtual std::shared_ptr<CentralController> net_instaweb::RewriteDriverFactory::GetCentralController ( NamedLockManager lock_manager)
protectedvirtual

Allow sub-classes to pick which CentralController they want to use. lock_manager is owned by the caller and must outlive the Controller. This uses shared_ptr to solve lifecycle differences among different implementations.

Reimplemented in net_instaweb::SystemRewriteDriverFactory.

Hasher* net_instaweb::RewriteDriverFactory::hasher ( )
Todo:
TODO(sligocki): Remove hasher() and force people to make a NewHasher when they need one.
void net_instaweb::RewriteDriverFactory::InitializeDefaultOptions ( )

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.

static void net_instaweb::RewriteDriverFactory::InitializeDefaultOptions ( RewriteOptions options)
static

Static version of the above. If you are using that you may also need to call reset_default_options.

void net_instaweb::RewriteDriverFactory::InitServerContext ( ServerContext server_context)

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.

void net_instaweb::RewriteDriverFactory::InitStubDecodingServerContext ( ServerContext context)
protected

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 ( )
protectedvirtual

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()

virtual int net_instaweb::RewriteDriverFactory::LowPriorityLoadSheddingThreshold ( ) const
protectedvirtual

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

virtual ServerContext* net_instaweb::RewriteDriverFactory::NewDecodingServerContext ( )
protectedpure virtual

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.

virtual ExperimentMatcher* net_instaweb::RewriteDriverFactory::NewExperimentMatcher ( )
virtual

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

virtual RewriteOptions* net_instaweb::RewriteDriverFactory::NewRewriteOptions ( )
virtual

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, net_instaweb::FileRewriter, and net_instaweb::CustomRewriteTestBase< OptionsClass >::CustomTestRewriteDriverFactory.

virtual RewriteOptions* net_instaweb::RewriteDriverFactory::NewRewriteOptionsForQuery ( )
virtual

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.

virtual ServerContext* net_instaweb::RewriteDriverFactory::NewServerContext ( )
protectedpure virtual

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.

RewriteStats* net_instaweb::RewriteDriverFactory::rewrite_stats ( )

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.

void net_instaweb::RewriteDriverFactory::set_base_url_async_fetcher ( UrlAsyncFetcher url_fetcher)

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.

void net_instaweb::RewriteDriverFactory::set_force_caching ( bool  u)
inline

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::SystemRewriteDriverFactory, net_instaweb::TestRewriteDriverFactory, net_instaweb::ApacheRewriteDriverFactory, and net_instaweb::FileRewriter.

virtual void net_instaweb::RewriteDriverFactory::ShutDown ( )
virtual

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* net_instaweb::RewriteDriverFactory::statistics ( )
inline

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

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

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

bool net_instaweb::RewriteDriverFactory::TerminateServerContext ( ServerContext server_context)
protected

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

Timer* net_instaweb::RewriteDriverFactory::timer ( )

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().

virtual bool net_instaweb::RewriteDriverFactory::UseBeaconResultsInFilters ( ) const
pure virtual

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::SystemRewriteDriverFactory, net_instaweb::TestRewriteDriverFactory, and net_instaweb::FileRewriter.


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