Page Speed Optimization Libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | List of all members
net_instaweb::CombiningFilter::Context Class Reference
Inheritance diagram for net_instaweb::CombiningFilter::Context:

Public Member Functions

 Context (RewriteDriver *driver, CombiningFilter *filter, MockScheduler *scheduler)
void AddElement (HtmlElement *element, HtmlElement::Attribute *href, const ResourcePtr &resource)
- Public Member Functions inherited from net_instaweb::RewriteContext
 RewriteContext (RewriteDriver *driver, RewriteContext *parent, ResourceContext *resource_context)
int num_slots () const
ResourceSlotPtr slot (int index) const
int num_outputs () const
OutputResourcePtr output (int i) const
int num_output_partitions () const
const CachedResult * output_partition (int i) const
CachedResult * mutable_output_partition (int i)
bool chained () const
void AddSlot (const ResourceSlotPtr &slot)
void RemoveLastSlot ()
void AddNestedContext (RewriteContext *context)
void CallFetchInputs ()
void CallLockFailed ()
void CallStartFetchImpl ()
void Initiate ()
bool Fetch (const OutputResourcePtr &output_resource, AsyncFetch *fetch, MessageHandler *message_handler)
bool slow () const
bool is_metadata_cache_miss () const
 This particular rewrite was a metadata cache miss.
bool has_parent () const
 Returns true if this is a nested rewriter.
bool IsNestedIn (StringPiece id) const
void CheckNotFrozen ()
RewriteContextparent ()
 Allows a nested rewriter to walk up its parent hierarchy.
const RewriteContextparent () const
int num_nested () const
 Accessors for the nested rewrites.
RewriteContextnested (int i) const
RewriteDriverDriver () const
void set_force_rewrite (bool x)
 If called with true, forces a rewrite and re-generates the output.
bool rewrite_uncacheable () const
void set_rewrite_uncacheable (bool rewrite_uncacheable)
const ResourceContext * resource_context () const
GoogleString ToString () const
 Returns debug information about this RewriteContext.
GoogleString ToStringWithPrefix (StringPiece prefix) const

Protected Member Functions

virtual bool Partition (OutputPartitions *partitions, OutputResourceVector *outputs)
virtual void Rewrite (int partition_index, CachedResult *partition, const OutputResourcePtr &output)
virtual bool OptimizationOnly () const
void DoRewrite (int partition_index, CachedResult *partition, OutputResourcePtr output)
bool PolicyPermitsRendering () const override
virtual void Render ()
virtual void WillNotRender ()
virtual void Cancel ()
void DisableRemovedSlots (const CachedResult *partition)
virtual const UrlSegmentEncoderencoder () const
virtual const char * id () const
 Returns the filter ID.
virtual OutputResourceKind kind () const
- Protected Member Functions inherited from net_instaweb::RewriteContext
ServerContextFindServerContext () const
const RewriteOptionsOptions () const
OutputPartitions * partitions ()
void AddRecheckDependency ()
virtual void PartitionAsync (OutputPartitions *partitions, OutputResourceVector *outputs)
void PartitionDone (RewriteResult result)
void CrossThreadPartitionDone (RewriteResult result)
void RewriteDone (RewriteResult result, int partition_index)
virtual bool SendFallbackResponse (StringPiece output_url_base, StringPiece contents, AsyncFetch *async_fetch, MessageHandler *handler)
void StartNestedTasks ()
virtual void Harvest ()
bool AreOutputsAllowedByCsp (CspDirective role) const
 Helper that checks that all output resources are OK with CSP as given role.
virtual GoogleString CacheKeySuffix () const
virtual GoogleString UserAgentCacheKey (const ResourceContext *context) const
virtual void EncodeUserAgentIntoResourceContext (ResourceContext *context)
void AttachDependentRequestTrace (const StringPiece &label)
RequestTracedependent_request_trace ()
void TracePrintf (const char *fmt,...)
virtual void StartFetchReconstruction ()
void DetachFetch ()
virtual bool DecodeFetchUrls (const OutputResourcePtr &output_resource, MessageHandler *message_handler, GoogleUrlStarVector *url_vector)
virtual void FixFetchFallbackHeaders (const CachedResult &cached_result, ResponseHeaders *headers)
virtual void FetchCallbackDone (bool success)
virtual void FetchTryFallback (const GoogleString &url, const StringPiece &hash)
void Freshen ()
 Freshens resources proactively to avoid expiration in the near future.
bool notify_driver_on_fetch_done () const
void set_notify_driver_on_fetch_done (bool value)
AsyncFetchasync_fetch ()
 Note that the following must only be called in the fetch flow.
bool FetchContextDetached ()
 Is fetch_ detached? Only call this in the fetch flow.
MessageHandlerfetch_message_handler ()
 The message handler for the fetch.
bool stale_rewrite () const
 Indicates whether we are serving a stale rewrite.
virtual int64 GetRewriteDeadlineAlarmMs () const
virtual bool CreationLockBeforeStartFetch () const
 Should the context call LockForCreation before checking the cache?
virtual bool FailOnHashMismatch () const
virtual bool ScheduleViaCentralController ()
virtual bool ScheduleNestedContextViaCentalController () const
void ObtainLockForCreation (ServerContext *server_context, Function *callback)
void ReleaseCreationLock (bool succeeded)

Additional Inherited Members

- Public Types inherited from net_instaweb::RewriteContext
typedef std::vector< InputInfo * > InputInfoStarVector
- Static Public Member Functions inherited from net_instaweb::RewriteContext
static void InitStats (Statistics *stats)
 Initializes statistics.
