diff options
author | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-25 00:58:38 +0000 |
---|---|---|
committer | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-25 00:58:38 +0000 |
commit | beb13401498aff7d63ff3b150066b499a424050f (patch) | |
tree | 0f3c97957d3976778566e810d7e2cf4ef5baab7e /webkit/appcache | |
parent | 203445cdc4715cfdff954ff8a2f2281df3a47ee6 (diff) | |
download | chromium_src-beb13401498aff7d63ff3b150066b499a424050f.zip chromium_src-beb13401498aff7d63ff3b150066b499a424050f.tar.gz chromium_src-beb13401498aff7d63ff3b150066b499a424050f.tar.bz2 |
AppCache: Add a helper method to AppCacheService to test if a request can be handled while offline.
BUG=65547, chromium-os:9559
TEST=none
Review URL: http://codereview.chromium.org/6269016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72433 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache')
-rw-r--r-- | webkit/appcache/appcache_service.cc | 48 | ||||
-rw-r--r-- | webkit/appcache/appcache_service.h | 6 |
2 files changed, 54 insertions, 0 deletions
diff --git a/webkit/appcache/appcache_service.cc b/webkit/appcache/appcache_service.cc index c6bba28..1eb4673 100644 --- a/webkit/appcache/appcache_service.cc +++ b/webkit/appcache/appcache_service.cc @@ -8,6 +8,7 @@ #include "base/message_loop.h" #include "base/stl_util-inl.h" #include "webkit/appcache/appcache_backend_impl.h" +#include "webkit/appcache/appcache_entry.h" #include "webkit/appcache/appcache_storage_impl.h" namespace appcache { @@ -60,6 +61,43 @@ void AppCacheService::AsyncHelper::Cancel() { service_ = NULL; } +// CanHandleOfflineHelper ------- + +class AppCacheService::CanHandleOfflineHelper : AsyncHelper { + public: + CanHandleOfflineHelper( + AppCacheService* service, const GURL& url, + net::CompletionCallback* callback) + : AsyncHelper(service, callback), url_(url) { + } + + virtual void Start() { + service_->storage()->FindResponseForMainRequest(url_, this); + } + + private: + // AppCacheStorage::Delegate override + virtual void OnMainResponseFound( + const GURL& url, const AppCacheEntry& entry, + const GURL& fallback_url, const AppCacheEntry& fallback_entry, + int64 cache_id, const GURL& mainfest_url, + bool was_blocked_by_policy); + + GURL url_; + DISALLOW_COPY_AND_ASSIGN(CanHandleOfflineHelper); +}; + +void AppCacheService::CanHandleOfflineHelper::OnMainResponseFound( + const GURL& url, const AppCacheEntry& entry, + const GURL& fallback_url, const AppCacheEntry& fallback_entry, + int64 cache_id, const GURL& mainfest_url, + bool was_blocked_by_policy) { + bool can = !was_blocked_by_policy && + (entry.has_response_id() || fallback_entry.has_response_id()); + CallCallback(can ? net::OK : net::ERR_FAILED); + delete this; +} + // DeleteHelper ------- class AppCacheService::DeleteHelper : public AsyncHelper { @@ -82,6 +120,7 @@ class AppCacheService::DeleteHelper : public AsyncHelper { appcache::AppCacheGroup* group, bool success); GURL manifest_url_; + DISALLOW_COPY_AND_ASSIGN(DeleteHelper); }; void AppCacheService::DeleteHelper::OnGroupLoaded( @@ -121,6 +160,7 @@ class AppCacheService::GetInfoHelper : AsyncHelper { virtual void OnAllInfo(AppCacheInfoCollection* collection); scoped_refptr<AppCacheInfoCollection> collection_; + DISALLOW_COPY_AND_ASSIGN(GetInfoHelper); }; void AppCacheService::GetInfoHelper::OnAllInfo( @@ -155,6 +195,14 @@ void AppCacheService::Initialize(const FilePath& cache_directory, storage_.reset(storage); } +void AppCacheService::CanHandleMainResourceOffline( + const GURL& url, + net::CompletionCallback* callback) { + CanHandleOfflineHelper* helper = + new CanHandleOfflineHelper(this, url, callback); + helper->Start(); +} + void AppCacheService::GetAllAppCacheInfo(AppCacheInfoCollection* collection, net::CompletionCallback* callback) { DCHECK(collection); diff --git a/webkit/appcache/appcache_service.h b/webkit/appcache/appcache_service.h index 7d200b3..6a0c931 100644 --- a/webkit/appcache/appcache_service.h +++ b/webkit/appcache/appcache_service.h @@ -58,6 +58,11 @@ class AppCacheService { storage_->PurgeMemory(); } + // Determines if a request for 'url' can be satisfied while offline. + // This method always completes asynchronously. + void CanHandleMainResourceOffline(const GURL& url, + net::CompletionCallback* callback); + // Populates 'collection' with info about all of the appcaches stored // within the service, 'callback' is invoked upon completion. The service // acquires a reference to the 'collection' until until completion. @@ -103,6 +108,7 @@ class AppCacheService { protected: class AsyncHelper; + class CanHandleOfflineHelper; class DeleteHelper; class GetInfoHelper; |