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 | 9 |
10 #include "webkit/appcache/appcache_service.h" | 10 #include "webkit/appcache/appcache_service.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 GetOriginsCallback* callback_ptr) { | 96 GetOriginsCallback* callback_ptr) { |
97 GetOriginsHelper(type, std::string(), callback_ptr); | 97 GetOriginsHelper(type, std::string(), callback_ptr); |
98 } | 98 } |
99 | 99 |
100 void AppCacheQuotaClient::GetOriginsForHost( | 100 void AppCacheQuotaClient::GetOriginsForHost( |
101 quota::StorageType type, | 101 quota::StorageType type, |
102 const std::string& host, | 102 const std::string& host, |
103 GetOriginsCallback* callback_ptr) { | 103 GetOriginsCallback* callback_ptr) { |
104 DCHECK(callback_ptr); | 104 DCHECK(callback_ptr); |
105 if (host.empty()) { | 105 if (host.empty()) { |
106 callback_ptr->Run(std::set<GURL>()); | 106 callback_ptr->Run(std::set<GURL>(), type); |
107 delete callback_ptr; | 107 delete callback_ptr; |
108 return; | 108 return; |
109 } | 109 } |
110 GetOriginsHelper(type, host, callback_ptr); | 110 GetOriginsHelper(type, host, callback_ptr); |
111 } | 111 } |
112 | 112 |
113 void AppCacheQuotaClient::DeleteOriginData(const GURL& origin, | 113 void AppCacheQuotaClient::DeleteOriginData(const GURL& origin, |
114 quota::StorageType type, | 114 quota::StorageType type, |
115 DeletionCallback* callback_ptr) { | 115 DeletionCallback* callback_ptr) { |
116 DCHECK(callback_ptr); | 116 DCHECK(callback_ptr); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 | 159 |
160 void AppCacheQuotaClient::GetOriginsHelper( | 160 void AppCacheQuotaClient::GetOriginsHelper( |
161 quota::StorageType type, | 161 quota::StorageType type, |
162 const std::string& opt_host, | 162 const std::string& opt_host, |
163 GetOriginsCallback* callback_ptr) { | 163 GetOriginsCallback* callback_ptr) { |
164 DCHECK(callback_ptr); | 164 DCHECK(callback_ptr); |
165 DCHECK(!quota_manager_is_destroyed_); | 165 DCHECK(!quota_manager_is_destroyed_); |
166 | 166 |
167 scoped_ptr<GetOriginsCallback> callback(callback_ptr); | 167 scoped_ptr<GetOriginsCallback> callback(callback_ptr); |
168 if (!service_) { | 168 if (!service_) { |
169 callback->Run(std::set<GURL>()); | 169 callback->Run(std::set<GURL>(), type); |
170 return; | 170 return; |
171 } | 171 } |
172 | 172 |
173 if (!appcache_is_ready_) { | 173 if (!appcache_is_ready_) { |
174 pending_origins_requests_.push_back(OriginsRequest()); | 174 pending_origins_requests_.push_back(OriginsRequest()); |
175 pending_origins_requests_.back().opt_host = opt_host; | 175 pending_origins_requests_.back().opt_host = opt_host; |
176 pending_origins_requests_.back().type = type; | 176 pending_origins_requests_.back().type = type; |
177 pending_origins_requests_.back().callback = callback.release(); | 177 pending_origins_requests_.back().callback = callback.release(); |
178 return; | 178 return; |
179 } | 179 } |
180 | 180 |
181 if (type == quota::kStorageTypePersistent) { | 181 if (type == quota::kStorageTypePersistent) { |
182 callback->Run(std::set<GURL>()); | 182 callback->Run(std::set<GURL>(), type); |
183 return; | 183 return; |
184 } | 184 } |
185 | 185 |
186 const AppCacheStorage::UsageMap* map = GetUsageMap(); | 186 const AppCacheStorage::UsageMap* map = GetUsageMap(); |
187 std::set<GURL> origins; | 187 std::set<GURL> origins; |
188 for (AppCacheStorage::UsageMap::const_iterator iter = map->begin(); | 188 for (AppCacheStorage::UsageMap::const_iterator iter = map->begin(); |
189 iter != map->end(); ++iter) { | 189 iter != map->end(); ++iter) { |
190 if (opt_host.empty() || iter->first.host() == opt_host) | 190 if (opt_host.empty() || iter->first.host() == opt_host) |
191 origins.insert(iter->first); | 191 origins.insert(iter->first); |
192 } | 192 } |
193 callback->Run(origins); | 193 callback->Run(origins, type); |
194 } | 194 } |
195 | 195 |
196 void AppCacheQuotaClient::ProcessPendingRequests() { | 196 void AppCacheQuotaClient::ProcessPendingRequests() { |
197 DCHECK(appcache_is_ready_); | 197 DCHECK(appcache_is_ready_); |
198 while (!pending_usage_requests_.empty()) { | 198 while (!pending_usage_requests_.empty()) { |
199 UsageRequest& request = pending_usage_requests_.front(); | 199 UsageRequest& request = pending_usage_requests_.front(); |
200 GetOriginUsage(request.origin, request.type, request.callback); | 200 GetOriginUsage(request.origin, request.type, request.callback); |
201 pending_usage_requests_.pop_front(); | 201 pending_usage_requests_.pop_front(); |
202 } | 202 } |
203 while (!pending_origins_requests_.empty()) { | 203 while (!pending_origins_requests_.empty()) { |
204 OriginsRequest& request = pending_origins_requests_.front(); | 204 OriginsRequest& request = pending_origins_requests_.front(); |
205 GetOriginsHelper(request.type, request.opt_host, request.callback); | 205 GetOriginsHelper(request.type, request.opt_host, request.callback); |
206 pending_origins_requests_.pop_front(); | 206 pending_origins_requests_.pop_front(); |
207 } | 207 } |
208 if (!pending_delete_requests_.empty()) { | 208 if (!pending_delete_requests_.empty()) { |
209 // Just start the first delete, others will follow upon completion. | 209 // Just start the first delete, others will follow upon completion. |
210 DeleteRequest request = pending_delete_requests_.front(); | 210 DeleteRequest request = pending_delete_requests_.front(); |
211 pending_delete_requests_.pop_front(); | 211 pending_delete_requests_.pop_front(); |
212 DeleteOriginData(request.origin, request.type, request.callback); | 212 DeleteOriginData(request.origin, request.type, request.callback); |
213 } | 213 } |
214 } | 214 } |
215 | 215 |
216 void AppCacheQuotaClient::AbortPendingRequests() { | 216 void AppCacheQuotaClient::AbortPendingRequests() { |
217 while (!pending_usage_requests_.empty()) { | 217 while (!pending_usage_requests_.empty()) { |
218 pending_usage_requests_.front().callback->Run(0); | 218 pending_usage_requests_.front().callback->Run(0); |
219 delete pending_usage_requests_.front().callback; | 219 delete pending_usage_requests_.front().callback; |
220 pending_usage_requests_.pop_front(); | 220 pending_usage_requests_.pop_front(); |
221 } | 221 } |
222 while (!pending_origins_requests_.empty()) { | 222 while (!pending_origins_requests_.empty()) { |
223 pending_origins_requests_.front().callback->Run(std::set<GURL>()); | 223 pending_origins_requests_.front().callback->Run(std::set<GURL>(), |
| 224 pending_origins_requests_.front().type); |
224 delete pending_origins_requests_.front().callback; | 225 delete pending_origins_requests_.front().callback; |
225 pending_origins_requests_.pop_front(); | 226 pending_origins_requests_.pop_front(); |
226 } | 227 } |
227 while (!pending_delete_requests_.empty()) { | 228 while (!pending_delete_requests_.empty()) { |
228 pending_delete_requests_.front().callback->Run(quota::kQuotaErrorAbort); | 229 pending_delete_requests_.front().callback->Run(quota::kQuotaErrorAbort); |
229 delete pending_delete_requests_.front().callback; | 230 delete pending_delete_requests_.front().callback; |
230 pending_delete_requests_.pop_front(); | 231 pending_delete_requests_.pop_front(); |
231 } | 232 } |
232 } | 233 } |
233 | 234 |
(...skipping 30 matching lines...) Expand all Loading... |
264 current_delete_request_callback_.reset(); | 265 current_delete_request_callback_.reset(); |
265 service_delete_callback_.release()->Cancel(); | 266 service_delete_callback_.release()->Cancel(); |
266 } else { | 267 } else { |
267 service_delete_callback_ = NULL; | 268 service_delete_callback_ = NULL; |
268 } | 269 } |
269 if (quota_manager_is_destroyed_) | 270 if (quota_manager_is_destroyed_) |
270 delete this; | 271 delete this; |
271 } | 272 } |
272 | 273 |
273 } // namespace appcache | 274 } // namespace appcache |
OLD | NEW |