summaryrefslogtreecommitdiffstats
path: root/webkit/quota
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-18 20:29:47 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-18 20:29:47 +0000
commit07abfeef1f921f596d6815f95dabb9f6d0afe596 (patch)
tree43c46eb3301720b14f85977d64a80ecd8b704cb5 /webkit/quota
parenta2cdf1e8ca027b5bc7aa38df5761b86376da6932 (diff)
downloadchromium_src-07abfeef1f921f596d6815f95dabb9f6d0afe596.zip
chromium_src-07abfeef1f921f596d6815f95dabb9f6d0afe596.tar.gz
chromium_src-07abfeef1f921f596d6815f95dabb9f6d0afe596.tar.bz2
base::Bind: Final cleanups in webkit/quota.
BUG=none TEST=none R=csilv@chromium.org Review URL: http://codereview.chromium.org/8342004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106116 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/quota')
-rw-r--r--webkit/quota/mock_storage_client.cc27
-rw-r--r--webkit/quota/mock_storage_client.h3
-rw-r--r--webkit/quota/quota_manager.cc35
-rw-r--r--webkit/quota/quota_task.cc9
-rw-r--r--webkit/quota/quota_temporary_storage_evictor_unittest.cc49
5 files changed, 67 insertions, 56 deletions
diff --git a/webkit/quota/mock_storage_client.cc b/webkit/quota/mock_storage_client.cc
index 2188df4..66ed587 100644
--- a/webkit/quota/mock_storage_client.cc
+++ b/webkit/quota/mock_storage_client.cc
@@ -6,6 +6,7 @@
#include "base/atomic_sequence_num.h"
#include "base/basictypes.h"
+#include "base/bind.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
#include "base/message_loop_proxy.h"
@@ -48,7 +49,7 @@ MockStorageClient::MockStorageClient(
: quota_manager_proxy_(quota_manager_proxy),
id_(MockStorageClientIDSequencer::GetInstance()->NextMockID()),
mock_time_counter_(0),
- runnable_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
for (size_t i = 0; i < mock_data_size; ++i) {
origin_data_[make_pair(GURL(mock_data[i].origin), mock_data[i].type)] =
mock_data[i].usage;
@@ -109,35 +110,35 @@ void MockStorageClient::GetOriginUsage(const GURL& origin_url,
StorageType type,
const GetUsageCallback& callback) {
base::MessageLoopProxy::current()->PostTask(
- FROM_HERE, runnable_factory_.NewRunnableMethod(
- &MockStorageClient::RunGetOriginUsage,
- origin_url, type, callback));
+ FROM_HERE,
+ base::Bind(&MockStorageClient::RunGetOriginUsage,
+ weak_factory_.GetWeakPtr(), origin_url, type, callback));
}
void MockStorageClient::GetOriginsForType(
StorageType type, const GetOriginsCallback& callback) {
base::MessageLoopProxy::current()->PostTask(
- FROM_HERE, runnable_factory_.NewRunnableMethod(
- &MockStorageClient::RunGetOriginsForType,
- type, callback));
+ FROM_HERE,
+ base::Bind(&MockStorageClient::RunGetOriginsForType,
+ weak_factory_.GetWeakPtr(), type, callback));
}
void MockStorageClient::GetOriginsForHost(
StorageType type, const std::string& host,
const GetOriginsCallback& callback) {
base::MessageLoopProxy::current()->PostTask(
- FROM_HERE, runnable_factory_.NewRunnableMethod(
- &MockStorageClient::RunGetOriginsForHost,
- type, host, callback));
+ FROM_HERE,
+ base::Bind(&MockStorageClient::RunGetOriginsForHost,
+ weak_factory_.GetWeakPtr(), type, host, callback));
}
void MockStorageClient::DeleteOriginData(
const GURL& origin, StorageType type,
const DeletionCallback& callback) {
base::MessageLoopProxy::current()->PostTask(
- FROM_HERE, runnable_factory_.NewRunnableMethod(
- &MockStorageClient::RunDeleteOriginData,
- origin, type, callback));
+ FROM_HERE,
+ base::Bind(&MockStorageClient::RunDeleteOriginData,
+ weak_factory_.GetWeakPtr(), origin, type, callback));
}
void MockStorageClient::RunGetOriginUsage(
diff --git a/webkit/quota/mock_storage_client.h b/webkit/quota/mock_storage_client.h
index 7317c76..1e42b75 100644
--- a/webkit/quota/mock_storage_client.h
+++ b/webkit/quota/mock_storage_client.h
@@ -11,6 +11,7 @@
#include <utility>
#include "base/compiler_specific.h"
+#include "base/memory/weak_ptr.h"
#include "base/task.h"
#include "base/time.h"
#include "googleurl/src/gurl.h"
@@ -81,7 +82,7 @@ class MockStorageClient : public QuotaClient {
int mock_time_counter_;
- ScopedRunnableMethodFactory<MockStorageClient> runnable_factory_;
+ base::WeakPtrFactory<MockStorageClient> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(MockStorageClient);
};
diff --git a/webkit/quota/quota_manager.cc b/webkit/quota/quota_manager.cc
index 99f6449..5392054 100644
--- a/webkit/quota/quota_manager.cc
+++ b/webkit/quota/quota_manager.cc
@@ -12,7 +12,6 @@
#include "base/callback.h"
#include "base/command_line.h"
#include "base/file_path.h"
-#include "base/memory/ref_counted.h"
#include "base/message_loop_proxy.h"
#include "base/metrics/histogram.h"
#include "base/string_number_conversions.h"
@@ -1559,10 +1558,12 @@ void QuotaManager::DeleteOnCorrectThread() const {
void QuotaManagerProxy::RegisterClient(QuotaClient* client) {
if (!io_thread_->BelongsToCurrentThread()) {
- io_thread_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &QuotaManagerProxy::RegisterClient, client));
+ io_thread_->PostTask(
+ FROM_HERE,
+ base::Bind(&QuotaManagerProxy::RegisterClient, this, client));
return;
}
+
if (manager_)
manager_->RegisterClient(client);
else
@@ -1574,11 +1575,13 @@ void QuotaManagerProxy::NotifyStorageAccessed(
const GURL& origin,
StorageType type) {
if (!io_thread_->BelongsToCurrentThread()) {
- io_thread_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &QuotaManagerProxy::NotifyStorageAccessed,
- client_id, origin, type));
+ io_thread_->PostTask(
+ FROM_HERE,
+ base::Bind(&QuotaManagerProxy::NotifyStorageAccessed, this, client_id,
+ origin, type));
return;
}
+
if (manager_)
manager_->NotifyStorageAccessed(client_id, origin, type);
}
@@ -1589,11 +1592,13 @@ void QuotaManagerProxy::NotifyStorageModified(
StorageType type,
int64 delta) {
if (!io_thread_->BelongsToCurrentThread()) {
- io_thread_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &QuotaManagerProxy::NotifyStorageModified,
- client_id, origin, type, delta));
+ io_thread_->PostTask(
+ FROM_HERE,
+ base::Bind(&QuotaManagerProxy::NotifyStorageModified, this, client_id,
+ origin, type, delta));
return;
}
+
if (manager_)
manager_->NotifyStorageModified(client_id, origin, type, delta);
}
@@ -1601,10 +1606,12 @@ void QuotaManagerProxy::NotifyStorageModified(
void QuotaManagerProxy::NotifyOriginInUse(
const GURL& origin) {
if (!io_thread_->BelongsToCurrentThread()) {
- io_thread_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &QuotaManagerProxy::NotifyOriginInUse, origin));
+ io_thread_->PostTask(
+ FROM_HERE,
+ base::Bind(&QuotaManagerProxy::NotifyOriginInUse, this, origin));
return;
}
+
if (manager_)
manager_->NotifyOriginInUse(origin);
}
@@ -1612,8 +1619,10 @@ void QuotaManagerProxy::NotifyOriginInUse(
void QuotaManagerProxy::NotifyOriginNoLongerInUse(
const GURL& origin) {
if (!io_thread_->BelongsToCurrentThread()) {
- io_thread_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &QuotaManagerProxy::NotifyOriginNoLongerInUse, origin));
+ io_thread_->PostTask(
+ FROM_HERE,
+ base::Bind(&QuotaManagerProxy::NotifyOriginNoLongerInUse, this,
+ origin));
return;
}
if (manager_)
diff --git a/webkit/quota/quota_task.cc b/webkit/quota/quota_task.cc
index f42ae4f..28d275f 100644
--- a/webkit/quota/quota_task.cc
+++ b/webkit/quota/quota_task.cc
@@ -7,6 +7,7 @@
#include <algorithm>
#include <functional>
+#include "base/bind.h"
#include "base/message_loop.h"
#include "base/message_loop_proxy.h"
@@ -61,15 +62,17 @@ QuotaThreadTask::~QuotaThreadTask() {
}
void QuotaThreadTask::Run() {
- target_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &QuotaThreadTask::CallRunOnTargetThread));
+ target_message_loop_->PostTask(
+ FROM_HERE,
+ base::Bind(&QuotaThreadTask::CallRunOnTargetThread, this));
}
void QuotaThreadTask::CallRunOnTargetThread() {
DCHECK(target_message_loop_->BelongsToCurrentThread());
if (RunOnTargetThreadAsync())
original_message_loop()->PostTask(
- FROM_HERE, NewRunnableMethod(this, &QuotaThreadTask::CallCompleted));
+ FROM_HERE,
+ base::Bind(&QuotaThreadTask::CallCompleted, this));
}
bool QuotaThreadTask::RunOnTargetThreadAsync() {
diff --git a/webkit/quota/quota_temporary_storage_evictor_unittest.cc b/webkit/quota/quota_temporary_storage_evictor_unittest.cc
index fa4f0b2..226be6b 100644
--- a/webkit/quota/quota_temporary_storage_evictor_unittest.cc
+++ b/webkit/quota/quota_temporary_storage_evictor_unittest.cc
@@ -7,7 +7,9 @@
#include <utility>
#include "base/bind.h"
+#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
#include "base/message_loop_proxy.h"
#include "base/task.h"
@@ -52,8 +54,8 @@ class MockQuotaEvictionHandler : public quota::QuotaEvictionHandler {
callback.Run(quota::kQuotaErrorInvalidAccess, QuotaAndUsage());
return;
}
- if (task_for_get_usage_and_quota_.get())
- task_for_get_usage_and_quota_->Run();
+ if (!task_for_get_usage_and_quota_.is_null())
+ task_for_get_usage_and_quota_.Run();
QuotaAndUsage quota_and_usage = {
GetUsage(), unlimited_usage_, quota_, available_space_ };
callback.Run(quota::kQuotaStatusOk, quota_and_usage);
@@ -86,8 +88,8 @@ class MockQuotaEvictionHandler : public quota::QuotaEvictionHandler {
void set_available_space(int64 available_space) {
available_space_ = available_space;
}
- void set_task_for_get_usage_and_quota(CancelableTask* task) {
- task_for_get_usage_and_quota_.reset(task);
+ void set_task_for_get_usage_and_quota(const base::Closure& task) {
+ task_for_get_usage_and_quota_= task;
}
void set_error_on_evict_origin_data(bool error_on_evict_origin_data) {
error_on_evict_origin_data_ = error_on_evict_origin_data;
@@ -135,7 +137,7 @@ class MockQuotaEvictionHandler : public quota::QuotaEvictionHandler {
bool error_on_get_usage_and_quota_;
QuotaTemporaryStorageEvictorTest *test_;
- scoped_ptr<CancelableTask> task_for_get_usage_and_quota_;
+ base::Closure task_for_get_usage_and_quota_;
};
} // anonymous namespace
@@ -144,7 +146,7 @@ class QuotaTemporaryStorageEvictorTest : public testing::Test {
public:
QuotaTemporaryStorageEvictorTest()
: num_get_usage_and_quota_for_eviction_(0),
- runnable_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {}
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {}
void SetUp() {
quota_eviction_handler_.reset(new MockQuotaEvictionHandler(this));
@@ -226,8 +228,7 @@ class QuotaTemporaryStorageEvictorTest : public testing::Test {
int num_get_usage_and_quota_for_eviction_;
- ScopedRunnableMethodFactory<QuotaTemporaryStorageEvictorTest>
- runnable_factory_;
+ base::WeakPtrFactory<QuotaTemporaryStorageEvictorTest> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(QuotaTemporaryStorageEvictorTest);
};
@@ -286,12 +287,11 @@ TEST_F(QuotaTemporaryStorageEvictorTest, RepeatedEvictionTest) {
quota_eviction_handler()->set_quota(1000);
quota_eviction_handler()->set_available_space(1000000000);
quota_eviction_handler()->set_task_for_get_usage_and_quota(
- runnable_factory_.NewRunnableMethod(
- &QuotaTemporaryStorageEvictorTest::TaskForRepeatedEvictionTest,
- std::make_pair(GURL("http://www.e.com"), e_size),
- GURL(),
- initial_total_size - d_size,
- initial_total_size - d_size + e_size - c_size));
+ base::Bind(&QuotaTemporaryStorageEvictorTest::TaskForRepeatedEvictionTest,
+ weak_factory_.GetWeakPtr(),
+ std::make_pair(GURL("http://www.e.com"), e_size), GURL(),
+ initial_total_size - d_size,
+ initial_total_size - d_size + e_size - c_size));
EXPECT_EQ(initial_total_size, quota_eviction_handler()->GetUsage());
temporary_storage_evictor()->Start();
MessageLoop::current()->RunAllPending();
@@ -320,12 +320,9 @@ TEST_F(QuotaTemporaryStorageEvictorTest, RepeatedEvictionSkippedTest) {
quota_eviction_handler()->set_quota(1000);
quota_eviction_handler()->set_available_space(1000000000);
quota_eviction_handler()->set_task_for_get_usage_and_quota(
- runnable_factory_.NewRunnableMethod(
- &QuotaTemporaryStorageEvictorTest::TaskForRepeatedEvictionTest,
- std::make_pair(GURL(), 0),
- GURL(),
- initial_total_size - d_size,
- initial_total_size - d_size));
+ base::Bind(&QuotaTemporaryStorageEvictorTest::TaskForRepeatedEvictionTest,
+ weak_factory_.GetWeakPtr(), std::make_pair(GURL(), 0), GURL(),
+ initial_total_size - d_size, initial_total_size - d_size));
EXPECT_EQ(initial_total_size, quota_eviction_handler()->GetUsage());
set_repeated_eviction(true);
temporary_storage_evictor()->Start();
@@ -356,12 +353,12 @@ TEST_F(QuotaTemporaryStorageEvictorTest, RepeatedEvictionWithAccessOriginTest) {
quota_eviction_handler()->set_quota(1000);
quota_eviction_handler()->set_available_space(1000000000);
quota_eviction_handler()->set_task_for_get_usage_and_quota(
- runnable_factory_.NewRunnableMethod(
- &QuotaTemporaryStorageEvictorTest::TaskForRepeatedEvictionTest,
- std::make_pair(GURL("http://www.e.com"), e_size),
- GURL("http://www.c.com"),
- initial_total_size - d_size,
- initial_total_size - d_size + e_size - b_size));
+ base::Bind(&QuotaTemporaryStorageEvictorTest::TaskForRepeatedEvictionTest,
+ weak_factory_.GetWeakPtr(),
+ std::make_pair(GURL("http://www.e.com"), e_size),
+ GURL("http://www.c.com"),
+ initial_total_size - d_size,
+ initial_total_size - d_size + e_size - b_size));
EXPECT_EQ(initial_total_size, quota_eviction_handler()->GetUsage());
temporary_storage_evictor()->Start();
MessageLoop::current()->RunAllPending();