summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authortzik@chromium.org <tzik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-18 14:11:03 +0000
committertzik@chromium.org <tzik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-18 14:11:03 +0000
commit4d99be5a3d20c3a3654f282328065f9ff54d6f39 (patch)
treeb355c0c05f4879373ab23998dfb49253ff6f9e9e /webkit
parent58ae297434a9e33d1006c52b6d13d8a78e3b7e5e (diff)
downloadchromium_src-4d99be5a3d20c3a3654f282328065f9ff54d6f39.zip
chromium_src-4d99be5a3d20c3a3654f282328065f9ff54d6f39.tar.gz
chromium_src-4d99be5a3d20c3a3654f282328065f9ff54d6f39.tar.bz2
Use base::Callback in Quota related code.
BUG=None TEST='Compilation should finished successfull and all quota related tests should be passed.' Review URL: http://codereview.chromium.org/8070001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106060 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/appcache/appcache_quota_client.cc93
-rw-r--r--webkit/appcache/appcache_quota_client.h27
-rw-r--r--webkit/appcache/appcache_quota_client_unittest.cc34
-rw-r--r--webkit/appcache/appcache_storage_impl.cc7
-rw-r--r--webkit/appcache/appcache_storage_impl.h1
-rw-r--r--webkit/appcache/appcache_storage_impl_unittest.cc23
-rw-r--r--webkit/database/database_quota_client.cc48
-rw-r--r--webkit/database/database_quota_client.h14
-rw-r--r--webkit/database/database_quota_client_unittest.cc34
-rw-r--r--webkit/fileapi/file_system_operation.cc47
-rw-r--r--webkit/fileapi/file_system_operation.h2
-rw-r--r--webkit/fileapi/file_system_operation_unittest.cc7
-rw-r--r--webkit/fileapi/file_system_operation_write_unittest.cc8
-rw-r--r--webkit/fileapi/file_system_quota_client.cc35
-rw-r--r--webkit/fileapi/file_system_quota_client.h27
-rw-r--r--webkit/fileapi/file_system_quota_client_unittest.cc38
-rw-r--r--webkit/fileapi/file_system_quota_unittest.cc9
-rw-r--r--webkit/fileapi/obfuscated_file_util_unittest.cc11
-rw-r--r--webkit/quota/mock_quota_manager.cc24
-rw-r--r--webkit/quota/mock_quota_manager.h12
-rw-r--r--webkit/quota/mock_quota_manager_unittest.cc20
-rw-r--r--webkit/quota/mock_storage_client.cc50
-rw-r--r--webkit/quota/mock_storage_client.h21
-rw-r--r--webkit/quota/quota_client.h16
-rw-r--r--webkit/quota/quota_manager.cc253
-rw-r--r--webkit/quota/quota_manager.h49
-rw-r--r--webkit/quota/quota_manager_unittest.cc100
-rw-r--r--webkit/quota/quota_temporary_storage_evictor.cc8
-rw-r--r--webkit/quota/quota_temporary_storage_evictor.h3
-rw-r--r--webkit/quota/quota_temporary_storage_evictor_unittest.cc14
-rw-r--r--webkit/quota/quota_types.h68
-rw-r--r--webkit/quota/usage_tracker.cc60
-rw-r--r--webkit/quota/usage_tracker.h11
33 files changed, 597 insertions, 577 deletions
diff --git a/webkit/appcache/appcache_quota_client.cc b/webkit/appcache/appcache_quota_client.cc
index 94ce7fb..35c81c5 100644
--- a/webkit/appcache/appcache_quota_client.cc
+++ b/webkit/appcache/appcache_quota_client.cc
@@ -6,6 +6,7 @@
#include <algorithm>
#include <map>
+#include <set>
#include "webkit/appcache/appcache_service.h"
@@ -36,7 +37,7 @@ AppCacheQuotaClient::~AppCacheQuotaClient() {
DCHECK(pending_usage_requests_.empty());
DCHECK(pending_origins_requests_.empty());
DCHECK(pending_delete_requests_.empty());
- DCHECK(!current_delete_request_callback_.get());
+ DCHECK(current_delete_request_callback_.is_null());
}
QuotaClient::ID AppCacheQuotaClient::id() const {
@@ -45,8 +46,8 @@ QuotaClient::ID AppCacheQuotaClient::id() const {
void AppCacheQuotaClient::OnQuotaManagerDestroyed() {
DeletePendingRequests();
- if (current_delete_request_callback_.get()) {
- current_delete_request_callback_.reset();
+ if (!current_delete_request_callback_.is_null()) {
+ current_delete_request_callback_.Reset();
service_delete_callback_.release()->Cancel();
} else {
service_delete_callback_ = NULL;
@@ -59,13 +60,12 @@ void AppCacheQuotaClient::OnQuotaManagerDestroyed() {
void AppCacheQuotaClient::GetOriginUsage(
const GURL& origin,
quota::StorageType type,
- GetUsageCallback* callback_ptr) {
- DCHECK(callback_ptr);
+ const GetUsageCallback& callback) {
+ DCHECK(!callback.is_null());
DCHECK(!quota_manager_is_destroyed_);
- scoped_ptr<GetUsageCallback> callback(callback_ptr);
if (!service_) {
- callback->Run(0);
+ callback.Run(0);
return;
}
@@ -73,64 +73,61 @@ void AppCacheQuotaClient::GetOriginUsage(
pending_usage_requests_.push_back(UsageRequest());
pending_usage_requests_.back().origin = origin;
pending_usage_requests_.back().type = type;
- pending_usage_requests_.back().callback = callback.release();
+ pending_usage_requests_.back().callback = callback;
return;
}
if (type == quota::kStorageTypePersistent) {
- callback->Run(0);
+ callback.Run(0);
return;
}
const AppCacheStorage::UsageMap* map = GetUsageMap();
AppCacheStorage::UsageMap::const_iterator found = map->find(origin);
if (found == map->end()) {
- callback->Run(0);
+ callback.Run(0);
return;
}
- callback->Run(found->second);
+ callback.Run(found->second);
}
void AppCacheQuotaClient::GetOriginsForType(
quota::StorageType type,
- GetOriginsCallback* callback_ptr) {
- GetOriginsHelper(type, std::string(), callback_ptr);
+ const GetOriginsCallback& callback) {
+ GetOriginsHelper(type, std::string(), callback);
}
void AppCacheQuotaClient::GetOriginsForHost(
quota::StorageType type,
const std::string& host,
- GetOriginsCallback* callback_ptr) {
- DCHECK(callback_ptr);
+ const GetOriginsCallback& callback) {
+ DCHECK(!callback.is_null());
if (host.empty()) {
- callback_ptr->Run(std::set<GURL>(), type);
- delete callback_ptr;
+ callback.Run(std::set<GURL>(), type);
return;
}
- GetOriginsHelper(type, host, callback_ptr);
+ GetOriginsHelper(type, host, callback);
}
void AppCacheQuotaClient::DeleteOriginData(const GURL& origin,
quota::StorageType type,
- DeletionCallback* callback_ptr) {
- DCHECK(callback_ptr);
+ const DeletionCallback& callback) {
DCHECK(!quota_manager_is_destroyed_);
- scoped_ptr<DeletionCallback> callback(callback_ptr);
if (!service_) {
- callback->Run(quota::kQuotaErrorAbort);
+ callback.Run(quota::kQuotaErrorAbort);
return;
}
- if (!appcache_is_ready_ || current_delete_request_callback_.get()) {
+ if (!appcache_is_ready_ || !current_delete_request_callback_.is_null()) {
pending_delete_requests_.push_back(DeleteRequest());
pending_delete_requests_.back().origin = origin;
pending_delete_requests_.back().type = type;
- pending_delete_requests_.back().callback = callback.release();
+ pending_delete_requests_.back().callback = callback;
return;
}
- current_delete_request_callback_.swap(callback);
+ current_delete_request_callback_ = callback;
if (type == quota::kStorageTypePersistent) {
DidDeleteAppCachesForOrigin(net::OK);
return;
@@ -138,20 +135,29 @@ void AppCacheQuotaClient::DeleteOriginData(const GURL& origin,
service_->DeleteAppCachesForOrigin(origin, service_delete_callback_);
}
+AppCacheQuotaClient::UsageRequest::UsageRequest() {}
+AppCacheQuotaClient::UsageRequest::~UsageRequest() {}
+
+AppCacheQuotaClient::OriginsRequest::OriginsRequest() {}
+AppCacheQuotaClient::OriginsRequest::~OriginsRequest() {}
+
+AppCacheQuotaClient::DeleteRequest::DeleteRequest() {}
+AppCacheQuotaClient::DeleteRequest::~DeleteRequest() {}
+
void AppCacheQuotaClient::DidDeleteAppCachesForOrigin(int rv) {
DCHECK(service_);
if (quota_manager_is_destroyed_)
return;
// Finish the request by calling our callers callback.
- current_delete_request_callback_->Run(NetErrorCodeToQuotaStatus(rv));
- current_delete_request_callback_.reset();
+ current_delete_request_callback_.Run(NetErrorCodeToQuotaStatus(rv));
+ current_delete_request_callback_.Reset();
if (pending_delete_requests_.empty())
return;
// Start the next in the queue.
DeleteRequest& next_request = pending_delete_requests_.front();
- current_delete_request_callback_.reset(next_request.callback);
+ current_delete_request_callback_ = next_request.callback;
service_->DeleteAppCachesForOrigin(next_request.origin,
service_delete_callback_);
pending_delete_requests_.pop_front();
@@ -160,13 +166,12 @@ void AppCacheQuotaClient::DidDeleteAppCachesForOrigin(int rv) {
void AppCacheQuotaClient::GetOriginsHelper(
quota::StorageType type,
const std::string& opt_host,
- GetOriginsCallback* callback_ptr) {
- DCHECK(callback_ptr);
+ const GetOriginsCallback& callback) {
+ DCHECK(!callback.is_null());
DCHECK(!quota_manager_is_destroyed_);
- scoped_ptr<GetOriginsCallback> callback(callback_ptr);
if (!service_) {
- callback->Run(std::set<GURL>(), type);
+ callback.Run(std::set<GURL>(), type);
return;
}
@@ -174,12 +179,12 @@ void AppCacheQuotaClient::GetOriginsHelper(
pending_origins_requests_.push_back(OriginsRequest());
pending_origins_requests_.back().opt_host = opt_host;
pending_origins_requests_.back().type = type;
- pending_origins_requests_.back().callback = callback.release();
+ pending_origins_requests_.back().callback = callback;
return;
}
if (type == quota::kStorageTypePersistent) {
- callback->Run(std::set<GURL>(), type);
+ callback.Run(std::set<GURL>(), type);
return;
}
@@ -190,7 +195,7 @@ void AppCacheQuotaClient::GetOriginsHelper(
if (opt_host.empty() || iter->first.host() == opt_host)
origins.insert(iter->first);
}
- callback->Run(origins, type);
+ callback.Run(origins, type);
}
void AppCacheQuotaClient::ProcessPendingRequests() {
@@ -215,34 +220,28 @@ void AppCacheQuotaClient::ProcessPendingRequests() {
void AppCacheQuotaClient::AbortPendingRequests() {
while (!pending_usage_requests_.empty()) {
- pending_usage_requests_.front().callback->Run(0);
- delete pending_usage_requests_.front().callback;
+ pending_usage_requests_.front().callback.Run(0);
pending_usage_requests_.pop_front();
}
while (!pending_origins_requests_.empty()) {
- pending_origins_requests_.front().callback->Run(std::set<GURL>(),
+ pending_origins_requests_.front().callback.Run(std::set<GURL>(),
pending_origins_requests_.front().type);
- delete pending_origins_requests_.front().callback;
pending_origins_requests_.pop_front();
}
while (!pending_delete_requests_.empty()) {
- pending_delete_requests_.front().callback->Run(quota::kQuotaErrorAbort);
- delete pending_delete_requests_.front().callback;
+ pending_delete_requests_.front().callback.Run(quota::kQuotaErrorAbort);
pending_delete_requests_.pop_front();
}
}
void AppCacheQuotaClient::DeletePendingRequests() {
while (!pending_usage_requests_.empty()) {
- delete pending_usage_requests_.front().callback;
pending_usage_requests_.pop_front();
}
while (!pending_origins_requests_.empty()) {
- delete pending_origins_requests_.front().callback;
pending_origins_requests_.pop_front();
}
while (!pending_delete_requests_.empty()) {
- delete pending_delete_requests_.front().callback;
pending_delete_requests_.pop_front();
}
}
@@ -260,9 +259,9 @@ void AppCacheQuotaClient::NotifyAppCacheReady() {
void AppCacheQuotaClient::NotifyAppCacheDestroyed() {
service_ = NULL;
AbortPendingRequests();
- if (current_delete_request_callback_.get()) {
- current_delete_request_callback_->Run(quota::kQuotaErrorAbort);
- current_delete_request_callback_.reset();
+ if (!current_delete_request_callback_.is_null()) {
+ current_delete_request_callback_.Run(quota::kQuotaErrorAbort);
+ current_delete_request_callback_.Reset();
service_delete_callback_.release()->Cancel();
} else {
service_delete_callback_ = NULL;
diff --git a/webkit/appcache/appcache_quota_client.h b/webkit/appcache/appcache_quota_client.h
index 5f0387c..175f017 100644
--- a/webkit/appcache/appcache_quota_client.h
+++ b/webkit/appcache/appcache_quota_client.h
@@ -39,15 +39,15 @@ class AppCacheQuotaClient : public quota::QuotaClient {
virtual void OnQuotaManagerDestroyed();
virtual void GetOriginUsage(const GURL& origin,
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:
friend class AppCacheService; // for NotifyAppCacheIsDestroyed
@@ -57,17 +57,26 @@ class AppCacheQuotaClient : public quota::QuotaClient {
struct UsageRequest {
GURL origin;
quota::StorageType type;
- GetUsageCallback* callback;
+ GetUsageCallback callback;
+
+ UsageRequest();
+ ~UsageRequest();
};
struct OriginsRequest {
quota::StorageType type;
std::string opt_host;
- GetOriginsCallback* callback;
+ GetOriginsCallback callback;
+
+ OriginsRequest();
+ ~OriginsRequest();
};
struct DeleteRequest {
GURL origin;
quota::StorageType type;
- DeletionCallback* callback;
+ DeletionCallback callback;
+
+ DeleteRequest();
+ ~DeleteRequest();
};
typedef std::deque<UsageRequest> UsageRequestQueue;
typedef std::deque<OriginsRequest> OriginsRequestQueue;
@@ -78,7 +87,7 @@ class AppCacheQuotaClient : public quota::QuotaClient {
void DidDeleteAppCachesForOrigin(int rv);
void GetOriginsHelper(quota::StorageType type,
const std::string& opt_host,
- GetOriginsCallback* callback_ptr);
+ const GetOriginsCallback& callback);
void ProcessPendingRequests();
void AbortPendingRequests();
void DeletePendingRequests();
@@ -96,7 +105,7 @@ class AppCacheQuotaClient : public quota::QuotaClient {
// And once it's ready, we can only handle one delete request at a time,
// so we queue up additional requests while one is in already in progress.
- scoped_ptr<DeletionCallback> current_delete_request_callback_;
+ DeletionCallback current_delete_request_callback_;
scoped_refptr<net::CancelableOldCompletionCallback<AppCacheQuotaClient> >
service_delete_callback_;
diff --git a/webkit/appcache/appcache_quota_client_unittest.cc b/webkit/appcache/appcache_quota_client_unittest.cc
index fb967ac..28428bc 100644
--- a/webkit/appcache/appcache_quota_client_unittest.cc
+++ b/webkit/appcache/appcache_quota_client_unittest.cc
@@ -3,7 +3,9 @@
// found in the LICENSE file.
#include <map>
+#include <set>
+#include "base/bind.h"
#include "base/memory/scoped_callback_factory.h"
#include "base/message_loop.h"
#include "base/message_loop_proxy.h"
@@ -34,7 +36,7 @@ class AppCacheQuotaClientTest : public testing::Test {
num_get_origin_usage_completions_(0),
num_get_origins_completions_(0),
num_delete_origins_completions_(0),
- callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
}
int64 GetOriginUsage(
@@ -80,35 +82,39 @@ class AppCacheQuotaClientTest : public testing::Test {
quota::QuotaClient* client,
const GURL& origin,
quota::StorageType type) {
- client->GetOriginUsage(origin, type,
- callback_factory_.NewCallback(
- &AppCacheQuotaClientTest::OnGetOriginUsageComplete));
+ client->GetOriginUsage(
+ origin, type,
+ base::Bind(&AppCacheQuotaClientTest::OnGetOriginUsageComplete,
+ weak_factory_.GetWeakPtr()));
}
void AsyncGetOriginsForType(
quota::QuotaClient* client,
quota::StorageType type) {
- client->GetOriginsForType(type,
- callback_factory_.NewCallback(
- &AppCacheQuotaClientTest::OnGetOriginsComplete));
+ client->GetOriginsForType(
+ type,
+ base::Bind(&AppCacheQuotaClientTest::OnGetOriginsComplete,
+ weak_factory_.GetWeakPtr()));
}
void AsyncGetOriginsForHost(
quota::QuotaClient* client,
quota::StorageType type,
const std::string& host) {
- client->GetOriginsForHost(type, host,
- callback_factory_.NewCallback(
- &AppCacheQuotaClientTest::OnGetOriginsComplete));
+ client->GetOriginsForHost(
+ type, host,
+ base::Bind(&AppCacheQuotaClientTest::OnGetOriginsComplete,
+ weak_factory_.GetWeakPtr()));
}
void AsyncDeleteOriginData(
quota::QuotaClient* client,
quota::StorageType type,
const GURL& origin) {
- client->DeleteOriginData(origin, type,
- callback_factory_.NewCallback(
- &AppCacheQuotaClientTest::OnDeleteOriginDataComplete));
+ client->DeleteOriginData(
+ origin, type,
+ base::Bind(&AppCacheQuotaClientTest::OnDeleteOriginDataComplete,
+ weak_factory_.GetWeakPtr()));
}
void SetUsageMapEntry(const GURL& origin, int64 usage) {
@@ -157,7 +163,7 @@ class AppCacheQuotaClientTest : public testing::Test {
int num_get_origins_completions_;
int num_delete_origins_completions_;
MockAppCacheService mock_service_;
- base::ScopedCallbackFactory<AppCacheQuotaClientTest> callback_factory_;
+ base::WeakPtrFactory<AppCacheQuotaClientTest> weak_factory_;
};
diff --git a/webkit/appcache/appcache_storage_impl.cc b/webkit/appcache/appcache_storage_impl.cc
index 0812dc1..bd16ae2 100644
--- a/webkit/appcache/appcache_storage_impl.cc
+++ b/webkit/appcache/appcache_storage_impl.cc
@@ -4,8 +4,12 @@
#include "webkit/appcache/appcache_storage_impl.h"
+#include <algorithm>
+#include <functional>
#include <set>
+#include <vector>
+#include "base/bind.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/message_loop.h"
@@ -549,7 +553,8 @@ void AppCacheStorageImpl::StoreGroupAndCacheTask::GetQuotaThenSchedule() {
storage_->pending_quota_queries_.insert(this);
quota_manager->GetUsageAndQuota(
group_record_.origin, quota::kStorageTypeTemporary,
- NewCallback(this, &StoreGroupAndCacheTask::OnQuotaCallback));
+ base::Bind(&StoreGroupAndCacheTask::OnQuotaCallback,
+ base::Unretained(this)));
}
void AppCacheStorageImpl::StoreGroupAndCacheTask::OnQuotaCallback(
diff --git a/webkit/appcache/appcache_storage_impl.h b/webkit/appcache/appcache_storage_impl.h
index b8f1a91..de3705f 100644
--- a/webkit/appcache/appcache_storage_impl.h
+++ b/webkit/appcache/appcache_storage_impl.h
@@ -8,6 +8,7 @@
#include <deque>
#include <map>
#include <set>
+#include <utility>
#include <vector>
#include "base/file_path.h"
diff --git a/webkit/appcache/appcache_storage_impl_unittest.cc b/webkit/appcache/appcache_storage_impl_unittest.cc
index cb5c7d1..cc3a5ba 100644
--- a/webkit/appcache/appcache_storage_impl_unittest.cc
+++ b/webkit/appcache/appcache_storage_impl_unittest.cc
@@ -131,21 +131,20 @@ class AppCacheStorageImplTest : public testing::Test {
virtual void GetUsageAndQuota(
const GURL& origin, quota::StorageType type,
- GetUsageAndQuotaCallback* callback) {
+ const GetUsageAndQuotaCallback& callback) OVERRIDE {
EXPECT_EQ(kOrigin, origin);
EXPECT_EQ(quota::kStorageTypeTemporary, type);
if (async_) {
MessageLoop::current()->PostTask(FROM_HERE,
- NewRunnableMethod(this, &MockQuotaManager::CallCallbackAndDelete,
+ NewRunnableMethod(this, &MockQuotaManager::CallCallback,
callback));
return;
}
- CallCallbackAndDelete(callback);
+ CallCallback(callback);
}
- void CallCallbackAndDelete(GetUsageAndQuotaCallback* callback) {
- callback->Run(quota::kQuotaStatusOk, 0, kMockQuota);
- delete callback;
+ void CallCallback(const GetUsageAndQuotaCallback& callback) {
+ callback.Run(quota::kQuotaStatusOk, 0, kMockQuota);
}
bool async_;
@@ -164,7 +163,7 @@ class AppCacheStorageImplTest : public testing::Test {
virtual void NotifyStorageAccessed(quota::QuotaClient::ID client_id,
const GURL& origin,
- quota::StorageType type) {
+ quota::StorageType type) OVERRIDE {
EXPECT_EQ(quota::QuotaClient::kAppcache, client_id);
EXPECT_EQ(quota::kStorageTypeTemporary, type);
++notify_storage_accessed_count_;
@@ -174,7 +173,7 @@ class AppCacheStorageImplTest : public testing::Test {
virtual void NotifyStorageModified(quota::QuotaClient::ID client_id,
const GURL& origin,
quota::StorageType type,
- int64 delta) {
+ int64 delta) OVERRIDE {
EXPECT_EQ(quota::QuotaClient::kAppcache, client_id);
EXPECT_EQ(quota::kStorageTypeTemporary, type);
++notify_storage_modified_count_;
@@ -183,9 +182,9 @@ class AppCacheStorageImplTest : public testing::Test {
}
// Not needed for our tests.
- virtual void RegisterClient(quota::QuotaClient* client) {}
- virtual void NotifyOriginInUse(const GURL& origin) {}
- virtual void NotifyOriginNoLongerInUse(const GURL& origin) {}
+ virtual void RegisterClient(quota::QuotaClient* client) OVERRIDE {}
+ virtual void NotifyOriginInUse(const GURL& origin) OVERRIDE {}
+ virtual void NotifyOriginNoLongerInUse(const GURL& origin) OVERRIDE {}
int notify_storage_accessed_count_;
int notify_storage_modified_count_;
@@ -203,7 +202,7 @@ class AppCacheStorageImplTest : public testing::Test {
: test_(test), method_(method) {
}
- virtual void Run() {
+ virtual void Run() OVERRIDE {
test_->SetUpTest();
// Ensure InitTask execution prior to conducting a test.
diff --git a/webkit/database/database_quota_client.cc b/webkit/database/database_quota_client.cc
index 32482fd..fd2eb5a 100644
--- a/webkit/database/database_quota_client.cc
+++ b/webkit/database/database_quota_client.cc
@@ -137,7 +137,7 @@ class DatabaseQuotaClient::DeleteOriginTask : public HelperTask {
DatabaseQuotaClient* client,
base::MessageLoopProxy* db_tracker_thread,
const GURL& origin_url,
- DeletionCallback* caller_callback)
+ const DeletionCallback& caller_callback)
: HelperTask(client, db_tracker_thread),
origin_url_(origin_url),
result_(quota::kQuotaStatusUnknown),
@@ -148,14 +148,14 @@ class DatabaseQuotaClient::DeleteOriginTask : public HelperTask {
private:
virtual void Completed() OVERRIDE {
- if (!caller_callback_.get())
+ if (caller_callback_.is_null())
return;
- caller_callback_->Run(result_);
- caller_callback_.reset();
+ caller_callback_.Run(result_);
+ caller_callback_.Reset();
}
virtual void Aborted() OVERRIDE {
- caller_callback_.reset();
+ caller_callback_.Reset();
}
virtual bool RunOnTargetThreadAsync() OVERRIDE {
@@ -178,7 +178,7 @@ class DatabaseQuotaClient::DeleteOriginTask : public HelperTask {
const GURL origin_url_;
quota::QuotaStatusCode result_;
- scoped_ptr<DeletionCallback> caller_callback_;
+ DeletionCallback caller_callback_;
net::OldCompletionCallbackImpl<DeleteOriginTask> completion_callback_;
};
@@ -204,18 +204,17 @@ void DatabaseQuotaClient::OnQuotaManagerDestroyed() {
void DatabaseQuotaClient::GetOriginUsage(
const GURL& origin_url,
quota::StorageType type,
- GetUsageCallback* callback_ptr) {
- DCHECK(callback_ptr);
+ const GetUsageCallback& callback) {
+ DCHECK(!callback.is_null());
DCHECK(db_tracker_.get());
- scoped_ptr<GetUsageCallback> callback(callback_ptr);
// All databases are 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, db_tracker_thread_, origin_url));
task->Start();
@@ -224,18 +223,17 @@ void DatabaseQuotaClient::GetOriginUsage(
void DatabaseQuotaClient::GetOriginsForType(
quota::StorageType type,
- GetOriginsCallback* callback_ptr) {
- DCHECK(callback_ptr);
+ const GetOriginsCallback& callback) {
+ DCHECK(!callback.is_null());
DCHECK(db_tracker_.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, db_tracker_thread_, type));
task->Start();
@@ -245,18 +243,17 @@ void DatabaseQuotaClient::GetOriginsForType(
void DatabaseQuotaClient::GetOriginsForHost(
quota::StorageType type,
const std::string& host,
- GetOriginsCallback* callback_ptr) {
- DCHECK(callback_ptr);
+ const GetOriginsCallback& callback) {
+ DCHECK(!callback.is_null());
DCHECK(db_tracker_.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, db_tracker_thread_, host, type));
task->Start();
@@ -265,20 +262,19 @@ void DatabaseQuotaClient::GetOriginsForHost(
void DatabaseQuotaClient::DeleteOriginData(const GURL& origin,
quota::StorageType type,
- DeletionCallback* callback_ptr) {
- DCHECK(callback_ptr);
+ const DeletionCallback& callback) {
+ DCHECK(!callback.is_null());
DCHECK(db_tracker_.get());
- scoped_ptr<DeletionCallback> callback(callback_ptr);
// All databases are in the temp namespace for now, so nothing to delete.
if (type != quota::kStorageTypeTemporary) {
- callback->Run(quota::kQuotaStatusOk);
+ callback.Run(quota::kQuotaStatusOk);
return;
}
scoped_refptr<DeleteOriginTask> task(
new DeleteOriginTask(this, db_tracker_thread_,
- origin, callback.release()));
+ origin, callback));
task->Start();
}
diff --git a/webkit/database/database_quota_client.h b/webkit/database/database_quota_client.h
index fb37ff61..b9fed41 100644
--- a/webkit/database/database_quota_client.h
+++ b/webkit/database/database_quota_client.h
@@ -34,15 +34,15 @@ class DatabaseQuotaClient : public quota::QuotaClient,
virtual void OnQuotaManagerDestroyed();
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;
@@ -52,17 +52,17 @@ class DatabaseQuotaClient : 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/webkit/database/database_quota_client_unittest.cc b/webkit/database/database_quota_client_unittest.cc
index ba91206..09f096e 100644
--- a/webkit/database/database_quota_client_unittest.cc
+++ b/webkit/database/database_quota_client_unittest.cc
@@ -4,8 +4,8 @@
#include <map>
+#include "base/bind.h"
#include "base/file_path.h"
-#include "base/memory/scoped_callback_factory.h"
#include "base/message_loop.h"
#include "base/message_loop_proxy.h"
#include "base/utf_string_conversions.h"
@@ -126,7 +126,7 @@ class DatabaseQuotaClientTest : public testing::Test {
kOriginOther("http://other"),
usage_(0),
mock_tracker_(new MockDatabaseTracker),
- callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
}
int64 GetOriginUsage(
@@ -134,9 +134,10 @@ class DatabaseQuotaClientTest : public testing::Test {
const GURL& origin,
quota::StorageType type) {
usage_ = 0;
- client->GetOriginUsage(origin, type,
- callback_factory_.NewCallback(
- &DatabaseQuotaClientTest::OnGetOriginUsageComplete));
+ client->GetOriginUsage(
+ origin, type,
+ base::Bind(&DatabaseQuotaClientTest::OnGetOriginUsageComplete,
+ weak_factory_.GetWeakPtr()));
MessageLoop::current()->RunAllPending();
return usage_;
}
@@ -145,9 +146,10 @@ class DatabaseQuotaClientTest : public testing::Test {
quota::QuotaClient* client,
quota::StorageType type) {
origins_.clear();
- client->GetOriginsForType(type,
- callback_factory_.NewCallback(
- &DatabaseQuotaClientTest::OnGetOriginsComplete));
+ client->GetOriginsForType(
+ type,
+ base::Bind(&DatabaseQuotaClientTest::OnGetOriginsComplete,
+ weak_factory_.GetWeakPtr()));
MessageLoop::current()->RunAllPending();
return origins_;
}
@@ -157,9 +159,10 @@ class DatabaseQuotaClientTest : public testing::Test {
quota::StorageType type,
const std::string& host) {
origins_.clear();
- client->GetOriginsForHost(type, host,
- callback_factory_.NewCallback(
- &DatabaseQuotaClientTest::OnGetOriginsComplete));
+ client->GetOriginsForHost(
+ type, host,
+ base::Bind(&DatabaseQuotaClientTest::OnGetOriginsComplete,
+ weak_factory_.GetWeakPtr()));
MessageLoop::current()->RunAllPending();
return origins_;
}
@@ -169,9 +172,10 @@ class DatabaseQuotaClientTest : public testing::Test {
quota::StorageType type,
const GURL& origin) {
delete_status_ = quota::kQuotaStatusUnknown;
- client->DeleteOriginData(origin, type,
- callback_factory_.NewCallback(
- &DatabaseQuotaClientTest::OnDeleteOriginDataComplete));
+ client->DeleteOriginData(
+ origin, type,
+ base::Bind(&DatabaseQuotaClientTest::OnDeleteOriginDataComplete,
+ weak_factory_.GetWeakPtr()));
MessageLoop::current()->RunAllPending();
return delete_status_ == quota::kQuotaStatusOk;
}
@@ -199,7 +203,7 @@ class DatabaseQuotaClientTest : public testing::Test {
quota::StorageType type_;
quota::QuotaStatusCode delete_status_;
scoped_refptr<MockDatabaseTracker> mock_tracker_;
- base::ScopedCallbackFactory<DatabaseQuotaClientTest> callback_factory_;
+ base::WeakPtrFactory<DatabaseQuotaClientTest> weak_factory_;
};
diff --git a/webkit/fileapi/file_system_operation.cc b/webkit/fileapi/file_system_operation.cc
index b89fda2..113517b 100644
--- a/webkit/fileapi/file_system_operation.cc
+++ b/webkit/fileapi/file_system_operation.cc
@@ -122,8 +122,10 @@ void FileSystemOperation::CreateFile(const GURL& path,
file_system_operation_context_.set_src_file_util(file_util);
exclusive_ = exclusive;
- GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback(
- &FileSystemOperation::DelayedCreateFileForQuota));
+ GetUsageAndQuotaThenCallback(
+ origin_url,
+ base::Bind(&FileSystemOperation::DelayedCreateFileForQuota,
+ weak_factory_.GetWeakPtr()));
}
void FileSystemOperation::DelayedCreateFileForQuota(
@@ -168,8 +170,10 @@ void FileSystemOperation::CreateDirectory(const GURL& path,
exclusive_ = exclusive;
recursive_ = recursive;
- GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback(
- &FileSystemOperation::DelayedCreateDirectoryForQuota));
+ GetUsageAndQuotaThenCallback(
+ origin_url,
+ base::Bind(&FileSystemOperation::DelayedCreateDirectoryForQuota,
+ weak_factory_.GetWeakPtr()));
}
void FileSystemOperation::DelayedCreateDirectoryForQuota(
@@ -217,8 +221,10 @@ void FileSystemOperation::Copy(const GURL& src_path,
if (!file_system_operation_context_.dest_file_util())
file_system_operation_context_.set_dest_file_util(dest_file_util);
- GetUsageAndQuotaThenCallback(dest_origin_url, callback_factory_.NewCallback(
- &FileSystemOperation::DelayedCopyForQuota));
+ GetUsageAndQuotaThenCallback(
+ dest_origin_url,
+ base::Bind(&FileSystemOperation::DelayedCopyForQuota,
+ weak_factory_.GetWeakPtr()));
}
void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status,
@@ -266,8 +272,10 @@ void FileSystemOperation::Move(const GURL& src_path,
if (!file_system_operation_context_.dest_file_util())
file_system_operation_context_.set_dest_file_util(dest_file_util);
- GetUsageAndQuotaThenCallback(dest_origin_url, callback_factory_.NewCallback(
- &FileSystemOperation::DelayedMoveForQuota));
+ GetUsageAndQuotaThenCallback(
+ dest_origin_url,
+ base::Bind(&FileSystemOperation::DelayedMoveForQuota,
+ weak_factory_.GetWeakPtr()));
}
void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status,
@@ -438,8 +446,10 @@ void FileSystemOperation::Write(
new net::URLRequest(blob_url, file_writer_delegate_.get()));
blob_request_->set_context(url_request_context);
- GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback(
- &FileSystemOperation::DelayedWriteForQuota));
+ GetUsageAndQuotaThenCallback(
+ origin_url,
+ base::Bind(&FileSystemOperation::DelayedWriteForQuota,
+ weak_factory_.GetWeakPtr()));
}
void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status,
@@ -480,8 +490,10 @@ void FileSystemOperation::Truncate(const GURL& path, int64 length) {
file_system_operation_context_.set_src_file_util(file_util);
length_ = length;
- GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback(
- &FileSystemOperation::DelayedTruncateForQuota));
+ GetUsageAndQuotaThenCallback(
+ origin_url,
+ base::Bind(&FileSystemOperation::DelayedTruncateForQuota,
+ weak_factory_.GetWeakPtr()));
}
void FileSystemOperation::DelayedTruncateForQuota(quota::QuotaStatusCode status,
@@ -569,8 +581,10 @@ void FileSystemOperation::OpenFile(const GURL& path,
file_system_operation_context_.set_src_file_util(file_util);
file_flags_ = file_flags;
- GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback(
- &FileSystemOperation::DelayedOpenFileForQuota));
+ GetUsageAndQuotaThenCallback(
+ origin_url,
+ base::Bind(&FileSystemOperation::DelayedOpenFileForQuota,
+ weak_factory_.GetWeakPtr()));
}
void FileSystemOperation::DelayedOpenFileForQuota(quota::QuotaStatusCode status,
@@ -623,7 +637,7 @@ void FileSystemOperation::Cancel(FileSystemOperation* cancel_operation_ptr) {
void FileSystemOperation::GetUsageAndQuotaThenCallback(
const GURL& origin_url,
- quota::QuotaManager::GetUsageAndQuotaCallback* callback) {
+ const quota::QuotaManager::GetUsageAndQuotaCallback& callback) {
quota::QuotaManagerProxy* quota_manager_proxy =
file_system_context()->quota_manager_proxy();
if (!quota_manager_proxy ||
@@ -631,8 +645,7 @@ void FileSystemOperation::GetUsageAndQuotaThenCallback(
file_system_operation_context_.src_type())) {
// If we don't have the quota manager or the requested filesystem type
// does not support quota, we should be able to let it go.
- callback->Run(quota::kQuotaStatusOk, 0, kint64max);
- delete callback;
+ callback.Run(quota::kQuotaStatusOk, 0, kint64max);
return;
}
DCHECK(quota_manager_proxy);
diff --git a/webkit/fileapi/file_system_operation.h b/webkit/fileapi/file_system_operation.h
index 5876692..3fa1338 100644
--- a/webkit/fileapi/file_system_operation.h
+++ b/webkit/fileapi/file_system_operation.h
@@ -112,7 +112,7 @@ class FileSystemOperation {
void GetUsageAndQuotaThenCallback(
const GURL& origin_url,
- quota::QuotaManager::GetUsageAndQuotaCallback* callback);
+ const quota::QuotaManager::GetUsageAndQuotaCallback& callback);
void DelayedCreateFileForQuota(quota::QuotaStatusCode status,
int64 usage, int64 quota);
diff --git a/webkit/fileapi/file_system_operation_unittest.cc b/webkit/fileapi/file_system_operation_unittest.cc
index a0c67d3..fbf44b7 100644
--- a/webkit/fileapi/file_system_operation_unittest.cc
+++ b/webkit/fileapi/file_system_operation_unittest.cc
@@ -51,11 +51,10 @@ class MockQuotaManager : public QuotaManager {
virtual void GetUsageAndQuota(
const GURL& origin, quota::StorageType type,
- GetUsageAndQuotaCallback* callback) {
+ const GetUsageAndQuotaCallback& callback) OVERRIDE {
EXPECT_EQ(origin_, origin);
EXPECT_EQ(type_, type);
- callback->Run(quota::kQuotaStatusOk, usage_, quota_);
- delete callback;
+ callback.Run(quota::kQuotaStatusOk, usage_, quota_);
}
private:
@@ -97,7 +96,7 @@ class MockQuotaManagerProxy : public QuotaManagerProxy {
EXPECT_FALSE(registered_client_);
}
- virtual void RegisterClient(QuotaClient* client) {
+ virtual void RegisterClient(QuotaClient* client) OVERRIDE {
EXPECT_FALSE(registered_client_);
registered_client_ = client;
}
diff --git a/webkit/fileapi/file_system_operation_write_unittest.cc b/webkit/fileapi/file_system_operation_write_unittest.cc
index 8a00927..7d211c6 100644
--- a/webkit/fileapi/file_system_operation_write_unittest.cc
+++ b/webkit/fileapi/file_system_operation_write_unittest.cc
@@ -50,10 +50,10 @@ class MockQuotaManager : public QuotaManager {
usage_(0),
quota_(quota) {}
- virtual void GetUsageAndQuota(const GURL& origin, quota::StorageType type,
- GetUsageAndQuotaCallback* callback) {
- callback->Run(quota::kQuotaStatusOk, usage_, quota_);
- delete callback;
+ virtual void GetUsageAndQuota(
+ const GURL& origin, quota::StorageType type,
+ const GetUsageAndQuotaCallback& callback) OVERRIDE {
+ callback.Run(quota::kQuotaStatusOk, usage_, quota_);
}
void set_usage(int64 usage) { usage_ = usage; }
diff --git a/webkit/fileapi/file_system_quota_client.cc b/webkit/fileapi/file_system_quota_client.cc
index 3f8e2e5..662f1ff 100644
--- a/webkit/fileapi/file_system_quota_client.cc
+++ b/webkit/fileapi/file_system_quota_client.cc
@@ -138,7 +138,7 @@ class FileSystemQuotaClient::DeleteOriginTask
scoped_refptr<MessageLoopProxy> file_message_loop,
const GURL& origin,
FileSystemType type,
- DeletionCallback* callback)
+ const DeletionCallback& callback)
: QuotaThreadTask(quota_client, file_message_loop),
file_system_context_(quota_client->file_system_context_),
origin_(origin),
@@ -158,14 +158,14 @@ class FileSystemQuotaClient::DeleteOriginTask
}
virtual void Completed() OVERRIDE {
- callback_->Run(status_);
+ callback_.Run(status_);
}
private:
FileSystemContext* file_system_context_;
GURL origin_;
FileSystemType type_;
quota::QuotaStatusCode status_;
- scoped_ptr<DeletionCallback> callback_;
+ DeletionCallback callback_;
};
FileSystemQuotaClient::FileSystemQuotaClient(
@@ -192,13 +192,12 @@ void FileSystemQuotaClient::OnQuotaManagerDestroyed() {
void FileSystemQuotaClient::GetOriginUsage(
const GURL& origin_url,
StorageType storage_type,
- GetUsageCallback* callback_ptr) {
- DCHECK(callback_ptr);
- scoped_ptr<GetUsageCallback> callback(callback_ptr);
+ const GetUsageCallback& callback) {
+ DCHECK(!callback.is_null());
if (is_incognito_) {
// We don't support FileSystem in incognito mode yet.
- callback->Run(0);
+ callback.Run(0);
return;
}
@@ -206,7 +205,7 @@ void FileSystemQuotaClient::GetOriginUsage(
DCHECK(type != kFileSystemTypeUnknown);
if (pending_usage_callbacks_.Add(
- std::make_pair(type, origin_url.spec()), callback.release())) {
+ std::make_pair(type, origin_url.spec()), callback)) {
scoped_refptr<GetOriginUsageTask> task(
new GetOriginUsageTask(this, file_message_loop_, origin_url, type));
task->Start();
@@ -215,19 +214,20 @@ void FileSystemQuotaClient::GetOriginUsage(
void FileSystemQuotaClient::GetOriginsForType(
StorageType storage_type,
- GetOriginsCallback* callback_ptr) {
+ const GetOriginsCallback& callback) {
+ DCHECK(!callback.is_null());
+
std::set<GURL> origins;
- scoped_ptr<GetOriginsCallback> callback(callback_ptr);
if (is_incognito_) {
// We don't support FileSystem in incognito mode yet.
- callback->Run(origins, storage_type);
+ callback.Run(origins, storage_type);
return;
}
FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type);
DCHECK(type != kFileSystemTypeUnknown);
- if (pending_origins_for_type_callbacks_.Add(type, callback.release())) {
+ if (pending_origins_for_type_callbacks_.Add(type, callback)) {
scoped_refptr<GetOriginsForTypeTask> task(
new GetOriginsForTypeTask(this, file_message_loop_, type));
task->Start();
@@ -237,12 +237,13 @@ void FileSystemQuotaClient::GetOriginsForType(
void FileSystemQuotaClient::GetOriginsForHost(
StorageType storage_type,
const std::string& host,
- GetOriginsCallback* callback_ptr) {
+ const GetOriginsCallback& callback) {
+ DCHECK(!callback.is_null());
+
std::set<GURL> origins;
- scoped_ptr<GetOriginsCallback> callback(callback_ptr);
if (is_incognito_) {
// We don't support FileSystem in incognito mode yet.
- callback->Run(origins, storage_type);
+ callback.Run(origins, storage_type);
return;
}
@@ -250,7 +251,7 @@ void FileSystemQuotaClient::GetOriginsForHost(
DCHECK(type != kFileSystemTypeUnknown);
if (pending_origins_for_host_callbacks_.Add(
- std::make_pair(type, host), callback.release())) {
+ std::make_pair(type, host), callback)) {
scoped_refptr<GetOriginsForHostTask> task(
new GetOriginsForHostTask(this, file_message_loop_,
type, host));
@@ -260,7 +261,7 @@ void FileSystemQuotaClient::GetOriginsForHost(
void FileSystemQuotaClient::DeleteOriginData(const GURL& origin,
StorageType type,
- DeletionCallback* callback) {
+ const DeletionCallback& callback) {
FileSystemType fs_type = QuotaStorageTypeToFileSystemType(type);
DCHECK(fs_type != kFileSystemTypeUnknown);
scoped_refptr<DeleteOriginTask> task(
diff --git a/webkit/fileapi/file_system_quota_client.h b/webkit/fileapi/file_system_quota_client.h
index 4045628..35c0b79 100644
--- a/webkit/fileapi/file_system_quota_client.h
+++ b/webkit/fileapi/file_system_quota_client.h
@@ -43,15 +43,18 @@ class FileSystemQuotaClient : public quota::QuotaClient,
virtual void OnQuotaManagerDestroyed() OVERRIDE;
virtual void GetOriginUsage(const GURL& origin_url,
quota::StorageType type,
- GetUsageCallback* callback) OVERRIDE;
- virtual void GetOriginsForType(quota::StorageType type,
- GetOriginsCallback* callback) OVERRIDE;
- virtual void GetOriginsForHost(quota::StorageType type,
- const std::string& host,
- GetOriginsCallback* callback) OVERRIDE;
- virtual void DeleteOriginData(const GURL& origin,
- quota::StorageType type,
- DeletionCallback* callback) OVERRIDE;
+ const GetUsageCallback& callback) OVERRIDE;
+ virtual void GetOriginsForType(
+ quota::StorageType type,
+ const GetOriginsCallback& callback) OVERRIDE;
+ virtual void GetOriginsForHost(
+ quota::StorageType type,
+ const std::string& host,
+ const GetOriginsCallback& callback) OVERRIDE;
+ virtual void DeleteOriginData(
+ const GURL& origin,
+ quota::StorageType type,
+ const DeletionCallback& callback) OVERRIDE;
private:
class GetOriginUsageTask;
@@ -61,16 +64,16 @@ class FileSystemQuotaClient : public quota::QuotaClient,
class DeleteOriginTask;
typedef std::pair<fileapi::FileSystemType, std::string> TypeAndHostOrOrigin;
- typedef quota::CallbackQueueMap1<GetUsageCallback*,
+ typedef quota::CallbackQueueMap1<GetUsageCallback,
TypeAndHostOrOrigin,
int64
> UsageCallbackMap;
- typedef quota::CallbackQueueMap2<GetOriginsCallback*,
+ typedef quota::CallbackQueueMap2<GetOriginsCallback,
fileapi::FileSystemType,
const std::set<GURL>&,
quota::StorageType
> OriginsForTypeCallbackMap;
- typedef quota::CallbackQueueMap2<GetOriginsCallback*,
+ typedef quota::CallbackQueueMap2<GetOriginsCallback,
TypeAndHostOrOrigin,
const std::set<GURL>&,
quota::StorageType
diff --git a/webkit/fileapi/file_system_quota_client_unittest.cc b/webkit/fileapi/file_system_quota_client_unittest.cc
index 59d11dd..39e5314 100644
--- a/webkit/fileapi/file_system_quota_client_unittest.cc
+++ b/webkit/fileapi/file_system_quota_client_unittest.cc
@@ -2,9 +2,9 @@
// 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/basictypes.h"
#include "base/file_util.h"
-#include "base/memory/scoped_callback_factory.h"
#include "base/message_loop.h"
#include "base/message_loop_proxy.h"
#include "base/platform_file.h"
@@ -45,7 +45,7 @@ class MockFileSystemPathManager : public FileSystemPathManager {
class FileSystemQuotaClientTest : public testing::Test {
public:
FileSystemQuotaClientTest()
- : callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
+ : weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
additional_callback_count_(0),
deletion_status_(quota::kQuotaStatusUnknown) {
}
@@ -79,9 +79,10 @@ class FileSystemQuotaClientTest : public testing::Test {
void GetOriginUsageAsync(FileSystemQuotaClient* quota_client,
const std::string& origin_url,
quota::StorageType type) {
- quota_client->GetOriginUsage(GURL(origin_url), type,
- callback_factory_.NewCallback(
- &FileSystemQuotaClientTest::OnGetUsage));
+ quota_client->GetOriginUsage(
+ GURL(origin_url), type,
+ base::Bind(&FileSystemQuotaClientTest::OnGetUsage,
+ weak_factory_.GetWeakPtr()));
}
int64 GetOriginUsage(FileSystemQuotaClient* quota_client,
@@ -95,9 +96,10 @@ class FileSystemQuotaClientTest : public testing::Test {
const std::set<GURL>& GetOriginsForType(FileSystemQuotaClient* quota_client,
quota::StorageType type) {
origins_.clear();
- quota_client->GetOriginsForType(type,
- callback_factory_.NewCallback(
- &FileSystemQuotaClientTest::OnGetOrigins));
+ quota_client->GetOriginsForType(
+ type,
+ base::Bind(&FileSystemQuotaClientTest::OnGetOrigins,
+ weak_factory_.GetWeakPtr()));
MessageLoop::current()->RunAllPending();
return origins_;
}
@@ -106,9 +108,10 @@ class FileSystemQuotaClientTest : public testing::Test {
quota::StorageType type,
const std::string& host) {
origins_.clear();
- quota_client->GetOriginsForHost(type, host,
- callback_factory_.NewCallback(
- &FileSystemQuotaClientTest::OnGetOrigins));
+ quota_client->GetOriginsForHost(
+ type, host,
+ base::Bind(&FileSystemQuotaClientTest::OnGetOrigins,
+ weak_factory_.GetWeakPtr()));
MessageLoop::current()->RunAllPending();
return origins_;
}
@@ -116,9 +119,10 @@ class FileSystemQuotaClientTest : public testing::Test {
void RunAdditionalOriginUsageTask(FileSystemQuotaClient* quota_client,
const std::string& origin_url,
quota::StorageType type) {
- quota_client->GetOriginUsage(GURL(origin_url), type,
- callback_factory_.NewCallback(
- &FileSystemQuotaClientTest::OnGetAdditionalUsage));
+ quota_client->GetOriginUsage(
+ GURL(origin_url), type,
+ base::Bind(&FileSystemQuotaClientTest::OnGetAdditionalUsage,
+ weak_factory_.GetWeakPtr()));
}
FilePath GetOriginBasePath(const std::string& origin_url,
@@ -234,8 +238,8 @@ class FileSystemQuotaClientTest : public testing::Test {
deletion_status_ = quota::kQuotaStatusUnknown;
quota_client->DeleteOriginData(
GURL(origin), type,
- callback_factory_.NewCallback(
- &FileSystemQuotaClientTest::OnDeleteOrigin));
+ base::Bind(&FileSystemQuotaClientTest::OnDeleteOrigin,
+ weak_factory_.GetWeakPtr()));
}
int64 usage() const { return usage_; }
@@ -266,7 +270,7 @@ class FileSystemQuotaClientTest : public testing::Test {
ScopedTempDir data_dir_;
scoped_refptr<FileSystemContext> file_system_context_;
- base::ScopedCallbackFactory<FileSystemQuotaClientTest> callback_factory_;
+ base::WeakPtrFactory<FileSystemQuotaClientTest> weak_factory_;
int64 usage_;
int additional_callback_count_;
std::set<GURL> origins_;
diff --git a/webkit/fileapi/file_system_quota_unittest.cc b/webkit/fileapi/file_system_quota_unittest.cc
index 6eddf09..f901d43 100644
--- a/webkit/fileapi/file_system_quota_unittest.cc
+++ b/webkit/fileapi/file_system_quota_unittest.cc
@@ -7,6 +7,7 @@
// 2) the described size in .usage, and
// 3) the result of QuotaManager::GetUsageAndQuota.
+#include "base/bind.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/memory/scoped_callback_factory.h"
@@ -32,7 +33,7 @@ class FileSystemQuotaTest : public testing::Test {
public:
FileSystemQuotaTest()
: local_file_util_(new LocalFileUtil(QuotaFileUtil::CreateDefault())),
- callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
+ weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
status_(kFileOperationStatusNotSet),
quota_status_(quota::kQuotaStatusUnknown),
usage_(-1),
@@ -74,8 +75,8 @@ class FileSystemQuotaTest : public testing::Test {
void GetUsageAndQuotaFromQuotaManager() {
quota_manager_->GetUsageAndQuota(
test_helper_.origin(), test_helper_.storage_type(),
- callback_factory_.NewCallback(
- &FileSystemQuotaTest::OnGetUsageAndQuota));
+ base::Bind(&FileSystemQuotaTest::OnGetUsageAndQuota,
+ weak_factory_.GetWeakPtr()));
MessageLoop::current()->RunAllPending();
}
@@ -122,7 +123,7 @@ class FileSystemQuotaTest : public testing::Test {
scoped_refptr<quota::QuotaManager> quota_manager_;
scoped_ptr<LocalFileUtil> local_file_util_;
- base::ScopedCallbackFactory<FileSystemQuotaTest> callback_factory_;
+ base::WeakPtrFactory<FileSystemQuotaTest> weak_factory_;
// For post-operation status.
int status_;
diff --git a/webkit/fileapi/obfuscated_file_util_unittest.cc b/webkit/fileapi/obfuscated_file_util_unittest.cc
index 3881370..75ba956 100644
--- a/webkit/fileapi/obfuscated_file_util_unittest.cc
+++ b/webkit/fileapi/obfuscated_file_util_unittest.cc
@@ -6,10 +6,10 @@
#include <set>
#include <string>
+#include "base/bind.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/memory/scoped_ptr.h"
-#include "base/memory/scoped_callback_factory.h"
#include "base/message_loop.h"
#include "base/platform_file.h"
#include "base/scoped_temp_dir.h"
@@ -133,7 +133,7 @@ class ObfuscatedFileUtilTest : public testing::Test {
ObfuscatedFileUtilTest()
: origin_(GURL("http://www.example.com")),
type_(kFileSystemTypeTemporary),
- callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
+ weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
test_helper_(origin_, type_),
quota_status_(quota::kQuotaStatusUnknown),
usage_(-1) {
@@ -212,8 +212,8 @@ class ObfuscatedFileUtilTest : public testing::Test {
void GetUsageFromQuotaManager() {
quota_manager_->GetUsageAndQuota(
origin(), test_helper_.storage_type(),
- callback_factory_.NewCallback(
- &ObfuscatedFileUtilTest::OnGetUsage));
+ base::Bind(&ObfuscatedFileUtilTest::OnGetUsage,
+ weak_factory_.GetWeakPtr()));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(quota::kQuotaStatusOk, quota_status_);
}
@@ -483,8 +483,7 @@ class ObfuscatedFileUtilTest : public testing::Test {
scoped_refptr<FileSystemContext> file_system_context_;
GURL origin_;
fileapi::FileSystemType type_;
- base::ScopedCallbackFactory<ObfuscatedFileUtilTest>
- callback_factory_;
+ base::WeakPtrFactory<ObfuscatedFileUtilTest> weak_factory_;
FileSystemTestOriginHelper test_helper_;
quota::QuotaStatusCode quota_status_;
int64 usage_;
diff --git a/webkit/quota/mock_quota_manager.cc b/webkit/quota/mock_quota_manager.cc
index 67f1ee3..52d2735 100644
--- a/webkit/quota/mock_quota_manager.cc
+++ b/webkit/quota/mock_quota_manager.cc
@@ -23,7 +23,7 @@ class MockQuotaManager::GetModifiedSinceTask : public QuotaThreadTask {
GetModifiedSinceTask(MockQuotaManager* manager,
const std::set<GURL>& origins,
StorageType type,
- GetOriginsCallback* callback)
+ const GetOriginsCallback& callback)
: QuotaThreadTask(manager, manager->io_thread_),
origins_(origins),
type_(type),
@@ -33,17 +33,17 @@ class MockQuotaManager::GetModifiedSinceTask : public QuotaThreadTask {
virtual void RunOnTargetThread() OVERRIDE {}
virtual void Completed() OVERRIDE {
- callback_->Run(origins_, type_);
+ callback_.Run(origins_, type_);
}
virtual void Aborted() OVERRIDE {
- callback_->Run(std::set<GURL>(), type_);
+ callback_.Run(std::set<GURL>(), type_);
}
private:
std::set<GURL> origins_;
StorageType type_;
- scoped_ptr<GetOriginsCallback> callback_;
+ GetOriginsCallback callback_;
DISALLOW_COPY_AND_ASSIGN(GetModifiedSinceTask);
};
@@ -51,7 +51,7 @@ class MockQuotaManager::GetModifiedSinceTask : public QuotaThreadTask {
class MockQuotaManager::DeleteOriginDataTask : public QuotaThreadTask {
public:
DeleteOriginDataTask(MockQuotaManager* manager,
- StatusCallback* callback)
+ const StatusCallback& callback)
: QuotaThreadTask(manager, manager->io_thread_),
callback_(callback) {}
@@ -59,15 +59,15 @@ class MockQuotaManager::DeleteOriginDataTask : public QuotaThreadTask {
virtual void RunOnTargetThread() OVERRIDE {}
virtual void Completed() OVERRIDE {
- callback_->Run(quota::kQuotaStatusOk);
+ callback_.Run(quota::kQuotaStatusOk);
}
virtual void Aborted() OVERRIDE {
- callback_->Run(quota::kQuotaErrorAbort);
+ callback_.Run(quota::kQuotaErrorAbort);
}
private:
- scoped_ptr<StatusCallback> callback_;
+ StatusCallback callback_;
DISALLOW_COPY_AND_ASSIGN(DeleteOriginDataTask);
};
@@ -110,8 +110,10 @@ bool MockQuotaManager::OriginHasData(const GURL& origin,
return false;
}
-void MockQuotaManager::GetOriginsModifiedSince(StorageType type,
- base::Time modified_since, GetOriginsCallback* callback) {
+void MockQuotaManager::GetOriginsModifiedSince(
+ StorageType type,
+ base::Time modified_since,
+ const GetOriginsCallback& callback) {
std::set<GURL> origins_to_return;
for (std::vector<OriginInfo>::const_iterator current = origins_.begin();
current != origins_.end();
@@ -124,7 +126,7 @@ void MockQuotaManager::GetOriginsModifiedSince(StorageType type,
}
void MockQuotaManager::DeleteOriginData(const GURL& origin, StorageType type,
- StatusCallback* callback) {
+ const StatusCallback& callback) {
for (std::vector<OriginInfo>::iterator current = origins_.begin();
current != origins_.end();
++current) {
diff --git a/webkit/quota/mock_quota_manager.h b/webkit/quota/mock_quota_manager.h
index 636404d..1f6fb0b 100644
--- a/webkit/quota/mock_quota_manager.h
+++ b/webkit/quota/mock_quota_manager.h
@@ -59,15 +59,17 @@ class MockQuotaManager : public QuotaManager {
// Overrides QuotaManager's implementation with a canned implementation that
// allows clients to set up the origin database that should be queried. This
// method will only search through the origins added explicitly via AddOrigin.
- virtual void GetOriginsModifiedSince(StorageType type,
- base::Time modified_since,
- GetOriginsCallback* callback) OVERRIDE;
+ virtual void GetOriginsModifiedSince(
+ StorageType type,
+ base::Time modified_since,
+ const GetOriginsCallback& callback) OVERRIDE;
// Removes an origin from the canned list of origins, but doesn't touch
// anything on disk.
virtual void DeleteOriginData(const GURL& origin,
StorageType type,
- StatusCallback* callback) OVERRIDE;
+ const StatusCallback& callback) OVERRIDE;
+
private:
class GetModifiedSinceTask;
class DeleteOriginDataTask;
@@ -80,4 +82,4 @@ class MockQuotaManager : public QuotaManager {
} // namespace quota
-#endif // WEBKIT_QUOTA_MOCK_QUOTA_MANAGER_H_
+#endif // WEBKIT_QUOTA_MOCK_QUOTA_MANAGER_H_
diff --git a/webkit/quota/mock_quota_manager_unittest.cc b/webkit/quota/mock_quota_manager_unittest.cc
index 503f8aa..5f1d1b6 100644
--- a/webkit/quota/mock_quota_manager_unittest.cc
+++ b/webkit/quota/mock_quota_manager_unittest.cc
@@ -5,8 +5,8 @@
#include <set>
+#include "base/bind.h"
#include "base/file_util.h"
-#include "base/memory/scoped_callback_factory.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "base/message_loop_proxy.h"
@@ -29,7 +29,7 @@ const GURL kOrigin3(kTestOrigin3);
class MockQuotaManagerTest : public testing::Test {
public:
MockQuotaManagerTest()
- : callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
+ : weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
deletion_callback_count_(0) {
}
@@ -51,9 +51,10 @@ class MockQuotaManagerTest : public testing::Test {
}
void GetModifiedOrigins(StorageType type, base::Time since) {
- manager_->GetOriginsModifiedSince(type, since,
- callback_factory_.NewCallback(
- &MockQuotaManagerTest::GotModifiedOrigins));
+ manager_->GetOriginsModifiedSince(
+ type, since,
+ base::Bind(&MockQuotaManagerTest::GotModifiedOrigins,
+ weak_factory_.GetWeakPtr()));
}
void GotModifiedOrigins(const std::set<GURL>& origins, StorageType type) {
@@ -62,9 +63,10 @@ class MockQuotaManagerTest : public testing::Test {
}
void DeleteOriginData(const GURL& origin, StorageType type) {
- manager_->DeleteOriginData(origin, type,
- callback_factory_.NewCallback(
- &MockQuotaManagerTest::DeletedOriginData));
+ manager_->DeleteOriginData(
+ origin, type,
+ base::Bind(&MockQuotaManagerTest::DeletedOriginData,
+ weak_factory_.GetWeakPtr()));
}
void DeletedOriginData(QuotaStatusCode status) {
@@ -90,7 +92,7 @@ class MockQuotaManagerTest : public testing::Test {
private:
ScopedTempDir data_dir_;
- base::ScopedCallbackFactory<MockQuotaManagerTest> callback_factory_;
+ base::WeakPtrFactory<MockQuotaManagerTest> weak_factory_;
scoped_refptr<MockQuotaManager> manager_;
scoped_refptr<MockSpecialStoragePolicy> policy_;
diff --git a/webkit/quota/mock_storage_client.cc b/webkit/quota/mock_storage_client.cc
index d42ed8d..2188df4 100644
--- a/webkit/quota/mock_storage_client.cc
+++ b/webkit/quota/mock_storage_client.cc
@@ -55,13 +55,7 @@ MockStorageClient::MockStorageClient(
}
}
-MockStorageClient::~MockStorageClient() {
- STLDeleteContainerPointers(usage_callbacks_.begin(), usage_callbacks_.end());
- STLDeleteContainerPointers(
- origins_callbacks_.begin(), origins_callbacks_.end());
- STLDeleteContainerPointers(
- deletion_callbacks_.begin(), deletion_callbacks_.end());
-}
+MockStorageClient::~MockStorageClient() {}
void MockStorageClient::AddOriginAndNotify(
const GURL& origin_url, StorageType type, int64 size) {
@@ -113,8 +107,7 @@ void MockStorageClient::OnQuotaManagerDestroyed() {
void MockStorageClient::GetOriginUsage(const GURL& origin_url,
StorageType type,
- GetUsageCallback* callback) {
- usage_callbacks_.insert(callback);
+ const GetUsageCallback& callback) {
base::MessageLoopProxy::current()->PostTask(
FROM_HERE, runnable_factory_.NewRunnableMethod(
&MockStorageClient::RunGetOriginUsage,
@@ -122,8 +115,7 @@ void MockStorageClient::GetOriginUsage(const GURL& origin_url,
}
void MockStorageClient::GetOriginsForType(
- StorageType type, GetOriginsCallback* callback) {
- origins_callbacks_.insert(callback);
+ StorageType type, const GetOriginsCallback& callback) {
base::MessageLoopProxy::current()->PostTask(
FROM_HERE, runnable_factory_.NewRunnableMethod(
&MockStorageClient::RunGetOriginsForType,
@@ -132,8 +124,7 @@ void MockStorageClient::GetOriginsForType(
void MockStorageClient::GetOriginsForHost(
StorageType type, const std::string& host,
- GetOriginsCallback* callback) {
- origins_callbacks_.insert(callback);
+ const GetOriginsCallback& callback) {
base::MessageLoopProxy::current()->PostTask(
FROM_HERE, runnable_factory_.NewRunnableMethod(
&MockStorageClient::RunGetOriginsForHost,
@@ -142,8 +133,7 @@ void MockStorageClient::GetOriginsForHost(
void MockStorageClient::DeleteOriginData(
const GURL& origin, StorageType type,
- DeletionCallback* callback) {
- deletion_callbacks_.insert(callback);
+ const DeletionCallback& callback) {
base::MessageLoopProxy::current()->PostTask(
FROM_HERE, runnable_factory_.NewRunnableMethod(
&MockStorageClient::RunDeleteOriginData,
@@ -151,35 +141,30 @@ void MockStorageClient::DeleteOriginData(
}
void MockStorageClient::RunGetOriginUsage(
- const GURL& origin_url, StorageType type, GetUsageCallback* callback_ptr) {
- usage_callbacks_.erase(callback_ptr);
- scoped_ptr<GetUsageCallback> callback(callback_ptr);
+ const GURL& origin_url, StorageType type,
+ const GetUsageCallback& callback) {
OriginDataMap::iterator find = origin_data_.find(make_pair(origin_url, type));
if (find == origin_data_.end()) {
- callback->Run(0);
+ callback.Run(0);
} else {
- callback->Run(find->second);
+ callback.Run(find->second);
}
}
void MockStorageClient::RunGetOriginsForType(
- StorageType type, GetOriginsCallback* callback_ptr) {
- scoped_ptr<GetOriginsCallback> callback(callback_ptr);
- origins_callbacks_.erase(callback_ptr);
+ StorageType type, const GetOriginsCallback& callback) {
std::set<GURL> origins;
for (OriginDataMap::iterator iter = origin_data_.begin();
iter != origin_data_.end(); ++iter) {
if (type == iter->first.second)
origins.insert(iter->first.first);
}
- callback->Run(origins, type);
+ callback.Run(origins, type);
}
void MockStorageClient::RunGetOriginsForHost(
StorageType type, const std::string& host,
- GetOriginsCallback* callback_ptr) {
- scoped_ptr<GetOriginsCallback> callback(callback_ptr);
- origins_callbacks_.erase(callback_ptr);
+ const GetOriginsCallback& callback) {
std::set<GURL> origins;
for (OriginDataMap::iterator iter = origin_data_.begin();
iter != origin_data_.end(); ++iter) {
@@ -187,19 +172,17 @@ void MockStorageClient::RunGetOriginsForHost(
if (type == iter->first.second && host == host_or_spec)
origins.insert(iter->first.first);
}
- callback->Run(origins, type);
+ callback.Run(origins, type);
}
void MockStorageClient::RunDeleteOriginData(
const GURL& origin_url,
StorageType type,
- DeletionCallback* callback_ptr) {
- scoped_ptr<DeletionCallback> callback(callback_ptr);
+ const DeletionCallback& callback) {
ErrorOriginSet::iterator itr_error =
error_origins_.find(make_pair(origin_url, type));
if (itr_error != error_origins_.end()) {
- deletion_callbacks_.erase(callback_ptr);
- callback->Run(kQuotaErrorInvalidModification);
+ callback.Run(kQuotaErrorInvalidModification);
return;
}
@@ -212,8 +195,7 @@ void MockStorageClient::RunDeleteOriginData(
origin_data_.erase(itr);
}
- deletion_callbacks_.erase(callback_ptr);
- callback->Run(kQuotaStatusOk);
+ callback.Run(kQuotaStatusOk);
}
} // namespace quota
diff --git a/webkit/quota/mock_storage_client.h b/webkit/quota/mock_storage_client.h
index fdc2677..7317c76 100644
--- a/webkit/quota/mock_storage_client.h
+++ b/webkit/quota/mock_storage_client.h
@@ -8,6 +8,7 @@
#include <map>
#include <set>
#include <string>
+#include <utility>
#include "base/compiler_specific.h"
#include "base/task.h"
@@ -48,27 +49,27 @@ class MockStorageClient : public QuotaClient {
virtual void OnQuotaManagerDestroyed() OVERRIDE;
virtual void GetOriginUsage(const GURL& origin_url,
StorageType type,
- GetUsageCallback* callback) OVERRIDE;
+ const GetUsageCallback& callback) OVERRIDE;
virtual void GetOriginsForType(StorageType type,
- GetOriginsCallback* callback) OVERRIDE;
+ const GetOriginsCallback& callback) OVERRIDE;
virtual void GetOriginsForHost(StorageType type, const std::string& host,
- GetOriginsCallback* callback) OVERRIDE;
+ const GetOriginsCallback& callback) OVERRIDE;
virtual void DeleteOriginData(const GURL& origin,
StorageType type,
- DeletionCallback* callback) OVERRIDE;
+ const DeletionCallback& callback) OVERRIDE;
private:
void RunGetOriginUsage(const GURL& origin_url,
StorageType type,
- GetUsageCallback* callback);
+ const GetUsageCallback& callback);
void RunGetOriginsForType(StorageType type,
- GetOriginsCallback* callback);
+ const GetOriginsCallback& callback);
void RunGetOriginsForHost(StorageType type,
const std::string& host,
- GetOriginsCallback* callback);
+ const GetOriginsCallback& callback);
void RunDeleteOriginData(const GURL& origin_url,
StorageType type,
- DeletionCallback* callback);
+ const DeletionCallback& callback);
scoped_refptr<QuotaManagerProxy> quota_manager_proxy_;
const ID id_;
@@ -78,10 +79,6 @@ class MockStorageClient : public QuotaClient {
typedef std::set<std::pair<GURL, StorageType> > ErrorOriginSet;
ErrorOriginSet error_origins_;
- std::set<GetUsageCallback*> usage_callbacks_;
- std::set<GetOriginsCallback*> origins_callbacks_;
- std::set<DeletionCallback*> deletion_callbacks_;
-
int mock_time_counter_;
ScopedRunnableMethodFactory<MockStorageClient> runnable_factory_;
diff --git a/webkit/quota/quota_client.h b/webkit/quota/quota_client.h
index 312e5d0..eb26c24 100644
--- a/webkit/quota/quota_client.h
+++ b/webkit/quota/quota_client.h
@@ -9,7 +9,7 @@
#include <set>
#include <string>
-#include "base/callback_old.h"
+#include "base/callback.h"
#include "base/time.h"
#include "googleurl/src/gurl.h"
#include "webkit/quota/quota_types.h"
@@ -22,10 +22,10 @@ namespace quota {
// All the methods are assumed to be called on the IO thread in the browser.
class QuotaClient {
public:
- typedef Callback1<int64>::Type GetUsageCallback;
- typedef Callback2<const std::set<GURL>&, StorageType>::Type
+ typedef base::Callback<void(int64)> GetUsageCallback; // NOLINT
+ typedef base::Callback<void(const std::set<GURL>&, StorageType)>
GetOriginsCallback;
- typedef Callback1<QuotaStatusCode>::Type DeletionCallback;
+ typedef base::Callback<void(QuotaStatusCode)> DeletionCallback;
virtual ~QuotaClient() {}
@@ -48,23 +48,23 @@ class QuotaClient {
// |origin_url| and |type|.
virtual void GetOriginUsage(const GURL& origin_url,
StorageType type,
- GetUsageCallback* callback) = 0;
+ const GetUsageCallback& callback) = 0;
// Called by the QuotaManager.
// Returns a list of origins that has data in the |type| storage.
virtual void GetOriginsForType(StorageType type,
- GetOriginsCallback* callback) = 0;
+ const GetOriginsCallback& callback) = 0;
// Called by the QuotaManager.
// Returns a list of origins that match the |host|.
virtual void GetOriginsForHost(StorageType type,
const std::string& host,
- GetOriginsCallback* callback) = 0;
+ const GetOriginsCallback& callback) = 0;
// Called by the QuotaManager.
virtual void DeleteOriginData(const GURL& origin,
StorageType type,
- DeletionCallback* callback) = 0;
+ const DeletionCallback& callback) = 0;
};
// TODO(dmikurube): Replace it to std::vector for efficiency.
diff --git a/webkit/quota/quota_manager.cc b/webkit/quota/quota_manager.cc
index 5b417fa..99f6449 100644
--- a/webkit/quota/quota_manager.cc
+++ b/webkit/quota/quota_manager.cc
@@ -15,7 +15,6 @@
#include "base/memory/ref_counted.h"
#include "base/message_loop_proxy.h"
#include "base/metrics/histogram.h"
-#include "base/stl_util.h"
#include "base/string_number_conversions.h"
#include "base/sys_info.h"
#include "base/time.h"
@@ -30,8 +29,6 @@
(name), static_cast<int>((sample) / kMBytes), \
1, 10 * 1024 * 1024 /* 10TB */, 100)
-using base::ScopedCallbackFactory;
-
namespace quota {
namespace {
@@ -76,24 +73,22 @@ const int QuotaManager::kEvictionIntervalInMilliSeconds =
// Callback translators.
void CallGetUsageAndQuotaCallback(
- QuotaManager::GetUsageAndQuotaCallback* callback,
+ const QuotaManager::GetUsageAndQuotaCallback& callback,
bool unlimited,
QuotaStatusCode status,
const QuotaAndUsage& quota_and_usage) {
int64 usage =
unlimited ? quota_and_usage.unlimited_usage : quota_and_usage.usage;
int64 quota = unlimited ? kint64max : quota_and_usage.quota;
- callback->Run(status, usage, quota);
- delete callback;
+ callback.Run(status, usage, quota);
}
void CallQuotaCallback(
- QuotaCallback* callback,
+ const QuotaCallback& callback,
StorageType type,
QuotaStatusCode status,
const QuotaAndUsage& quota_and_usage) {
- callback->Run(status, type, quota_and_usage.quota);
- delete callback;
+ callback.Run(status, type, quota_and_usage.quota);
}
// This class is for posting GetUsage/GetQuota tasks, gathering
@@ -171,7 +166,7 @@ class QuotaManager::UsageAndQuotaDispatcherTask : public QuotaTask {
available_space_(-1),
quota_status_(kQuotaStatusUnknown),
waiting_callbacks_(1),
- ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) {}
+ weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {}
virtual ~UsageAndQuotaDispatcherTask() {}
@@ -246,27 +241,28 @@ class QuotaManager::UsageAndQuotaDispatcherTask : public QuotaTask {
// Subclasses must call following methods to create a new 'waitable'
// callback, which decrements waiting_callbacks when it is called.
- GlobalUsageCallback* NewWaitableGlobalUsageCallback() {
+ GlobalUsageCallback NewWaitableGlobalUsageCallback() {
++waiting_callbacks_;
- return callback_factory_.NewCallback(
- &UsageAndQuotaDispatcherTask::DidGetGlobalUsage);
+ return base::Bind(&UsageAndQuotaDispatcherTask::DidGetGlobalUsage,
+ weak_factory_.GetWeakPtr());
}
- HostUsageCallback* NewWaitableHostUsageCallback() {
+ HostUsageCallback NewWaitableHostUsageCallback() {
++waiting_callbacks_;
- return callback_factory_.NewCallback(
- &UsageAndQuotaDispatcherTask::DidGetHostUsage);
+ return base::Bind(&UsageAndQuotaDispatcherTask::DidGetHostUsage,
+ weak_factory_.GetWeakPtr());
}
- HostQuotaCallback* NewWaitableHostQuotaCallback() {
+ HostQuotaCallback NewWaitableHostQuotaCallback() {
++waiting_callbacks_;
- return callback_factory_.NewCallback(
- &UsageAndQuotaDispatcherTask::DidGetHostQuota);
+ return base::Bind(&UsageAndQuotaDispatcherTask::DidGetHostQuota,
+ weak_factory_.GetWeakPtr());
}
- AvailableSpaceCallback* NewWaitableAvailableSpaceCallback() {
+ AvailableSpaceCallback NewWaitableAvailableSpaceCallback() {
++waiting_callbacks_;
- return callback_factory_.NewCallback(
- &UsageAndQuotaDispatcherTask::DidGetAvailableSpace);
+ return base::Bind(&UsageAndQuotaDispatcherTask::DidGetAvailableSpace,
+ weak_factory_.GetWeakPtr());
}
+
private:
void CheckCompleted() {
if (--waiting_callbacks_ <= 0) {
@@ -292,7 +288,7 @@ class QuotaManager::UsageAndQuotaDispatcherTask : public QuotaTask {
QuotaStatusCode quota_status_;
CallbackList callbacks_;
int waiting_callbacks_;
- ScopedCallbackFactory<UsageAndQuotaDispatcherTask> callback_factory_;
+ base::WeakPtrFactory<UsageAndQuotaDispatcherTask> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(UsageAndQuotaDispatcherTask);
};
@@ -304,28 +300,30 @@ class QuotaManager::GetUsageInfoTask : public QuotaTask {
public:
GetUsageInfoTask(
QuotaManager* manager,
- GetUsageInfoCallback* callback)
+ const GetUsageInfoCallback& callback)
: QuotaTask(manager),
callback_(callback),
- ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) {
+ weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
}
protected:
virtual void Run() OVERRIDE {
remaining_trackers_ = 2;
// This will populate cached hosts and usage info.
manager()->GetUsageTracker(kStorageTypeTemporary)->GetGlobalUsage(
- callback_factory_.NewCallback(&GetUsageInfoTask::DidGetGlobalUsage));
+ base::Bind(&GetUsageInfoTask::DidGetGlobalUsage,
+ weak_factory_.GetWeakPtr()));
manager()->GetUsageTracker(kStorageTypePersistent)->GetGlobalUsage(
- callback_factory_.NewCallback(&GetUsageInfoTask::DidGetGlobalUsage));
+ base::Bind(&GetUsageInfoTask::DidGetGlobalUsage,
+ weak_factory_.GetWeakPtr()));
}
virtual void Completed() OVERRIDE {
- callback_->Run(entries_);
+ callback_.Run(entries_);
DeleteSoon();
}
virtual void Aborted() OVERRIDE {
- callback_->Run(UsageInfoEntries());
+ callback_.Run(UsageInfoEntries());
DeleteSoon();
}
@@ -350,9 +348,9 @@ class QuotaManager::GetUsageInfoTask : public QuotaTask {
return static_cast<QuotaManager*>(observer());
}
- scoped_ptr<GetUsageInfoCallback> callback_;
+ GetUsageInfoCallback callback_;
UsageInfoEntries entries_;
- base::ScopedCallbackFactory<GetUsageInfoTask> callback_factory_;
+ base::WeakPtrFactory<GetUsageInfoTask> weak_factory_;
int remaining_trackers_;
DISALLOW_COPY_AND_ASSIGN(GetUsageInfoTask);
@@ -464,14 +462,14 @@ class QuotaManager::OriginDataDeleter : public QuotaTask {
OriginDataDeleter(QuotaManager* manager,
const GURL& origin,
StorageType type,
- StatusCallback* callback)
+ const StatusCallback& callback)
: QuotaTask(manager),
origin_(origin),
type_(type),
error_count_(0),
remaining_clients_(-1),
callback_(callback),
- ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) {}
+ weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {}
protected:
virtual void Run() OVERRIDE {
@@ -479,23 +477,25 @@ class QuotaManager::OriginDataDeleter : public QuotaTask {
remaining_clients_ = manager()->clients_.size();
for (QuotaClientList::iterator iter = manager()->clients_.begin();
iter != manager()->clients_.end(); ++iter) {
- (*iter)->DeleteOriginData(origin_, type_, callback_factory_.NewCallback(
- &OriginDataDeleter::DidDeleteOriginData));
+ (*iter)->DeleteOriginData(
+ origin_, type_,
+ base::Bind(&OriginDataDeleter::DidDeleteOriginData,
+ weak_factory_.GetWeakPtr()));
}
}
virtual void Completed() OVERRIDE {
if (error_count_ == 0) {
manager()->DeleteOriginFromDatabase(origin_, type_);
- callback_->Run(kQuotaStatusOk);
+ callback_.Run(kQuotaStatusOk);
} else {
- callback_->Run(kQuotaErrorInvalidModification);
+ callback_.Run(kQuotaErrorInvalidModification);
}
DeleteSoon();
}
virtual void Aborted() OVERRIDE {
- callback_->Run(kQuotaErrorAbort);
+ callback_.Run(kQuotaErrorAbort);
DeleteSoon();
}
@@ -517,9 +517,9 @@ class QuotaManager::OriginDataDeleter : public QuotaTask {
StorageType type_;
int error_count_;
int remaining_clients_;
- scoped_ptr<StatusCallback> callback_;
+ StatusCallback callback_;
- ScopedCallbackFactory<OriginDataDeleter> callback_factory_;
+ base::WeakPtrFactory<OriginDataDeleter> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(OriginDataDeleter);
};
@@ -592,7 +592,7 @@ class QuotaManager::UpdateTemporaryQuotaOverrideTask
UpdateTemporaryQuotaOverrideTask(
QuotaManager* manager,
int64 new_quota,
- QuotaCallback* callback)
+ const QuotaCallback& callback)
: DatabaseTaskBase(manager),
new_quota_(new_quota),
callback_(callback) {}
@@ -618,14 +618,14 @@ class QuotaManager::UpdateTemporaryQuotaOverrideTask
private:
void CallCallback(QuotaStatusCode status, StorageType type, int64 quota) {
- if (callback_.get()) {
- callback_->Run(status, type, quota);
- callback_.reset();
+ if (!callback_.is_null()) {
+ callback_.Run(status, type, quota);
+ callback_.Reset();
}
}
int64 new_quota_;
- scoped_ptr<QuotaCallback> callback_;
+ QuotaCallback callback_;
};
class QuotaManager::GetPersistentHostQuotaTask
@@ -634,7 +634,7 @@ class QuotaManager::GetPersistentHostQuotaTask
GetPersistentHostQuotaTask(
QuotaManager* manager,
const std::string& host,
- HostQuotaCallback* callback)
+ const HostQuotaCallback& callback)
: DatabaseTaskBase(manager),
host_(host),
quota_(-1),
@@ -646,13 +646,13 @@ class QuotaManager::GetPersistentHostQuotaTask
quota_ = 0;
}
virtual void DatabaseTaskCompleted() OVERRIDE {
- callback_->Run(kQuotaStatusOk,
- host_, kStorageTypePersistent, quota_);
+ callback_.Run(kQuotaStatusOk,
+ host_, kStorageTypePersistent, quota_);
}
private:
std::string host_;
int64 quota_;
- scoped_ptr<HostQuotaCallback> callback_;
+ HostQuotaCallback callback_;
};
class QuotaManager::UpdatePersistentHostQuotaTask
@@ -662,7 +662,7 @@ class QuotaManager::UpdatePersistentHostQuotaTask
QuotaManager* manager,
const std::string& host,
int new_quota,
- HostQuotaCallback* callback)
+ const HostQuotaCallback& callback)
: DatabaseTaskBase(manager),
host_(host),
new_quota_(new_quota),
@@ -678,18 +678,18 @@ class QuotaManager::UpdatePersistentHostQuotaTask
}
virtual void DatabaseTaskCompleted() OVERRIDE {
- callback_->Run(db_disabled() ? kQuotaErrorInvalidAccess : kQuotaStatusOk,
- host_, kStorageTypePersistent, new_quota_);
+ callback_.Run(db_disabled() ? kQuotaErrorInvalidAccess : kQuotaStatusOk,
+ host_, kStorageTypePersistent, new_quota_);
}
virtual void Aborted() OVERRIDE {
- callback_.reset();
+ callback_.Reset();
}
private:
std::string host_;
int64 new_quota_;
- scoped_ptr<HostQuotaCallback> callback_;
+ HostQuotaCallback callback_;
};
class QuotaManager::GetLRUOriginTask
@@ -804,7 +804,7 @@ class QuotaManager::AvailableSpaceQueryTask : public QuotaThreadTask {
public:
AvailableSpaceQueryTask(
QuotaManager* manager,
- AvailableSpaceCallback* callback)
+ const AvailableSpaceCallback& callback)
: QuotaThreadTask(manager, manager->db_thread_),
profile_path_(manager->profile_path_),
space_(-1),
@@ -818,17 +818,17 @@ class QuotaManager::AvailableSpaceQueryTask : public QuotaThreadTask {
}
virtual void Aborted() OVERRIDE {
- callback_.reset();
+ callback_.Reset();
}
virtual void Completed() OVERRIDE {
- callback_->Run(kQuotaStatusOk, space_);
+ callback_.Run(kQuotaStatusOk, space_);
}
private:
FilePath profile_path_;
int64 space_;
- scoped_ptr<AvailableSpaceCallback> callback_;
+ AvailableSpaceCallback callback_;
};
class QuotaManager::UpdateAccessTimeTask
@@ -893,7 +893,7 @@ class QuotaManager::GetModifiedSinceTask
QuotaManager* manager,
StorageType type,
base::Time modified_since,
- GetOriginsCallback* callback)
+ GetOriginsCallback callback)
: DatabaseTaskBase(manager),
type_(type),
modified_since_(modified_since),
@@ -908,18 +908,18 @@ class QuotaManager::GetModifiedSinceTask
}
virtual void DatabaseTaskCompleted() OVERRIDE {
- callback_->Run(origins_, type_);
+ callback_.Run(origins_, type_);
}
virtual void Aborted() OVERRIDE {
- callback_->Run(std::set<GURL>(), type_);
+ callback_.Run(std::set<GURL>(), type_);
}
private:
StorageType type_;
base::Time modified_since_;
std::set<GURL> origins_;
- scoped_ptr<GetOriginsCallback> callback_;
+ GetOriginsCallback callback_;
};
class QuotaManager::DumpQuotaTableTask
@@ -934,7 +934,7 @@ class QuotaManager::DumpQuotaTableTask
public:
DumpQuotaTableTask(
QuotaManager* manager,
- Callback* callback)
+ const Callback& callback)
: DatabaseTaskBase(manager),
callback_(callback) {
}
@@ -947,11 +947,11 @@ class QuotaManager::DumpQuotaTableTask
}
virtual void Aborted() OVERRIDE {
- callback_->Run(TableEntries());
+ callback_.Run(TableEntries());
}
virtual void DatabaseTaskCompleted() OVERRIDE {
- callback_->Run(entries_);
+ callback_.Run(entries_);
}
private:
@@ -960,7 +960,7 @@ class QuotaManager::DumpQuotaTableTask
return true;
}
- scoped_ptr<Callback> callback_;
+ Callback callback_;
TableEntries entries_;
};
@@ -976,7 +976,7 @@ class QuotaManager::DumpOriginInfoTableTask
public:
DumpOriginInfoTableTask(
QuotaManager* manager,
- Callback* callback)
+ const Callback& callback)
: DatabaseTaskBase(manager),
callback_(callback) {
}
@@ -989,11 +989,11 @@ class QuotaManager::DumpOriginInfoTableTask
}
virtual void Aborted() OVERRIDE {
- callback_->Run(TableEntries());
+ callback_.Run(TableEntries());
}
virtual void DatabaseTaskCompleted() OVERRIDE {
- callback_->Run(entries_);
+ callback_.Run(entries_);
}
private:
@@ -1002,7 +1002,7 @@ class QuotaManager::DumpOriginInfoTableTask
return true;
}
- scoped_ptr<Callback> callback_;
+ Callback callback_;
TableEntries entries_;
};
@@ -1025,8 +1025,7 @@ QuotaManager::QuotaManager(bool is_incognito,
temporary_quota_override_(-1),
desired_available_space_(-1),
special_storage_policy_(special_storage_policy),
- ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)),
- ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
+ weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
}
QuotaManager::~QuotaManager() {
@@ -1038,7 +1037,7 @@ QuotaManager::~QuotaManager() {
db_thread_->DeleteSoon(FROM_HERE, database_.release());
}
-void QuotaManager::GetUsageInfo(GetUsageInfoCallback* callback) {
+void QuotaManager::GetUsageInfo(const GetUsageInfoCallback& callback) {
LazyInitialize();
GetUsageInfoTask* get_usage_info = new GetUsageInfoTask(this, callback);
get_usage_info->Start();
@@ -1046,26 +1045,24 @@ void QuotaManager::GetUsageInfo(GetUsageInfoCallback* callback) {
void QuotaManager::GetUsageAndQuota(
const GURL& origin, StorageType type,
- GetUsageAndQuotaCallback* callback) {
+ const GetUsageAndQuotaCallback& callback) {
GetUsageAndQuotaInternal(origin, type, false /* global */,
base::Bind(&CallGetUsageAndQuotaCallback,
callback, IsStorageUnlimited(origin)));
}
-void QuotaManager::GetAvailableSpace(AvailableSpaceCallback* callback) {
+void QuotaManager::GetAvailableSpace(const AvailableSpaceCallback& callback) {
if (is_incognito_) {
- callback->Run(kQuotaStatusOk, kIncognitoDefaultTemporaryQuota);
- delete callback;
+ callback.Run(kQuotaStatusOk, kIncognitoDefaultTemporaryQuota);
return;
}
make_scoped_refptr(new AvailableSpaceQueryTask(this, callback))->Start();
}
-void QuotaManager::GetTemporaryGlobalQuota(QuotaCallback* callback) {
+void QuotaManager::GetTemporaryGlobalQuota(const QuotaCallback& callback) {
if (temporary_quota_override_ > 0) {
- callback->Run(kQuotaStatusOk, kStorageTypeTemporary,
- temporary_quota_override_);
- delete callback;
+ callback.Run(kQuotaStatusOk, kStorageTypeTemporary,
+ temporary_quota_override_);
return;
}
GetUsageAndQuotaInternal(
@@ -1074,80 +1071,77 @@ void QuotaManager::GetTemporaryGlobalQuota(QuotaCallback* callback) {
}
void QuotaManager::SetTemporaryGlobalOverrideQuota(
- int64 new_quota, QuotaCallback* callback_ptr) {
- scoped_ptr<QuotaCallback> callback(callback_ptr);
+ int64 new_quota, const QuotaCallback& callback) {
LazyInitialize();
if (new_quota < 0) {
- if (callback.get())
- callback->Run(kQuotaErrorInvalidModification,
- kStorageTypeTemporary, -1);
+ if (!callback.is_null())
+ callback.Run(kQuotaErrorInvalidModification,
+ kStorageTypeTemporary, -1);
return;
}
if (db_disabled_) {
- if (callback.get())
- callback->Run(kQuotaErrorInvalidAccess,
- kStorageTypeTemporary, -1);
+ if (callback.is_null())
+ callback.Run(kQuotaErrorInvalidAccess,
+ kStorageTypeTemporary, -1);
return;
}
make_scoped_refptr(new UpdateTemporaryQuotaOverrideTask(
- this, new_quota, callback.release()))->Start();
+ this, new_quota, callback))->Start();
}
void QuotaManager::GetPersistentHostQuota(const std::string& host,
- HostQuotaCallback* callback_ptr) {
- scoped_ptr<HostQuotaCallback> callback(callback_ptr);
+ const HostQuotaCallback& callback) {
LazyInitialize();
if (host.empty()) {
// This could happen if we are called on file:///.
// TODO(kinuko) We may want to respect --allow-file-access-from-files
// command line switch.
- callback->Run(kQuotaStatusOk, host, kStorageTypePersistent, 0);
+ callback.Run(kQuotaStatusOk, host, kStorageTypePersistent, 0);
return;
}
scoped_refptr<GetPersistentHostQuotaTask> task(
- new GetPersistentHostQuotaTask(this, host, callback.release()));
+ new GetPersistentHostQuotaTask(this, host, callback));
task->Start();
}
void QuotaManager::SetPersistentHostQuota(const std::string& host,
int64 new_quota,
- HostQuotaCallback* callback_ptr) {
- scoped_ptr<HostQuotaCallback> callback(callback_ptr);
+ const HostQuotaCallback& callback) {
LazyInitialize();
if (host.empty()) {
// This could happen if we are called on file:///.
- callback->Run(kQuotaErrorNotSupported, host, kStorageTypePersistent, 0);
+ callback.Run(kQuotaErrorNotSupported, host, kStorageTypePersistent, 0);
return;
}
if (new_quota < 0) {
- callback->Run(kQuotaErrorInvalidModification,
- host, kStorageTypePersistent, -1);
+ callback.Run(kQuotaErrorInvalidModification,
+ host, kStorageTypePersistent, -1);
return;
}
if (!db_disabled_) {
scoped_refptr<UpdatePersistentHostQuotaTask> task(
new UpdatePersistentHostQuotaTask(
- this, host, new_quota, callback.release()));
+ this, host, new_quota, callback));
task->Start();
} else {
- callback->Run(kQuotaErrorInvalidAccess,
+ callback.Run(kQuotaErrorInvalidAccess,
host, kStorageTypePersistent, -1);
}
}
-void QuotaManager::GetGlobalUsage(
- StorageType type,
- GlobalUsageCallback* callback) {
+void QuotaManager::GetGlobalUsage(StorageType type,
+ const GlobalUsageCallback& callback) {
LazyInitialize();
GetUsageTracker(type)->GetGlobalUsage(callback);
}
-void QuotaManager::GetHostUsage(const std::string& host, StorageType type,
- HostUsageCallback* callback) {
+void QuotaManager::GetHostUsage(const std::string& host,
+ StorageType type,
+ const HostUsageCallback& callback) {
LazyInitialize();
GetUsageTracker(type)->GetHostUsage(host, callback);
}
@@ -1165,10 +1159,9 @@ void QuotaManager::GetStatistics(
}
}
-void QuotaManager::GetOriginsModifiedSince(
- StorageType type,
- base::Time modified_since,
- GetOriginsCallback* callback) {
+void QuotaManager::GetOriginsModifiedSince(StorageType type,
+ base::Time modified_since,
+ const GetOriginsCallback& callback) {
LazyInitialize();
make_scoped_refptr(new GetModifiedSinceTask(
this, type, modified_since, callback))->Start();
@@ -1228,12 +1221,11 @@ void QuotaManager::NotifyOriginNoLongerInUse(const GURL& origin) {
}
void QuotaManager::DeleteOriginData(
- const GURL& origin, StorageType type, StatusCallback* callback) {
+ const GURL& origin, StorageType type, const StatusCallback& callback) {
LazyInitialize();
if (origin.is_empty() || clients_.empty()) {
- callback->Run(kQuotaStatusOk);
- delete callback;
+ callback.Run(kQuotaStatusOk);
return;
}
@@ -1363,12 +1355,12 @@ void QuotaManager::GetUsageAndQuotaInternal(
}
}
-void QuotaManager::DumpQuotaTable(DumpQuotaTableCallback* callback) {
+void QuotaManager::DumpQuotaTable(const DumpQuotaTableCallback& callback) {
make_scoped_refptr(new DumpQuotaTableTask(this, callback))->Start();
}
void QuotaManager::DumpOriginInfoTable(
- DumpOriginInfoTableCallback* callback) {
+ const DumpOriginInfoTableCallback& callback) {
make_scoped_refptr(new DumpOriginInfoTableTask(this, callback))->Start();
}
@@ -1402,8 +1394,7 @@ void QuotaManager::GetLRUOrigin(
task->Start();
}
-void QuotaManager::DidOriginDataEvicted(
- QuotaStatusCode status) {
+void QuotaManager::DidOriginDataEvicted(QuotaStatusCode status) {
DCHECK(io_thread_->BelongsToCurrentThread());
// We only try evict origins that are not in use, so basically
@@ -1413,23 +1404,24 @@ void QuotaManager::DidOriginDataEvicted(
if (status != kQuotaStatusOk)
origins_in_error_[eviction_context_.evicted_origin]++;
- eviction_context_.evict_origin_data_callback->Run(status);
- eviction_context_.evict_origin_data_callback.reset();
+ eviction_context_.evict_origin_data_callback.Run(status);
+ eviction_context_.evict_origin_data_callback.Reset();
}
void QuotaManager::EvictOriginData(
const GURL& origin,
StorageType type,
- EvictOriginDataCallback* callback) {
+ const EvictOriginDataCallback& callback) {
DCHECK(io_thread_->BelongsToCurrentThread());
DCHECK_EQ(type, kStorageTypeTemporary);
eviction_context_.evicted_origin = origin;
eviction_context_.evicted_type = type;
- eviction_context_.evict_origin_data_callback.reset(callback);
+ eviction_context_.evict_origin_data_callback = callback;
- DeleteOriginData(origin, type, callback_factory_.NewCallback(
- &QuotaManager::DidOriginDataEvicted));
+ DeleteOriginData(origin, type,
+ base::Bind(&QuotaManager::DidOriginDataEvicted,
+ weak_factory_.GetWeakPtr()));
}
void QuotaManager::GetUsageAndQuotaForEviction(
@@ -1451,11 +1443,13 @@ void QuotaManager::StartEviction() {
void QuotaManager::ReportHistogram() {
GetGlobalUsage(kStorageTypeTemporary,
- callback_factory_.NewCallback(
- &QuotaManager::DidGetTemporaryGlobalUsageForHistogram));
+ base::Bind(
+ &QuotaManager::DidGetTemporaryGlobalUsageForHistogram,
+ weak_factory_.GetWeakPtr()));
GetGlobalUsage(kStorageTypePersistent,
- callback_factory_.NewCallback(
- &QuotaManager::DidGetPersistentGlobalUsageForHistogram));
+ base::Bind(
+ &QuotaManager::DidGetPersistentGlobalUsageForHistogram,
+ weak_factory_.GetWeakPtr()));
}
void QuotaManager::DidGetTemporaryGlobalUsageForHistogram(
@@ -1523,8 +1517,9 @@ void QuotaManager::DidRunInitializeTask() {
// Kick the first GetTemporaryGlobalQuota. This internally fetches (and
// caches) the usage of all origins and checks the available disk space.
- GetTemporaryGlobalQuota(callback_factory_.NewCallback(
- &QuotaManager::DidGetInitialTemporaryGlobalQuota));
+ GetTemporaryGlobalQuota(
+ base::Bind(&QuotaManager::DidGetInitialTemporaryGlobalQuota,
+ weak_factory_.GetWeakPtr()));
}
void QuotaManager::DidGetInitialTemporaryGlobalQuota(
diff --git a/webkit/quota/quota_manager.h b/webkit/quota/quota_manager.h
index 033b4b0..77490b5 100644
--- a/webkit/quota/quota_manager.h
+++ b/webkit/quota/quota_manager.h
@@ -11,13 +11,14 @@
#include <map>
#include <set>
#include <string>
+#include <utility>
#include <vector>
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/file_path.h"
#include "base/memory/ref_counted.h"
-#include "base/memory/scoped_callback_factory.h"
+#include "base/memory/weak_ptr.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "webkit/quota/quota_database.h"
@@ -73,7 +74,7 @@ class QuotaEvictionHandler {
virtual void EvictOriginData(
const GURL& origin,
StorageType type,
- EvictOriginDataCallback* callback) = 0;
+ const EvictOriginDataCallback& callback) = 0;
virtual void GetUsageAndQuotaForEviction(
const GetUsageAndQuotaForEvictionCallback& callback) = 0;
@@ -97,9 +98,10 @@ class QuotaManager : public QuotaTaskObserver,
public base::RefCountedThreadSafe<
QuotaManager, QuotaManagerDeleter> {
public:
- typedef Callback3<QuotaStatusCode,
- int64 /* usage */,
- int64 /* quota */>::Type GetUsageAndQuotaCallback;
+ typedef base::Callback<void(QuotaStatusCode,
+ int64 /* usage */,
+ int64 /* quota */)>
+ GetUsageAndQuotaCallback;
QuotaManager(bool is_incognito,
const FilePath& profile_path,
@@ -113,14 +115,14 @@ class QuotaManager : public QuotaTaskObserver,
QuotaManagerProxy* proxy() { return proxy_.get(); }
// Called by clients or webapps. Returns usage per host.
- void GetUsageInfo(GetUsageInfoCallback* callback);
+ void GetUsageInfo(const GetUsageInfoCallback& callback);
// Called by clients or webapps.
// This method is declared as virtual to allow test code to override it.
// note: returns host usage and quota
virtual void GetUsageAndQuota(const GURL& origin,
StorageType type,
- GetUsageAndQuotaCallback* callback);
+ const GetUsageAndQuotaCallback& callback);
// Called by clients via proxy.
// Client storage should call this method when storage is accessed.
@@ -149,24 +151,24 @@ class QuotaManager : public QuotaTaskObserver,
// Called by UI.
virtual void DeleteOriginData(const GURL& origin,
StorageType type,
- StatusCallback* callback);
+ const StatusCallback& callback);
// Called by UI and internal modules.
- void GetAvailableSpace(AvailableSpaceCallback* callback);
- void GetTemporaryGlobalQuota(QuotaCallback* callback);
+ void GetAvailableSpace(const AvailableSpaceCallback& callback);
+ void GetTemporaryGlobalQuota(const QuotaCallback& callback);
// Ok to call with NULL callback.
void SetTemporaryGlobalOverrideQuota(int64 new_quota,
- QuotaCallback* callback);
+ const QuotaCallback& callback);
void GetPersistentHostQuota(const std::string& host,
- HostQuotaCallback* callback);
+ const HostQuotaCallback& callback);
void SetPersistentHostQuota(const std::string& host,
int64 new_quota,
- HostQuotaCallback* callback);
- void GetGlobalUsage(StorageType type, GlobalUsageCallback* callback);
+ const HostQuotaCallback& callback);
+ void GetGlobalUsage(StorageType type, const GlobalUsageCallback& callback);
void GetHostUsage(const std::string& host, StorageType type,
- HostUsageCallback* callback);
+ const HostUsageCallback& callback);
void GetStatistics(std::map<std::string, std::string>* statistics);
@@ -177,7 +179,7 @@ class QuotaManager : public QuotaTaskObserver,
virtual void GetOriginsModifiedSince(StorageType type,
base::Time modified_since,
- GetOriginsCallback* callback);
+ const GetOriginsCallback& callback);
bool ResetUsageTracker(StorageType type);
@@ -221,8 +223,9 @@ class QuotaManager : public QuotaTaskObserver,
typedef std::vector<QuotaTableEntry> QuotaTableEntries;
typedef std::vector<OriginInfoTableEntry> OriginInfoTableEntries;
- typedef Callback1<const QuotaTableEntries&>::Type DumpQuotaTableCallback;
- typedef Callback1<const OriginInfoTableEntries&>::Type
+ typedef base::Callback<void(const QuotaTableEntries&)>
+ DumpQuotaTableCallback;
+ typedef base::Callback<void(const OriginInfoTableEntries&)>
DumpOriginInfoTableCallback;
struct EvictionContext {
@@ -230,7 +233,8 @@ class QuotaManager : public QuotaTaskObserver,
virtual ~EvictionContext() {}
GURL evicted_origin;
StorageType evicted_type;
- scoped_ptr<EvictOriginDataCallback> evict_origin_data_callback;
+
+ EvictOriginDataCallback evict_origin_data_callback;
};
typedef std::pair<std::string, StorageType> HostAndType;
@@ -285,8 +289,8 @@ class QuotaManager : public QuotaTaskObserver,
bool global,
const UsageAndQuotaDispatcherCallback& callback);
- void DumpQuotaTable(DumpQuotaTableCallback* callback);
- void DumpOriginInfoTable(DumpOriginInfoTableCallback* callback);
+ void DumpQuotaTable(const DumpQuotaTableCallback& callback);
+ void DumpOriginInfoTable(const DumpOriginInfoTableCallback& callback);
// Methods for eviction logic.
void StartEviction();
@@ -315,7 +319,7 @@ class QuotaManager : public QuotaTaskObserver,
virtual void EvictOriginData(
const GURL& origin,
StorageType type,
- EvictOriginDataCallback* callback) OVERRIDE;
+ const EvictOriginDataCallback& callback) OVERRIDE;
virtual void GetUsageAndQuotaForEviction(
const GetUsageAndQuotaForEvictionCallback& callback) OVERRIDE;
@@ -364,7 +368,6 @@ class QuotaManager : public QuotaTaskObserver,
scoped_refptr<SpecialStoragePolicy> special_storage_policy_;
- base::ScopedCallbackFactory<QuotaManager> callback_factory_;
base::WeakPtrFactory<QuotaManager> weak_factory_;
base::RepeatingTimer<QuotaManager> histogram_timer_;
diff --git a/webkit/quota/quota_manager_unittest.cc b/webkit/quota/quota_manager_unittest.cc
index 949a4d8..cd4cf73 100644
--- a/webkit/quota/quota_manager_unittest.cc
+++ b/webkit/quota/quota_manager_unittest.cc
@@ -8,7 +8,6 @@
#include "base/bind.h"
#include "base/file_util.h"
-#include "base/memory/scoped_callback_factory.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
@@ -40,8 +39,7 @@ class QuotaManagerTest : public testing::Test {
public:
QuotaManagerTest()
- : callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
- weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
+ : weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
mock_time_counter_(0) {
}
@@ -78,25 +76,27 @@ class QuotaManagerTest : public testing::Test {
void GetUsageInfo() {
usage_info_.clear();
- quota_manager_->GetUsageInfo(callback_factory_.NewCallback(
- &QuotaManagerTest::DidGetUsageInfo));
+ quota_manager_->GetUsageInfo(
+ base::Bind(&QuotaManagerTest::DidGetUsageInfo,
+ weak_factory_.GetWeakPtr()));
}
void GetUsageAndQuota(const GURL& origin, StorageType type) {
quota_status_ = kQuotaStatusUnknown;
usage_ = -1;
quota_ = -1;
- quota_manager_->GetUsageAndQuota(origin, type,
- callback_factory_.NewCallback(
- &QuotaManagerTest::DidGetUsageAndQuota));
+ quota_manager_->GetUsageAndQuota(
+ origin, type,
+ base::Bind(&QuotaManagerTest::DidGetUsageAndQuota,
+ weak_factory_.GetWeakPtr()));
}
void GetTemporaryGlobalQuota() {
quota_status_ = kQuotaStatusUnknown;
quota_ = -1;
quota_manager_->GetTemporaryGlobalQuota(
- callback_factory_.NewCallback(
- &QuotaManagerTest::DidGetQuota));
+ base::Bind(&QuotaManagerTest::DidGetQuota,
+ weak_factory_.GetWeakPtr()));
}
void SetTemporaryGlobalQuota(int64 new_quota) {
@@ -104,8 +104,8 @@ class QuotaManagerTest : public testing::Test {
quota_ = -1;
quota_manager_->SetTemporaryGlobalOverrideQuota(
new_quota,
- callback_factory_.NewCallback(
- &QuotaManagerTest::DidGetQuota));
+ base::Bind(&QuotaManagerTest::DidGetQuota,
+ weak_factory_.GetWeakPtr()));
}
void GetPersistentHostQuota(const std::string& host) {
@@ -113,9 +113,10 @@ class QuotaManagerTest : public testing::Test {
host_.clear();
type_ = kStorageTypeUnknown;
quota_ = -1;
- quota_manager_->GetPersistentHostQuota(host,
- callback_factory_.NewCallback(
- &QuotaManagerTest::DidGetHostQuota));
+ quota_manager_->GetPersistentHostQuota(
+ host,
+ base::Bind(&QuotaManagerTest::DidGetHostQuota,
+ weak_factory_.GetWeakPtr()));
}
void SetPersistentHostQuota(const std::string& host, int64 new_quota) {
@@ -123,33 +124,37 @@ class QuotaManagerTest : public testing::Test {
host_.clear();
type_ = kStorageTypeUnknown;
quota_ = -1;
- quota_manager_->SetPersistentHostQuota(host, new_quota,
- callback_factory_.NewCallback(
- &QuotaManagerTest::DidGetHostQuota));
+ quota_manager_->SetPersistentHostQuota(
+ host, new_quota,
+ base::Bind(&QuotaManagerTest::DidGetHostQuota,
+ weak_factory_.GetWeakPtr()));
}
void GetGlobalUsage(StorageType type) {
type_ = kStorageTypeUnknown;
usage_ = -1;
unlimited_usage_ = -1;
- quota_manager_->GetGlobalUsage(type,
- callback_factory_.NewCallback(
- &QuotaManagerTest::DidGetGlobalUsage));
+ quota_manager_->GetGlobalUsage(
+ type,
+ base::Bind(&QuotaManagerTest::DidGetGlobalUsage,
+ weak_factory_.GetWeakPtr()));
}
void GetHostUsage(const std::string& host, StorageType type) {
host_.clear();
type_ = kStorageTypeUnknown;
usage_ = -1;
- quota_manager_->GetHostUsage(host, type,
- callback_factory_.NewCallback(
- &QuotaManagerTest::DidGetHostUsage));
+ quota_manager_->GetHostUsage(
+ host, type,
+ base::Bind(&QuotaManagerTest::DidGetHostUsage,
+ weak_factory_.GetWeakPtr()));
}
void RunAdditionalUsageAndQuotaTask(const GURL& origin, StorageType type) {
- quota_manager_->GetUsageAndQuota(origin, type,
- callback_factory_.NewCallback(
- &QuotaManagerTest::DidGetUsageAndQuotaAdditional));
+ quota_manager_->GetUsageAndQuota(
+ origin, type,
+ base::Bind(&QuotaManagerTest::DidGetUsageAndQuotaAdditional,
+ weak_factory_.GetWeakPtr()));
}
void DeleteClientOriginData(QuotaClient* client,
@@ -157,33 +162,36 @@ class QuotaManagerTest : public testing::Test {
StorageType type) {
DCHECK(client);
quota_status_ = kQuotaStatusUnknown;
- client->DeleteOriginData(origin, type,
- callback_factory_.NewCallback(
- &QuotaManagerTest::StatusCallback));
+ client->DeleteOriginData(
+ origin, type,
+ base::Bind(&QuotaManagerTest::StatusCallback,
+ weak_factory_.GetWeakPtr()));
}
void EvictOriginData(const GURL& origin,
StorageType type) {
quota_status_ = kQuotaStatusUnknown;
- quota_manager_->EvictOriginData(origin, type,
- callback_factory_.NewCallback(
- &QuotaManagerTest::StatusCallback));
+ quota_manager_->EvictOriginData(
+ origin, type,
+ base::Bind(&QuotaManagerTest::StatusCallback,
+ weak_factory_.GetWeakPtr()));
}
void DeleteOriginData(const GURL& origin,
StorageType type) {
quota_status_ = kQuotaStatusUnknown;
- quota_manager_->DeleteOriginData(origin, type,
- callback_factory_.NewCallback(
- &QuotaManagerTest::StatusCallback));
+ quota_manager_->DeleteOriginData(
+ origin, type,
+ base::Bind(&QuotaManagerTest::StatusCallback,
+ weak_factory_.GetWeakPtr()));
}
void GetAvailableSpace() {
quota_status_ = kQuotaStatusUnknown;
available_space_ = -1;
quota_manager_->GetAvailableSpace(
- callback_factory_.NewCallback(
- &QuotaManagerTest::DidGetAvailableSpace));
+ base::Bind(&QuotaManagerTest::DidGetAvailableSpace,
+ weak_factory_.GetWeakPtr()));
}
void GetUsageAndQuotaForEviction() {
@@ -234,23 +242,24 @@ class QuotaManagerTest : public testing::Test {
void GetOriginsModifiedSince(StorageType type, base::Time modified_since) {
modified_origins_.clear();
modified_origins_type_ = kStorageTypeUnknown;
- quota_manager_->GetOriginsModifiedSince(type, modified_since,
- callback_factory_.NewCallback(
- &QuotaManagerTest::DidGetModifiedOrigins));
+ quota_manager_->GetOriginsModifiedSince(
+ type, modified_since,
+ base::Bind(&QuotaManagerTest::DidGetModifiedOrigins,
+ weak_factory_.GetWeakPtr()));
}
void DumpQuotaTable() {
quota_entries_.clear();
quota_manager_->DumpQuotaTable(
- callback_factory_.NewCallback(
- &QuotaManagerTest::DidDumpQuotaTable));
+ base::Bind(&QuotaManagerTest::DidDumpQuotaTable,
+ weak_factory_.GetWeakPtr()));
}
void DumpOriginInfoTable() {
origin_info_entries_.clear();
quota_manager_->DumpOriginInfoTable(
- callback_factory_.NewCallback(
- &QuotaManagerTest::DidDumpOriginInfoTable));
+ base::Bind(&QuotaManagerTest::DidDumpOriginInfoTable,
+ weak_factory_.GetWeakPtr()));
}
void DidGetUsageInfo(const UsageInfoEntries& entries) {
@@ -376,7 +385,6 @@ class QuotaManagerTest : public testing::Test {
}
ScopedTempDir data_dir_;
- base::ScopedCallbackFactory<QuotaManagerTest> callback_factory_;
base::WeakPtrFactory<QuotaManagerTest> weak_factory_;
scoped_refptr<QuotaManager> quota_manager_;
diff --git a/webkit/quota/quota_temporary_storage_evictor.cc b/webkit/quota/quota_temporary_storage_evictor.cc
index 0e919f6..30bac6d 100644
--- a/webkit/quota/quota_temporary_storage_evictor.cc
+++ b/webkit/quota/quota_temporary_storage_evictor.cc
@@ -4,6 +4,8 @@
#include "webkit/quota/quota_temporary_storage_evictor.h"
+#include <algorithm>
+
#include "base/bind.h"
#include "base/metrics/histogram.h"
#include "googleurl/src/gurl.h"
@@ -41,7 +43,6 @@ QuotaTemporaryStorageEvictor::QuotaTemporaryStorageEvictor(
quota_eviction_handler_(quota_eviction_handler),
interval_ms_(interval_ms),
repeated_eviction_(true),
- callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
DCHECK(quota_eviction_handler);
}
@@ -218,8 +219,9 @@ void QuotaTemporaryStorageEvictor::OnGotLRUOrigin(const GURL& origin) {
}
quota_eviction_handler_->EvictOriginData(origin, kStorageTypeTemporary,
- callback_factory_.NewCallback(
- &QuotaTemporaryStorageEvictor::OnEvictionComplete));
+ base::Bind(
+ &QuotaTemporaryStorageEvictor::OnEvictionComplete,
+ weak_factory_.GetWeakPtr()));
}
void QuotaTemporaryStorageEvictor::OnEvictionComplete(
diff --git a/webkit/quota/quota_temporary_storage_evictor.h b/webkit/quota/quota_temporary_storage_evictor.h
index a537171..a26924a 100644
--- a/webkit/quota/quota_temporary_storage_evictor.h
+++ b/webkit/quota/quota_temporary_storage_evictor.h
@@ -9,7 +9,6 @@
#include <map>
#include <string>
-#include "base/memory/scoped_callback_factory.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/non_thread_safe.h"
#include "base/timer.h"
@@ -132,8 +131,6 @@ class QuotaTemporaryStorageEvictor : public base::NonThreadSafe {
base::OneShotTimer<QuotaTemporaryStorageEvictor> eviction_timer_;
base::RepeatingTimer<QuotaTemporaryStorageEvictor> histogram_timer_;
-
- base::ScopedCallbackFactory<QuotaTemporaryStorageEvictor> callback_factory_;
base::WeakPtrFactory<QuotaTemporaryStorageEvictor> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(QuotaTemporaryStorageEvictor);
diff --git a/webkit/quota/quota_temporary_storage_evictor_unittest.cc b/webkit/quota/quota_temporary_storage_evictor_unittest.cc
index 361d4a0..fa4f0b2 100644
--- a/webkit/quota/quota_temporary_storage_evictor_unittest.cc
+++ b/webkit/quota/quota_temporary_storage_evictor_unittest.cc
@@ -2,16 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "testing/gtest/include/gtest/gtest.h"
-
#include <list>
#include <map>
+#include <utility>
#include "base/bind.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "base/message_loop_proxy.h"
#include "base/task.h"
+#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/quota/mock_storage_client.h"
#include "webkit/quota/quota_manager.h"
#include "webkit/quota/quota_temporary_storage_evictor.h"
@@ -24,7 +24,7 @@ namespace {
class MockQuotaEvictionHandler : public quota::QuotaEvictionHandler {
public:
- MockQuotaEvictionHandler(QuotaTemporaryStorageEvictorTest *test)
+ explicit MockQuotaEvictionHandler(QuotaTemporaryStorageEvictorTest *test)
: quota_(0),
unlimited_usage_(0),
available_space_(0),
@@ -35,17 +35,15 @@ class MockQuotaEvictionHandler : public quota::QuotaEvictionHandler {
virtual void EvictOriginData(
const GURL& origin,
StorageType type,
- EvictOriginDataCallback* callback) OVERRIDE {
+ const EvictOriginDataCallback& callback) OVERRIDE {
if (error_on_evict_origin_data_) {
- callback->Run(quota::kQuotaErrorInvalidModification);
- delete callback;
+ callback.Run(quota::kQuotaErrorInvalidModification);
return;
}
int64 origin_usage = EnsureOriginRemoved(origin);
if (origin_usage >= 0)
available_space_ += origin_usage;
- callback->Run(quota::kQuotaStatusOk);
- delete callback;
+ callback.Run(quota::kQuotaStatusOk);
}
virtual void GetUsageAndQuotaForEviction(
diff --git a/webkit/quota/quota_types.h b/webkit/quota/quota_types.h
index a07c14c..b14be0c 100644
--- a/webkit/quota/quota_types.h
+++ b/webkit/quota/quota_types.h
@@ -10,10 +10,10 @@
#include <map>
#include <set>
#include <string>
+#include <vector>
#include "base/basictypes.h"
-#include "base/callback_old.h"
-#include "base/stl_util.h"
+#include "base/callback.h"
class GURL;
@@ -40,23 +40,21 @@ struct UsageInfo;
typedef std::vector<UsageInfo> UsageInfoEntries;
// Common callback types that are used throughout in the quota module.
-typedef Callback2<StorageType, int64>::Type UsageCallback;
-typedef Callback3<StorageType, int64, int64>::Type GlobalUsageCallback;
-typedef Callback3<QuotaStatusCode,
- StorageType,
- int64>::Type QuotaCallback;
-typedef Callback3<const std::string& /* host */,
- StorageType,
- int64>::Type HostUsageCallback;
-typedef Callback4<QuotaStatusCode,
- const std::string& /* host */,
- StorageType,
- int64>::Type HostQuotaCallback;
-typedef Callback2<QuotaStatusCode,
- int64>::Type AvailableSpaceCallback;
-typedef Callback1<QuotaStatusCode>::Type StatusCallback;
-typedef Callback2<const std::set<GURL>&, StorageType>::Type GetOriginsCallback;
-typedef Callback1<const UsageInfoEntries&>::Type GetUsageInfoCallback;
+typedef base::Callback<void(StorageType, int64)> UsageCallback;
+typedef base::Callback<void(StorageType, int64, int64)> GlobalUsageCallback;
+typedef base::Callback<void(QuotaStatusCode, StorageType, int64)>
+ QuotaCallback;
+typedef base::Callback<void(const std::string&, StorageType, int64)>
+ HostUsageCallback;
+typedef base::Callback<void(QuotaStatusCode,
+ const std::string&,
+ StorageType,
+ int64)> HostQuotaCallback;
+typedef base::Callback<void(QuotaStatusCode, int64)> AvailableSpaceCallback;
+typedef base::Callback<void(QuotaStatusCode)> StatusCallback;
+typedef base::Callback<void(const std::set<GURL>&, StorageType)>
+ GetOriginsCallback;
+typedef base::Callback<void(const UsageInfoEntries&)> GetUsageInfoCallback;
// Simple template wrapper for a callback queue.
template <typename CallbackType>
@@ -65,12 +63,10 @@ class CallbackQueueBase {
typedef typename std::deque<CallbackType> Queue;
typedef typename Queue::iterator iterator;
- virtual ~CallbackQueueBase() {
- STLDeleteContainerPointers(callbacks_.begin(), callbacks_.end());
- }
+ virtual ~CallbackQueueBase() {}
// Returns true if the given |callback| is the first one added to the queue.
- bool Add(CallbackType callback) {
+ bool Add(const CallbackType& callback) {
callbacks_.push_back(callback);
return (callbacks_.size() == 1);
}
@@ -92,8 +88,7 @@ class CallbackQueue1 : public CallbackQueueBase<CallbackType1> {
// Note: template-derived class needs 'this->' to access its base class.
for (typename Queue::iterator iter = this->callbacks_.begin();
iter != this->callbacks_.end(); ++iter) {
- (*iter)->Run(arg);
- delete *iter;
+ iter->Run(arg);
}
this->callbacks_.clear();
}
@@ -107,8 +102,7 @@ class CallbackQueue2 : public CallbackQueueBase<CallbackType2> {
void Run(A1 arg1, A2 arg2) {
for (typename Queue::iterator iter = this->callbacks_.begin();
iter != this->callbacks_.end(); ++iter) {
- (*iter)->Run(arg1, arg2);
- delete *iter;
+ iter->Run(arg1, arg2);
}
this->callbacks_.clear();
}
@@ -122,8 +116,7 @@ class CallbackQueue3 : public CallbackQueueBase<CallbackType3> {
void Run(A1 arg1, A2 arg2, A3 arg3) {
for (typename Queue::iterator iter = this->callbacks_.begin();
iter != this->callbacks_.end(); ++iter) {
- (*iter)->Run(arg1, arg2, arg3);
- delete *iter;
+ iter->Run(arg1, arg2, arg3);
}
this->callbacks_.clear();
}
@@ -138,18 +131,17 @@ class CallbackQueue4 : public CallbackQueueBase<CallbackType4> {
void Run(A1 arg1, A2 arg2, A3 arg3, A4 arg4) {
for (typename Queue::iterator iter = this->callbacks_.begin();
iter != this->callbacks_.end(); ++iter) {
- (*iter)->Run(arg1, arg2, arg3, arg4);
- delete *iter;
+ iter->Run(arg1, arg2, arg3, arg4);
}
this->callbacks_.clear();
}
};
-typedef CallbackQueue2<UsageCallback*,
+typedef CallbackQueue2<UsageCallback,
StorageType, int64> UsageCallbackQueue;
-typedef CallbackQueue3<GlobalUsageCallback*,
+typedef CallbackQueue3<GlobalUsageCallback,
StorageType, int64, int64> GlobalUsageCallbackQueue;
-typedef CallbackQueue3<QuotaCallback*,
+typedef CallbackQueue3<QuotaCallback,
QuotaStatusCode,
StorageType, int64> QuotaCallbackQueue;
@@ -159,7 +151,7 @@ class CallbackQueueMapBase {
typedef std::map<KEY, CallbackQueueType> CallbackMap;
typedef typename CallbackMap::iterator iterator;
- bool Add(const KEY& key, CallbackType callback) {
+ bool Add(const KEY& key, const CallbackType& callback) {
return callback_map_[key].Add(callback);
}
@@ -276,11 +268,11 @@ class CallbackQueueMap4
}
};
-typedef CallbackQueueMap1<UsageCallback*, GURL, int64> OriginUsageCallbackMap;
-typedef CallbackQueueMap3<HostUsageCallback*, std::string,
+typedef CallbackQueueMap1<UsageCallback, GURL, int64> OriginUsageCallbackMap;
+typedef CallbackQueueMap3<HostUsageCallback, std::string,
const std::string&,
StorageType, int64> HostUsageCallbackMap;
-typedef CallbackQueueMap4<HostQuotaCallback*, std::string,
+typedef CallbackQueueMap4<HostQuotaCallback, std::string,
QuotaStatusCode,
const std::string&,
StorageType, int64> HostQuotaCallbackMap;
diff --git a/webkit/quota/usage_tracker.cc b/webkit/quota/usage_tracker.cc
index 53a733b..0eb2411 100644
--- a/webkit/quota/usage_tracker.cc
+++ b/webkit/quota/usage_tracker.cc
@@ -8,7 +8,9 @@
#include <deque>
#include <set>
#include <string>
+#include <vector>
+#include "base/bind.h"
#include "base/message_loop_proxy.h"
#include "base/stl_util.h"
#include "net/base/net_util.h"
@@ -31,7 +33,7 @@ class ClientUsageTracker::GatherUsageTaskBase : public QuotaTask {
: QuotaTask(tracker),
client_(client),
tracker_(tracker),
- callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
DCHECK(tracker_);
DCHECK(client_);
client_tracker_ = tracker_->GetClientTracker(client_->id());
@@ -75,7 +77,8 @@ class ClientUsageTracker::GatherUsageTaskBase : public QuotaTask {
client_->GetOriginUsage(
*iter,
tracker_->type(),
- callback_factory_.NewCallback(&GatherUsageTaskBase::DidGetUsage));
+ base::Bind(&GatherUsageTaskBase::DidGetUsage,
+ weak_factory_.GetWeakPtr()));
}
protected:
@@ -121,7 +124,7 @@ class ClientUsageTracker::GatherUsageTaskBase : public QuotaTask {
ClientUsageTracker* client_tracker_;
std::deque<GURL> pending_origins_;
std::map<GURL, int64> origin_usage_map_;
- base::ScopedCallbackFactory<GatherUsageTaskBase> callback_factory_;
+ base::WeakPtrFactory<GatherUsageTaskBase> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(GatherUsageTaskBase);
};
@@ -136,7 +139,7 @@ class ClientUsageTracker::GatherGlobalUsageTask
QuotaClient* client)
: GatherUsageTaskBase(tracker, client),
client_(client),
- callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
DCHECK(tracker);
DCHECK(client);
}
@@ -145,8 +148,8 @@ class ClientUsageTracker::GatherGlobalUsageTask
protected:
virtual void Run() OVERRIDE {
client_->GetOriginsForType(tracker()->type(),
- callback_factory_.NewCallback(
- &GatherUsageTaskBase::GetUsageForOrigins));
+ base::Bind(&GatherUsageTaskBase::GetUsageForOrigins,
+ weak_factory_.GetWeakPtr()));
}
virtual void Completed() OVERRIDE {
@@ -155,7 +158,7 @@ class ClientUsageTracker::GatherGlobalUsageTask
private:
QuotaClient* client_;
- base::ScopedCallbackFactory<GatherUsageTaskBase> callback_factory_;
+ base::WeakPtrFactory<GatherUsageTaskBase> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(GatherGlobalUsageTask);
};
@@ -172,7 +175,7 @@ class ClientUsageTracker::GatherHostUsageTask
: GatherUsageTaskBase(tracker, client),
client_(client),
host_(host),
- callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
DCHECK(client_);
}
virtual ~GatherHostUsageTask() {}
@@ -180,8 +183,8 @@ class ClientUsageTracker::GatherHostUsageTask
protected:
virtual void Run() OVERRIDE {
client_->GetOriginsForHost(tracker()->type(), host_,
- callback_factory_.NewCallback(
- &GatherUsageTaskBase::GetUsageForOrigins));
+ base::Bind(&GatherUsageTaskBase::GetUsageForOrigins,
+ weak_factory_.GetWeakPtr()));
}
virtual void Completed() OVERRIDE {
@@ -191,7 +194,7 @@ class ClientUsageTracker::GatherHostUsageTask
private:
QuotaClient* client_;
std::string host_;
- base::ScopedCallbackFactory<GatherUsageTaskBase> callback_factory_;
+ base::WeakPtrFactory<GatherUsageTaskBase> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(GatherHostUsageTask);
};
@@ -201,7 +204,7 @@ class ClientUsageTracker::GatherHostUsageTask
UsageTracker::UsageTracker(const QuotaClientList& clients, StorageType type,
SpecialStoragePolicy* special_storage_policy)
: type_(type),
- callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
for (QuotaClientList::const_iterator iter = clients.begin();
iter != clients.end();
++iter) {
@@ -222,11 +225,10 @@ ClientUsageTracker* UsageTracker::GetClientTracker(QuotaClient::ID client_id) {
return NULL;
}
-void UsageTracker::GetGlobalUsage(GlobalUsageCallback* callback) {
+void UsageTracker::GetGlobalUsage(const GlobalUsageCallback& callback) {
if (client_tracker_map_.size() == 0) {
// No clients registered.
- callback->Run(type_, 0, 0);
- delete callback;
+ callback.Run(type_, 0, 0);
return;
}
if (global_usage_callbacks_.Add(callback)) {
@@ -238,18 +240,18 @@ void UsageTracker::GetGlobalUsage(GlobalUsageCallback* callback) {
for (ClientTrackerMap::iterator iter = client_tracker_map_.begin();
iter != client_tracker_map_.end();
++iter) {
- iter->second->GetGlobalUsage(callback_factory_.NewCallback(
- &UsageTracker::DidGetClientGlobalUsage));
+ iter->second->GetGlobalUsage(
+ base::Bind(&UsageTracker::DidGetClientGlobalUsage,
+ weak_factory_.GetWeakPtr()));
}
}
}
void UsageTracker::GetHostUsage(
- const std::string& host, HostUsageCallback* callback) {
+ const std::string& host, const HostUsageCallback& callback) {
if (client_tracker_map_.size() == 0) {
// No clients registered.
- callback->Run(host, type_, 0);
- delete callback;
+ callback.Run(host, type_, 0);
return;
}
if (host_usage_callbacks_.Add(host, callback)) {
@@ -259,8 +261,9 @@ void UsageTracker::GetHostUsage(
for (ClientTrackerMap::iterator iter = client_tracker_map_.begin();
iter != client_tracker_map_.end();
++iter) {
- iter->second->GetHostUsage(host, callback_factory_.NewCallback(
- &UsageTracker::DidGetClientHostUsage));
+ iter->second->GetHostUsage(host,
+ base::Bind(&UsageTracker::DidGetClientHostUsage,
+ weak_factory_.GetWeakPtr()));
}
}
}
@@ -357,10 +360,9 @@ ClientUsageTracker::~ClientUsageTracker() {
special_storage_policy_->RemoveObserver(this);
}
-void ClientUsageTracker::GetGlobalUsage(GlobalUsageCallback* callback) {
+void ClientUsageTracker::GetGlobalUsage(const GlobalUsageCallback& callback) {
if (global_usage_retrieved_) {
- callback->Run(type_, global_usage_, GetCachedGlobalUnlimitedUsage());
- delete callback;
+ callback.Run(type_, global_usage_, GetCachedGlobalUnlimitedUsage());
return;
}
DCHECK(!global_usage_callback_.HasCallbacks());
@@ -370,12 +372,11 @@ void ClientUsageTracker::GetGlobalUsage(GlobalUsageCallback* callback) {
}
void ClientUsageTracker::GetHostUsage(
- const std::string& host, HostUsageCallback* callback) {
+ const std::string& host, const HostUsageCallback& callback) {
HostSet::const_iterator found = cached_hosts_.find(host);
if (found != cached_hosts_.end()) {
// TODO(kinuko): Drop host_usage_map_ cache periodically.
- callback->Run(host, type_, GetCachedHostUsage(host));
- delete callback;
+ callback.Run(host, type_, GetCachedHostUsage(host));
return;
}
if (!host_usage_callbacks_.Add(host, callback) || global_usage_task_)
@@ -400,7 +401,8 @@ void ClientUsageTracker::UpdateUsageCache(
// We don't know about this host yet, so populate our cache for it.
GetHostUsage(host,
- NewCallback(this, &ClientUsageTracker::NoopHostUsageCallback));
+ base::Bind(&ClientUsageTracker::NoopHostUsageCallback,
+ base::Unretained(this)));
}
void ClientUsageTracker::GetCachedHostsUsage(
diff --git a/webkit/quota/usage_tracker.h b/webkit/quota/usage_tracker.h
index c3782ad..2f7eed0 100644
--- a/webkit/quota/usage_tracker.h
+++ b/webkit/quota/usage_tracker.h
@@ -13,7 +13,6 @@
#include "base/basictypes.h"
#include "base/callback.h"
-#include "base/memory/scoped_callback_factory.h"
#include "base/memory/scoped_ptr.h"
#include "base/threading/non_thread_safe.h"
#include "googleurl/src/gurl.h"
@@ -38,8 +37,8 @@ class UsageTracker : public QuotaTaskObserver {
StorageType type() const { return type_; }
ClientUsageTracker* GetClientTracker(QuotaClient::ID client_id);
- void GetGlobalUsage(GlobalUsageCallback* callback);
- void GetHostUsage(const std::string& host, HostUsageCallback* callback);
+ void GetGlobalUsage(const GlobalUsageCallback& callback);
+ void GetHostUsage(const std::string& host, const HostUsageCallback& callback);
void UpdateUsageCache(QuotaClient::ID client_id,
const GURL& origin,
int64 delta);
@@ -75,7 +74,7 @@ class UsageTracker : public QuotaTaskObserver {
GlobalUsageCallbackQueue global_usage_callbacks_;
HostUsageCallbackMap host_usage_callbacks_;
- base::ScopedCallbackFactory<UsageTracker> callback_factory_;
+ base::WeakPtrFactory<UsageTracker> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(UsageTracker);
};
@@ -90,8 +89,8 @@ class ClientUsageTracker : public SpecialStoragePolicy::Observer,
SpecialStoragePolicy* special_storage_policy);
virtual ~ClientUsageTracker();
- void GetGlobalUsage(GlobalUsageCallback* callback);
- void GetHostUsage(const std::string& host, HostUsageCallback* callback);
+ void GetGlobalUsage(const GlobalUsageCallback& callback);
+ void GetHostUsage(const std::string& host, const HostUsageCallback& callback);
void UpdateUsageCache(const GURL& origin, int64 delta);
void GetCachedHostsUsage(std::map<std::string, int64>* host_usage) const;
void GetCachedOrigins(std::set<GURL>* origins) const;