diff options
author | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-28 21:03:42 +0000 |
---|---|---|
committer | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-28 21:03:42 +0000 |
commit | 1b9d9d32cace653d70f294ffde8a66ac6eb991b9 (patch) | |
tree | a44efc932c3796c0755127e6758d0875427301b3 /webkit/appcache | |
parent | 30927710a0b1ea177c64133a590d38452b5ee4f1 (diff) | |
download | chromium_src-1b9d9d32cace653d70f294ffde8a66ac6eb991b9.zip chromium_src-1b9d9d32cace653d70f294ffde8a66ac6eb991b9.tar.gz chromium_src-1b9d9d32cace653d70f294ffde8a66ac6eb991b9.tar.bz2 |
Work around CancelableCompletionCallback threading restrictions.
Review URL: https://chromiumcodereview.appspot.com/9456036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124020 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache')
-rw-r--r-- | webkit/appcache/appcache_quota_client.cc | 26 | ||||
-rw-r--r-- | webkit/appcache/appcache_quota_client.h | 5 |
2 files changed, 21 insertions, 10 deletions
diff --git a/webkit/appcache/appcache_quota_client.cc b/webkit/appcache/appcache_quota_client.cc index ed36956..cedcc3e 100644 --- a/webkit/appcache/appcache_quota_client.cc +++ b/webkit/appcache/appcache_quota_client.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -34,10 +34,7 @@ void RunFront(appcache::AppCacheQuotaClient::RequestQueue* queue) { namespace appcache { AppCacheQuotaClient::AppCacheQuotaClient(AppCacheService* service) - : ALLOW_THIS_IN_INITIALIZER_LIST(service_delete_callback_( - base::Bind(&AppCacheQuotaClient::DidDeleteAppCachesForOrigin, - base::Unretained(this)))), - service_(service), + : service_(service), appcache_is_ready_(false), quota_manager_is_destroyed_(false) { } @@ -56,7 +53,7 @@ void AppCacheQuotaClient::OnQuotaManagerDestroyed() { DeletePendingRequests(); if (!current_delete_request_callback_.is_null()) { current_delete_request_callback_.Reset(); - service_delete_callback_.Cancel(); + GetServiceDeleteCallback()->Cancel(); } quota_manager_is_destroyed_ = true; @@ -139,7 +136,7 @@ void AppCacheQuotaClient::DeleteOriginData(const GURL& origin, } service_->DeleteAppCachesForOrigin( - origin, service_delete_callback_.callback()); + origin, GetServiceDeleteCallback()->callback()); } void AppCacheQuotaClient::DidDeleteAppCachesForOrigin(int rv) { @@ -210,6 +207,19 @@ const AppCacheStorage::UsageMap* AppCacheQuotaClient::GetUsageMap() { return service_->storage()->usage_map(); } +net::CancelableCompletionCallback* +AppCacheQuotaClient::GetServiceDeleteCallback() { + // Lazily created due to CancelableCompletionCallback's threading + // restrictions, there is no way to detach from the thread created on. + if (!service_delete_callback_.get()) { + service_delete_callback_.reset( + new net::CancelableCompletionCallback( + base::Bind(&AppCacheQuotaClient::DidDeleteAppCachesForOrigin, + base::Unretained(this)))); + } + return service_delete_callback_.get(); +} + void AppCacheQuotaClient::NotifyAppCacheReady() { appcache_is_ready_ = true; ProcessPendingRequests(); @@ -226,7 +236,7 @@ void AppCacheQuotaClient::NotifyAppCacheDestroyed() { if (!current_delete_request_callback_.is_null()) { current_delete_request_callback_.Run(quota::kQuotaErrorAbort); current_delete_request_callback_.Reset(); - service_delete_callback_.Cancel(); + GetServiceDeleteCallback()->Cancel(); } if (quota_manager_is_destroyed_) diff --git a/webkit/appcache/appcache_quota_client.h b/webkit/appcache/appcache_quota_client.h index e81a833..705ab6d 100644 --- a/webkit/appcache/appcache_quota_client.h +++ b/webkit/appcache/appcache_quota_client.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -65,6 +65,7 @@ class AppCacheQuotaClient : public quota::QuotaClient { void ProcessPendingRequests(); void DeletePendingRequests(); const AppCacheStorage::UsageMap* GetUsageMap(); + net::CancelableCompletionCallback* GetServiceDeleteCallback(); // For use by appcache internals during initialization and shutdown. APPCACHE_EXPORT void NotifyAppCacheReady(); @@ -78,7 +79,7 @@ class AppCacheQuotaClient : public quota::QuotaClient { // 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. DeletionCallback current_delete_request_callback_; - net::CancelableCompletionCallback service_delete_callback_; + scoped_ptr<net::CancelableCompletionCallback> service_delete_callback_; AppCacheService* service_; bool appcache_is_ready_; |