Page Speed Optimization Libraries
1.13.35.1
|
#include "rewrite_driver_factory.h"
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. | |
MessageHandler * | html_parse_message_handler () |
MessageHandler * | message_handler () |
FileSystem * | file_system () |
NonceGenerator * | nonce_generator () |
Hasher * | hasher () |
UrlNamer * | url_namer () |
UserAgentMatcher * | user_agent_matcher () |
StaticAssetManager * | static_asset_manager () |
SHA1Signature * | signature () |
RewriteOptions * | default_options () |
virtual RewriteOptionsManager * | NewRewriteOptionsManager () |
Timer * | timer () |
NamedLockManager * | lock_manager () |
QueuedWorkerPool * | WorkerPool (WorkerPoolCategory pool) |
Scheduler * | scheduler () |
UsageDataReporter * | usage_data_reporter () |
const pagespeed::js::JsTokenizerPatterns * | js_tokenizer_patterns () const |
const std::vector< const UserAgentNormalizer * > & | user_agent_normalizers () |
virtual UrlAsyncFetcher * | ComputeUrlAsyncFetcher () |
ServerContext * | CreateServerContext () |
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 () |
RewriteStats * | rewrite_stats () |
virtual bool | HasWaveforms () const |
Returns true if the server supports waveforms in its status page. | |
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 RewriteOptions * | NewRewriteOptions () |
virtual RewriteOptions * | NewRewriteOptionsForQuery () |
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 ExperimentMatcher * | NewExperimentMatcher () |
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 UrlAsyncFetcher * | DefaultAsyncUrlFetcher ()=0 |
virtual MessageHandler * | DefaultHtmlParseMessageHandler ()=0 |
virtual MessageHandler * | DefaultMessageHandler ()=0 |
virtual FileSystem * | DefaultFileSystem ()=0 |
virtual NonceGenerator * | DefaultNonceGenerator () |
virtual Timer * | DefaultTimer () |
virtual SHA1Signature * | DefaultSignature () |
virtual Hasher * | NewHasher ()=0 |
virtual ServerContext * | NewServerContext ()=0 |
virtual ServerContext * | NewDecodingServerContext ()=0 |
virtual CriticalImagesFinder * | DefaultCriticalImagesFinder (ServerContext *server_context) |
virtual CriticalSelectorFinder * | DefaultCriticalSelectorFinder (ServerContext *server_context) |
virtual NamedLockManager * | DefaultLockManager () |
virtual UrlNamer * | DefaultUrlNamer () |
virtual UserAgentMatcher * | DefaultUserAgentMatcher () |
virtual UsageDataReporter * | DefaultUsageDataReporter () |
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) |
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) |
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.
|
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 |
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.
|
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 |
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 |
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.
|
inline |
Returns the set of directories that we (our our subclasses) have created thus far.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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 | ( | ) |
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 |
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 |
Initializes statistics variables. This must be done at process startup to enable shared memory segments in Apache to be set up.
|
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.
|
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()
|
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
|
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 |
Creates an ExperimentMatcher, which is used to match clients or sessions to a specific experiment.
|
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 |
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.
|
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.
|
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.
|
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 |
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.
|
inline |
statistics (default is NullStatistics). This can be overridden by calling SetStatistics, either from subclasses or externally.
|
inline |
Queues an object for deletion at the last phase of RewriteDriverFactory destruction.
|
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().
|
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.