Page Speed Optimization Libraries  1.5.27.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Protected Member Functions | Friends
net_instaweb::OutputResource Class Reference
Inheritance diagram for net_instaweb::OutputResource:
net_instaweb::Resource

List of all members.

Public Member Functions

 OutputResource (ServerContext *server_context, const StringPiece &resolved_base, const StringPiece &unmapped_base, const StringPiece &original_base, const ResourceNamer &resource_id, const RewriteOptions *options, OutputResourceKind kind)
virtual void LoadAndCallback (NotCacheablePolicy not_cacheable_policy, AsyncCallback *callback, MessageHandler *handler)
virtual GoogleString url () const
GoogleString UrlEvenIfHashNotSet ()
void DumpToDisk (MessageHandler *handler)
NamedLockCreationLock ()
bool TryLockForCreation ()
void LockForCreation (QueuedWorkerPool::Sequence *worker, Function *callback)
void DropCreationLock ()
 Drops the lock created by above, if any.
void UpdateCachedResultPreservingInputInfo (CachedResult *to_update) const
virtual GoogleString name_key () const
GoogleString HttpCacheKey () const
const GoogleString & resolved_base () const
 output-specific
const GoogleString & unmapped_base () const
const GoogleString & original_base () const
const ResourceNamerfull_name () const
ResourceNamermutable_full_name ()
StringPiece name () const
StringPiece experiment () const
StringPiece suffix () const
StringPiece filter_prefix () const
StringPiece hash () const
bool has_hash () const
GoogleString decoded_base () const
bool IsWritten () const
virtual void SetType (const ContentType *type)
 Sets the type of the output resource, and thus also its suffix.
const CachedResult * cached_result () const
CachedResult * EnsureCachedResultCreated ()
void clear_cached_result ()
void set_cached_result (CachedResult *cached_result)
CachedResult * ReleaseCachedResult ()
 Transfers up ownership of any cached result and clears pointer to it.
OutputResourceKind kind () const
bool has_lock () const
void SetWritten (bool written)
 This is called by CacheCallback::Done in rewrite_driver.cc.
virtual const RewriteOptionsrewrite_options () const
WriterBeginWrite (MessageHandler *message_handler)
void EndWrite (MessageHandler *message_handler)
virtual bool UseHttpCache () const

Protected Member Functions

 REFCOUNT_FRIEND_DECLARATION (OutputResource)

Friends

class RewriteDriver
 for ReadIfCachedWithStatus
class ServerContext
class ServerContextTest

Constructor & Destructor Documentation

net_instaweb::OutputResource::OutputResource ( ServerContext server_context,
const StringPiece &  resolved_base,
const StringPiece &  unmapped_base,
const StringPiece &  original_base,
const ResourceNamer resource_id,
const RewriteOptions options,
OutputResourceKind  kind 
)

Construct an OutputResource. For the moment, we pass in type redundantly even though full_name embeds an extension. This reflects current code structure rather than a principled stand on anything.

Todo:
TODO(jmaessen): remove redundancy.

The 'options' argument can be NULL. This is done in the Fetch path because that field is only used for domain sharding, and during the fetch, further domain makes no sense.

Parameters:
original_baseaka source domain
resource_idaka cnamed domain

Member Function Documentation

Interface for directly setting the value of the resource. It must not have been set otherwise! The return value of BeginWrite is owned by this OutputResource.

const CachedResult* net_instaweb::OutputResource::cached_result ( ) const [inline]

Whenever output resources are created via RewriteDriver (except DecodeOutputResource) it looks up cached information on any previous creation of that resource, including the full filename and any filter-specific metadata. If such information is available, this method will return non-NULL.

Note: cached_result() will also be non-NULL if you explicitly create the result from a filter by calling EnsureCachedResultCreated()

The output is const because we do not check that the CachedResult has not been written. If you want to modify the CachedResult, use EnsureCachedResultCreated instead.

Lazily initialize and return creation_lock_. If the resource is expensive to create, this lock should be held during its creation to avoid multiple rewrites happening at once. The lock will be unlocked on destruction, DropCreationLock, or EndWrite (called from RewriteDriver::Write)

