#include "rewrite_driver_factory.h"
Classes | |
class | Deleter |
Public Types | |
enum | WorkerPoolName { kHtmlWorkers, kRewriteWorkers, kLowPriorityRewriteWorkers, kNumWorkerPools } |
Public Member Functions | |
RewriteDriverFactory (ThreadSystem *thread_system) | |
Takes ownership of thread_system. | |
RewriteDriverFactory () | |
Initializes thread_system_ using ThreadSystem::ComputeThreadSystem(). | |
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_url_namer (UrlNamer *url_namer) |
void | set_timer (Timer *timer) |
void | set_critical_images_finder (CriticalImagesFinder *finder) |
void | set_blink_critical_line_data_finder (BlinkCriticalLineDataFinder *finder) |
void | set_enable_property_cache (bool enabled) |
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_fetcher (UrlFetcher *url_fetcher) |
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 () |
Hasher * | hasher () |
FilenameEncoder * | filename_encoder () |
UrlNamer * | url_namer () |
UserAgentMatcher * | user_agent_matcher () |
StaticJavascriptManager * | static_javascript_manager () |
RewriteOptions * | default_options () |
Timer * | timer () |
HTTPCache * | http_cache () |
PropertyCache * | page_property_cache () |
PropertyCache * | client_property_cache () |
NamedLockManager * | lock_manager () |
QueuedWorkerPool * | WorkerPool (WorkerPoolName pool) |
Scheduler * | scheduler () |
UsageDataReporter * | usage_data_reporter () |
PropertyCache * | MakePropertyCache (const GoogleString &cache_key_prefix, CacheInterface *cache) const |
Builds a PropertyCache given a key prefix and a CacheInterface. | |
virtual UrlFetcher * | ComputeUrlFetcher () |
virtual UrlAsyncFetcher * | ComputeUrlAsyncFetcher () |
virtual HTTPCache * | ComputeHTTPCache () |
Computes the HTTPCache using the CacheInterface. This is not thread-safe. | |
ResourceManager * | CreateResourceManager () |
void | InitResourceManager (ResourceManager *resource_manager) |
virtual void | AddPlatformSpecificRewritePasses (RewriteDriver *driver) |
virtual void | AddPlatformSpecificDecodingPasses (RewriteDriver *driver) |
virtual void | ApplyPlatformSpecificConfiguration (RewriteDriver *driver) |
ThreadSystem * | thread_system () |
CriticalImagesFinder * | critical_images_finder () |
BlinkCriticalLineDataFinder * | blink_critical_line_data_finder () |
const StringSet & | created_directories () const |
bool | async_rewrites () |
RewriteStats * | rewrite_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 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_delete (Function *f) |
virtual bool | IsDebugClient (const GoogleString &ip) const |
Base method that returns true if the given ip is a debug ip. | |
virtual AbstractClientState * | NewClientState () |
Static Public Member Functions | |
static void | Initialize (Statistics *statistics) |
static void | Terminate () |
Protected Member Functions | |
bool | FetchersComputed () const |
void | StopCacheWrites () |
StringPiece | filename_prefix () |
bool | TerminateResourceManager (ResourceManager *rm) |
virtual UrlFetcher * | DefaultUrlFetcher ()=0 |
virtual UrlAsyncFetcher * | DefaultAsyncUrlFetcher ()=0 |
virtual MessageHandler * | DefaultHtmlParseMessageHandler ()=0 |
virtual MessageHandler * | DefaultMessageHandler ()=0 |
virtual FileSystem * | DefaultFileSystem ()=0 |
virtual Timer * | DefaultTimer ()=0 |
virtual Hasher * | NewHasher ()=0 |
virtual CriticalImagesFinder * | DefaultCriticalImagesFinder () |
Default implementation returns NULL. | |
virtual BlinkCriticalLineDataFinder * | DefaultBlinkCriticalLineDataFinder () |
Default implementation returns NULL. | |
virtual CacheInterface * | DefaultCacheInterface ()=0 |
Note: Returned CacheInterface should be thread-safe. | |
virtual NamedLockManager * | DefaultLockManager () |
virtual UrlNamer * | DefaultUrlNamer () |
virtual UserAgentMatcher * | DefaultUserAgentMatcher () |
virtual UsageDataReporter * | DefaultUsageDataReporter () |
virtual QueuedWorkerPool * | CreateWorkerPool (WorkerPoolName name) |
virtual int | LowPriorityLoadSheddingThreshold () const |
virtual Scheduler * | CreateScheduler () |
virtual void | FetcherSetupHooks () |
Called before creating the url fetchers. | |
virtual StringPiece | LockFilePrefix () |
CacheInterface * | cache_backend () |
Return memo-ized backend cache interface. | |
virtual CacheInterface * | property_cache_backend () |
Return the CacheInterface to be used by the property cache. | |
virtual StaticJavascriptManager * | DefaultStaticJavascriptManager () |
virtual void | SetupCohorts () |
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 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.
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::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 UrlFetcher* net_instaweb::RewriteDriverFactory::ComputeUrlFetcher | ( | ) | [virtual] |
Computes URL fetchers using the based 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 CreateResourceManager.
const StringSet& net_instaweb::RewriteDriverFactory::created_directories | ( | ) | const [inline] |
Returns the set of directories that we (our our subclasses) have created thus far.
ResourceManager* net_instaweb::RewriteDriverFactory::CreateResourceManager | ( | ) |
Threadsafe mechanism to create a managed ResourceManager. The ResourceManager is owned by the factory, and should not be deleted directly. Currently it is not possible to delete a resource manager except by deleting the entire factory.
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.
virtual QueuedWorkerPool* net_instaweb::RewriteDriverFactory::CreateWorkerPool | ( | WorkerPoolName | 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.
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::ApacheRewriteDriverFactory.
virtual StaticJavascriptManager* net_instaweb::RewriteDriverFactory::DefaultStaticJavascriptManager | ( | ) | [protected, virtual] |
Creates a StaticJavascriptManager instance. Default implementation creates an instance that disables serving of filter javascript via gstatic (gstatic.com is the domain google uses for serving static content).
virtual UrlFetcher* net_instaweb::RewriteDriverFactory::DefaultUrlFetcher | ( | ) | [protected, pure virtual] |
Implementors of RewriteDriverFactory must supply default definitions for each of these methods, although they may be overridden via set_ methods above.
Implemented in net_instaweb::ApacheRewriteDriverFactory, net_instaweb::FileRewriter, and net_instaweb::TestRewriteDriverFactory.
virtual UrlNamer* net_instaweb::RewriteDriverFactory::DefaultUrlNamer | ( | ) | [protected, virtual] |
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_delete | ( | 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.
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.
void net_instaweb::RewriteDriverFactory::InitResourceManager | ( | ResourceManager * | resource_manager | ) |
Initializes a ResourceManager that has been new'd directly. This allows 2-phase initialization if required. There is no need to call this if you use CreateResourceManager.
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()
virtual int net_instaweb::RewriteDriverFactory::LowPriorityLoadSheddingThreshold | ( | ) | const [protected, virtual] |
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 AbstractClientState* net_instaweb::RewriteDriverFactory::NewClientState | ( | ) | [virtual] |
Creates a new AbstractClientState object that must be populated. Subclasses can override this to create an appropriate AbstractClientState subclass if the default isn't acceptable.
virtual RewriteOptions* net_instaweb::RewriteDriverFactory::NewRewriteOptions | ( | ) | [virtual] |
Creates a new empty RewriteOptions object, with no default settings. Note that InitResourceManager() will copy the factory's default_options() into the resource manager's global_options(), but this method just provides a blank set of options.
Reimplemented in net_instaweb::ApacheRewriteDriverFactory, and net_instaweb::TestRewriteDriverFactory.
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.
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 ComputeResourceManager, which is thread-safe.
void net_instaweb::RewriteDriverFactory::set_base_url_fetcher | ( | UrlFetcher * | url_fetcher | ) |
You should either call set_base_url_fetcher, set_base_url_async_fetcher, or neither. Do not set both. If you want to enable real async fetching, because you are serving or want to model live traffic, then call set_base_url_async_fetcher before calling url_fetcher.
These fetchers may be used directly when serving traffic, or they may be aggregated with other fetchers (e.g. for slurping).
You cannot set either base URL fetcher once ComputeUrlFetcher 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 RewriteDriveFactory 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 ComputeUrlFetcher or ComputeUrlAsyncFetcher.
virtual void net_instaweb::RewriteDriverFactory::SetupCohorts | ( | ) | [inline, protected, virtual] |
Sets up the property cache cohorts. Should be called only after the property cache is initialized.
virtual void net_instaweb::RewriteDriverFactory::ShutDown | ( | ) | [virtual] |
Clean up all the factory-owned resources: fetchers, pools, Resource Managers, the Drivers owned by the Resource Managers, and worker threads.
Reimplemented in net_instaweb::ApacheRewriteDriverFactory.
Statistics* net_instaweb::RewriteDriverFactory::statistics | ( | ) | [inline] |
statistics (default is NullStatistics). This can be overridden by calling SetStatistics, either from subclasses or externally.
Reimplemented in net_instaweb::FileRewriter.
bool net_instaweb::RewriteDriverFactory::TerminateResourceManager | ( | ResourceManager * | rm | ) | [protected] |
Used by subclasses to indicate that a ResourceManager has been terminated. Returns true if this was the last resource manager known to this factory.
Timer* net_instaweb::RewriteDriverFactory::timer | ( | ) |
These accessors are *not* thread-safe. They must be called once prior to forking threads, e.g. via ComputeUrlFetcher().