Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: webkit/appcache/appcache_quota_client.cc

Issue 9456036: Work around CancelableCompletionCallback threading restrictions. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/appcache/appcache_quota_client.h" 5 #include "webkit/appcache/appcache_quota_client.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 10
(...skipping 16 matching lines...) Expand all
27 void RunFront(appcache::AppCacheQuotaClient::RequestQueue* queue) { 27 void RunFront(appcache::AppCacheQuotaClient::RequestQueue* queue) {
28 base::Closure request = queue->front(); 28 base::Closure request = queue->front();
29 queue->pop_front(); 29 queue->pop_front();
30 request.Run(); 30 request.Run();
31 } 31 }
32 } // namespace 32 } // namespace
33 33
34 namespace appcache { 34 namespace appcache {
35 35
36 AppCacheQuotaClient::AppCacheQuotaClient(AppCacheService* service) 36 AppCacheQuotaClient::AppCacheQuotaClient(AppCacheService* service)
37 : ALLOW_THIS_IN_INITIALIZER_LIST(service_delete_callback_( 37 : service_(service),
38 base::Bind(&AppCacheQuotaClient::DidDeleteAppCachesForOrigin,
39 base::Unretained(this)))),
40 service_(service),
41 appcache_is_ready_(false), 38 appcache_is_ready_(false),
42 quota_manager_is_destroyed_(false) { 39 quota_manager_is_destroyed_(false) {
43 } 40 }
44 41
45 AppCacheQuotaClient::~AppCacheQuotaClient() { 42 AppCacheQuotaClient::~AppCacheQuotaClient() {
46 DCHECK(pending_batch_requests_.empty()); 43 DCHECK(pending_batch_requests_.empty());
47 DCHECK(pending_serial_requests_.empty()); 44 DCHECK(pending_serial_requests_.empty());
48 DCHECK(current_delete_request_callback_.is_null()); 45 DCHECK(current_delete_request_callback_.is_null());
49 } 46 }
50 47
51 QuotaClient::ID AppCacheQuotaClient::id() const { 48 QuotaClient::ID AppCacheQuotaClient::id() const {
52 return kAppcache; 49 return kAppcache;
53 } 50 }
54 51
55 void AppCacheQuotaClient::OnQuotaManagerDestroyed() { 52 void AppCacheQuotaClient::OnQuotaManagerDestroyed() {
56 DeletePendingRequests(); 53 DeletePendingRequests();
57 if (!current_delete_request_callback_.is_null()) { 54 if (!current_delete_request_callback_.is_null()) {
58 current_delete_request_callback_.Reset(); 55 current_delete_request_callback_.Reset();
59 service_delete_callback_.Cancel(); 56 GetServiceDeleteCallback()->Cancel();
60 } 57 }
61 58
62 quota_manager_is_destroyed_ = true; 59 quota_manager_is_destroyed_ = true;
63 if (!service_) 60 if (!service_)
64 delete this; 61 delete this;
65 } 62 }
66 63
67 void AppCacheQuotaClient::GetOriginUsage( 64 void AppCacheQuotaClient::GetOriginUsage(
68 const GURL& origin, 65 const GURL& origin,
69 quota::StorageType type, 66 quota::StorageType type,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 return; 129 return;
133 } 130 }
134 131
135 current_delete_request_callback_ = callback; 132 current_delete_request_callback_ = callback;
136 if (type == quota::kStorageTypePersistent) { 133 if (type == quota::kStorageTypePersistent) {
137 DidDeleteAppCachesForOrigin(net::OK); 134 DidDeleteAppCachesForOrigin(net::OK);
138 return; 135 return;
139 } 136 }
140 137
141 service_->DeleteAppCachesForOrigin( 138 service_->DeleteAppCachesForOrigin(
142 origin, service_delete_callback_.callback()); 139 origin, GetServiceDeleteCallback()->callback());
143 } 140 }
144 141
145 void AppCacheQuotaClient::DidDeleteAppCachesForOrigin(int rv) { 142 void AppCacheQuotaClient::DidDeleteAppCachesForOrigin(int rv) {
146 DCHECK(service_); 143 DCHECK(service_);
147 if (quota_manager_is_destroyed_) 144 if (quota_manager_is_destroyed_)
148 return; 145 return;
149 146
150 // Finish the request by calling our callers callback. 147 // Finish the request by calling our callers callback.
151 current_delete_request_callback_.Run(NetErrorCodeToQuotaStatus(rv)); 148 current_delete_request_callback_.Run(NetErrorCodeToQuotaStatus(rv));
152 current_delete_request_callback_.Reset(); 149 current_delete_request_callback_.Reset();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 void AppCacheQuotaClient::DeletePendingRequests() { 200 void AppCacheQuotaClient::DeletePendingRequests() {
204 pending_batch_requests_.clear(); 201 pending_batch_requests_.clear();
205 pending_serial_requests_.clear(); 202 pending_serial_requests_.clear();
206 } 203 }
207 204
208 const AppCacheStorage::UsageMap* AppCacheQuotaClient::GetUsageMap() { 205 const AppCacheStorage::UsageMap* AppCacheQuotaClient::GetUsageMap() {
209 DCHECK(service_); 206 DCHECK(service_);
210 return service_->storage()->usage_map(); 207 return service_->storage()->usage_map();
211 } 208 }
212 209
210 net::CancelableCompletionCallback*
211 AppCacheQuotaClient::GetServiceDeleteCallback() {
212 // Lazily created due to CancelableCompletionCallback's threading
213 // restrictions, there is no way to detach from the thread created on.
214 if (!service_delete_callback_.get()) {
215 service_delete_callback_.reset(
216 new net::CancelableCompletionCallback(
217 base::Bind(&AppCacheQuotaClient::DidDeleteAppCachesForOrigin,
218 base::Unretained(this))));
219 }
220 return service_delete_callback_.get();
221 }
222
213 void AppCacheQuotaClient::NotifyAppCacheReady() { 223 void AppCacheQuotaClient::NotifyAppCacheReady() {
214 appcache_is_ready_ = true; 224 appcache_is_ready_ = true;
215 ProcessPendingRequests(); 225 ProcessPendingRequests();
216 } 226 }
217 227
218 void AppCacheQuotaClient::NotifyAppCacheDestroyed() { 228 void AppCacheQuotaClient::NotifyAppCacheDestroyed() {
219 service_ = NULL; 229 service_ = NULL;
220 while (!pending_batch_requests_.empty()) 230 while (!pending_batch_requests_.empty())
221 RunFront(&pending_batch_requests_); 231 RunFront(&pending_batch_requests_);
222 232
223 while (!pending_serial_requests_.empty()) 233 while (!pending_serial_requests_.empty())
224 RunFront(&pending_serial_requests_); 234 RunFront(&pending_serial_requests_);
225 235
226 if (!current_delete_request_callback_.is_null()) { 236 if (!current_delete_request_callback_.is_null()) {
227 current_delete_request_callback_.Run(quota::kQuotaErrorAbort); 237 current_delete_request_callback_.Run(quota::kQuotaErrorAbort);
228 current_delete_request_callback_.Reset(); 238 current_delete_request_callback_.Reset();
229 service_delete_callback_.Cancel(); 239 GetServiceDeleteCallback()->Cancel();
230 } 240 }
231 241
232 if (quota_manager_is_destroyed_) 242 if (quota_manager_is_destroyed_)
233 delete this; 243 delete this;
234 } 244 }
235 245
236 } // namespace appcache 246 } // namespace appcache
OLDNEW
« webkit/appcache/appcache_quota_client.h ('K') | « webkit/appcache/appcache_quota_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698