Some output resources have mangled names derived from input resource(s), such as when combining CSS files. When we need to regenerate the output resource given just its URL we need to convert the URL back to its constituent input resource URLs. Our url() method can return a modified version of the input resources' host and path if our resource manager has a non-standard url_namer(), so when trying to regenerate the input resources' URL we need to reverse that modification. Note that the default UrlNamer class doesn't do any modification, and that the decoding of the leaf names is done separetly by the UrlMultipartEncoder class.

Save resource contents to disk, for testing and debugging purposes. Precondition: the resource contents must be fully set. The resource will be saved under the resource manager's filename_prefix() using with URL escaped using its filename_encoder().

If there is no cached output information, creates an empty one, without any information filled in (so no url(), or timestamps).

The primary use of this method is to let filters store any metadata they want before calling RewriteDriver::Write. This never returns null. We will DCHECK that the cached result has not been written.

Builds a canonical URL in a form for use with the HTTP cache. The DomainLawyer from options is used to find the proper domain in case there is a fetch for the unsharded form, or the wrong shard.

For example, if you have a resource styles.css ModPagespeedMapRewriteDomain master alias ModPagespeedShardDomain master shard1,shard2 then all HTTP cache puts/gets will use the key "http://master/style.css", which can be obtained from an output resource using this method.

bool net_instaweb::OutputResource::IsWritten ( ) const [inline]

In a scalable installation where the sprites must be kept in a database, we cannot serve HTML that references new resources that have not been committed yet, and committing to a database may take too long to block on the HTML rewrite. So we will want to refactor this to check to see whether the desired resource is already known. For now we'll assume we can commit to serving the resource during the HTML rewriter.

virtual void net_instaweb::OutputResource::LoadAndCallback ( NotCacheablePolicy  not_cacheable_policy,
AsyncCallback callback,
MessageHandler message_handler 
) [virtual]

Load the resource asynchronously, storing ResponseHeaders and contents in object. Calls 'callback' when finished. The ResourcePtr used to construct 'callback' must be the same as the resource used to invoke this method.

Setting not_cacheable_policy to kLoadEvenIfNotCacheable will permit it to consider loading to be successful on Cache-Control:private and Cache-Control:no-cache resources. It should not affect /whether/ the callback gets involved, only whether it gets true or false.

Implements net_instaweb::Resource.

Attempt to obtain a named lock for the resource, scheduling the callback in the provided worker if we do so and scheduling a cancellation if locking times out.

virtual GoogleString net_instaweb::OutputResource::name_key ( ) const [virtual]

The NameKey describes the source url and rewriter used, without hash and content type information. This is used to find previously-computed filter results whose output hash and content type is unknown. The full name of a resource is of the form path/prefix.encoded_resource_name.hash.extension we know prefix and name, but not the hash, and we don't always even have the extension, which might have changes as the result of, for example image optimization (e.g. gif->png). But We can "remember" the hash/extension for as long as the origin URL was cacheable. So we construct this as a key: path/prefix.encoded_resource_name and use that to map to the hash-code and extension. If we know the hash-code then we may also be able to look up the contents in the same cache.

virtual const RewriteOptions* net_instaweb::OutputResource::rewrite_options ( ) const [inline, virtual]

Obtain rewrite options for this. Any resources which return true for UseHttpCache() but don't unconditionally return true for loaded() must override this in a useful way. Used in cache invalidation.

Implements net_instaweb::Resource.

void net_instaweb::OutputResource::set_cached_result ( CachedResult *  cached_result) [inline]

Sets the cached-result to an already-existing, externally owned buffer. We need to make sure not to free it on destruction.

Attempt to obtain a named lock for the resource without blocking. Return true if we do so.

Update the passed in CachedResult from the CachedResult in this OutputResource.

virtual GoogleString net_instaweb::OutputResource::url ( ) const [virtual]

NOTE: url() will crash if resource has does not have a hash set yet. Specifically, this will occur if the resource has not been completely written yet. Before that point, the final URL cannot be known.

Note: the OutputResource will never have a query string, even when ModPagespeedAddOptionsToUrls is on.

Implements net_instaweb::Resource.

Returns the same as url(), but with a spoofed hash in case no hash was set yet. Use this for error reporting, etc. where you do not know whether the output resource has a valid hash yet.

virtual bool net_instaweb::OutputResource::UseHttpCache ( ) const [inline, virtual]

Returns whether this type of resource should use the HTTP Cache. This method is based on properties of the class, not the resource itself, and helps short-circuit pointless cache lookups for file-based and data URLs.

Implements net_instaweb::Resource.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines