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

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

Issue 7470008: Improve IndexedDB's quota support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged delete methods; simplify GetUsageCallback Created 9 years, 4 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 {
35 public:
36 DeleteOriginTask(IndexedDBQuotaClient* client,
37 base::MessageLoopProxy* webkit_thread_message_loop,
38 const GURL& origin_url,
39 DeletionCallback* callback)
40 : HelperTask(client, webkit_thread_message_loop),
41 origin_url_(origin_url), callback_(callback) {
42 }
43 private:
44 virtual void RunOnTargetThread() OVERRIDE {
45 indexed_db_context_->DeleteIndexedDBForOrigin(origin_url_);
46 }
47 virtual void Aborted() OVERRIDE {
48 callback_.reset();
49 }
50 virtual void Completed() OVERRIDE {
51 callback_->Run(quota::kQuotaStatusOk);
52 callback_.reset();
53 }
54 GURL origin_url_;
55 scoped_ptr<DeletionCallback> callback_;
56 };
57
34 class IndexedDBQuotaClient::GetOriginUsageTask : public HelperTask { 58 class IndexedDBQuotaClient::GetOriginUsageTask : public HelperTask {
35 public: 59 public:
36 GetOriginUsageTask( 60 GetOriginUsageTask(
37 IndexedDBQuotaClient* client, 61 IndexedDBQuotaClient* client,
38 base::MessageLoopProxy* webkit_thread_message_loop, 62 base::MessageLoopProxy* webkit_thread_message_loop,
39 const GURL& origin_url) 63 const GURL& origin_url)
40 : HelperTask(client, webkit_thread_message_loop), 64 : HelperTask(client, webkit_thread_message_loop),
41 origin_url_(origin_url), usage_(0) { 65 origin_url_(origin_url), usage_(0) {
42 } 66 }
43 67
44 private: 68 private:
45 virtual void RunOnTargetThread() OVERRIDE { 69 virtual void RunOnTargetThread() OVERRIDE {
46 string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin_url_); 70 usage_ = indexed_db_context_->InitializeDiskUsage(origin_url_);
michaeln 2011/08/04 22:11:55 Its a little odd to see this function calling an '
dgrogan 2011/08/04 23:44:56 You're right. Changed.
47 FilePath file_path = indexed_db_context_->GetIndexedDBFilePath(origin_id);
48 usage_ = 0;
49 usage_ = file_util::ComputeDirectorySize(file_path);
50 } 71 }
51 virtual void Completed() OVERRIDE { 72 virtual void Completed() OVERRIDE {
73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
52 client_->DidGetOriginUsage(origin_url_, usage_); 74 client_->DidGetOriginUsage(origin_url_, usage_);
53 } 75 }
54 GURL origin_url_; 76 GURL origin_url_;
55 int64 usage_; 77 int64 usage_;
56 }; 78 };
57 79
58 class IndexedDBQuotaClient::GetOriginsTaskBase : public HelperTask { 80 class IndexedDBQuotaClient::GetOriginsTaskBase : public HelperTask {
59 protected: 81 protected:
60 GetOriginsTaskBase( 82 GetOriginsTaskBase(
61 IndexedDBQuotaClient* client, 83 IndexedDBQuotaClient* client,
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 if (origins_for_host_callbacks_.Add(host, callback.release())) { 217 if (origins_for_host_callbacks_.Add(host, callback.release())) {
196 scoped_refptr<GetOriginsForHostTask> task( 218 scoped_refptr<GetOriginsForHostTask> task(
197 new GetOriginsForHostTask(this, webkit_thread_message_loop_, host)); 219 new GetOriginsForHostTask(this, webkit_thread_message_loop_, host));
198 task->Start(); 220 task->Start();
199 } 221 }
200 } 222 }
201 223
202 void IndexedDBQuotaClient::DeleteOriginData(const GURL& origin, 224 void IndexedDBQuotaClient::DeleteOriginData(const GURL& origin,
203 quota::StorageType type, 225 quota::StorageType type,
204 DeletionCallback* callback) { 226 DeletionCallback* callback) {
205 // TODO(tzik): implement me 227 if (type != quota::kStorageTypeTemporary) {
206 callback->Run(quota::kQuotaErrorNotSupported); 228 callback->Run(quota::kQuotaErrorNotSupported);
207 delete callback; 229 return;
230 }
231 scoped_refptr<DeleteOriginTask> task(
232 new DeleteOriginTask(this,
233 webkit_thread_message_loop_,
234 origin,
235 callback));
236 task->Start();
208 } 237 }
209 238
210 void IndexedDBQuotaClient::DidGetOriginUsage( 239 void IndexedDBQuotaClient::DidGetOriginUsage(
211 const GURL& origin_url, int64 usage) { 240 const GURL& origin_url, int64 usage) {
212 DCHECK(usage_for_origin_callbacks_.HasCallbacks(origin_url)); 241 DCHECK(usage_for_origin_callbacks_.HasCallbacks(origin_url));
213 usage_for_origin_callbacks_.Run(origin_url, usage); 242 usage_for_origin_callbacks_.Run(origin_url, usage);
214 } 243 }
215 244
216 void IndexedDBQuotaClient::DidGetAllOrigins(const std::set<GURL>& origins) { 245 void IndexedDBQuotaClient::DidGetAllOrigins(const std::set<GURL>& origins) {
217 DCHECK(origins_for_type_callbacks_.HasCallbacks()); 246 DCHECK(origins_for_type_callbacks_.HasCallbacks());
218 origins_for_type_callbacks_.Run(origins); 247 origins_for_type_callbacks_.Run(origins);
219 } 248 }
220 249
221 void IndexedDBQuotaClient::DidGetOriginsForHost( 250 void IndexedDBQuotaClient::DidGetOriginsForHost(
222 const std::string& host, const std::set<GURL>& origins) { 251 const std::string& host, const std::set<GURL>& origins) {
223 DCHECK(origins_for_host_callbacks_.HasCallbacks(host)); 252 DCHECK(origins_for_host_callbacks_.HasCallbacks(host));
224 origins_for_host_callbacks_.Run(host, origins); 253 origins_for_host_callbacks_.Run(host, origins);
225 } 254 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698