summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-27 02:38:14 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-27 02:38:14 +0000
commita6e77be9914de7c821bf6827cb432f42c4353686 (patch)
tree23216e870c653e6320bc1b5a01a7ad45227c775c
parentbf3816ece9d2c01f22ff73692f576e45ae4581cf (diff)
downloadchromium_src-a6e77be9914de7c821bf6827cb432f42c4353686.zip
chromium_src-a6e77be9914de7c821bf6827cb432f42c4353686.tar.gz
chromium_src-a6e77be9914de7c821bf6827cb432f42c4353686.tar.bz2
base::Bind: Convert BrowsingDataLocalStorageHelper::StartFetching.
BUG=none TEST=none R=csilv@chromium.org Review URL: http://codereview.chromium.org/8393036 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107522 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/browsing_data_local_storage_helper.cc23
-rw-r--r--chrome/browser/browsing_data_local_storage_helper.h17
-rw-r--r--chrome/browser/browsing_data_local_storage_helper_browsertest.cc13
-rw-r--r--chrome/browser/cookies_tree_model.cc10
-rw-r--r--chrome/browser/mock_browsing_data_local_storage_helper.cc10
-rw-r--r--chrome/browser/mock_browsing_data_local_storage_helper.h18
6 files changed, 50 insertions, 41 deletions
diff --git a/chrome/browser/browsing_data_local_storage_helper.cc b/chrome/browser/browsing_data_local_storage_helper.cc
index a270f21..8b84fc2 100644
--- a/chrome/browser/browsing_data_local_storage_helper.cc
+++ b/chrome/browser/browsing_data_local_storage_helper.cc
@@ -48,7 +48,6 @@ BrowsingDataLocalStorageHelper::LocalStorageInfo::~LocalStorageInfo() {}
BrowsingDataLocalStorageHelper::BrowsingDataLocalStorageHelper(
Profile* profile)
: profile_(profile),
- completion_callback_(NULL),
is_fetching_(false) {
DCHECK(profile_);
}
@@ -57,12 +56,13 @@ BrowsingDataLocalStorageHelper::~BrowsingDataLocalStorageHelper() {
}
void BrowsingDataLocalStorageHelper::StartFetching(
- Callback1<const std::list<LocalStorageInfo>& >::Type* callback) {
+ const base::Callback<void(const std::list<LocalStorageInfo>&)>& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!is_fetching_);
- DCHECK(callback);
+ DCHECK_EQ(false, callback.is_null());
+
is_fetching_ = true;
- completion_callback_.reset(callback);
+ completion_callback_ = callback;
BrowserThread::PostTask(
BrowserThread::WEBKIT, FROM_HERE,
base::Bind(
@@ -72,7 +72,7 @@ void BrowsingDataLocalStorageHelper::StartFetching(
void BrowsingDataLocalStorageHelper::CancelNotification() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- completion_callback_.reset(NULL);
+ completion_callback_.Reset();
}
void BrowsingDataLocalStorageHelper::DeleteLocalStorageFile(
@@ -128,9 +128,9 @@ void BrowsingDataLocalStorageHelper::NotifyInUIThread() {
DCHECK(is_fetching_);
// Note: completion_callback_ mutates only in the UI thread, so it's safe to
// test it here.
- if (completion_callback_ != NULL) {
- completion_callback_->Run(local_storage_info_);
- completion_callback_.reset();
+ if (!completion_callback_.is_null()) {
+ completion_callback_.Run(local_storage_info_);
+ completion_callback_.Reset();
}
is_fetching_ = false;
}
@@ -178,12 +178,13 @@ bool CannedBrowsingDataLocalStorageHelper::empty() const {
}
void CannedBrowsingDataLocalStorageHelper::StartFetching(
- Callback1<const std::list<LocalStorageInfo>& >::Type* callback) {
+ const base::Callback<void(const std::list<LocalStorageInfo>&)>& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!is_fetching_);
- DCHECK(callback);
+ DCHECK_EQ(false, callback.is_null());
+
is_fetching_ = true;
- completion_callback_.reset(callback);
+ completion_callback_ = callback;
BrowserThread::PostTask(
BrowserThread::WEBKIT, FROM_HERE,
base::Bind(&CannedBrowsingDataLocalStorageHelper::
diff --git a/chrome/browser/browsing_data_local_storage_helper.h b/chrome/browser/browsing_data_local_storage_helper.h
index 53a88a9..84c51931 100644
--- a/chrome/browser/browsing_data_local_storage_helper.h
+++ b/chrome/browser/browsing_data_local_storage_helper.h
@@ -10,7 +10,8 @@
#include <set>
#include <string>
-#include "base/callback_old.h"
+#include "base/callback.h"
+#include "base/compiler_specific.h"
#include "base/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/synchronization/lock.h"
@@ -64,7 +65,7 @@ class BrowsingDataLocalStorageHelper
// callback.
// This must be called only in the UI thread.
virtual void StartFetching(
- Callback1<const std::list<LocalStorageInfo>& >::Type* callback);
+ const base::Callback<void(const std::list<LocalStorageInfo>&)>& callback);
// Cancels the notification callback (i.e., the window that created it no
// longer exists).
// This must be called only in the UI thread.
@@ -82,8 +83,7 @@ class BrowsingDataLocalStorageHelper
Profile* profile_;
// This only mutates on the UI thread.
- scoped_ptr<Callback1<const std::list<LocalStorageInfo>& >::Type >
- completion_callback_;
+ base::Callback<void(const std::list<LocalStorageInfo>&)> completion_callback_;
// Indicates whether or not we're currently fetching information:
// it's true when StartFetching() is called in the UI thread, and it's reset
@@ -113,7 +113,7 @@ class CannedBrowsingDataLocalStorageHelper
// Return a copy of the local storage helper. Only one consumer can use the
// StartFetching method at a time, so we need to create a copy of the helper
- // everytime we instantiate a cookies tree model for it.
+ // every time we instantiate a cookies tree model for it.
CannedBrowsingDataLocalStorageHelper* Clone();
// Add a local storage to the set of canned local storages that is returned
@@ -126,10 +126,11 @@ class CannedBrowsingDataLocalStorageHelper
// True if no local storages are currently stored.
bool empty() const;
- // BrowsingDataLocalStorageHelper methods.
+ // BrowsingDataLocalStorageHelper implementation.
virtual void StartFetching(
- Callback1<const std::list<LocalStorageInfo>& >::Type* callback);
- virtual void CancelNotification() {}
+ const base::Callback<void(const std::list<LocalStorageInfo>&)>& callback)
+ OVERRIDE;
+ virtual void CancelNotification() OVERRIDE {}
private:
virtual ~CannedBrowsingDataLocalStorageHelper();
diff --git a/chrome/browser/browsing_data_local_storage_helper_browsertest.cc b/chrome/browser/browsing_data_local_storage_helper_browsertest.cc
index 6687973..27f98b9 100644
--- a/chrome/browser/browsing_data_local_storage_helper_browsertest.cc
+++ b/chrome/browser/browsing_data_local_storage_helper_browsertest.cc
@@ -5,6 +5,8 @@
#include <string>
#include "base/basictypes.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/file_path.h"
#include "base/file_util.h"
@@ -23,7 +25,7 @@
namespace {
typedef
BrowsingDataHelperCallback<BrowsingDataLocalStorageHelper::LocalStorageInfo>
- TestCompletionCallback;
+ TestCompletionCallback;
const FilePath::CharType kTestFile0[] =
FILE_PATH_LITERAL("http_www.chromium.org_0.localstorage");
@@ -107,7 +109,8 @@ IN_PROC_BROWSER_TEST_F(BrowsingDataLocalStorageHelperTest, CallbackCompletes) {
CreateLocalStorageFilesForTest();
StopTestOnCallback stop_test_on_callback(local_storage_helper);
local_storage_helper->StartFetching(
- NewCallback(&stop_test_on_callback, &StopTestOnCallback::Callback));
+ base::Bind(&StopTestOnCallback::Callback,
+ base::Unretained(&stop_test_on_callback)));
// Blocks until StopTestOnCallback::Callback is notified.
ui_test_utils::RunMessageLoop();
}
@@ -153,7 +156,8 @@ IN_PROC_BROWSER_TEST_F(BrowsingDataLocalStorageHelperTest,
TestCompletionCallback callback;
helper->StartFetching(
- NewCallback(&callback, &TestCompletionCallback::callback));
+ base::Bind(&TestCompletionCallback::callback,
+ base::Unretained(&callback)));
std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo> result =
callback.result();
@@ -178,7 +182,8 @@ IN_PROC_BROWSER_TEST_F(BrowsingDataLocalStorageHelperTest, CannedUnique) {
TestCompletionCallback callback;
helper->StartFetching(
- NewCallback(&callback, &TestCompletionCallback::callback));
+ base::Bind(&TestCompletionCallback::callback,
+ base::Unretained(&callback)));
std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo> result =
callback.result();
diff --git a/chrome/browser/cookies_tree_model.cc b/chrome/browser/cookies_tree_model.cc
index 1df16c8..002b8e7 100644
--- a/chrome/browser/cookies_tree_model.cc
+++ b/chrome/browser/cookies_tree_model.cc
@@ -634,11 +634,13 @@ CookiesTreeModel::CookiesTreeModel(
base::Bind(&CookiesTreeModel::OnDatabaseModelInfoLoaded,
base::Unretained(this)));
DCHECK(local_storage_helper_);
- local_storage_helper_->StartFetching(NewCallback(
- this, &CookiesTreeModel::OnLocalStorageModelInfoLoaded));
+ local_storage_helper_->StartFetching(
+ base::Bind(&CookiesTreeModel::OnLocalStorageModelInfoLoaded,
+ base::Unretained(this)));
if (session_storage_helper_) {
- session_storage_helper_->StartFetching(NewCallback(
- this, &CookiesTreeModel::OnSessionStorageModelInfoLoaded));
+ session_storage_helper_->StartFetching(
+ base::Bind(&CookiesTreeModel::OnSessionStorageModelInfoLoaded,
+ base::Unretained(this)));
}
// TODO(michaeln): When all of the UI implementations have been updated, make
diff --git a/chrome/browser/mock_browsing_data_local_storage_helper.cc b/chrome/browser/mock_browsing_data_local_storage_helper.cc
index 9bdbda7..7f22368 100644
--- a/chrome/browser/mock_browsing_data_local_storage_helper.cc
+++ b/chrome/browser/mock_browsing_data_local_storage_helper.cc
@@ -17,12 +17,12 @@ MockBrowsingDataLocalStorageHelper::~MockBrowsingDataLocalStorageHelper() {
}
void MockBrowsingDataLocalStorageHelper::StartFetching(
- Callback1<const std::list<LocalStorageInfo>& >::Type* callback) {
- callback_.reset(callback);
+ const base::Callback<void(const std::list<LocalStorageInfo>&)>& callback) {
+ callback_ = callback;
}
void MockBrowsingDataLocalStorageHelper::CancelNotification() {
- callback_.reset(NULL);
+ callback_.Reset();
}
void MockBrowsingDataLocalStorageHelper::DeleteLocalStorageFile(
@@ -46,8 +46,8 @@ void MockBrowsingDataLocalStorageHelper::AddLocalStorageSamples() {
}
void MockBrowsingDataLocalStorageHelper::Notify() {
- CHECK(callback_.get());
- callback_->Run(response_);
+ CHECK_EQ(false, callback_.is_null());
+ callback_.Run(response_);
}
void MockBrowsingDataLocalStorageHelper::Reset() {
diff --git a/chrome/browser/mock_browsing_data_local_storage_helper.h b/chrome/browser/mock_browsing_data_local_storage_helper.h
index 0163184..dbc6a4a 100644
--- a/chrome/browser/mock_browsing_data_local_storage_helper.h
+++ b/chrome/browser/mock_browsing_data_local_storage_helper.h
@@ -10,6 +10,7 @@
#include <map>
#include "base/callback.h"
+#include "base/compiler_specific.h"
#include "chrome/browser/browsing_data_local_storage_helper.h"
// Mock for BrowsingDataLocalStorageHelper.
@@ -20,12 +21,12 @@ class MockBrowsingDataLocalStorageHelper
public:
explicit MockBrowsingDataLocalStorageHelper(Profile* profile);
+ // BrowsingDataLocalStorageHelper implementation.
virtual void StartFetching(
- Callback1<const std::list<LocalStorageInfo>& >::Type* callback);
-
- virtual void CancelNotification();
-
- virtual void DeleteLocalStorageFile(const FilePath& file_path);
+ const base::Callback<void(const std::list<LocalStorageInfo>&)>& callback)
+ OVERRIDE;
+ virtual void CancelNotification() OVERRIDE;
+ virtual void DeleteLocalStorageFile(const FilePath& file_path) OVERRIDE;
// Adds some LocalStorageInfo samples.
void AddLocalStorageSamples();
@@ -36,8 +37,8 @@ class MockBrowsingDataLocalStorageHelper
// Marks all local storage files as existing.
void Reset();
- // Returns true if all local storage files were deleted since the last
- // Reset() invokation.
+ // Returns true if all local storage files were deleted since the last Reset()
+ // invocation.
bool AllDeleted();
FilePath last_deleted_file_;
@@ -47,8 +48,7 @@ class MockBrowsingDataLocalStorageHelper
Profile* profile_;
- scoped_ptr<Callback1<const std::list<LocalStorageInfo>& >::Type >
- callback_;
+ base::Callback<void(const std::list<LocalStorageInfo>&)> callback_;
std::map<const FilePath::StringType, bool> files_;