|
Page Speed Optimization Libraries
1.13.35.1
|
#include "async_fetch_with_lock.h"
Public Member Functions | |
| AsyncFetchWithLock (const Hasher *hasher, const RequestContextPtr &request_context, const GoogleString &url, const GoogleString &cache_key, NamedLockManager *lock_manager, MessageHandler *message_handler) | |
| void | Start (UrlAsyncFetcher *fetcher) |
| const GoogleString & | url () const |
| Url to be fetched. | |
| const GoogleString & | cache_key () const |
| Cache key to be locked. | |
Public Member Functions inherited from net_instaweb::AsyncFetch | |
| AsyncFetch (const RequestContextPtr &request_ctx) | |
| void | HeadersComplete () |
| void | Done (bool success) |
| virtual bool | Write (const StringPiece &content, MessageHandler *handler) |
| virtual bool | Flush (MessageHandler *handler) |
| virtual bool | IsCachedResultValid (const ResponseHeaders &headers) |
| RequestHeaders * | request_headers () |
| void | set_request_headers (RequestHeaders *headers) |
| void | SetRequestHeadersTakingOwnership (RequestHeaders *headers) |
| Same as above, but takes ownership. | |
| const RequestHeaders * | request_headers () const |
| ResponseHeaders * | response_headers () |
| See doc for request_headers and set_request_headers. | |
| void | set_response_headers (ResponseHeaders *headers) |
| ResponseHeaders * | extra_response_headers () |
| void | set_extra_response_headers (ResponseHeaders *headers) |
| virtual bool | IsBackgroundFetch () const |
| virtual void | Reset () |
| bool | headers_complete () const |
| bool | content_length_known () const |
| int64 | content_length () const |
| void | set_content_length (int64 x) |
| GoogleString | LoggingString () |
| virtual const RequestContextPtr & | request_context () |
| virtual AbstractLogRecord * | log_record () |
| void | FixCacheControlForGoogleCache () |
Public Member Functions inherited from net_instaweb::Writer | |
| virtual bool | Dump (Writer *writer, MessageHandler *message_handler) |
Protected Member Functions | |
| virtual bool | ShouldYieldToRedundantFetchInProgress ()=0 |
| virtual void | Finalize (bool lock_failure, bool success) |
| virtual void | StartFetch (UrlAsyncFetcher *fetcher, MessageHandler *handler)=0 |
| virtual void | HandleDone (bool success) |
| virtual void | HandleHeadersComplete () |
| virtual bool | HandleWrite (const StringPiece &content, MessageHandler *handler) |
| virtual bool | HandleFlush (MessageHandler *handler) |
Friends | |
| class | RewriteContextTest |
Additional Inherited Members | |
Static Public Member Functions inherited from net_instaweb::AsyncFetch | |
| static bool | IsGoogleCacheVia (StringPiece via_value) |
Static Public Attributes inherited from net_instaweb::AsyncFetch | |
| static const int | kContentLengthUnknown = -1 |
AsyncFetch object which tries to acquire lock before fetching content. Start() will returns false, if it fails to acquire lock. Note that acquiring a lock will fail if same resource is fetching somewhere else. Caller will call the Start() which will try to acquire a lock and internally call StartFetch() which actually triggers a fetch. Sequence of the events: 1) Caller calls AsyncFetchWithLock::Start(). 2) Start() will try to acquire lock. If lock is acquired successfully, AsyncFetchWithLock::StartFetch() will be called, otherwise AsyncFetchWithLock::Finalize() is called with lock_failure as true and success as false and StartFetch() returns false and async_fetch_with_lock object will be deleted. Note: StartFetch() will be called in case of lock failure only if ShouldYieldToRedundantFetchInProgress() returns false. 3) Subclass defines StartFetch() function which actually triggers UrlAsyncFetcher::Fetch(). 4) Subclass can override HandleHeadersComplete(), HandleWrite(), HandleFlush() and HandleDone() for special handling during fetch. HandleDone() also releases the lock. Note: If any of these functions is overridden, then AsyncFetchWithLock::HandleXXX should also be called. 5) Lastly AsyncFetchWithLock::Finalize() is called just before async_fetch delete itself.
|
protectedvirtual |
Finalize is called either when we fail to acquire acquire a lock or at the end of request after releasing the lock.
|
protectedvirtual |
Releases the lock. If subclass overrides the function, then, it should also call AsyncFetchWithLock::HandleDone()
Implements net_instaweb::AsyncFetch.
|
protectedvirtual |
HandleHeadersComplete(), HandleWrite() and HandleFlush() are no-op functions and any special handling can be done in subclass and must call the superclass function before returning.
Implements net_instaweb::AsyncFetch.
|
protectedpure virtual |
If someone is already fetching this resource, should we yield to them and try again later? If so, return true. Otherwise, if we must fetch the resource regardless, return false.
| void net_instaweb::AsyncFetchWithLock::Start | ( | UrlAsyncFetcher * | fetcher | ) |
This will first try to acquire lock and triggers fetch by calling StartFetch() if successful. calls Finalize(true, false), if it fails to acquire lock, and deletes this.
|
protectedpure virtual |
StartFetch() will be called after the lock is acquired. The subclass implements this function and is responsible for UrlAsyncFetcher::Fetch().
1.8.6