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

Side by Side Diff: content/browser/in_process_webkit/indexed_db_quota_client.cc

Issue 8070001: Use base::Callback in Quota related code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: choke lint Created 9 years, 2 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 "content/browser/in_process_webkit/indexed_db_quota_client.h" 5 #include "content/browser/in_process_webkit/indexed_db_quota_client.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/message_loop_proxy.h" 10 #include "base/message_loop_proxy.h"
(...skipping 13 matching lines...) Expand all
24 IndexedDBQuotaClient* client, 24 IndexedDBQuotaClient* client,
25 base::MessageLoopProxy* webkit_thread_message_loop) 25 base::MessageLoopProxy* webkit_thread_message_loop)
26 : QuotaThreadTask(client, webkit_thread_message_loop), 26 : QuotaThreadTask(client, webkit_thread_message_loop),
27 client_(client), indexed_db_context_(client->indexed_db_context_) { 27 client_(client), indexed_db_context_(client->indexed_db_context_) {
28 } 28 }
29 29
30 IndexedDBQuotaClient* client_; 30 IndexedDBQuotaClient* client_;
31 scoped_refptr<IndexedDBContext> indexed_db_context_; 31 scoped_refptr<IndexedDBContext> indexed_db_context_;
32 }; 32 };
33 33
34 class IndexedDBQuotaClient::DeleteOriginTask : public HelperTask { 34 class IndexedDBQuotaClient::DeleteOriginTask : public HelperTask {
awong 2011/09/29 18:05:15 Could this be simplified with PostTaskAndReply?
tzik 2011/10/11 04:53:57 Later.
35 public: 35 public:
36 DeleteOriginTask(IndexedDBQuotaClient* client, 36 DeleteOriginTask(IndexedDBQuotaClient* client,
37 base::MessageLoopProxy* webkit_thread_message_loop, 37 base::MessageLoopProxy* webkit_thread_message_loop,
38 const GURL& origin_url, 38 const GURL& origin_url,
39 DeletionCallback* callback) 39 DeletionCallback callback)
40 : HelperTask(client, webkit_thread_message_loop), 40 : HelperTask(client, webkit_thread_message_loop),
41 origin_url_(origin_url), callback_(callback) { 41 origin_url_(origin_url), callback_(callback) {
42 } 42 }
43 private: 43 private:
44 virtual void RunOnTargetThread() OVERRIDE { 44 virtual void RunOnTargetThread() OVERRIDE {
45 indexed_db_context_->DeleteIndexedDBForOrigin(origin_url_); 45 indexed_db_context_->DeleteIndexedDBForOrigin(origin_url_);
46 } 46 }
47 virtual void Aborted() OVERRIDE { 47 virtual void Aborted() OVERRIDE {
48 callback_.reset(); 48 callback_.Reset();
49 } 49 }
50 virtual void Completed() OVERRIDE { 50 virtual void Completed() OVERRIDE {
51 callback_->Run(quota::kQuotaStatusOk); 51 callback_.Run(quota::kQuotaStatusOk);
52 callback_.reset(); 52 callback_.Reset();
53 } 53 }
54 GURL origin_url_; 54 GURL origin_url_;
55 scoped_ptr<DeletionCallback> callback_; 55 DeletionCallback callback_;
56 }; 56 };
57 57
58 class IndexedDBQuotaClient::GetOriginUsageTask : public HelperTask { 58 class IndexedDBQuotaClient::GetOriginUsageTask : public HelperTask {
59 public: 59 public:
60 GetOriginUsageTask( 60 GetOriginUsageTask(
61 IndexedDBQuotaClient* client, 61 IndexedDBQuotaClient* client,
62 base::MessageLoopProxy* webkit_thread_message_loop, 62 base::MessageLoopProxy* webkit_thread_message_loop,
63 const GURL& origin_url) 63 const GURL& origin_url)
64 : HelperTask(client, webkit_thread_message_loop), 64 : HelperTask(client, webkit_thread_message_loop),
65 origin_url_(origin_url), usage_(0) { 65 origin_url_(origin_url), usage_(0) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 return kIndexedDatabase; 161 return kIndexedDatabase;
162 } 162 }
163 163
164 void IndexedDBQuotaClient::OnQuotaManagerDestroyed() { 164 void IndexedDBQuotaClient::OnQuotaManagerDestroyed() {
165 delete this; 165 delete this;
166 } 166 }
167 167
168 void IndexedDBQuotaClient::GetOriginUsage( 168 void IndexedDBQuotaClient::GetOriginUsage(
169 const GURL& origin_url, 169 const GURL& origin_url,
170 quota::StorageType type, 170 quota::StorageType type,
171 GetUsageCallback* callback_ptr) { 171 GetUsageCallback callback) {
172 DCHECK(callback_ptr); 172 DCHECK(!callback.is_null());
173 DCHECK(indexed_db_context_.get()); 173 DCHECK(indexed_db_context_.get());
174 scoped_ptr<GetUsageCallback> callback(callback_ptr);
175 174
176 // IndexedDB is in the temp namespace for now. 175 // IndexedDB is in the temp namespace for now.
177 if (type != quota::kStorageTypeTemporary) { 176 if (type != quota::kStorageTypeTemporary) {
178 callback->Run(0); 177 callback.Run(0);
179 return; 178 return;
180 } 179 }
181 180
182 if (usage_for_origin_callbacks_.Add(origin_url, callback.release())) { 181 if (usage_for_origin_callbacks_.Add(origin_url, callback)) {
183 scoped_refptr<GetOriginUsageTask> task( 182 scoped_refptr<GetOriginUsageTask> task(
184 new GetOriginUsageTask(this, webkit_thread_message_loop_, origin_url)); 183 new GetOriginUsageTask(this, webkit_thread_message_loop_, origin_url));
185 task->Start(); 184 task->Start();
186 } 185 }
187 } 186 }
188 187
189 void IndexedDBQuotaClient::GetOriginsForType( 188 void IndexedDBQuotaClient::GetOriginsForType(
190 quota::StorageType type, 189 quota::StorageType type,
191 GetOriginsCallback* callback_ptr) { 190 GetOriginsCallback callback) {
192 DCHECK(callback_ptr); 191 DCHECK(!callback.is_null());
193 DCHECK(indexed_db_context_.get()); 192 DCHECK(indexed_db_context_.get());
194 scoped_ptr<GetOriginsCallback> callback(callback_ptr);
195 193
196 // All databases are in the temp namespace for now. 194 // All databases are in the temp namespace for now.
197 if (type != quota::kStorageTypeTemporary) { 195 if (type != quota::kStorageTypeTemporary) {
198 callback->Run(std::set<GURL>(), type); 196 callback.Run(std::set<GURL>(), type);
199 return; 197 return;
200 } 198 }
201 199
202 if (origins_for_type_callbacks_.Add(callback.release())) { 200 if (origins_for_type_callbacks_.Add(callback)) {
203 scoped_refptr<GetAllOriginsTask> task( 201 scoped_refptr<GetAllOriginsTask> task(
204 new GetAllOriginsTask(this, webkit_thread_message_loop_, type)); 202 new GetAllOriginsTask(this, webkit_thread_message_loop_, type));
205 task->Start(); 203 task->Start();
206 } 204 }
207 } 205 }
208 206
209 void IndexedDBQuotaClient::GetOriginsForHost( 207 void IndexedDBQuotaClient::GetOriginsForHost(
210 quota::StorageType type, 208 quota::StorageType type,
211 const std::string& host, 209 const std::string& host,
212 GetOriginsCallback* callback_ptr) { 210 GetOriginsCallback callback) {
213 DCHECK(callback_ptr); 211 DCHECK(!callback.is_null());
214 DCHECK(indexed_db_context_.get()); 212 DCHECK(indexed_db_context_.get());
215 scoped_ptr<GetOriginsCallback> callback(callback_ptr);
216 213
217 // All databases are in the temp namespace for now. 214 // All databases are in the temp namespace for now.
218 if (type != quota::kStorageTypeTemporary) { 215 if (type != quota::kStorageTypeTemporary) {
219 callback->Run(std::set<GURL>(), type); 216 callback.Run(std::set<GURL>(), type);
220 return; 217 return;
221 } 218 }
222 219
223 if (origins_for_host_callbacks_.Add(host, callback.release())) { 220 if (origins_for_host_callbacks_.Add(host, callback)) {
224 scoped_refptr<GetOriginsForHostTask> task( 221 scoped_refptr<GetOriginsForHostTask> task(
225 new GetOriginsForHostTask( 222 new GetOriginsForHostTask(
226 this, webkit_thread_message_loop_, host, type)); 223 this, webkit_thread_message_loop_, host, type));
227 task->Start(); 224 task->Start();
228 } 225 }
229 } 226 }
230 227
231 void IndexedDBQuotaClient::DeleteOriginData(const GURL& origin, 228 void IndexedDBQuotaClient::DeleteOriginData(const GURL& origin,
232 quota::StorageType type, 229 quota::StorageType type,
233 DeletionCallback* callback) { 230 DeletionCallback callback) {
234 if (type != quota::kStorageTypeTemporary) { 231 if (type != quota::kStorageTypeTemporary) {
235 callback->Run(quota::kQuotaErrorNotSupported); 232 callback.Run(quota::kQuotaErrorNotSupported);
236 return; 233 return;
237 } 234 }
238 scoped_refptr<DeleteOriginTask> task( 235 scoped_refptr<DeleteOriginTask> task(
awong 2011/09/29 18:05:15 I'm thinking something like webkit_thread_message
tzik 2011/10/11 04:53:57 Sounds good. But this CL is already too big, let m
239 new DeleteOriginTask(this, 236 new DeleteOriginTask(this,
240 webkit_thread_message_loop_, 237 webkit_thread_message_loop_,
241 origin, 238 origin,
242 callback)); 239 callback));
243 task->Start(); 240 task->Start();
244 } 241 }
245 242
246 void IndexedDBQuotaClient::DidGetOriginUsage( 243 void IndexedDBQuotaClient::DidGetOriginUsage(
247 const GURL& origin_url, int64 usage) { 244 const GURL& origin_url, int64 usage) {
248 DCHECK(usage_for_origin_callbacks_.HasCallbacks(origin_url)); 245 DCHECK(usage_for_origin_callbacks_.HasCallbacks(origin_url));
249 usage_for_origin_callbacks_.Run(origin_url, usage); 246 usage_for_origin_callbacks_.Run(origin_url, usage);
250 } 247 }
251 248
252 void IndexedDBQuotaClient::DidGetAllOrigins(const std::set<GURL>& origins, 249 void IndexedDBQuotaClient::DidGetAllOrigins(const std::set<GURL>& origins,
253 quota::StorageType type) { 250 quota::StorageType type) {
254 DCHECK(origins_for_type_callbacks_.HasCallbacks()); 251 DCHECK(origins_for_type_callbacks_.HasCallbacks());
255 origins_for_type_callbacks_.Run(origins, type); 252 origins_for_type_callbacks_.Run(origins, type);
256 } 253 }
257 254
258 void IndexedDBQuotaClient::DidGetOriginsForHost( 255 void IndexedDBQuotaClient::DidGetOriginsForHost(
259 const std::string& host, const std::set<GURL>& origins, 256 const std::string& host, const std::set<GURL>& origins,
260 quota::StorageType type) { 257 quota::StorageType type) {
261 DCHECK(origins_for_host_callbacks_.HasCallbacks(host)); 258 DCHECK(origins_for_host_callbacks_.HasCallbacks(host));
262 origins_for_host_callbacks_.Run(host, origins, type); 259 origins_for_host_callbacks_.Run(host, origins, type);
263 } 260 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698