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

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

Issue 8070001: Use base::Callback in Quota related code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 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 "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/location.h" 9 #include "base/location.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 std::string host_; 130 std::string host_;
131 quota::StorageType type_; 131 quota::StorageType type_;
132 }; 132 };
133 133
134 class DatabaseQuotaClient::DeleteOriginTask : public HelperTask { 134 class DatabaseQuotaClient::DeleteOriginTask : public HelperTask {
135 public: 135 public:
136 DeleteOriginTask( 136 DeleteOriginTask(
137 DatabaseQuotaClient* client, 137 DatabaseQuotaClient* client,
138 base::MessageLoopProxy* db_tracker_thread, 138 base::MessageLoopProxy* db_tracker_thread,
139 const GURL& origin_url, 139 const GURL& origin_url,
140 DeletionCallback* caller_callback) 140 const DeletionCallback& caller_callback)
141 : HelperTask(client, db_tracker_thread), 141 : HelperTask(client, db_tracker_thread),
142 origin_url_(origin_url), 142 origin_url_(origin_url),
143 result_(quota::kQuotaStatusUnknown), 143 result_(quota::kQuotaStatusUnknown),
144 caller_callback_(caller_callback), 144 caller_callback_(caller_callback),
145 ALLOW_THIS_IN_INITIALIZER_LIST(completion_callback_( 145 ALLOW_THIS_IN_INITIALIZER_LIST(completion_callback_(
146 this, &DeleteOriginTask::OnOldCompletionCallback)) { 146 this, &DeleteOriginTask::OnOldCompletionCallback)) {
147 } 147 }
148 148
149 private: 149 private:
150 virtual void Completed() OVERRIDE { 150 virtual void Completed() OVERRIDE {
151 if (!caller_callback_.get()) 151 if (caller_callback_.is_null())
152 return; 152 return;
153 caller_callback_->Run(result_); 153 caller_callback_.Run(result_);
154 caller_callback_.reset(); 154 caller_callback_.Reset();
155 } 155 }
156 156
157 virtual void Aborted() OVERRIDE { 157 virtual void Aborted() OVERRIDE {
158 caller_callback_.reset(); 158 caller_callback_.Reset();
159 } 159 }
160 160
161 virtual bool RunOnTargetThreadAsync() OVERRIDE { 161 virtual bool RunOnTargetThreadAsync() OVERRIDE {
162 AddRef(); // balanced in OnOldCompletionCallback 162 AddRef(); // balanced in OnOldCompletionCallback
163 string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin_url_); 163 string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin_url_);
164 int rv = db_tracker_->DeleteDataForOrigin(origin_id, &completion_callback_); 164 int rv = db_tracker_->DeleteDataForOrigin(origin_id, &completion_callback_);
165 if (rv == net::ERR_IO_PENDING) 165 if (rv == net::ERR_IO_PENDING)
166 return false; // we wait for the callback 166 return false; // we wait for the callback
167 OnOldCompletionCallback(rv); 167 OnOldCompletionCallback(rv);
168 return false; 168 return false;
169 } 169 }
170 170
171 void OnOldCompletionCallback(int rv) { 171 void OnOldCompletionCallback(int rv) {
172 if (rv == net::OK) 172 if (rv == net::OK)
173 result_ = quota::kQuotaStatusOk; 173 result_ = quota::kQuotaStatusOk;
174 original_message_loop()->PostTask( 174 original_message_loop()->PostTask(
175 FROM_HERE, NewRunnableMethod(this, &DeleteOriginTask::CallCompleted)); 175 FROM_HERE, NewRunnableMethod(this, &DeleteOriginTask::CallCompleted));
176 Release(); // balanced in RunOnTargetThreadAsync 176 Release(); // balanced in RunOnTargetThreadAsync
177 } 177 }
178 178
179 const GURL origin_url_; 179 const GURL origin_url_;
180 quota::QuotaStatusCode result_; 180 quota::QuotaStatusCode result_;
181 scoped_ptr<DeletionCallback> caller_callback_; 181 DeletionCallback caller_callback_;
182 net::OldCompletionCallbackImpl<DeleteOriginTask> completion_callback_; 182 net::OldCompletionCallbackImpl<DeleteOriginTask> completion_callback_;
183 }; 183 };
184 184
185 // DatabaseQuotaClient -------------------------------------------------------- 185 // DatabaseQuotaClient --------------------------------------------------------
186 186
187 DatabaseQuotaClient::DatabaseQuotaClient( 187 DatabaseQuotaClient::DatabaseQuotaClient(
188 base::MessageLoopProxy* db_tracker_thread, 188 base::MessageLoopProxy* db_tracker_thread,
189 DatabaseTracker* db_tracker) 189 DatabaseTracker* db_tracker)
190 : db_tracker_thread_(db_tracker_thread), db_tracker_(db_tracker) { 190 : db_tracker_thread_(db_tracker_thread), db_tracker_(db_tracker) {
191 } 191 }
192 192
193 DatabaseQuotaClient::~DatabaseQuotaClient() { 193 DatabaseQuotaClient::~DatabaseQuotaClient() {
194 } 194 }
195 195
196 QuotaClient::ID DatabaseQuotaClient::id() const { 196 QuotaClient::ID DatabaseQuotaClient::id() const {
197 return kDatabase; 197 return kDatabase;
198 } 198 }
199 199
200 void DatabaseQuotaClient::OnQuotaManagerDestroyed() { 200 void DatabaseQuotaClient::OnQuotaManagerDestroyed() {
201 delete this; 201 delete this;
202 } 202 }
203 203
204 void DatabaseQuotaClient::GetOriginUsage( 204 void DatabaseQuotaClient::GetOriginUsage(
205 const GURL& origin_url, 205 const GURL& origin_url,
206 quota::StorageType type, 206 quota::StorageType type,
207 GetUsageCallback* callback_ptr) { 207 const GetUsageCallback& callback) {
208 DCHECK(callback_ptr); 208 DCHECK(!callback.is_null());
209 DCHECK(db_tracker_.get()); 209 DCHECK(db_tracker_.get());
210 scoped_ptr<GetUsageCallback> callback(callback_ptr);
211 210
212 // All databases are in the temp namespace for now. 211 // All databases are in the temp namespace for now.
213 if (type != quota::kStorageTypeTemporary) { 212 if (type != quota::kStorageTypeTemporary) {
214 callback->Run(0); 213 callback.Run(0);
215 return; 214 return;
216 } 215 }
217 216
218 if (usage_for_origin_callbacks_.Add(origin_url, callback.release())) { 217 if (usage_for_origin_callbacks_.Add(origin_url, callback)) {
219 scoped_refptr<GetOriginUsageTask> task( 218 scoped_refptr<GetOriginUsageTask> task(
220 new GetOriginUsageTask(this, db_tracker_thread_, origin_url)); 219 new GetOriginUsageTask(this, db_tracker_thread_, origin_url));
221 task->Start(); 220 task->Start();
222 } 221 }
223 } 222 }
224 223
225 void DatabaseQuotaClient::GetOriginsForType( 224 void DatabaseQuotaClient::GetOriginsForType(
226 quota::StorageType type, 225 quota::StorageType type,
227 GetOriginsCallback* callback_ptr) { 226 const GetOriginsCallback& callback) {
228 DCHECK(callback_ptr); 227 DCHECK(!callback.is_null());
229 DCHECK(db_tracker_.get()); 228 DCHECK(db_tracker_.get());
230 scoped_ptr<GetOriginsCallback> callback(callback_ptr);
231 229
232 // All databases are in the temp namespace for now. 230 // All databases are in the temp namespace for now.
233 if (type != quota::kStorageTypeTemporary) { 231 if (type != quota::kStorageTypeTemporary) {
234 callback->Run(std::set<GURL>(), type); 232 callback.Run(std::set<GURL>(), type);
235 return; 233 return;
236 } 234 }
237 235
238 if (origins_for_type_callbacks_.Add(callback.release())) { 236 if (origins_for_type_callbacks_.Add(callback)) {
239 scoped_refptr<GetAllOriginsTask> task( 237 scoped_refptr<GetAllOriginsTask> task(
240 new GetAllOriginsTask(this, db_tracker_thread_, type)); 238 new GetAllOriginsTask(this, db_tracker_thread_, type));
241 task->Start(); 239 task->Start();
242 } 240 }
243 } 241 }
244 242
245 void DatabaseQuotaClient::GetOriginsForHost( 243 void DatabaseQuotaClient::GetOriginsForHost(
246 quota::StorageType type, 244 quota::StorageType type,
247 const std::string& host, 245 const std::string& host,
248 GetOriginsCallback* callback_ptr) { 246 const GetOriginsCallback& callback) {
249 DCHECK(callback_ptr); 247 DCHECK(!callback.is_null());
250 DCHECK(db_tracker_.get()); 248 DCHECK(db_tracker_.get());
251 scoped_ptr<GetOriginsCallback> callback(callback_ptr);
252 249
253 // All databases are in the temp namespace for now. 250 // All databases are in the temp namespace for now.
254 if (type != quota::kStorageTypeTemporary) { 251 if (type != quota::kStorageTypeTemporary) {
255 callback->Run(std::set<GURL>(), type); 252 callback.Run(std::set<GURL>(), type);
256 return; 253 return;
257 } 254 }
258 255
259 if (origins_for_host_callbacks_.Add(host, callback.release())) { 256 if (origins_for_host_callbacks_.Add(host, callback)) {
260 scoped_refptr<GetOriginsForHostTask> task( 257 scoped_refptr<GetOriginsForHostTask> task(
261 new GetOriginsForHostTask(this, db_tracker_thread_, host, type)); 258 new GetOriginsForHostTask(this, db_tracker_thread_, host, type));
262 task->Start(); 259 task->Start();
263 } 260 }
264 } 261 }
265 262
266 void DatabaseQuotaClient::DeleteOriginData(const GURL& origin, 263 void DatabaseQuotaClient::DeleteOriginData(const GURL& origin,
267 quota::StorageType type, 264 quota::StorageType type,
268 DeletionCallback* callback_ptr) { 265 const DeletionCallback& callback) {
269 DCHECK(callback_ptr); 266 DCHECK(!callback.is_null());
270 DCHECK(db_tracker_.get()); 267 DCHECK(db_tracker_.get());
271 scoped_ptr<DeletionCallback> callback(callback_ptr);
272 268
273 // All databases are in the temp namespace for now, so nothing to delete. 269 // All databases are in the temp namespace for now, so nothing to delete.
274 if (type != quota::kStorageTypeTemporary) { 270 if (type != quota::kStorageTypeTemporary) {
275 callback->Run(quota::kQuotaStatusOk); 271 callback.Run(quota::kQuotaStatusOk);
276 return; 272 return;
277 } 273 }
278 274
279 scoped_refptr<DeleteOriginTask> task( 275 scoped_refptr<DeleteOriginTask> task(
280 new DeleteOriginTask(this, db_tracker_thread_, 276 new DeleteOriginTask(this, db_tracker_thread_,
281 origin, callback.release())); 277 origin, callback));
282 task->Start(); 278 task->Start();
283 } 279 }
284 280
285 void DatabaseQuotaClient::DidGetOriginUsage( 281 void DatabaseQuotaClient::DidGetOriginUsage(
286 const GURL& origin_url, int64 usage) { 282 const GURL& origin_url, int64 usage) {
287 DCHECK(usage_for_origin_callbacks_.HasCallbacks(origin_url)); 283 DCHECK(usage_for_origin_callbacks_.HasCallbacks(origin_url));
288 usage_for_origin_callbacks_.Run(origin_url, usage); 284 usage_for_origin_callbacks_.Run(origin_url, usage);
289 } 285 }
290 286
291 void DatabaseQuotaClient::DidGetAllOrigins(const std::set<GURL>& origins, 287 void DatabaseQuotaClient::DidGetAllOrigins(const std::set<GURL>& origins,
292 quota::StorageType type) { 288 quota::StorageType type) {
293 DCHECK(origins_for_type_callbacks_.HasCallbacks()); 289 DCHECK(origins_for_type_callbacks_.HasCallbacks());
294 origins_for_type_callbacks_.Run(origins, type); 290 origins_for_type_callbacks_.Run(origins, type);
295 } 291 }
296 292
297 void DatabaseQuotaClient::DidGetOriginsForHost( 293 void DatabaseQuotaClient::DidGetOriginsForHost(
298 const std::string& host, const std::set<GURL>& origins, 294 const std::string& host, const std::set<GURL>& origins,
299 quota::StorageType type) { 295 quota::StorageType type) {
300 DCHECK(origins_for_host_callbacks_.HasCallbacks(host)); 296 DCHECK(origins_for_host_callbacks_.HasCallbacks(host));
301 origins_for_host_callbacks_.Run(host, origins, type); 297 origins_for_host_callbacks_.Run(host, origins, type);
302 } 298 }
303 299
304 } // namespace webkit_database 300 } // namespace webkit_database
OLDNEW
« no previous file with comments | « webkit/database/database_quota_client.h ('k') | webkit/database/database_quota_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698