OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/appcache/appcache_quota_client.h" | 5 #include "content/browser/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 "base/bind_helpers.h" |
13 #include "content/browser/appcache/appcache_service_impl.h" | 13 #include "content/browser/appcache/appcache_service_impl.h" |
14 | 14 |
15 using quota::QuotaClient; | 15 using storage::QuotaClient; |
16 | 16 |
17 namespace { | 17 namespace { |
18 quota::QuotaStatusCode NetErrorCodeToQuotaStatus(int code) { | 18 storage::QuotaStatusCode NetErrorCodeToQuotaStatus(int code) { |
19 if (code == net::OK) | 19 if (code == net::OK) |
20 return quota::kQuotaStatusOk; | 20 return storage::kQuotaStatusOk; |
21 else if (code == net::ERR_ABORTED) | 21 else if (code == net::ERR_ABORTED) |
22 return quota::kQuotaErrorAbort; | 22 return storage::kQuotaErrorAbort; |
23 else | 23 else |
24 return quota::kQuotaStatusUnknown; | 24 return storage::kQuotaStatusUnknown; |
25 } | 25 } |
26 | 26 |
27 void RunFront(content::AppCacheQuotaClient::RequestQueue* queue) { | 27 void RunFront(content::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 content { | 34 namespace content { |
(...skipping 19 matching lines...) Expand all Loading... |
54 if (!current_delete_request_callback_.is_null()) { | 54 if (!current_delete_request_callback_.is_null()) { |
55 current_delete_request_callback_.Reset(); | 55 current_delete_request_callback_.Reset(); |
56 GetServiceDeleteCallback()->Cancel(); | 56 GetServiceDeleteCallback()->Cancel(); |
57 } | 57 } |
58 | 58 |
59 quota_manager_is_destroyed_ = true; | 59 quota_manager_is_destroyed_ = true; |
60 if (!service_) | 60 if (!service_) |
61 delete this; | 61 delete this; |
62 } | 62 } |
63 | 63 |
64 void AppCacheQuotaClient::GetOriginUsage( | 64 void AppCacheQuotaClient::GetOriginUsage(const GURL& origin, |
65 const GURL& origin, | 65 storage::StorageType type, |
66 quota::StorageType type, | 66 const GetUsageCallback& callback) { |
67 const GetUsageCallback& callback) { | |
68 DCHECK(!callback.is_null()); | 67 DCHECK(!callback.is_null()); |
69 DCHECK(!quota_manager_is_destroyed_); | 68 DCHECK(!quota_manager_is_destroyed_); |
70 | 69 |
71 if (!service_) { | 70 if (!service_) { |
72 callback.Run(0); | 71 callback.Run(0); |
73 return; | 72 return; |
74 } | 73 } |
75 | 74 |
76 if (!appcache_is_ready_) { | 75 if (!appcache_is_ready_) { |
77 pending_batch_requests_.push_back( | 76 pending_batch_requests_.push_back( |
78 base::Bind(&AppCacheQuotaClient::GetOriginUsage, | 77 base::Bind(&AppCacheQuotaClient::GetOriginUsage, |
79 base::Unretained(this), origin, type, callback)); | 78 base::Unretained(this), origin, type, callback)); |
80 return; | 79 return; |
81 } | 80 } |
82 | 81 |
83 if (type != quota::kStorageTypeTemporary) { | 82 if (type != storage::kStorageTypeTemporary) { |
84 callback.Run(0); | 83 callback.Run(0); |
85 return; | 84 return; |
86 } | 85 } |
87 | 86 |
88 const AppCacheStorage::UsageMap* map = GetUsageMap(); | 87 const AppCacheStorage::UsageMap* map = GetUsageMap(); |
89 AppCacheStorage::UsageMap::const_iterator found = map->find(origin); | 88 AppCacheStorage::UsageMap::const_iterator found = map->find(origin); |
90 if (found == map->end()) { | 89 if (found == map->end()) { |
91 callback.Run(0); | 90 callback.Run(0); |
92 return; | 91 return; |
93 } | 92 } |
94 callback.Run(found->second); | 93 callback.Run(found->second); |
95 } | 94 } |
96 | 95 |
97 void AppCacheQuotaClient::GetOriginsForType( | 96 void AppCacheQuotaClient::GetOriginsForType( |
98 quota::StorageType type, | 97 storage::StorageType type, |
99 const GetOriginsCallback& callback) { | 98 const GetOriginsCallback& callback) { |
100 GetOriginsHelper(type, std::string(), callback); | 99 GetOriginsHelper(type, std::string(), callback); |
101 } | 100 } |
102 | 101 |
103 void AppCacheQuotaClient::GetOriginsForHost( | 102 void AppCacheQuotaClient::GetOriginsForHost( |
104 quota::StorageType type, | 103 storage::StorageType type, |
105 const std::string& host, | 104 const std::string& host, |
106 const GetOriginsCallback& callback) { | 105 const GetOriginsCallback& callback) { |
107 DCHECK(!callback.is_null()); | 106 DCHECK(!callback.is_null()); |
108 if (host.empty()) { | 107 if (host.empty()) { |
109 callback.Run(std::set<GURL>()); | 108 callback.Run(std::set<GURL>()); |
110 return; | 109 return; |
111 } | 110 } |
112 GetOriginsHelper(type, host, callback); | 111 GetOriginsHelper(type, host, callback); |
113 } | 112 } |
114 | 113 |
115 void AppCacheQuotaClient::DeleteOriginData(const GURL& origin, | 114 void AppCacheQuotaClient::DeleteOriginData(const GURL& origin, |
116 quota::StorageType type, | 115 storage::StorageType type, |
117 const DeletionCallback& callback) { | 116 const DeletionCallback& callback) { |
118 DCHECK(!quota_manager_is_destroyed_); | 117 DCHECK(!quota_manager_is_destroyed_); |
119 | 118 |
120 if (!service_) { | 119 if (!service_) { |
121 callback.Run(quota::kQuotaErrorAbort); | 120 callback.Run(storage::kQuotaErrorAbort); |
122 return; | 121 return; |
123 } | 122 } |
124 | 123 |
125 if (!appcache_is_ready_ || !current_delete_request_callback_.is_null()) { | 124 if (!appcache_is_ready_ || !current_delete_request_callback_.is_null()) { |
126 pending_serial_requests_.push_back( | 125 pending_serial_requests_.push_back( |
127 base::Bind(&AppCacheQuotaClient::DeleteOriginData, | 126 base::Bind(&AppCacheQuotaClient::DeleteOriginData, |
128 base::Unretained(this), origin, type, callback)); | 127 base::Unretained(this), origin, type, callback)); |
129 return; | 128 return; |
130 } | 129 } |
131 | 130 |
132 current_delete_request_callback_ = callback; | 131 current_delete_request_callback_ = callback; |
133 if (type != quota::kStorageTypeTemporary) { | 132 if (type != storage::kStorageTypeTemporary) { |
134 DidDeleteAppCachesForOrigin(net::OK); | 133 DidDeleteAppCachesForOrigin(net::OK); |
135 return; | 134 return; |
136 } | 135 } |
137 | 136 |
138 service_->DeleteAppCachesForOrigin( | 137 service_->DeleteAppCachesForOrigin( |
139 origin, GetServiceDeleteCallback()->callback()); | 138 origin, GetServiceDeleteCallback()->callback()); |
140 } | 139 } |
141 | 140 |
142 bool AppCacheQuotaClient::DoesSupport(quota::StorageType type) const { | 141 bool AppCacheQuotaClient::DoesSupport(storage::StorageType type) const { |
143 return type == quota::kStorageTypeTemporary; | 142 return type == storage::kStorageTypeTemporary; |
144 } | 143 } |
145 | 144 |
146 void AppCacheQuotaClient::DidDeleteAppCachesForOrigin(int rv) { | 145 void AppCacheQuotaClient::DidDeleteAppCachesForOrigin(int rv) { |
147 DCHECK(service_); | 146 DCHECK(service_); |
148 if (quota_manager_is_destroyed_) | 147 if (quota_manager_is_destroyed_) |
149 return; | 148 return; |
150 | 149 |
151 // Finish the request by calling our callers callback. | 150 // Finish the request by calling our callers callback. |
152 current_delete_request_callback_.Run(NetErrorCodeToQuotaStatus(rv)); | 151 current_delete_request_callback_.Run(NetErrorCodeToQuotaStatus(rv)); |
153 current_delete_request_callback_.Reset(); | 152 current_delete_request_callback_.Reset(); |
154 if (pending_serial_requests_.empty()) | 153 if (pending_serial_requests_.empty()) |
155 return; | 154 return; |
156 | 155 |
157 // Start the next in the queue. | 156 // Start the next in the queue. |
158 RunFront(&pending_serial_requests_); | 157 RunFront(&pending_serial_requests_); |
159 } | 158 } |
160 | 159 |
161 void AppCacheQuotaClient::GetOriginsHelper( | 160 void AppCacheQuotaClient::GetOriginsHelper(storage::StorageType type, |
162 quota::StorageType type, | 161 const std::string& opt_host, |
163 const std::string& opt_host, | 162 const GetOriginsCallback& callback) { |
164 const GetOriginsCallback& callback) { | |
165 DCHECK(!callback.is_null()); | 163 DCHECK(!callback.is_null()); |
166 DCHECK(!quota_manager_is_destroyed_); | 164 DCHECK(!quota_manager_is_destroyed_); |
167 | 165 |
168 if (!service_) { | 166 if (!service_) { |
169 callback.Run(std::set<GURL>()); | 167 callback.Run(std::set<GURL>()); |
170 return; | 168 return; |
171 } | 169 } |
172 | 170 |
173 if (!appcache_is_ready_) { | 171 if (!appcache_is_ready_) { |
174 pending_batch_requests_.push_back( | 172 pending_batch_requests_.push_back( |
175 base::Bind(&AppCacheQuotaClient::GetOriginsHelper, | 173 base::Bind(&AppCacheQuotaClient::GetOriginsHelper, |
176 base::Unretained(this), type, opt_host, callback)); | 174 base::Unretained(this), type, opt_host, callback)); |
177 return; | 175 return; |
178 } | 176 } |
179 | 177 |
180 if (type != quota::kStorageTypeTemporary) { | 178 if (type != storage::kStorageTypeTemporary) { |
181 callback.Run(std::set<GURL>()); | 179 callback.Run(std::set<GURL>()); |
182 return; | 180 return; |
183 } | 181 } |
184 | 182 |
185 const AppCacheStorage::UsageMap* map = GetUsageMap(); | 183 const AppCacheStorage::UsageMap* map = GetUsageMap(); |
186 std::set<GURL> origins; | 184 std::set<GURL> origins; |
187 for (AppCacheStorage::UsageMap::const_iterator iter = map->begin(); | 185 for (AppCacheStorage::UsageMap::const_iterator iter = map->begin(); |
188 iter != map->end(); ++iter) { | 186 iter != map->end(); ++iter) { |
189 if (opt_host.empty() || iter->first.host() == opt_host) | 187 if (opt_host.empty() || iter->first.host() == opt_host) |
190 origins.insert(iter->first); | 188 origins.insert(iter->first); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 | 232 |
235 void AppCacheQuotaClient::NotifyAppCacheDestroyed() { | 233 void AppCacheQuotaClient::NotifyAppCacheDestroyed() { |
236 service_ = NULL; | 234 service_ = NULL; |
237 while (!pending_batch_requests_.empty()) | 235 while (!pending_batch_requests_.empty()) |
238 RunFront(&pending_batch_requests_); | 236 RunFront(&pending_batch_requests_); |
239 | 237 |
240 while (!pending_serial_requests_.empty()) | 238 while (!pending_serial_requests_.empty()) |
241 RunFront(&pending_serial_requests_); | 239 RunFront(&pending_serial_requests_); |
242 | 240 |
243 if (!current_delete_request_callback_.is_null()) { | 241 if (!current_delete_request_callback_.is_null()) { |
244 current_delete_request_callback_.Run(quota::kQuotaErrorAbort); | 242 current_delete_request_callback_.Run(storage::kQuotaErrorAbort); |
245 current_delete_request_callback_.Reset(); | 243 current_delete_request_callback_.Reset(); |
246 GetServiceDeleteCallback()->Cancel(); | 244 GetServiceDeleteCallback()->Cancel(); |
247 } | 245 } |
248 | 246 |
249 if (quota_manager_is_destroyed_) | 247 if (quota_manager_is_destroyed_) |
250 delete this; | 248 delete this; |
251 } | 249 } |
252 | 250 |
253 } // namespace content | 251 } // namespace content |
OLD | NEW |