diff options
author | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-05 23:40:02 +0000 |
---|---|---|
committer | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-05 23:40:02 +0000 |
commit | d68a4fc6f448c6ebf407e2817320e7736c4735ee (patch) | |
tree | d76e2c91aa67af5a880ec81eddcbf2d12887e865 /webkit/appcache/appcache_service.cc | |
parent | 63eb6c0bebc31046bbd954ef21dee86dca9d7fe3 (diff) | |
download | chromium_src-d68a4fc6f448c6ebf407e2817320e7736c4735ee.zip chromium_src-d68a4fc6f448c6ebf407e2817320e7736c4735ee.tar.gz chromium_src-d68a4fc6f448c6ebf407e2817320e7736c4735ee.tar.bz2 |
Hook up the content settings UI to the appcache.
* Populate the tree view with appcaches
* Delete selected appcaches from the tree view
* Delete the date range indicated in the browsing data remover
TEST=manual
BUG=34634
Review URL: http://codereview.chromium.org/660423
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40796 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache/appcache_service.cc')
-rw-r--r-- | webkit/appcache/appcache_service.cc | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/webkit/appcache/appcache_service.cc b/webkit/appcache/appcache_service.cc index 65cc457..a6bc24a 100644 --- a/webkit/appcache/appcache_service.cc +++ b/webkit/appcache/appcache_service.cc @@ -5,17 +5,142 @@ #include "webkit/appcache/appcache_service.h" #include "base/logging.h" +#include "base/message_loop.h" +#include "base/stl_util-inl.h" #include "webkit/appcache/appcache_backend_impl.h" #include "webkit/appcache/appcache_storage_impl.h" namespace appcache { +// AsyncHelper ------- + +class AppCacheService::AsyncHelper + : public AppCacheStorage::Delegate { + public: + AsyncHelper( + AppCacheService* service, net::CompletionCallback* callback) + : service_(service), callback_(callback) { + service_->pending_helpers_.insert(this); + } + + virtual ~AsyncHelper() { + if (service_) + service_->pending_helpers_.erase(this); + } + + virtual void Start() = 0; + virtual void Cancel(); + + protected: + void CallCallback(int rv) { + if (callback_) { + // Defer to guarentee async completion. + MessageLoop::current()->PostTask( + FROM_HERE, + NewRunnableFunction(&DeferredCallCallback, callback_, rv)); + } + callback_ = NULL; + } + + static void DeferredCallCallback(net::CompletionCallback* callback, int rv) { + callback->Run(rv); + } + + AppCacheService* service_; + net::CompletionCallback* callback_; +}; + +void AppCacheService::AsyncHelper::Cancel() { + CallCallback(net::ERR_ABORTED); + service_->storage()->CancelDelegateCallbacks(this); + service_ = NULL; +} + +// DeleteHelper ------- + +class AppCacheService::DeleteHelper : public AsyncHelper { + public: + DeleteHelper( + AppCacheService* service, const GURL& manifest_url, + net::CompletionCallback* callback) + : AsyncHelper(service, callback), manifest_url_(manifest_url) { + } + + virtual void Start() { + service_->storage()->LoadOrCreateGroup(manifest_url_, this); + } + + private: + // AppCacheStorage::Delegate methods + virtual void OnGroupLoaded( + appcache::AppCacheGroup* group, const GURL& manifest_url); + virtual void OnGroupMadeObsolete( + appcache::AppCacheGroup* group, bool success); + + GURL manifest_url_; +}; + +void AppCacheService::DeleteHelper::OnGroupLoaded( + appcache::AppCacheGroup* group, const GURL& manifest_url) { + if (group) { + group->set_being_deleted(true); + group->CancelUpdate(); + service_->storage()->MakeGroupObsolete(group, this); + } else { + CallCallback(net::ERR_FAILED); + delete this; + } +} + +void AppCacheService::DeleteHelper::OnGroupMadeObsolete( + appcache::AppCacheGroup* group, bool success) { + CallCallback(success ? net::OK : net::ERR_FAILED); + delete this; +} + +// GetInfoHelper ------- + +class AppCacheService::GetInfoHelper : AsyncHelper { + public: + GetInfoHelper( + AppCacheService* service, AppCacheInfoCollection* collection, + net::CompletionCallback* callback) + : AsyncHelper(service, callback), collection_(collection) { + } + + virtual void Start() { + service_->storage()->GetAllInfo(this); + } + + private: + // AppCacheStorage::Delegate override + virtual void OnAllInfo(AppCacheInfoCollection* collection); + + scoped_refptr<AppCacheInfoCollection> collection_; +}; + +void AppCacheService::GetInfoHelper::OnAllInfo( + AppCacheInfoCollection* collection) { + if (collection) + collection->infos_by_origin.swap(collection_->infos_by_origin); + CallCallback(collection ? net::OK : net::ERR_FAILED); + delete this; +} + + +// AppCacheService ------- + AppCacheService::AppCacheService() : appcache_policy_(NULL), request_context_(NULL) { } AppCacheService::~AppCacheService() { DCHECK(backends_.empty()); + + std::for_each(pending_helpers_.begin(), + pending_helpers_.end(), + std::mem_fun(&AsyncHelper::Cancel)); + STLDeleteElements(&pending_helpers_); } void AppCacheService::Initialize(const FilePath& cache_directory) { @@ -25,6 +150,19 @@ void AppCacheService::Initialize(const FilePath& cache_directory) { storage_.reset(storage); } +void AppCacheService::GetAllAppCacheInfo(AppCacheInfoCollection* collection, + net::CompletionCallback* callback) { + DCHECK(collection); + GetInfoHelper* helper = new GetInfoHelper(this, collection, callback); + helper->Start(); +} + +void AppCacheService::DeleteAppCacheGroup(const GURL& manifest_url, + net::CompletionCallback* callback) { + DeleteHelper* helper = new DeleteHelper(this, manifest_url, callback); + helper->Start(); +} + void AppCacheService::RegisterBackend( AppCacheBackendImpl* backend_impl) { DCHECK(backends_.find(backend_impl->process_id()) == backends_.end()); |