OLD | NEW |
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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" |
12 #include "webkit/appcache/appcache_service.h" | 13 #include "webkit/appcache/appcache_service.h" |
13 | 14 |
14 using quota::QuotaClient; | 15 using quota::QuotaClient; |
15 | 16 |
16 namespace { | 17 namespace { |
17 quota::QuotaStatusCode NetErrorCodeToQuotaStatus(int code) { | 18 quota::QuotaStatusCode NetErrorCodeToQuotaStatus(int code) { |
18 if (code == net::OK) | 19 if (code == net::OK) |
19 return quota::kQuotaStatusOk; | 20 return quota::kQuotaStatusOk; |
20 else if (code == net::ERR_ABORTED) | 21 else if (code == net::ERR_ABORTED) |
21 return quota::kQuotaErrorAbort; | 22 return quota::kQuotaErrorAbort; |
22 else | 23 else |
23 return quota::kQuotaStatusUnknown; | 24 return quota::kQuotaStatusUnknown; |
24 } | 25 } |
25 | 26 |
26 void RunFront(appcache::AppCacheQuotaClient::RequestQueue* queue) { | 27 void RunFront(appcache::AppCacheQuotaClient::RequestQueue* queue) { |
27 base::Closure request = queue->front(); | 28 base::Closure request = queue->front(); |
28 queue->pop_front(); | 29 queue->pop_front(); |
29 request.Run(); | 30 request.Run(); |
30 } | 31 } |
31 } // namespace | 32 } // namespace |
32 | 33 |
33 namespace appcache { | 34 namespace appcache { |
34 | 35 |
35 AppCacheQuotaClient::AppCacheQuotaClient(AppCacheService* service) | 36 AppCacheQuotaClient::AppCacheQuotaClient(AppCacheService* service) |
36 : ALLOW_THIS_IN_INITIALIZER_LIST(service_delete_callback_( | 37 : ALLOW_THIS_IN_INITIALIZER_LIST(service_delete_callback_( |
37 new net::CancelableOldCompletionCallback<AppCacheQuotaClient>( | 38 base::Bind(&AppCacheQuotaClient::DidDeleteAppCachesForOrigin, |
38 this, &AppCacheQuotaClient::DidDeleteAppCachesForOrigin))), | 39 base::Unretained(this)))), |
39 service_(service), appcache_is_ready_(false), | 40 service_(service), |
| 41 appcache_is_ready_(false), |
40 quota_manager_is_destroyed_(false) { | 42 quota_manager_is_destroyed_(false) { |
41 } | 43 } |
42 | 44 |
43 AppCacheQuotaClient::~AppCacheQuotaClient() { | 45 AppCacheQuotaClient::~AppCacheQuotaClient() { |
44 DCHECK(pending_batch_requests_.empty()); | 46 DCHECK(pending_batch_requests_.empty()); |
45 DCHECK(pending_serial_requests_.empty()); | 47 DCHECK(pending_serial_requests_.empty()); |
46 DCHECK(current_delete_request_callback_.is_null()); | 48 DCHECK(current_delete_request_callback_.is_null()); |
47 } | 49 } |
48 | 50 |
49 QuotaClient::ID AppCacheQuotaClient::id() const { | 51 QuotaClient::ID AppCacheQuotaClient::id() const { |
50 return kAppcache; | 52 return kAppcache; |
51 } | 53 } |
52 | 54 |
53 void AppCacheQuotaClient::OnQuotaManagerDestroyed() { | 55 void AppCacheQuotaClient::OnQuotaManagerDestroyed() { |
54 DeletePendingRequests(); | 56 DeletePendingRequests(); |
55 if (!current_delete_request_callback_.is_null()) { | 57 if (!current_delete_request_callback_.is_null()) { |
56 current_delete_request_callback_.Reset(); | 58 current_delete_request_callback_.Reset(); |
57 service_delete_callback_.release()->Cancel(); | 59 service_delete_callback_.Cancel(); |
58 } else { | |
59 service_delete_callback_ = NULL; | |
60 } | 60 } |
| 61 |
61 quota_manager_is_destroyed_ = true; | 62 quota_manager_is_destroyed_ = true; |
62 if (!service_) | 63 if (!service_) |
63 delete this; | 64 delete this; |
64 } | 65 } |
65 | 66 |
66 void AppCacheQuotaClient::GetOriginUsage( | 67 void AppCacheQuotaClient::GetOriginUsage( |
67 const GURL& origin, | 68 const GURL& origin, |
68 quota::StorageType type, | 69 quota::StorageType type, |
69 const GetUsageCallback& callback) { | 70 const GetUsageCallback& callback) { |
70 DCHECK(!callback.is_null()); | 71 DCHECK(!callback.is_null()); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 base::Bind(&AppCacheQuotaClient::DeleteOriginData, | 130 base::Bind(&AppCacheQuotaClient::DeleteOriginData, |
130 base::Unretained(this), origin, type, callback)); | 131 base::Unretained(this), origin, type, callback)); |
131 return; | 132 return; |
132 } | 133 } |
133 | 134 |
134 current_delete_request_callback_ = callback; | 135 current_delete_request_callback_ = callback; |
135 if (type == quota::kStorageTypePersistent) { | 136 if (type == quota::kStorageTypePersistent) { |
136 DidDeleteAppCachesForOrigin(net::OK); | 137 DidDeleteAppCachesForOrigin(net::OK); |
137 return; | 138 return; |
138 } | 139 } |
139 service_->DeleteAppCachesForOrigin(origin, service_delete_callback_); | 140 |
| 141 service_->DeleteAppCachesForOrigin( |
| 142 origin, service_delete_callback_.callback()); |
140 } | 143 } |
141 | 144 |
142 void AppCacheQuotaClient::DidDeleteAppCachesForOrigin(int rv) { | 145 void AppCacheQuotaClient::DidDeleteAppCachesForOrigin(int rv) { |
143 DCHECK(service_); | 146 DCHECK(service_); |
144 if (quota_manager_is_destroyed_) | 147 if (quota_manager_is_destroyed_) |
145 return; | 148 return; |
146 | 149 |
147 // Finish the request by calling our callers callback. | 150 // Finish the request by calling our callers callback. |
148 current_delete_request_callback_.Run(NetErrorCodeToQuotaStatus(rv)); | 151 current_delete_request_callback_.Run(NetErrorCodeToQuotaStatus(rv)); |
149 current_delete_request_callback_.Reset(); | 152 current_delete_request_callback_.Reset(); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 service_ = NULL; | 219 service_ = NULL; |
217 while (!pending_batch_requests_.empty()) | 220 while (!pending_batch_requests_.empty()) |
218 RunFront(&pending_batch_requests_); | 221 RunFront(&pending_batch_requests_); |
219 | 222 |
220 while (!pending_serial_requests_.empty()) | 223 while (!pending_serial_requests_.empty()) |
221 RunFront(&pending_serial_requests_); | 224 RunFront(&pending_serial_requests_); |
222 | 225 |
223 if (!current_delete_request_callback_.is_null()) { | 226 if (!current_delete_request_callback_.is_null()) { |
224 current_delete_request_callback_.Run(quota::kQuotaErrorAbort); | 227 current_delete_request_callback_.Run(quota::kQuotaErrorAbort); |
225 current_delete_request_callback_.Reset(); | 228 current_delete_request_callback_.Reset(); |
226 service_delete_callback_.release()->Cancel(); | 229 service_delete_callback_.Cancel(); |
227 } else { | |
228 service_delete_callback_ = NULL; | |
229 } | 230 } |
| 231 |
230 if (quota_manager_is_destroyed_) | 232 if (quota_manager_is_destroyed_) |
231 delete this; | 233 delete this; |
232 } | 234 } |
233 | 235 |
234 } // namespace appcache | 236 } // namespace appcache |
OLD | NEW |