#include "resource_slot.h"
Public Member Functions | |
ResourceSlot (const ResourcePtr &resource) | |
ResourcePtr | resource () const |
void | SetResource (const ResourcePtr &resource) |
void | set_disable_rendering (bool x) |
bool | disable_rendering () const |
void | set_should_delete_element (bool x) |
bool | should_delete_element () const |
bool | was_optimized () const |
void | set_was_optimized (bool x) |
Marks the slot as having been optimized. | |
virtual void | Render ()=0 |
virtual void | Finished () |
RewriteContext * | LastContext () const |
void | AddContext (RewriteContext *context) |
Adds a new context to this slot. | |
void | DetachContext (RewriteContext *context) |
virtual GoogleString | LocationString ()=0 |
Protected Member Functions | |
REFCOUNT_FRIEND_DECLARATION (ResourceSlot) |
A slot is a place in a web-site resource a URL is found, and may be rewritten. Types of slots include HTML element attributes and CSS background URLs. In principle they could also include JS ajax requests, although this is NYI.
void net_instaweb::ResourceSlot::DetachContext | ( | RewriteContext * | context | ) |
Detaches a context from the slot. This must be the first or last context that was added.
virtual void net_instaweb::ResourceSlot::Finished | ( | ) | [inline, virtual] |
Called after all contexts have had a chance to Render. This is especially useful for cases where Render was never called but you want something to be done to all slots.
Reimplemented in net_instaweb::CssResourceSlot.
RewriteContext* net_instaweb::ResourceSlot::LastContext | ( | ) | const |
Return the last context to have been added to this slot. Returns NULL if no context has been added to the slot so far.
virtual GoogleString net_instaweb::ResourceSlot::LocationString | ( | ) | [pure virtual] |
Returns a human-readable description of where this slot occurs, for use in log messages.
Implemented in net_instaweb::AjaxRewriteResourceSlot, net_instaweb::CssResourceSlot, net_instaweb::FetchResourceSlot, and net_instaweb::HtmlResourceSlot.
virtual void net_instaweb::ResourceSlot::Render | ( | ) | [pure virtual] |
Render is not thread-safe. This must be called from the thread that owns the DOM or CSS file.
Implemented in net_instaweb::AjaxRewriteResourceSlot, net_instaweb::CssResourceSlot, net_instaweb::FetchResourceSlot, and net_instaweb::HtmlResourceSlot.
void net_instaweb::ResourceSlot::set_disable_rendering | ( | bool | x | ) | [inline] |
If disable_rendering is true, this slot will do nothing on rendering, neither changing the URL or deleting any elements. This is intended for use of filters which do the entire work in the Context.
void net_instaweb::ResourceSlot::set_should_delete_element | ( | bool | x | ) | [inline] |
Determines whether rendering the slot deletes the HTML Element. For example, in the CSS combine filter we want the Render to rewrite the first <link href>="">, but delete all the other <link>s.
void net_instaweb::ResourceSlot::SetResource | ( | const ResourcePtr & | resource | ) |
Note that while slots can be mutated by multiple threads; they are implemented with thread-safety in mind -- only mainline render their results back into the DOM.
For example, SetResource may be run from a helper-thread, but we would not want that threaded mutation to propagate instantly back into the HTML or CSS DOM. We buffer the changes in the ResoureSlot and then render them in the request thread, synchronous to the HTML filter execution.
bool net_instaweb::ResourceSlot::was_optimized | ( | ) | const [inline] |
Returns true if any of the contexts touching this slot optimized it successfully. This in particular includes the case where a call to RewriteContext::Rewrite() on a partition containing this slot returned kRewriteOk.