summaryrefslogtreecommitdiffstats
path: root/webkit/database
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-22 02:25:21 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-22 02:25:21 +0000
commit00bbe166d7ec00625a5279016da55896196fd6c9 (patch)
treec566650f740ae6fcc0ccadf24da2d65efce76998 /webkit/database
parentc9aa14748937fcb2cc0404fd6ea88555d6d407c2 (diff)
downloadchromium_src-00bbe166d7ec00625a5279016da55896196fd6c9.zip
chromium_src-00bbe166d7ec00625a5279016da55896196fd6c9.tar.gz
chromium_src-00bbe166d7ec00625a5279016da55896196fd6c9.tar.bz2
base::Bind: Convert webkit/database.
BUG=none TEST=none R=ajwong Review URL: http://codereview.chromium.org/8965035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115465 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/database')
-rw-r--r--webkit/database/database_quota_client.cc17
-rw-r--r--webkit/database/database_quota_client_unittest.cc7
-rw-r--r--webkit/database/database_tracker.cc47
-rw-r--r--webkit/database/database_tracker.h16
-rw-r--r--webkit/database/database_tracker_unittest.cc15
5 files changed, 51 insertions, 51 deletions
diff --git a/webkit/database/database_quota_client.cc b/webkit/database/database_quota_client.cc
index 669052c..f38eb3d3 100644
--- a/webkit/database/database_quota_client.cc
+++ b/webkit/database/database_quota_client.cc
@@ -7,6 +7,7 @@
#include <vector>
#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/location.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop_proxy.h"
@@ -142,9 +143,7 @@ class DatabaseQuotaClient::DeleteOriginTask : public HelperTask {
: HelperTask(client, db_tracker_thread),
origin_url_(origin_url),
result_(quota::kQuotaStatusUnknown),
- caller_callback_(caller_callback),
- ALLOW_THIS_IN_INITIALIZER_LIST(completion_callback_(
- this, &DeleteOriginTask::OnOldCompletionCallback)) {
+ caller_callback_(caller_callback) {
}
private:
@@ -160,16 +159,18 @@ class DatabaseQuotaClient::DeleteOriginTask : public HelperTask {
}
virtual bool RunOnTargetThreadAsync() OVERRIDE {
- AddRef(); // balanced in OnOldCompletionCallback
+ AddRef(); // balanced in OnCompletionCallback
string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin_url_);
- int rv = db_tracker_->DeleteDataForOrigin(origin_id, &completion_callback_);
+ int rv = db_tracker_->DeleteDataForOrigin(
+ origin_id, base::Bind(&DeleteOriginTask::OnCompletionCallback,
+ base::Unretained(this)));
if (rv == net::ERR_IO_PENDING)
return false; // we wait for the callback
- OnOldCompletionCallback(rv);
+ OnCompletionCallback(rv);
return false;
}
- void OnOldCompletionCallback(int rv) {
+ void OnCompletionCallback(int rv) {
if (rv == net::OK)
result_ = quota::kQuotaStatusOk;
original_message_loop()->PostTask(
@@ -180,7 +181,7 @@ class DatabaseQuotaClient::DeleteOriginTask : public HelperTask {
const GURL origin_url_;
quota::QuotaStatusCode result_;
DeletionCallback caller_callback_;
- net::OldCompletionCallbackImpl<DeleteOriginTask> completion_callback_;
+ net::CompletionCallback completion_callback_;
};
// DatabaseQuotaClient --------------------------------------------------------
diff --git a/webkit/database/database_quota_client_unittest.cc b/webkit/database/database_quota_client_unittest.cc
index 797d7cf..b070046 100644
--- a/webkit/database/database_quota_client_unittest.cc
+++ b/webkit/database/database_quota_client_unittest.cc
@@ -9,6 +9,7 @@
#include "base/message_loop.h"
#include "base/message_loop_proxy.h"
#include "base/utf_string_conversions.h"
+#include "net/base/completion_callback.h"
#include "net/base/net_errors.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/database/database_quota_client.h"
@@ -68,7 +69,7 @@ class MockDatabaseTracker : public DatabaseTracker {
virtual int DeleteDataForOrigin(
const string16& origin_id,
- net::OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) OVERRIDE {
++delete_called_count_;
if (async_delete()) {
base::MessageLoopProxy::current()->PostTask(
@@ -80,8 +81,8 @@ class MockDatabaseTracker : public DatabaseTracker {
return net::OK;
}
- void AsyncDeleteDataForOrigin(net::OldCompletionCallback* callback) {
- callback->Run(net::OK);
+ void AsyncDeleteDataForOrigin(const net::CompletionCallback& callback) {
+ callback.Run(net::OK);
}
void AddMockDatabase(const GURL& origin, const char* name, int size) {
diff --git a/webkit/database/database_tracker.cc b/webkit/database/database_tracker.cc
index 980e8a1..9f6e180 100644
--- a/webkit/database/database_tracker.cc
+++ b/webkit/database/database_tracker.cc
@@ -216,8 +216,8 @@ void DatabaseTracker::DeleteDatabaseIfNeeded(const string16& origin_identifier,
if (dbs_to_be_deleted_[origin_identifier].empty())
dbs_to_be_deleted_.erase(origin_identifier);
- std::vector<net::OldCompletionCallback*> to_be_deleted;
- for (PendingCompletionMap::iterator callback = deletion_callbacks_.begin();
+ for (PendingDeletionCallbacks::iterator callback =
+ deletion_callbacks_.begin();
callback != deletion_callbacks_.end(); ++callback) {
DatabaseSet::iterator found_origin =
callback->second.find(origin_identifier);
@@ -227,16 +227,14 @@ void DatabaseTracker::DeleteDatabaseIfNeeded(const string16& origin_identifier,
if (databases.empty()) {
callback->second.erase(found_origin);
if (callback->second.empty()) {
- net::OldCompletionCallback* cb = callback->first;
- cb->Run(net::OK);
- to_be_deleted.push_back(cb);
+ net::CompletionCallback cb = callback->first;
+ cb.Run(net::OK);
}
}
}
}
- for (std::vector<net::OldCompletionCallback*>::iterator cb =
- to_be_deleted.begin(); cb != to_be_deleted.end(); ++cb)
- deletion_callbacks_.erase(*cb);
+
+ deletion_callbacks_.clear();
}
}
@@ -631,12 +629,11 @@ void DatabaseTracker::ScheduleDatabaseForDeletion(
void DatabaseTracker::ScheduleDatabasesForDeletion(
const DatabaseSet& databases,
- net::OldCompletionCallback* callback) {
- DCHECK(!callback ||
- deletion_callbacks_.find(callback) == deletion_callbacks_.end());
+ const net::CompletionCallback& callback) {
DCHECK(!databases.empty());
- if (callback)
- deletion_callbacks_[callback] = databases;
+
+ if (!callback.is_null())
+ deletion_callbacks_.push_back(std::make_pair(callback, databases));
for (DatabaseSet::const_iterator ori = databases.begin();
ori != databases.end(); ++ori) {
for (std::set<string16>::const_iterator db = ori->second.begin();
@@ -647,17 +644,17 @@ void DatabaseTracker::ScheduleDatabasesForDeletion(
int DatabaseTracker::DeleteDatabase(const string16& origin_identifier,
const string16& database_name,
- net::OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
if (!LazyInit())
return net::ERR_FAILED;
- DCHECK(!callback ||
- deletion_callbacks_.find(callback) == deletion_callbacks_.end());
-
if (database_connections_.IsDatabaseOpened(origin_identifier,
database_name)) {
- if (callback)
- deletion_callbacks_[callback][origin_identifier].insert(database_name);
+ if (!callback.is_null()) {
+ DatabaseSet set;
+ set[origin_identifier].insert(database_name);
+ deletion_callbacks_.push_back(std::make_pair(callback, set));
+ }
ScheduleDatabaseForDeletion(origin_identifier, database_name);
return net::ERR_IO_PENDING;
}
@@ -667,12 +664,10 @@ int DatabaseTracker::DeleteDatabase(const string16& origin_identifier,
int DatabaseTracker::DeleteDataModifiedSince(
const base::Time& cutoff,
- net::OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
if (!LazyInit())
return net::ERR_FAILED;
- DCHECK(!callback ||
- deletion_callbacks_.find(callback) == deletion_callbacks_.end());
DatabaseSet to_be_deleted;
std::vector<string16> origins_identifiers;
@@ -716,13 +711,11 @@ int DatabaseTracker::DeleteDataModifiedSince(
return net::OK;
}
-int DatabaseTracker::DeleteDataForOrigin(const string16& origin,
- net::OldCompletionCallback* callback) {
+int DatabaseTracker::DeleteDataForOrigin(
+ const string16& origin, const net::CompletionCallback& callback) {
if (!LazyInit())
return net::ERR_FAILED;
- DCHECK(!callback ||
- deletion_callbacks_.find(callback) == deletion_callbacks_.end());
DatabaseSet to_be_deleted;
std::vector<DatabaseDetails> details;
@@ -806,7 +799,7 @@ void DatabaseTracker::ClearLocalState(bool clear_all_databases) {
special_storage_policy_.get() &&
special_storage_policy_->HasSessionOnlyOrigins();
- // Clearning only session-only databases, and there are none.
+ // Clearing only session-only databases, and there are none.
if (!clear_all_databases && !has_session_only_databases)
return;
diff --git a/webkit/database/database_tracker.h b/webkit/database/database_tracker.h
index 5c728f9..8871e1b 100644
--- a/webkit/database/database_tracker.h
+++ b/webkit/database/database_tracker.h
@@ -7,6 +7,7 @@
#include <map>
#include <set>
+#include <utility>
#include "base/file_path.h"
#include "base/gtest_prod_util.h"
@@ -133,7 +134,7 @@ class DatabaseTracker
// if non-NULL.
int DeleteDatabase(const string16& origin_identifier,
const string16& database_name,
- net::OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
// Delete any databases that have been touched since the cutoff date that's
// supplied, omitting any that match IDs within |protected_origins|.
@@ -142,14 +143,14 @@ class DatabaseTracker
// if non-NULL. Protected origins, according the the SpecialStoragePolicy,
// are not deleted by this method.
int DeleteDataModifiedSince(const base::Time& cutoff,
- net::OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
// Delete all databases that belong to the given origin. Returns net::OK on
// success, net::FAILED if not all databases could be deleted, and
// net::ERR_IO_PENDING and |callback| is invoked upon completion, if non-NULL.
// virtual for unit testing only
virtual int DeleteDataForOrigin(const string16& origin_identifier,
- net::OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
bool IsIncognitoProfile() const { return is_incognito_; }
@@ -172,7 +173,8 @@ class DatabaseTracker
friend class MockDatabaseTracker; // for testing
typedef std::map<string16, std::set<string16> > DatabaseSet;
- typedef std::map<net::OldCompletionCallback*, DatabaseSet> PendingCompletionMap;
+ typedef std::vector<std::pair<net::CompletionCallback, DatabaseSet> >
+ PendingDeletionCallbacks;
typedef std::map<string16, base::PlatformFile> FileHandlesMap;
typedef std::map<string16, string16> OriginDirectoriesMap;
@@ -194,7 +196,7 @@ class DatabaseTracker
}
};
- // virtual for unittesting only
+ // virtual for unit-testing only.
virtual ~DatabaseTracker();
// Deletes the directory that stores all DBs in incognito mode, if it exists.
@@ -249,7 +251,7 @@ class DatabaseTracker
// Schedule a set of open databases for deletion. If non-null, callback is
// invoked upon completion.
void ScheduleDatabasesForDeletion(const DatabaseSet& databases,
- net::OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
// Returns the directory where all DB files for the given origin are stored.
string16 GetOriginDirectory(const string16& origin_identifier);
@@ -270,7 +272,7 @@ class DatabaseTracker
// The set of databases that should be deleted but are still opened
DatabaseSet dbs_to_be_deleted_;
- PendingCompletionMap deletion_callbacks_;
+ PendingDeletionCallbacks deletion_callbacks_;
// Apps and Extensions can have special rights.
scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_;
diff --git a/webkit/database/database_tracker_unittest.cc b/webkit/database/database_tracker_unittest.cc
index 4d4923d..408046b 100644
--- a/webkit/database/database_tracker_unittest.cc
+++ b/webkit/database/database_tracker_unittest.cc
@@ -214,8 +214,8 @@ class DatabaseTracker_TestHelper_Test {
// Delete db1. Should also delete origin1.
TestObserver observer;
tracker->AddObserver(&observer);
- TestOldCompletionCallback callback;
- int result = tracker->DeleteDatabase(kOrigin1, kDB1, &callback);
+ net::TestCompletionCallback callback;
+ int result = tracker->DeleteDatabase(kOrigin1, kDB1, callback.callback());
EXPECT_EQ(net::ERR_IO_PENDING, result);
ASSERT_FALSE(callback.have_result());
EXPECT_TRUE(observer.DidReceiveNewNotification());
@@ -252,7 +252,7 @@ class DatabaseTracker_TestHelper_Test {
base::Time yesterday = base::Time::Now();
yesterday -= base::TimeDelta::FromDays(1);
result = tracker->DeleteDataModifiedSince(
- yesterday, &callback);
+ yesterday, callback.callback());
EXPECT_EQ(net::ERR_IO_PENDING, result);
ASSERT_FALSE(callback.have_result());
EXPECT_TRUE(observer.DidReceiveNewNotification());
@@ -456,7 +456,8 @@ class DatabaseTracker_TestHelper_Test {
tracker->DatabaseClosed(kOriginId, kName);
EXPECT_TRUE(test_quota_proxy->WasAccessNotified(kOrigin));
- EXPECT_EQ(net::OK, tracker->DeleteDatabase(kOriginId, kName, NULL));
+ EXPECT_EQ(net::OK, tracker->DeleteDatabase(
+ kOriginId, kName, net::CompletionCallback()));
EXPECT_TRUE(test_quota_proxy->WasModificationNotified(kOrigin, -100));
test_quota_proxy->reset();
@@ -477,7 +478,8 @@ class DatabaseTracker_TestHelper_Test {
test_quota_proxy->reset();
EXPECT_EQ(net::ERR_IO_PENDING,
- tracker->DeleteDatabase(kOriginId, kName, NULL));
+ tracker->DeleteDatabase(kOriginId, kName,
+ net::CompletionCallback()));
EXPECT_FALSE(test_quota_proxy->WasModificationNotified(kOrigin, -100));
tracker->DatabaseClosed(kOriginId, kName);
@@ -804,7 +806,8 @@ class DatabaseTracker_TestHelper_Test {
tracker->DatabaseClosed(kOriginId, kEmptyName);
// Deleting it should return to the initial state.
- EXPECT_EQ(net::OK, tracker->DeleteDatabase(kOriginId, kEmptyName, NULL));
+ EXPECT_EQ(net::OK, tracker->DeleteDatabase(kOriginId, kEmptyName,
+ net::CompletionCallback()));
infos.clear();
EXPECT_TRUE(tracker->GetAllOriginsInfo(&infos));
EXPECT_TRUE(infos.empty());