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

Side by Side Diff: webkit/database/database_quota_client.cc

Issue 7046019: Implement DatabaseQuotaClient's DeteleteOriginData method. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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
« no previous file with comments | « webkit/database/database_quota_client.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "webkit/database/database_quota_client.h" 5 #include "webkit/database/database_quota_client.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/message_loop_proxy.h" 9 #include "base/message_loop_proxy.h"
10 #include "base/memory/scoped_ptr.h"
michaeln 2011/05/20 05:14:23 i'll fix the ordering here
11 #include "net/base/completion_callback.h"
12 #include "net/base/net_errors.h"
10 #include "net/base/net_util.h" 13 #include "net/base/net_util.h"
11 #include "webkit/database/database_tracker.h" 14 #include "webkit/database/database_tracker.h"
12 #include "webkit/database/database_util.h" 15 #include "webkit/database/database_util.h"
13 16
14 using quota::QuotaClient; 17 using quota::QuotaClient;
15 18
16 namespace webkit_database { 19 namespace webkit_database {
17 20
18 // Helper tasks --------------------------------------------------------------- 21 // Helper tasks ---------------------------------------------------------------
19 22
20 class DatabaseQuotaClient::HelperTask : public quota::QuotaThreadTask { 23 class DatabaseQuotaClient::HelperTask : public quota::QuotaThreadTask {
21 protected: 24 protected:
22 HelperTask( 25 HelperTask(
23 DatabaseQuotaClient* client, 26 DatabaseQuotaClient* client,
24 scoped_refptr<base::MessageLoopProxy> db_tracker_thread) 27 base::MessageLoopProxy* db_tracker_thread)
25 : QuotaThreadTask(client, db_tracker_thread), 28 : QuotaThreadTask(client, db_tracker_thread),
26 client_(client), db_tracker_(client->db_tracker_) { 29 client_(client), db_tracker_(client->db_tracker_) {
27 } 30 }
28 31
29 DatabaseQuotaClient* client_; 32 DatabaseQuotaClient* client_;
30 scoped_refptr<DatabaseTracker> db_tracker_; 33 scoped_refptr<DatabaseTracker> db_tracker_;
31 }; 34 };
32 35
33 class DatabaseQuotaClient::GetOriginUsageTask : public HelperTask { 36 class DatabaseQuotaClient::GetOriginUsageTask : public HelperTask {
34 public: 37 public:
35 GetOriginUsageTask( 38 GetOriginUsageTask(
36 DatabaseQuotaClient* client, 39 DatabaseQuotaClient* client,
37 scoped_refptr<base::MessageLoopProxy> db_tracker_thread, 40 base::MessageLoopProxy* db_tracker_thread,
38 const GURL& origin_url) 41 const GURL& origin_url)
39 : HelperTask(client, db_tracker_thread), 42 : HelperTask(client, db_tracker_thread),
40 origin_url_(origin_url), usage_(0) { 43 origin_url_(origin_url), usage_(0) {
41 } 44 }
42 45
43 private: 46 private:
44 virtual void RunOnTargetThread() OVERRIDE { 47 virtual void RunOnTargetThread() OVERRIDE {
45 OriginInfo info; 48 OriginInfo info;
46 if (db_tracker_->GetOriginInfo( 49 if (db_tracker_->GetOriginInfo(
47 DatabaseUtil::GetOriginIdentifier(origin_url_), 50 DatabaseUtil::GetOriginIdentifier(origin_url_),
48 &info)) { 51 &info)) {
49 usage_ = info.TotalSize(); 52 usage_ = info.TotalSize();
50 } 53 }
51 } 54 }
52 virtual void Completed() OVERRIDE { 55 virtual void Completed() OVERRIDE {
53 client_->DidGetOriginUsage(origin_url_, usage_); 56 client_->DidGetOriginUsage(origin_url_, usage_);
54 } 57 }
55 GURL origin_url_; 58 GURL origin_url_;
56 int64 usage_; 59 int64 usage_;
57 }; 60 };
58 61
59 class DatabaseQuotaClient::GetOriginsTaskBase : public HelperTask { 62 class DatabaseQuotaClient::GetOriginsTaskBase : public HelperTask {
60 protected: 63 protected:
61 GetOriginsTaskBase( 64 GetOriginsTaskBase(
62 DatabaseQuotaClient* client, 65 DatabaseQuotaClient* client,
63 scoped_refptr<base::MessageLoopProxy> db_tracker_thread) 66 base::MessageLoopProxy* db_tracker_thread)
64 : HelperTask(client, db_tracker_thread) { 67 : HelperTask(client, db_tracker_thread) {
65 } 68 }
66 69
67 virtual bool ShouldAddOrigin(const GURL& origin) = 0; 70 virtual bool ShouldAddOrigin(const GURL& origin) = 0;
68 71
69 virtual void RunOnTargetThread() OVERRIDE { 72 virtual void RunOnTargetThread() OVERRIDE {
70 std::vector<string16> origin_identifiers; 73 std::vector<string16> origin_identifiers;
71 if (db_tracker_->GetAllOriginIdentifiers(&origin_identifiers)) { 74 if (db_tracker_->GetAllOriginIdentifiers(&origin_identifiers)) {
72 for (std::vector<string16>::const_iterator iter = 75 for (std::vector<string16>::const_iterator iter =
73 origin_identifiers.begin(); 76 origin_identifiers.begin();
74 iter != origin_identifiers.end(); ++iter) { 77 iter != origin_identifiers.end(); ++iter) {
75 GURL origin = DatabaseUtil::GetOriginFromIdentifier(*iter); 78 GURL origin = DatabaseUtil::GetOriginFromIdentifier(*iter);
76 if (ShouldAddOrigin(origin)) 79 if (ShouldAddOrigin(origin))
77 origins_.insert(origin); 80 origins_.insert(origin);
78 } 81 }
79 } 82 }
80 } 83 }
81 84
82 std::set<GURL> origins_; 85 std::set<GURL> origins_;
83 }; 86 };
84 87
85 class DatabaseQuotaClient::GetAllOriginsTask : public GetOriginsTaskBase { 88 class DatabaseQuotaClient::GetAllOriginsTask : public GetOriginsTaskBase {
86 public: 89 public:
87 GetAllOriginsTask( 90 GetAllOriginsTask(
88 DatabaseQuotaClient* client, 91 DatabaseQuotaClient* client,
89 scoped_refptr<base::MessageLoopProxy> db_tracker_thread) 92 base::MessageLoopProxy* db_tracker_thread)
90 : GetOriginsTaskBase(client, db_tracker_thread) { 93 : GetOriginsTaskBase(client, db_tracker_thread) {
91 } 94 }
92 95
93 protected: 96 protected:
94 virtual bool ShouldAddOrigin(const GURL& origin) OVERRIDE { 97 virtual bool ShouldAddOrigin(const GURL& origin) OVERRIDE {
95 return true; 98 return true;
96 } 99 }
97 virtual void Completed() OVERRIDE { 100 virtual void Completed() OVERRIDE {
98 client_->DidGetAllOrigins(origins_); 101 client_->DidGetAllOrigins(origins_);
99 } 102 }
100 }; 103 };
101 104
102 class DatabaseQuotaClient::GetOriginsForHostTask : public GetOriginsTaskBase { 105 class DatabaseQuotaClient::GetOriginsForHostTask : public GetOriginsTaskBase {
103 public: 106 public:
104 GetOriginsForHostTask( 107 GetOriginsForHostTask(
105 DatabaseQuotaClient* client, 108 DatabaseQuotaClient* client,
106 scoped_refptr<base::MessageLoopProxy> db_tracker_thread, 109 base::MessageLoopProxy* db_tracker_thread,
107 const std::string& host) 110 const std::string& host)
108 : GetOriginsTaskBase(client, db_tracker_thread), 111 : GetOriginsTaskBase(client, db_tracker_thread),
109 host_(host) { 112 host_(host) {
110 } 113 }
111 114
112 private: 115 private:
113 virtual bool ShouldAddOrigin(const GURL& origin) OVERRIDE { 116 virtual bool ShouldAddOrigin(const GURL& origin) OVERRIDE {
114 return host_ == net::GetHostOrSpecFromURL(origin); 117 return host_ == net::GetHostOrSpecFromURL(origin);
115 } 118 }
116 virtual void Completed() OVERRIDE { 119 virtual void Completed() OVERRIDE {
117 client_->DidGetOriginsForHost(host_, origins_); 120 client_->DidGetOriginsForHost(host_, origins_);
118 } 121 }
119 std::string host_; 122 std::string host_;
120 }; 123 };
121 124
125 class DatabaseQuotaClient::DeleteOriginTask : public HelperTask {
126 public:
127 DeleteOriginTask(
128 DatabaseQuotaClient* client,
129 base::MessageLoopProxy* db_tracker_thread,
130 const GURL& origin_url,
131 DeletionCallback* caller_callback)
132 : HelperTask(client, db_tracker_thread),
133 origin_url_(origin_url),
134 result_(quota::kQuotaStatusUnknown),
135 is_complete_(false),
136 caller_callback_(caller_callback),
137 ALLOW_THIS_IN_INITIALIZER_LIST(completion_callback_(
138 this, &DeleteOriginTask::OnCompletionCallback)) {
139 }
140
141 private:
142 virtual void Completed() OVERRIDE {
143 if (!is_complete_ || !caller_callback_.get())
144 return; // not done yet or we were aborted
145 caller_callback_->Run(result_);
146 caller_callback_.reset();
147 }
148
149 virtual void Aborted() OVERRIDE {
150 caller_callback_.reset();
151 }
152
153 virtual void RunOnTargetThread() OVERRIDE {
154 AddRef(); // balanced in OnCompletionCallback
155
156 string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin_url_);
157 int rv = db_tracker_->DeleteDataForOrigin(origin_id, &completion_callback_);
158 if (rv == net::ERR_IO_PENDING)
159 return; // we wait for the callback
160
161 OnCompletionCallback(rv);
162 }
163
164 void OnCompletionCallback(int rv) {
165 is_complete_ = true;
166 if (rv == net::OK)
167 result_ = quota::kQuotaStatusOk;
168 original_message_loop()->PostTask(
169 FROM_HERE, NewRunnableMethod(this, &DeleteOriginTask::Completed));
170 Release();
171 }
172
173 const GURL origin_url_;
174 quota::QuotaStatusCode result_;
175 bool is_complete_;
176 scoped_ptr<DeletionCallback> caller_callback_;
177 net::CompletionCallbackImpl<DeleteOriginTask> completion_callback_;
178 };
179
122 // DatabaseQuotaClient -------------------------------------------------------- 180 // DatabaseQuotaClient --------------------------------------------------------
123 181
124 DatabaseQuotaClient::DatabaseQuotaClient( 182 DatabaseQuotaClient::DatabaseQuotaClient(
125 base::MessageLoopProxy* db_tracker_thread, 183 base::MessageLoopProxy* db_tracker_thread,
126 DatabaseTracker* db_tracker) 184 DatabaseTracker* db_tracker)
127 : db_tracker_thread_(db_tracker_thread), db_tracker_(db_tracker) { 185 : db_tracker_thread_(db_tracker_thread), db_tracker_(db_tracker) {
128 } 186 }
129 187
130 DatabaseQuotaClient::~DatabaseQuotaClient() { 188 DatabaseQuotaClient::~DatabaseQuotaClient() {
131 } 189 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 253
196 if (origins_for_host_callbacks_.Add(host, callback.release())) { 254 if (origins_for_host_callbacks_.Add(host, callback.release())) {
197 scoped_refptr<GetOriginsForHostTask> task( 255 scoped_refptr<GetOriginsForHostTask> task(
198 new GetOriginsForHostTask(this, db_tracker_thread_, host)); 256 new GetOriginsForHostTask(this, db_tracker_thread_, host));
199 task->Start(); 257 task->Start();
200 } 258 }
201 } 259 }
202 260
203 void DatabaseQuotaClient::DeleteOriginData(const GURL& origin, 261 void DatabaseQuotaClient::DeleteOriginData(const GURL& origin,
204 quota::StorageType type, 262 quota::StorageType type,
205 DeletionCallback* callback) { 263 DeletionCallback* callback_ptr) {
206 // TODO(tzik): implement me 264 DCHECK(callback_ptr);
207 callback->Run(quota::kQuotaErrorNotSupported); 265 DCHECK(db_tracker_.get());
208 delete callback; 266 scoped_ptr<DeletionCallback> callback(callback_ptr);
267
268 // All databases are in the temp namespace for now.
269 if (type != quota::kStorageTypeTemporary) {
270 callback->Run(quota::kQuotaStatusOk);
271 return;
272 }
273
274 scoped_refptr<DeleteOriginTask> task(
275 new DeleteOriginTask(this, db_tracker_thread_,
276 origin, callback.release()));
277 task->Start();
209 } 278 }
210 279
211 void DatabaseQuotaClient::DidGetOriginUsage( 280 void DatabaseQuotaClient::DidGetOriginUsage(
212 const GURL& origin_url, int64 usage) { 281 const GURL& origin_url, int64 usage) {
213 DCHECK(usage_for_origin_callbacks_.HasCallbacks(origin_url)); 282 DCHECK(usage_for_origin_callbacks_.HasCallbacks(origin_url));
214 usage_for_origin_callbacks_.Run(origin_url, usage); 283 usage_for_origin_callbacks_.Run(origin_url, usage);
215 } 284 }
216 285
217 void DatabaseQuotaClient::DidGetAllOrigins(const std::set<GURL>& origins) { 286 void DatabaseQuotaClient::DidGetAllOrigins(const std::set<GURL>& origins) {
218 DCHECK(origins_for_type_callbacks_.HasCallbacks()); 287 DCHECK(origins_for_type_callbacks_.HasCallbacks());
219 origins_for_type_callbacks_.Run(origins); 288 origins_for_type_callbacks_.Run(origins);
220 } 289 }
221 290
222 void DatabaseQuotaClient::DidGetOriginsForHost( 291 void DatabaseQuotaClient::DidGetOriginsForHost(
223 const std::string& host, const std::set<GURL>& origins) { 292 const std::string& host, const std::set<GURL>& origins) {
224 DCHECK(origins_for_host_callbacks_.HasCallbacks(host)); 293 DCHECK(origins_for_host_callbacks_.HasCallbacks(host));
225 origins_for_host_callbacks_.Run(host, origins); 294 origins_for_host_callbacks_.Run(host, origins);
226 } 295 }
227 296
228 } // namespace webkit_database 297 } // namespace webkit_database
OLDNEW
« no previous file with comments | « webkit/database/database_quota_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698