net_instaweb::Resource Class Reference

Inheritance diagram for net_instaweb::Resource:
net_instaweb::RefCounted< Resource > RefCountedThreadSafe net_instaweb::DataUrlInputResource net_instaweb::FileInputResource net_instaweb::OutputResource net_instaweb::UrlInputResource

List of all members.

Classes

class  AsyncCallback
class  FreshenCallback

Public Types

enum  HashHint { kOmitInputHash, kIncludeInputHash }
enum  NotCacheablePolicy { kLoadEvenIfNotCacheable, kReportFailureIfNotCacheable }

Public Member Functions

 Resource (ResourceManager *resource_manager, const ContentType *type)
ResourceManagerresource_manager () const
 Common methods across all deriviations.
virtual bool IsValidAndCacheable () const
bool loaded () const
bool HttpStatusOk () const
GoogleString ContentsHash () const
void AddInputInfoToPartition (HashHint suggest_include_content_hash, int index, CachedResult *partition)
virtual void FillInPartitionInputInfo (HashHint suggest_include_content_hash, InputInfo *input)
void FillInPartitionInputInfoFromResponseHeaders (const ResponseHeaders &headers, InputInfo *input)
int64 CacheExpirationTimeMs () const
StringPiece contents () const
ResponseHeadersresponse_headers ()
const ResponseHeadersresponse_headers () const
const ContentTypetype () const
virtual void SetType (const ContentType *type)
StringPiece charset () const
 Note: this is empty if the header is not specified.
void set_charset (StringPiece c)
virtual bool IsCacheableTypeOfResource () const
virtual GoogleString url () const =0
 Gets the absolute URL of the resource.
void DetermineContentType ()
virtual const RewriteOptionsrewrite_options () const =0
bool Link (HTTPValue *source, MessageHandler *handler)
virtual void Freshen (FreshenCallback *callback, MessageHandler *handler)
void LinkFallbackValue (HTTPValue *value)
 Links the stale fallback value that can be used in case a fetch fails.
void set_is_background_fetch (bool x)
bool is_background_fetch () const

Protected Member Functions

 REFCOUNT_FRIEND_DECLARATION (Resource)
virtual bool Load (MessageHandler *message_handler)=0
virtual void LoadAndCallback (NotCacheablePolicy not_cacheable_policy, AsyncCallback *callback, MessageHandler *message_handler)

Protected Attributes

ResourceManagerresource_manager_
const ContentTypetype_
GoogleString charset_
HTTPValue value_
 contains contents and meta-data
ResponseHeaders response_headers_
HTTPValue fallback_value_

Friends

class ResourceManager
class RewriteDriver
 for ReadIfCachedWithStatus
class UrlReadAsyncFetchCallback
class ResourceManagerHttpCallback

Member Enumeration Documentation

This enumerates possible follow-up behaviors when a requested resource was uncacheable.


Member Function Documentation

void net_instaweb::Resource::AddInputInfoToPartition ( HashHint  suggest_include_content_hash,
int  index,
CachedResult *  partition 
)

Adds a new InputInfo object representing this resource to CachedResult, assigning the index supplied.

int64 net_instaweb::Resource::CacheExpirationTimeMs (  )  const

Returns 0 if resource is not cacheable.

Todo:
TODO(sligocki): Look through callsites and make sure this is being interpreted correctly.
GoogleString net_instaweb::Resource::ContentsHash (  )  const

Computes (with non-trivial cost) a hash of contents of a loaded resource. Precondition: IsValidAndCacheable(). Warning: this uses contents_hasher_ and not the primary hasher, unlike the hashes computed by OutputResource for naming purposes on writes.

void net_instaweb::Resource::DetermineContentType (  ) 

Computes the content-type (and charset) based on response_headers and extension, and sets it via SetType.

virtual void net_instaweb::Resource::FillInPartitionInputInfo ( HashHint  suggest_include_content_hash,
InputInfo *  input 
) [virtual]

Set CachedResult's input info used for expiration validation. If include_content_hash is kIncludeInputHash, and it makes sense for the Resource type to check if resource changed based by content hash (e.g. it would be pointless for data:), the hash of resource's contents should also be set on 'input'.

Default one sets resource type as CACHED and sets an expiration timestamp, last modified, date, and, if requested, content hash. If a derived class has a different criterion for validity, override this method.

Reimplemented in net_instaweb::DataUrlInputResource, and net_instaweb::FileInputResource.

virtual void net_instaweb::Resource::Freshen ( FreshenCallback callback,
MessageHandler handler 
) [virtual]

Freshen a soon-to-expire resource so that we minimize the number of cache misses when serving live traffic. Note that callback may be NULL, and all subclasses must handle this.

Reimplemented in net_instaweb::UrlInputResource.

virtual bool net_instaweb::Resource::IsValidAndCacheable (  )  const [virtual]

Answers question: Are we allowed to rewrite the contents now?

Checks if the contents are loaded and valid and also if the resource is up-to-date and cacheable enought to be rewritten by us right now.

Reimplemented in net_instaweb::DataUrlInputResource, net_instaweb::FileInputResource, and net_instaweb::UrlInputResource.

bool net_instaweb::Resource::Link ( HTTPValue source,
MessageHandler handler 
)

Links in the HTTP contents and header from a fetched value. The contents are linked by sharing. The HTTPValue also contains a serialization of the headers, and this routine parses them into response_headers_ and return whether that was successful.

virtual bool net_instaweb::Resource::Load ( MessageHandler message_handler  )  [protected, pure virtual]

Load the resource asynchronously, storing ResponseHeaders and contents in cache. Returns true, if the resource is already loaded or loaded synchronously. Never reports uncacheable resources.

Implemented in net_instaweb::DataUrlInputResource, net_instaweb::FileInputResource, net_instaweb::OutputResource, and net_instaweb::UrlInputResource.

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

Same as Load, but calls a callback when finished. The ResourcePtr used to construct 'callback' must be the same as the resource used to invoke this method. If the resource is uncacheable, will only return true if not_cacheable_policy == kLoadEvenIfNotCacheable.

Reimplemented in net_instaweb::UrlInputResource.

bool net_instaweb::Resource::loaded (  )  const [inline]
Todo:
TODO(sligocki): Do we need these or can we just use IsValidAndCacheable everywhere?
virtual const RewriteOptions* net_instaweb::Resource::rewrite_options (  )  const [pure virtual]

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

Implemented in net_instaweb::DataUrlInputResource, net_instaweb::FileInputResource, net_instaweb::OutputResource, and net_instaweb::UrlInputResource.


Member Data Documentation

A stale value that can be used in case we aren't able to fetch a fresh version of the resource. Note that this should only be used if it is not empty.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Tue May 29 16:34:03 2012 for Page Speed Optimization Libraries by  doxygen 1.6.3