Chromium Code Reviews| Index: webkit/appcache/appcache_service.cc |
| =================================================================== |
| --- webkit/appcache/appcache_service.cc (revision 87543) |
| +++ webkit/appcache/appcache_service.cc (working copy) |
| @@ -9,6 +9,7 @@ |
| #include "base/stl_util-inl.h" |
| #include "webkit/appcache/appcache_backend_impl.h" |
| #include "webkit/appcache/appcache_entry.h" |
| +#include "webkit/appcache/appcache_quota_client.h" |
| #include "webkit/appcache/appcache_storage_impl.h" |
| #include "webkit/quota/quota_manager.h" |
| #include "webkit/quota/special_storage_policy.h" |
| @@ -143,6 +144,95 @@ |
| delete this; |
| } |
| +// DeleteOriginHelper ------- |
| + |
| +class AppCacheService::DeleteOriginHelper : public AsyncHelper { |
| + public: |
| + DeleteOriginHelper( |
| + AppCacheService* service, const GURL& origin, |
| + net::CompletionCallback* callback) |
| + : AsyncHelper(service, callback), origin_(origin), |
| + successes_(0), failures_(0) { |
| + } |
| + |
| + virtual void Start() { |
| + // We start by listing all caches, continues in OnAllInfo(). |
| + service_->storage()->GetAllInfo(this); |
| + } |
| + |
| + private: |
| + // AppCacheStorage::Delegate methods |
| + virtual void OnAllInfo(AppCacheInfoCollection* collection); |
| + virtual void OnGroupLoaded( |
| + appcache::AppCacheGroup* group, const GURL& manifest_url); |
| + virtual void OnGroupMadeObsolete( |
| + appcache::AppCacheGroup* group, bool success); |
| + |
| + void CacheCompleted(bool success); |
| + |
| + GURL origin_; |
| + AppCacheInfoVector caches_to_delete_; |
| + int successes_; |
| + int failures_; |
| + DISALLOW_COPY_AND_ASSIGN(DeleteOriginHelper); |
| +}; |
| + |
| +void AppCacheService::DeleteOriginHelper::OnAllInfo( |
| + AppCacheInfoCollection* collection) { |
| + if (!collection) { |
| + // Failed to get a listing. |
| + CallCallback(net::ERR_FAILED); |
| + delete this; |
| + return; |
| + } |
| + std::map<GURL, AppCacheInfoVector>::iterator found = |
| + collection->infos_by_origin.find(origin_); |
| + if (found == collection->infos_by_origin.end()) { |
| + // No caches for this origin. |
| + CallCallback(net::OK); |
| + delete this; |
| + return; |
| + } |
| + |
| + // We have some caches to delete. |
| + caches_to_delete_.swap(found->second); |
| + successes_ = 0; |
| + failures_ = 0; |
| + for (AppCacheInfoVector::iterator iter = caches_to_delete_.begin(); |
| + iter != caches_to_delete_.end(); ++iter) { |
| + service_->storage()->LoadOrCreateGroup(iter->manifest_url, this); |
| + } |
| +} |
| + |
| +void AppCacheService::DeleteOriginHelper::OnGroupLoaded( |
| + appcache::AppCacheGroup* group, const GURL& manifest_url) { |
| + if (group) { |
| + group->set_being_deleted(true); |
| + group->CancelUpdate(); |
| + service_->storage()->MakeGroupObsolete(group, this); |
| + } else { |
| + CacheCompleted(false); |
| + } |
| +} |
| + |
| +void AppCacheService::DeleteOriginHelper::OnGroupMadeObsolete( |
| + appcache::AppCacheGroup* group, bool success) { |
| + CacheCompleted(success); |
| +} |
| + |
| +void AppCacheService::DeleteOriginHelper::CacheCompleted(bool success) { |
| + if (success) |
| + ++successes_; |
| + else |
| + ++failures_; |
| + if ((successes_ + failures_) < static_cast<int>(caches_to_delete_.size())) |
| + return; |
| + |
| + CallCallback(!failures_ ? net::OK : net::ERR_FAILED); |
|
kinuko
2011/06/02 08:38:06
for readability can we write like (failures_ == 0
michaeln
2011/06/02 22:46:55
i thought it was a style thing, but not entirely s
|
| + delete this; |
| +} |
| + |
| + |
| // GetInfoHelper ------- |
| class AppCacheService::GetInfoHelper : AsyncHelper { |
| @@ -178,8 +268,12 @@ |
| AppCacheService::AppCacheService(quota::QuotaManagerProxy* quota_manager_proxy) |
| : appcache_policy_(NULL), quota_manager_proxy_(quota_manager_proxy), |
| + quota_client_(NULL), |
| request_context_(NULL) { |
| - // TODO(michaeln): Create and register our QuotaClient. |
| + if (quota_manager_proxy_) { |
| + quota_client_ = new AppCacheQuotaClient(this); |
| + quota_manager_proxy_->RegisterClient(quota_client_); |
| + } |
| } |
| AppCacheService::~AppCacheService() { |
| @@ -188,6 +282,8 @@ |
| pending_helpers_.end(), |
| std::mem_fun(&AsyncHelper::Cancel)); |
| STLDeleteElements(&pending_helpers_); |
| + if (quota_client_) |
| + quota_client_->NotifyAppCacheDestroyed(); |
| } |
| void AppCacheService::Initialize(const FilePath& cache_directory, |
| @@ -219,6 +315,12 @@ |
| helper->Start(); |
| } |
| +void AppCacheService::DeleteAppCachesForOrigin( |
| + const GURL& origin, net::CompletionCallback* callback) { |
| + DeleteOriginHelper* helper = new DeleteOriginHelper(this, origin, callback); |
| + helper->Start(); |
| +} |
| + |
| void AppCacheService::set_special_storage_policy( |
| quota::SpecialStoragePolicy* policy) { |
| special_storage_policy_ = policy; |