diff options
author | tzik@chromium.org <tzik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-19 05:40:44 +0000 |
---|---|---|
committer | tzik@chromium.org <tzik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-19 05:40:44 +0000 |
commit | e48a50f77510757f70593ead2b1d2e25eda25995 (patch) | |
tree | 036654875b8f787af8d52e900249db5882a9bcac /webkit/appcache | |
parent | e76c9666d967856694b1a433c7edf1443257899c (diff) | |
download | chromium_src-e48a50f77510757f70593ead2b1d2e25eda25995.zip chromium_src-e48a50f77510757f70593ead2b1d2e25eda25995.tar.gz chromium_src-e48a50f77510757f70593ead2b1d2e25eda25995.tar.bz2 |
Cleanup AppCacheQuotaClient using new Callback
BUG=None
TEST=AppCacheQuotaClientTest.PendingRequests
Review URL: http://codereview.chromium.org/8230012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106233 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache')
-rw-r--r-- | webkit/appcache/appcache_quota_client.cc | 103 | ||||
-rw-r--r-- | webkit/appcache/appcache_quota_client.h | 36 | ||||
-rw-r--r-- | webkit/appcache/appcache_storage_impl.cc | 5 |
3 files changed, 37 insertions, 107 deletions
diff --git a/webkit/appcache/appcache_quota_client.cc b/webkit/appcache/appcache_quota_client.cc index 35c81c5..b071910 100644 --- a/webkit/appcache/appcache_quota_client.cc +++ b/webkit/appcache/appcache_quota_client.cc @@ -8,6 +8,7 @@ #include <map> #include <set> +#include "base/bind.h" #include "webkit/appcache/appcache_service.h" using quota::QuotaClient; @@ -21,6 +22,12 @@ quota::QuotaStatusCode NetErrorCodeToQuotaStatus(int code) { else return quota::kQuotaStatusUnknown; } + +void RunFront(appcache::AppCacheQuotaClient::RequestQueue* queue) { + base::Closure request = queue->front(); + queue->pop_front(); + request.Run(); +} } // namespace namespace appcache { @@ -34,9 +41,8 @@ AppCacheQuotaClient::AppCacheQuotaClient(AppCacheService* service) } AppCacheQuotaClient::~AppCacheQuotaClient() { - DCHECK(pending_usage_requests_.empty()); - DCHECK(pending_origins_requests_.empty()); - DCHECK(pending_delete_requests_.empty()); + DCHECK(pending_batch_requests_.empty()); + DCHECK(pending_serial_requests_.empty()); DCHECK(current_delete_request_callback_.is_null()); } @@ -70,10 +76,9 @@ void AppCacheQuotaClient::GetOriginUsage( } if (!appcache_is_ready_) { - pending_usage_requests_.push_back(UsageRequest()); - pending_usage_requests_.back().origin = origin; - pending_usage_requests_.back().type = type; - pending_usage_requests_.back().callback = callback; + pending_batch_requests_.push_back( + base::Bind(&AppCacheQuotaClient::GetOriginUsage, + base::Unretained(this), origin, type, callback)); return; } @@ -120,10 +125,9 @@ void AppCacheQuotaClient::DeleteOriginData(const GURL& origin, } if (!appcache_is_ready_ || !current_delete_request_callback_.is_null()) { - pending_delete_requests_.push_back(DeleteRequest()); - pending_delete_requests_.back().origin = origin; - pending_delete_requests_.back().type = type; - pending_delete_requests_.back().callback = callback; + pending_serial_requests_.push_back( + base::Bind(&AppCacheQuotaClient::DeleteOriginData, + base::Unretained(this), origin, type, callback)); return; } @@ -135,15 +139,6 @@ void AppCacheQuotaClient::DeleteOriginData(const GURL& origin, service_->DeleteAppCachesForOrigin(origin, service_delete_callback_); } -AppCacheQuotaClient::UsageRequest::UsageRequest() {} -AppCacheQuotaClient::UsageRequest::~UsageRequest() {} - -AppCacheQuotaClient::OriginsRequest::OriginsRequest() {} -AppCacheQuotaClient::OriginsRequest::~OriginsRequest() {} - -AppCacheQuotaClient::DeleteRequest::DeleteRequest() {} -AppCacheQuotaClient::DeleteRequest::~DeleteRequest() {} - void AppCacheQuotaClient::DidDeleteAppCachesForOrigin(int rv) { DCHECK(service_); if (quota_manager_is_destroyed_) @@ -152,15 +147,11 @@ void AppCacheQuotaClient::DidDeleteAppCachesForOrigin(int rv) { // Finish the request by calling our callers callback. current_delete_request_callback_.Run(NetErrorCodeToQuotaStatus(rv)); current_delete_request_callback_.Reset(); - if (pending_delete_requests_.empty()) + if (pending_serial_requests_.empty()) return; // Start the next in the queue. - DeleteRequest& next_request = pending_delete_requests_.front(); - current_delete_request_callback_ = next_request.callback; - service_->DeleteAppCachesForOrigin(next_request.origin, - service_delete_callback_); - pending_delete_requests_.pop_front(); + RunFront(&pending_serial_requests_); } void AppCacheQuotaClient::GetOriginsHelper( @@ -176,10 +167,9 @@ void AppCacheQuotaClient::GetOriginsHelper( } if (!appcache_is_ready_) { - pending_origins_requests_.push_back(OriginsRequest()); - pending_origins_requests_.back().opt_host = opt_host; - pending_origins_requests_.back().type = type; - pending_origins_requests_.back().callback = callback; + pending_batch_requests_.push_back( + base::Bind(&AppCacheQuotaClient::GetOriginsHelper, + base::Unretained(this), type, opt_host, callback)); return; } @@ -200,50 +190,16 @@ void AppCacheQuotaClient::GetOriginsHelper( void AppCacheQuotaClient::ProcessPendingRequests() { DCHECK(appcache_is_ready_); - while (!pending_usage_requests_.empty()) { - UsageRequest& request = pending_usage_requests_.front(); - GetOriginUsage(request.origin, request.type, request.callback); - pending_usage_requests_.pop_front(); - } - while (!pending_origins_requests_.empty()) { - OriginsRequest& request = pending_origins_requests_.front(); - GetOriginsHelper(request.type, request.opt_host, request.callback); - pending_origins_requests_.pop_front(); - } - if (!pending_delete_requests_.empty()) { - // Just start the first delete, others will follow upon completion. - DeleteRequest request = pending_delete_requests_.front(); - pending_delete_requests_.pop_front(); - DeleteOriginData(request.origin, request.type, request.callback); - } -} + while (!pending_batch_requests_.empty()) + RunFront(&pending_batch_requests_); -void AppCacheQuotaClient::AbortPendingRequests() { - while (!pending_usage_requests_.empty()) { - pending_usage_requests_.front().callback.Run(0); - pending_usage_requests_.pop_front(); - } - while (!pending_origins_requests_.empty()) { - pending_origins_requests_.front().callback.Run(std::set<GURL>(), - pending_origins_requests_.front().type); - pending_origins_requests_.pop_front(); - } - while (!pending_delete_requests_.empty()) { - pending_delete_requests_.front().callback.Run(quota::kQuotaErrorAbort); - pending_delete_requests_.pop_front(); - } + if (!pending_serial_requests_.empty()) + RunFront(&pending_serial_requests_); } void AppCacheQuotaClient::DeletePendingRequests() { - while (!pending_usage_requests_.empty()) { - pending_usage_requests_.pop_front(); - } - while (!pending_origins_requests_.empty()) { - pending_origins_requests_.pop_front(); - } - while (!pending_delete_requests_.empty()) { - pending_delete_requests_.pop_front(); - } + pending_batch_requests_.clear(); + pending_serial_requests_.clear(); } const AppCacheStorage::UsageMap* AppCacheQuotaClient::GetUsageMap() { @@ -258,7 +214,12 @@ void AppCacheQuotaClient::NotifyAppCacheReady() { void AppCacheQuotaClient::NotifyAppCacheDestroyed() { service_ = NULL; - AbortPendingRequests(); + while (!pending_batch_requests_.empty()) + RunFront(&pending_batch_requests_); + + while (!pending_serial_requests_.empty()) + RunFront(&pending_serial_requests_); + if (!current_delete_request_callback_.is_null()) { current_delete_request_callback_.Run(quota::kQuotaErrorAbort); current_delete_request_callback_.Reset(); diff --git a/webkit/appcache/appcache_quota_client.h b/webkit/appcache/appcache_quota_client.h index 175f017..e394973 100644 --- a/webkit/appcache/appcache_quota_client.h +++ b/webkit/appcache/appcache_quota_client.h @@ -32,6 +32,8 @@ class AppCacheQuotaClientTest; // been destroyed. class AppCacheQuotaClient : public quota::QuotaClient { public: + typedef std::deque<base::Closure> RequestQueue; + virtual ~AppCacheQuotaClient(); // QuotaClient method overrides @@ -54,34 +56,6 @@ class AppCacheQuotaClient : public quota::QuotaClient { friend class AppCacheStorageImpl; // for NotifyAppCacheIsReady friend class AppCacheQuotaClientTest; - struct UsageRequest { - GURL origin; - quota::StorageType type; - GetUsageCallback callback; - - UsageRequest(); - ~UsageRequest(); - }; - struct OriginsRequest { - quota::StorageType type; - std::string opt_host; - GetOriginsCallback callback; - - OriginsRequest(); - ~OriginsRequest(); - }; - struct DeleteRequest { - GURL origin; - quota::StorageType type; - DeletionCallback callback; - - DeleteRequest(); - ~DeleteRequest(); - }; - typedef std::deque<UsageRequest> UsageRequestQueue; - typedef std::deque<OriginsRequest> OriginsRequestQueue; - typedef std::deque<DeleteRequest> DeleteRequestQueue; - APPCACHE_EXPORT explicit AppCacheQuotaClient(AppCacheService* service); void DidDeleteAppCachesForOrigin(int rv); @@ -89,7 +63,6 @@ class AppCacheQuotaClient : public quota::QuotaClient { const std::string& opt_host, const GetOriginsCallback& callback); void ProcessPendingRequests(); - void AbortPendingRequests(); void DeletePendingRequests(); const AppCacheStorage::UsageMap* GetUsageMap(); @@ -99,9 +72,8 @@ class AppCacheQuotaClient : public quota::QuotaClient { // Prior to appcache service being ready, we have to queue // up reqeusts and defer acting on them until we're ready. - UsageRequestQueue pending_usage_requests_; - OriginsRequestQueue pending_origins_requests_; - DeleteRequestQueue pending_delete_requests_; + RequestQueue pending_batch_requests_; + RequestQueue pending_serial_requests_; // And once it's ready, we can only handle one delete request at a time, // so we queue up additional requests while one is in already in progress. diff --git a/webkit/appcache/appcache_storage_impl.cc b/webkit/appcache/appcache_storage_impl.cc index 8e82dfa..ca112df 100644 --- a/webkit/appcache/appcache_storage_impl.cc +++ b/webkit/appcache/appcache_storage_impl.cc @@ -555,12 +555,10 @@ void AppCacheStorageImpl::StoreGroupAndCacheTask::GetQuotaThenSchedule() { } // We have to ask the quota manager for the value. - AddRef(); // balanced in the OnQuotaCallback storage_->pending_quota_queries_.insert(this); quota_manager->GetUsageAndQuota( group_record_.origin, quota::kStorageTypeTemporary, - base::Bind(&StoreGroupAndCacheTask::OnQuotaCallback, - base::Unretained(this))); + base::Bind(&StoreGroupAndCacheTask::OnQuotaCallback, this)); } void AppCacheStorageImpl::StoreGroupAndCacheTask::OnQuotaCallback( @@ -573,7 +571,6 @@ void AppCacheStorageImpl::StoreGroupAndCacheTask::OnQuotaCallback( storage_->pending_quota_queries_.erase(this); Schedule(); } - Release(); // balanced in GetQuotaThenSchedule } void AppCacheStorageImpl::StoreGroupAndCacheTask::Run() { |