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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: webkit/database/database_quota_client.cc
===================================================================
--- webkit/database/database_quota_client.cc (revision 85641)
+++ webkit/database/database_quota_client.cc (working copy)
@@ -6,7 +6,10 @@
#include <vector>
+#include "base/memory/scoped_ptr.h"
#include "base/message_loop_proxy.h"
+#include "net/base/completion_callback.h"
+#include "net/base/net_errors.h"
#include "net/base/net_util.h"
#include "webkit/database/database_tracker.h"
#include "webkit/database/database_util.h"
@@ -21,7 +24,7 @@
protected:
HelperTask(
DatabaseQuotaClient* client,
- scoped_refptr<base::MessageLoopProxy> db_tracker_thread)
+ base::MessageLoopProxy* db_tracker_thread)
: QuotaThreadTask(client, db_tracker_thread),
client_(client), db_tracker_(client->db_tracker_) {
}
@@ -34,7 +37,7 @@
public:
GetOriginUsageTask(
DatabaseQuotaClient* client,
- scoped_refptr<base::MessageLoopProxy> db_tracker_thread,
+ base::MessageLoopProxy* db_tracker_thread,
const GURL& origin_url)
: HelperTask(client, db_tracker_thread),
origin_url_(origin_url), usage_(0) {
@@ -60,7 +63,7 @@
protected:
GetOriginsTaskBase(
DatabaseQuotaClient* client,
- scoped_refptr<base::MessageLoopProxy> db_tracker_thread)
+ base::MessageLoopProxy* db_tracker_thread)
: HelperTask(client, db_tracker_thread) {
}
@@ -86,7 +89,7 @@
public:
GetAllOriginsTask(
DatabaseQuotaClient* client,
- scoped_refptr<base::MessageLoopProxy> db_tracker_thread)
+ base::MessageLoopProxy* db_tracker_thread)
: GetOriginsTaskBase(client, db_tracker_thread) {
}
@@ -103,7 +106,7 @@
public:
GetOriginsForHostTask(
DatabaseQuotaClient* client,
- scoped_refptr<base::MessageLoopProxy> db_tracker_thread,
+ base::MessageLoopProxy* db_tracker_thread,
const std::string& host)
: GetOriginsTaskBase(client, db_tracker_thread),
host_(host) {
@@ -119,6 +122,57 @@
std::string host_;
};
+class DatabaseQuotaClient::DeleteOriginTask : public HelperTask {
+ public:
+ DeleteOriginTask(
+ DatabaseQuotaClient* client,
+ base::MessageLoopProxy* db_tracker_thread,
+ const GURL& origin_url,
+ DeletionCallback* caller_callback)
+ : HelperTask(client, db_tracker_thread),
+ origin_url_(origin_url),
+ result_(quota::kQuotaStatusUnknown),
+ caller_callback_(caller_callback),
+ ALLOW_THIS_IN_INITIALIZER_LIST(completion_callback_(
+ this, &DeleteOriginTask::OnCompletionCallback)) {
+ }
+
+ private:
+ virtual void Completed() OVERRIDE {
+ if (!caller_callback_.get())
+ return;
+ caller_callback_->Run(result_);
+ caller_callback_.reset();
+ }
+
+ virtual void Aborted() OVERRIDE {
+ caller_callback_.reset();
+ }
+
+ virtual bool RunOnTargetThreadAsync() OVERRIDE {
+ AddRef(); // balanced in OnCompletionCallback
+ string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin_url_);
+ int rv = db_tracker_->DeleteDataForOrigin(origin_id, &completion_callback_);
+ if (rv == net::ERR_IO_PENDING)
+ return false; // we wait for the callback
+ OnCompletionCallback(rv);
+ return false;
+ }
+
+ void OnCompletionCallback(int rv) {
+ if (rv == net::OK)
+ result_ = quota::kQuotaStatusOk;
+ original_message_loop()->PostTask(
+ FROM_HERE, NewRunnableMethod(this, &DeleteOriginTask::CallCompleted));
+ Release(); // balanced in RunOnTargetThread
kinuko 2011/05/23 04:55:53 nit: RunOnTargetThread -> ...Async (in the comment
michaeln 2011/05/23 21:56:52 Done.
+ }
+
+ const GURL origin_url_;
+ quota::QuotaStatusCode result_;
+ scoped_ptr<DeletionCallback> caller_callback_;
+ net::CompletionCallbackImpl<DeleteOriginTask> completion_callback_;
+};
+
// DatabaseQuotaClient --------------------------------------------------------
DatabaseQuotaClient::DatabaseQuotaClient(
@@ -202,10 +256,21 @@
void DatabaseQuotaClient::DeleteOriginData(const GURL& origin,
quota::StorageType type,
- DeletionCallback* callback) {
- // TODO(tzik): implement me
- callback->Run(quota::kQuotaErrorNotSupported);
- delete callback;
+ DeletionCallback* callback_ptr) {
+ DCHECK(callback_ptr);
+ DCHECK(db_tracker_.get());
+ scoped_ptr<DeletionCallback> callback(callback_ptr);
+
+ // All databases are in the temp namespace for now.
kinuko 2011/05/23 04:55:53 Can we also say something like '... and no need to
michaeln 2011/05/23 21:56:52 Done.
+ if (type != quota::kStorageTypeTemporary) {
+ callback->Run(quota::kQuotaStatusOk);
+ return;
+ }
+
+ scoped_refptr<DeleteOriginTask> task(
+ new DeleteOriginTask(this, db_tracker_thread_,
+ origin, callback.release()));
+ task->Start();
}
void DatabaseQuotaClient::DidGetOriginUsage(

Powered by Google App Engine
This is Rietveld 408576698