- Static Public Attributes inherited from net_instaweb::RewriteContext
static const char kNumRewritesAbandonedForLockContention []
static const char kNumDeadlineAlarmInvocations []
static const char kHashMismatchMessage []
- Protected Types inherited from net_instaweb::RewriteContext
typedef std::vector< GoogleUrl * > GoogleUrlStarVector
- Static Protected Member Functions inherited from net_instaweb::RewriteContext
static bool LookupMetadataForOutputResourceImpl (OutputResourcePtr output_resource, const GoogleUrl &gurl, RewriteContext *rewrite_context, RewriteDriver *driver, GoogleString *error_out, CacheLookupResultCallback *callback)

Member Function Documentation

virtual void net_instaweb::CombiningFilter::Context::Cancel ( )

This method is invoked (in Rewrite thread) if this context got canceled due to an earlier filter sharing a slot with it having called set_disable_further_processing. Default implementation does nothing.

Reimplemented from net_instaweb::RewriteContext.

virtual const UrlSegmentEncoder* net_instaweb::CombiningFilter::Context::encoder ( ) const

This final set of protected methods can be optionally overridden by subclasses. All RewriteContexts define how they encode URLs and other associated information needed for a rewrite into a URL. The default implementation handles a single URL with no extra data. The RewriteContext owns the encoder.

TODO(jmarantz): remove the encoder from RewriteFilter.

Reimplemented from net_instaweb::RewriteContext.

virtual OutputResourceKind net_instaweb::CombiningFilter::Context::kind ( ) const

Rewrites come in three flavors, as described in output_resource_kind.h, so this method must be defined by subclasses to indicate which it is.

For example, we will avoid caching output_resource content in the HTTP cache for rewrites that are so quick to complete that it's fine to do the rewrite on every request. extend_cache is obviously in this category, and it's arguable we could treat js minification that way too (though we don't at the moment).

Implements net_instaweb::RewriteContext.

virtual bool net_instaweb::CombiningFilter::Context::OptimizationOnly ( ) const

If this returns true, running the rewriter isn't required for correctness of the page, so the engine will be permitted to drop the rewrite if needed to preserve system responsiveness.

Reimplemented from net_instaweb::RewriteContext.

virtual bool net_instaweb::CombiningFilter::Context::Partition ( OutputPartitions *  partitions,
OutputResourceVector *  outputs 

Partitions the input resources into one or more outputs. Return 'true' if the partitioning could complete (whether a rewrite was found or not), false if the attempt was abandoned and no conclusion can be drawn.

Note that if partitioner finds that the resources are not rewritable, it will still return true; it will simply have an empty inputs-array in OutputPartitions and leave 'outputs' unmodified. 'false' is only returned if the subclass skipped the rewrite attempt due to a lock conflict.

You must override one of Partition() or PartitionAsync(). Partition() is normally fine unless you need to do computations that can take a noticeable amount of time, since there are some scenarios under which page output may end up being held up for a partitioning step. If you do need to do something computationally expensive in partitioning steps, override PartitionAsync() instead.

Reimplemented from net_instaweb::RewriteContext.

bool net_instaweb::CombiningFilter::Context::PolicyPermitsRendering ( ) const

This method gives the context a chance to verify that rendering the result is consistent with the current document's (Content Security) Policy, which may be different than that of the page for which the result was first computed + cached. Most subclasses can just call AreOutputsAllowedByCsp(), with appropriate role.

Implements net_instaweb::RewriteContext.

virtual void net_instaweb::CombiningFilter::Context::Render ( )

Performs rendering activities that span multiple HTML slots. For example, in a filter that combines N slots to 1, N-1 of the HTML elements might need to be removed. That can be performed in Render(). This method is optional; the base-class implementation is empty.

Note that unlike Harvest(), this method runs in the HTML thread (for top-level rewrites), and only runs if the rewrite completes prior to the rewrite-deadline. If the rewrite does make it by the deadline, RewriteContext::Render() will be invoked regardless of whether any slots were actually optimized successfully.

Reimplemented from net_instaweb::RewriteContext.

virtual void net_instaweb::CombiningFilter::Context::Rewrite ( int  partition_index,
CachedResult *  partition,
const OutputResourcePtr output 

Takes a completed rewrite partition and rewrites it. When complete, implementations should call RewriteDone(kRewriteOk) if they successfully created an output resource using RewriteDriver::Write, and RewriteDone(kRewriteFailed) if they didn't. They may also call RewriteDone(kTooBusy) in case system load/resource usage makes it dangerous for the filter to do optimization at this time.

Any information about the inputs or output that may be needed to update the containing document should be stored inside the CachedResult.

If implementors wish to rewrite resources referred to from within the inputs (e.g. images in CSS), they may create nested rewrite contexts and call AddNestedContext() on each, and then StartNestedTasks() when all have been added.

TODO(jmarantz): check for resource completion from a different thread (while we were waiting for resource fetches) when Rewrite gets called.

Implements net_instaweb::RewriteContext.

virtual void net_instaweb::CombiningFilter::Context::WillNotRender ( )

Notifies the subclass that the filter will not be able to render its output to the containing HTML document, because it wasn't ready in time. Note that neither Render() nor WillNotRender() may be called in case this rewrite got canceled due to disable_further_processing(), or in case Partition() failed. This is called from the HTML thread, but should only be used for read access, and subclasss implementations are required to be reasonably quick since it's called with rewrite_mutex() held. It's called after any earlier contexts in filter order had completed their rendering, if any, but with no order guarantees with respect to other WillNotRender() invocations.

Reimplemented from net_instaweb::RewriteContext.

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