Page Speed Optimization Libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
net_instaweb::Resource Class Referenceabstract
Inheritance diagram for net_instaweb::Resource:
net_instaweb::RefCounted< Resource > net_instaweb::CacheableResourceBase net_instaweb::DataUrlInputResource net_instaweb::FileInputResource net_instaweb::OutputResource net_instaweb::GoogleFontServiceInputResource net_instaweb::UrlInputResource net_instaweb::InlineOutputResource


class  AsyncCallback
class  FreshenCallback

Public Types

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

Public Member Functions

 Resource (const RewriteDriver *driver, const ContentType *type)
ServerContextserver_context () const
 Common methods across all deriviations.
virtual bool IsValidAndCacheable () const
bool is_authorized_domain ()
void set_is_authorized_domain (bool is_authorized)
bool IsSafeToRewrite (bool rewrite_uncacheable, GoogleString *reason) const
bool IsSafeToRewrite (bool rewrite_uncacheable) const
bool loaded () const
bool HttpStatusOk () const
void LoadAsync (NotCacheablePolicy not_cacheable_policy, const RequestContextPtr &request_context, AsyncCallback *callback)
virtual void RefreshIfImminentlyExpiring ()
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 ExtractUncompressedContents () const
size_t UncompressedContentsSize () const
StringPiece raw_contents () const
ResponseHeadersresponse_headers ()
const ResponseHeadersresponse_headers () const
const ContentTypetype () const
virtual void SetType (const ContentType *type)
bool IsContentsEmpty () const
StringPiece charset () const
 Note: this is empty if the header is not specified.
void set_charset (StringPiece c)
virtual GoogleString url () const =0
 Gets the absolute URL of the resource.
virtual bool has_url () const
virtual GoogleString UrlForDebug () const
 Override if resource does not have a URL.
virtual GoogleString cache_key () const
void DetermineContentType ()
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
FetchResponseStatus fetch_response_status ()
void set_fetch_response_status (FetchResponseStatus x)
virtual bool UseHttpCache () const =0
- Public Member Functions inherited from net_instaweb::RefCounted< Resource >
void Release ()
void AddRef ()
bool HasOneRef ()

Protected Member Functions

virtual void LoadAndCallback (NotCacheablePolicy not_cacheable_policy, const RequestContextPtr &request_context, AsyncCallback *callback)=0
void set_enable_cache_purge (bool x)
ResponseHeaders::VaryOption respect_vary () const
void set_respect_vary (ResponseHeaders::VaryOption x)
void set_proactive_resource_freshening (bool x)
void set_disable_rewrite_on_no_transform (bool x)

Protected Attributes

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


class ServerContext
class ReadAsyncHttpCacheCallback
 uses LoadAndCallback
class RewriteDriver
 for ReadIfCachedWithStatus
class UrlReadAsyncFetchCallback
class DummyResource

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.

virtual GoogleString net_instaweb::Resource::cache_key ( ) const

Gets the cache key for resource. This may be different from URL if the resource is e.g. UA-dependent.

Reimplemented in net_instaweb::CacheableResourceBase, and net_instaweb::InlineOutputResource.

int64 net_instaweb::Resource::CacheExpirationTimeMs ( ) const

Returns 0 if resource is not cacheable.

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.

StringPiece net_instaweb::Resource::ExtractUncompressedContents ( ) const

Returns the uncompressed contents stored in value_. Although this is marked as const, it mutates the internal state of this object and is not thread safe.

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

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 

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::CacheableResourceBase.

virtual bool net_instaweb::Resource::has_url ( ) const

Most resources should have URLs, but inline resources will not and should override this function.

Reimplemented in net_instaweb::InlineOutputResource.

bool net_instaweb::Resource::is_authorized_domain ( )

Whether the domain on which the resource is present is explicitly authorized or not. Unauthorized resources can be created for the purpose of inlining content into the HTML.

bool net_instaweb::Resource::IsSafeToRewrite ( bool  rewrite_uncacheable,
GoogleString reason 
) const

Answers question: Are we allowed to rewrite the contents now? Checks if valid and cacheable and if it has a no-transform header. rewrite_uncacheable is used to answer question whether the resource can be optimized even if it is not cacheable. If a resource cannot be rewritten, the reason is appended to *reason.

bool net_instaweb::Resource::IsSafeToRewrite ( bool  rewrite_uncacheable) const
TODO(jmaessen): Convert all remaining call sites to use a reason.
virtual bool net_instaweb::Resource::IsValidAndCacheable ( ) const

Checks if the contents are loaded and valid and also if the resource is up-to-date and cacheable by a proxy like us.

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

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 void net_instaweb::Resource::LoadAndCallback ( NotCacheablePolicy  not_cacheable_policy,
const RequestContextPtr request_context,
AsyncCallback callback 
protectedpure 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.

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

void net_instaweb::Resource::LoadAsync ( NotCacheablePolicy  not_cacheable_policy,
const RequestContextPtr request_context,
AsyncCallback callback 

Loads contents of resource asynchronously, calling callback when done. If the resource contents are already loaded into the object, the callback will be called directly, rather than asynchronously. The resource will be passed to the callback, with its contents and headers filled in.

This is implemented in terms of LoadAndCallback, taking care of the case where the resource is already loaded.

bool net_instaweb::Resource::loaded ( ) const
TODO(sligocki): Do we need these or can we just use IsValidAndCacheable everywhere?
virtual void net_instaweb::Resource::RefreshIfImminentlyExpiring ( )

If the resource is about to expire from the cache, re-fetches the resource in background to try to prevent it from expiring.

Base implementation does nothing, since most subclasses of this do not use caching.

Reimplemented in net_instaweb::CacheableResourceBase.

size_t net_instaweb::Resource::UncompressedContentsSize ( ) const

Returns the size of the the ExtractUncompressedContents(). Like ExtractUncompressedContents(), this method can mutate the internal state of the object and is not thread safe.

virtual bool net_instaweb::Resource::UseHttpCache ( ) const
pure 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.

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

Member Data Documentation

HTTPValue net_instaweb::Resource::fallback_value_

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: