Chromium Code Reviews| Index: webkit/database/database_quota_client.cc |
| =================================================================== |
| --- webkit/database/database_quota_client.cc (revision 85641) |
| +++ webkit/database/database_quota_client.cc (working copy) |
| @@ -7,6 +7,9 @@ |
| #include <vector> |
| #include "base/message_loop_proxy.h" |
| +#include "base/memory/scoped_ptr.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,67 @@ |
| 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), |
| + is_complete_(false), |
| + caller_callback_(caller_callback), |
| + ALLOW_THIS_IN_INITIALIZER_LIST(completion_callback_( |
| + this, &DeleteOriginTask::OnCompletionCallback)) { |
| + } |
| + |
| + private: |
| + virtual void Completed() OVERRIDE { |
| + if (!is_complete_ || !caller_callback_.get()) |
| + return; // not done yet or we were aborted |
| + caller_callback_->Run(result_); |
| + caller_callback_.reset(); |
| + } |
| + |
| + virtual void Aborted() OVERRIDE { |
| + caller_callback_.reset(); // should i call it with the ABORT status code? |
|
kinuko
2011/05/20 02:13:24
If we could assume this task wouldn't be aborted e
michaeln
2011/05/20 05:14:23
keeping parity with the fsclient is good, so long
|
| + } |
| + |
| + virtual void RunOnTargetThread() OVERRIDE { |
| + AddRef(); // balanced in CompletionCallback |
| + |
| + string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin_url_); |
| + OriginInfo info; |
| + if (!db_tracker_->GetOriginInfo(origin_id, &info)) { |
| + OnCompletionCallback(net::OK); |
| + return; |
| + } |
| + |
| + int rv = db_tracker_->DeleteDataForOrigin(origin_id, &completion_callback_); |
| + if (rv == net::ERR_IO_PENDING) |
| + return; // we wait for the callback |
| + |
| + OnCompletionCallback(rv); |
| + } |
| + |
| + void OnCompletionCallback(int rv) { |
| + is_complete_ = true; |
| + if (rv == net::OK) |
| + result_ = quota::kQuotaStatusOk; |
| + original_message_loop()->PostTask( |
| + FROM_HERE, NewRunnableMethod(this, &DeleteOriginTask::Completed)); |
| + Release(); |
| + } |
| + |
| + const GURL origin_url_; |
| + quota::QuotaStatusCode result_; |
| + bool is_complete_; |
| + scoped_ptr<DeletionCallback> caller_callback_; |
| + net::CompletionCallbackImpl<DeleteOriginTask> completion_callback_; |
| +}; |
| + |
| // DatabaseQuotaClient -------------------------------------------------------- |
| DatabaseQuotaClient::DatabaseQuotaClient( |
| @@ -202,10 +266,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. |
| + if (type != quota::kStorageTypeTemporary) { |
| + callback->Run(quota::kQuotaStatusOk); |
|
tzik
2011/05/20 03:19:54
maybe callback->Run(quota::kQuotaErrorNotSupported
michaeln
2011/05/20 05:14:23
There's no way for the caller to know not to call
tzik
2011/05/20 13:26:50
I see. I totally agree with you.
|
| + return; |
| + } |
| + |
| + scoped_refptr<DeleteOriginTask> task( |
| + new DeleteOriginTask(this, db_tracker_thread_, |
| + origin, callback.release())); |
| + task->Start(); |
| } |
| void DatabaseQuotaClient::DidGetOriginUsage( |