diff options
Diffstat (limited to 'content/browser/in_process_webkit')
6 files changed, 75 insertions, 83 deletions
diff --git a/content/browser/in_process_webkit/indexed_db_browsertest.cc b/content/browser/in_process_webkit/indexed_db_browsertest.cc index 62b0a28..b112e30 100644 --- a/content/browser/in_process_webkit/indexed_db_browsertest.cc +++ b/content/browser/in_process_webkit/indexed_db_browsertest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/bind.h" #include "base/command_line.h" #include "base/file_path.h" #include "base/file_util.h" @@ -233,7 +234,7 @@ class IndexedDBBrowserTestWithLowQuota : public IndexedDBBrowserTest { return; } DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - qm->SetTemporaryGlobalOverrideQuota(bytes, NULL); + qm->SetTemporaryGlobalOverrideQuota(bytes, quota::QuotaCallback()); // Don't return until the quota has been set. scoped_refptr<base::ThreadTestHelper> helper( new base::ThreadTestHelper( diff --git a/content/browser/in_process_webkit/indexed_db_context.cc b/content/browser/in_process_webkit/indexed_db_context.cc index 99b0330..59fc64a 100644 --- a/content/browser/in_process_webkit/indexed_db_context.cc +++ b/content/browser/in_process_webkit/indexed_db_context.cc @@ -4,6 +4,7 @@ #include "content/browser/in_process_webkit/indexed_db_context.h" +#include "base/bind.h" #include "base/command_line.h" #include "base/file_util.h" #include "base/logging.h" @@ -87,41 +88,6 @@ const FilePath::CharType IndexedDBContext::kIndexedDBDirectory[] = const FilePath::CharType IndexedDBContext::kIndexedDBExtension[] = FILE_PATH_LITERAL(".leveldb"); -class IndexedDBContext::IndexedDBGetUsageAndQuotaCallback : - public quota::QuotaManager::GetUsageAndQuotaCallback { - public: - IndexedDBGetUsageAndQuotaCallback(IndexedDBContext* context, - const GURL& origin_url) - : context_(context), - origin_url_(origin_url) { - } - - void Run(quota::QuotaStatusCode status, int64 usage, int64 quota) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - DCHECK(status == quota::kQuotaStatusOk || status == quota::kQuotaErrorAbort) - << "status was " << status; - if (status == quota::kQuotaErrorAbort) { - // We seem to no longer care to wait around for the answer. - return; - } - BrowserThread::PostTask(BrowserThread::WEBKIT, FROM_HERE, - NewRunnableMethod(context_.get(), - &IndexedDBContext::GotUpdatedQuota, - origin_url_, - usage, - quota)); - } - - virtual void RunWithParams( - const Tuple3<quota::QuotaStatusCode, int64, int64>& params) { - Run(params.a, params.b, params.c); - } - - private: - scoped_refptr<IndexedDBContext> context_; - const GURL origin_url_; -}; - IndexedDBContext::IndexedDBContext( WebKitContext* webkit_context, quota::SpecialStoragePolicy* special_storage_policy, @@ -316,6 +282,25 @@ void IndexedDBContext::QueryDiskAndUpdateQuotaUsage(const GURL& origin_url) { } } +void IndexedDBContext::GotUsageAndQuota(const GURL& origin_url, + quota::QuotaStatusCode status, + int64 usage, int64 quota) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + DCHECK(status == quota::kQuotaStatusOk || status == quota::kQuotaErrorAbort) + << "status was " << status; + if (status == quota::kQuotaErrorAbort) { + // We seem to no longer care to wait around for the answer. + return; + } + BrowserThread::PostTask( + BrowserThread::WEBKIT, FROM_HERE, + NewRunnableMethod(this, + &IndexedDBContext::GotUpdatedQuota, + origin_url, + usage, + quota)); +} + void IndexedDBContext::GotUpdatedQuota(const GURL& origin_url, int64 usage, int64 quota) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); @@ -334,12 +319,11 @@ void IndexedDBContext::QueryAvailableQuota(const GURL& origin_url) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); if (!quota_manager_proxy()->quota_manager()) return; - IndexedDBGetUsageAndQuotaCallback* callback = - new IndexedDBGetUsageAndQuotaCallback(this, origin_url); quota_manager_proxy()->quota_manager()->GetUsageAndQuota( origin_url, quota::kStorageTypeTemporary, - callback); + base::Bind(&IndexedDBContext::GotUsageAndQuota, + this, origin_url)); } std::set<GURL>* IndexedDBContext::GetOriginSet() { diff --git a/content/browser/in_process_webkit/indexed_db_context.h b/content/browser/in_process_webkit/indexed_db_context.h index a7207e6..19c6b91 100644 --- a/content/browser/in_process_webkit/indexed_db_context.h +++ b/content/browser/in_process_webkit/indexed_db_context.h @@ -18,6 +18,7 @@ #include "content/browser/browser_thread.h" #include "content/common/content_export.h" #include "googleurl/src/gurl.h" +#include "webkit/quota/quota_types.h" class GURL; class FilePath; @@ -94,6 +95,8 @@ class CONTENT_EXPORT IndexedDBContext int64 ReadUsageFromDisk(const GURL& origin_url) const; void EnsureDiskUsageCacheInitialized(const GURL& origin_url); void QueryDiskAndUpdateQuotaUsage(const GURL& origin_url); + void GotUsageAndQuota(const GURL& origin_url, quota::QuotaStatusCode, + int64 usage, int64 quota); void GotUpdatedQuota(const GURL& origin_url, int64 usage, int64 quota); void QueryAvailableQuota(const GURL& origin_url); diff --git a/content/browser/in_process_webkit/indexed_db_quota_client.cc b/content/browser/in_process_webkit/indexed_db_quota_client.cc index 618f147..ce60d83 100644 --- a/content/browser/in_process_webkit/indexed_db_quota_client.cc +++ b/content/browser/in_process_webkit/indexed_db_quota_client.cc @@ -36,7 +36,7 @@ class IndexedDBQuotaClient::DeleteOriginTask : public HelperTask { DeleteOriginTask(IndexedDBQuotaClient* client, base::MessageLoopProxy* webkit_thread_message_loop, const GURL& origin_url, - DeletionCallback* callback) + const DeletionCallback& callback) : HelperTask(client, webkit_thread_message_loop), origin_url_(origin_url), callback_(callback) { } @@ -45,14 +45,14 @@ class IndexedDBQuotaClient::DeleteOriginTask : public HelperTask { indexed_db_context_->DeleteIndexedDBForOrigin(origin_url_); } virtual void Aborted() OVERRIDE { - callback_.reset(); + callback_.Reset(); } virtual void Completed() OVERRIDE { - callback_->Run(quota::kQuotaStatusOk); - callback_.reset(); + callback_.Run(quota::kQuotaStatusOk); + callback_.Reset(); } GURL origin_url_; - scoped_ptr<DeletionCallback> callback_; + DeletionCallback callback_; }; class IndexedDBQuotaClient::GetOriginUsageTask : public HelperTask { @@ -168,18 +168,17 @@ void IndexedDBQuotaClient::OnQuotaManagerDestroyed() { void IndexedDBQuotaClient::GetOriginUsage( const GURL& origin_url, quota::StorageType type, - GetUsageCallback* callback_ptr) { - DCHECK(callback_ptr); + const GetUsageCallback& callback) { + DCHECK(!callback.is_null()); DCHECK(indexed_db_context_.get()); - scoped_ptr<GetUsageCallback> callback(callback_ptr); // IndexedDB is in the temp namespace for now. if (type != quota::kStorageTypeTemporary) { - callback->Run(0); + callback.Run(0); return; } - if (usage_for_origin_callbacks_.Add(origin_url, callback.release())) { + if (usage_for_origin_callbacks_.Add(origin_url, callback)) { scoped_refptr<GetOriginUsageTask> task( new GetOriginUsageTask(this, webkit_thread_message_loop_, origin_url)); task->Start(); @@ -188,18 +187,17 @@ void IndexedDBQuotaClient::GetOriginUsage( void IndexedDBQuotaClient::GetOriginsForType( quota::StorageType type, - GetOriginsCallback* callback_ptr) { - DCHECK(callback_ptr); + const GetOriginsCallback& callback) { + DCHECK(!callback.is_null()); DCHECK(indexed_db_context_.get()); - scoped_ptr<GetOriginsCallback> callback(callback_ptr); // All databases are in the temp namespace for now. if (type != quota::kStorageTypeTemporary) { - callback->Run(std::set<GURL>(), type); + callback.Run(std::set<GURL>(), type); return; } - if (origins_for_type_callbacks_.Add(callback.release())) { + if (origins_for_type_callbacks_.Add(callback)) { scoped_refptr<GetAllOriginsTask> task( new GetAllOriginsTask(this, webkit_thread_message_loop_, type)); task->Start(); @@ -209,18 +207,17 @@ void IndexedDBQuotaClient::GetOriginsForType( void IndexedDBQuotaClient::GetOriginsForHost( quota::StorageType type, const std::string& host, - GetOriginsCallback* callback_ptr) { - DCHECK(callback_ptr); + const GetOriginsCallback& callback) { + DCHECK(!callback.is_null()); DCHECK(indexed_db_context_.get()); - scoped_ptr<GetOriginsCallback> callback(callback_ptr); // All databases are in the temp namespace for now. if (type != quota::kStorageTypeTemporary) { - callback->Run(std::set<GURL>(), type); + callback.Run(std::set<GURL>(), type); return; } - if (origins_for_host_callbacks_.Add(host, callback.release())) { + if (origins_for_host_callbacks_.Add(host, callback)) { scoped_refptr<GetOriginsForHostTask> task( new GetOriginsForHostTask( this, webkit_thread_message_loop_, host, type)); @@ -228,11 +225,12 @@ void IndexedDBQuotaClient::GetOriginsForHost( } } -void IndexedDBQuotaClient::DeleteOriginData(const GURL& origin, - quota::StorageType type, - DeletionCallback* callback) { +void IndexedDBQuotaClient::DeleteOriginData( + const GURL& origin, + quota::StorageType type, + const DeletionCallback& callback) { if (type != quota::kStorageTypeTemporary) { - callback->Run(quota::kQuotaErrorNotSupported); + callback.Run(quota::kQuotaErrorNotSupported); return; } scoped_refptr<DeleteOriginTask> task( diff --git a/content/browser/in_process_webkit/indexed_db_quota_client.h b/content/browser/in_process_webkit/indexed_db_quota_client.h index 8b2838e..90f13a2 100644 --- a/content/browser/in_process_webkit/indexed_db_quota_client.h +++ b/content/browser/in_process_webkit/indexed_db_quota_client.h @@ -33,15 +33,15 @@ class IndexedDBQuotaClient : public quota::QuotaClient, virtual void OnQuotaManagerDestroyed() OVERRIDE; virtual void GetOriginUsage(const GURL& origin_url, quota::StorageType type, - GetUsageCallback* callback) OVERRIDE; + const GetUsageCallback& callback) OVERRIDE; virtual void GetOriginsForType(quota::StorageType type, - GetOriginsCallback* callback) OVERRIDE; + const GetOriginsCallback& callback) OVERRIDE; virtual void GetOriginsForHost(quota::StorageType type, const std::string& host, - GetOriginsCallback* callback) OVERRIDE; + const GetOriginsCallback& callback) OVERRIDE; virtual void DeleteOriginData(const GURL& origin, quota::StorageType type, - DeletionCallback* callback) OVERRIDE; + const DeletionCallback& callback) OVERRIDE; private: class HelperTask; class GetOriginUsageTask; @@ -51,17 +51,17 @@ class IndexedDBQuotaClient : public quota::QuotaClient, class DeleteOriginTask; typedef quota::CallbackQueueMap1 - <GetUsageCallback*, + <GetUsageCallback, GURL, // origin int64 > UsageForOriginCallbackMap; typedef quota::CallbackQueue2 - <GetOriginsCallback*, + <GetOriginsCallback, const std::set<GURL>&, quota::StorageType > OriginsForTypeCallbackQueue; typedef quota::CallbackQueueMap2 - <GetOriginsCallback*, + <GetOriginsCallback, std::string, // host const std::set<GURL>&, quota::StorageType diff --git a/content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc b/content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc index d36f217..0b9d274 100644 --- a/content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc +++ b/content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc @@ -4,6 +4,7 @@ #include <map> +#include "base/bind.h" #include "base/file_path.h" #include "base/file_util.h" #include "base/memory/scoped_callback_factory.h" @@ -35,7 +36,7 @@ class IndexedDBQuotaClientTest : public testing::Test { kOriginB("http://host:8000"), kOriginOther("http://other"), usage_(0), - callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), + weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), message_loop_(MessageLoop::TYPE_IO), webkit_thread_(BrowserThread::WEBKIT, &message_loop_), io_thread_(BrowserThread::IO, &message_loop_) { @@ -64,9 +65,10 @@ class IndexedDBQuotaClientTest : public testing::Test { const GURL& origin, quota::StorageType type) { usage_ = -1; - client->GetOriginUsage(origin, type, - callback_factory_.NewCallback( - &IndexedDBQuotaClientTest::OnGetOriginUsageComplete)); + client->GetOriginUsage( + origin, type, + base::Bind(&IndexedDBQuotaClientTest::OnGetOriginUsageComplete, + weak_factory_.GetWeakPtr())); MessageLoop::current()->RunAllPending(); EXPECT_GT(usage_, -1); return usage_; @@ -77,9 +79,10 @@ class IndexedDBQuotaClientTest : public testing::Test { quota::StorageType type) { origins_.clear(); type_ = quota::kStorageTypeTemporary; - client->GetOriginsForType(type, - callback_factory_.NewCallback( - &IndexedDBQuotaClientTest::OnGetOriginsComplete)); + client->GetOriginsForType( + type, + base::Bind(&IndexedDBQuotaClientTest::OnGetOriginsComplete, + weak_factory_.GetWeakPtr())); MessageLoop::current()->RunAllPending(); return origins_; } @@ -90,9 +93,10 @@ class IndexedDBQuotaClientTest : public testing::Test { const std::string& host) { origins_.clear(); type_ = quota::kStorageTypeTemporary; - client->GetOriginsForHost(type, host, - callback_factory_.NewCallback( - &IndexedDBQuotaClientTest::OnGetOriginsComplete)); + client->GetOriginsForHost( + type, host, + base::Bind(&IndexedDBQuotaClientTest::OnGetOriginsComplete, + weak_factory_.GetWeakPtr())); MessageLoop::current()->RunAllPending(); return origins_; } @@ -100,8 +104,10 @@ class IndexedDBQuotaClientTest : public testing::Test { quota::QuotaStatusCode DeleteOrigin(quota::QuotaClient* client, const GURL& origin_url) { delete_status_ = quota::kQuotaStatusUnknown; - client->DeleteOriginData(origin_url, kTemp, callback_factory_.NewCallback( - &IndexedDBQuotaClientTest::OnDeleteOriginComplete)); + client->DeleteOriginData( + origin_url, kTemp, + base::Bind(&IndexedDBQuotaClientTest::OnDeleteOriginComplete, + weak_factory_.GetWeakPtr())); MessageLoop::current()->RunAllPending(); return delete_status_; } @@ -145,7 +151,7 @@ class IndexedDBQuotaClientTest : public testing::Test { std::set<GURL> origins_; quota::StorageType type_; scoped_refptr<IndexedDBContext> idb_context_; - base::ScopedCallbackFactory<IndexedDBQuotaClientTest> callback_factory_; + base::WeakPtrFactory<IndexedDBQuotaClientTest> weak_factory_; MessageLoop message_loop_; BrowserThread webkit_thread_; BrowserThread io_thread_; |