diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-24 23:47:39 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-24 23:47:39 +0000 |
commit | e8db17056d305c066ded8f64ea7eb59183e10db4 (patch) | |
tree | 19b9125dd7b0350bc55a8c21d4b83bf306731ede | |
parent | 926cf6ef9e4e408b3646bf42bf5dee3d9bfba99e (diff) | |
download | chromium_src-e8db17056d305c066ded8f64ea7eb59183e10db4.zip chromium_src-e8db17056d305c066ded8f64ea7eb59183e10db4.tar.gz chromium_src-e8db17056d305c066ded8f64ea7eb59183e10db4.tar.bz2 |
base::Bind: Convert BrowsingDataFileSystemHelper::StartFetching.
BUG=none
TEST=none
R=csilv@chromium.org
Review URL: http://codereview.chromium.org/8370026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107015 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browsing_data_file_system_helper.cc | 40 | ||||
-rw-r--r-- | chrome/browser/browsing_data_file_system_helper.h | 24 | ||||
-rw-r--r-- | chrome/browser/browsing_data_file_system_helper_unittest.cc | 10 | ||||
-rw-r--r-- | chrome/browser/cookies_tree_model.cc | 5 | ||||
-rw-r--r-- | chrome/browser/mock_browsing_data_file_system_helper.cc | 10 | ||||
-rw-r--r-- | chrome/browser/mock_browsing_data_file_system_helper.h | 17 |
6 files changed, 54 insertions, 52 deletions
diff --git a/chrome/browser/browsing_data_file_system_helper.cc b/chrome/browser/browsing_data_file_system_helper.cc index ad367b6..ae7c039 100644 --- a/chrome/browser/browsing_data_file_system_helper.cc +++ b/chrome/browser/browsing_data_file_system_helper.cc @@ -5,6 +5,7 @@ #include "chrome/browser/browsing_data_file_system_helper.h" #include "base/bind.h" +#include "base/compiler_specific.h" #include "base/file_util.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" @@ -26,10 +27,10 @@ class BrowsingDataFileSystemHelperImpl : public BrowsingDataFileSystemHelper { public: // BrowsingDataFileSystemHelper implementation explicit BrowsingDataFileSystemHelperImpl(Profile* profile); - virtual void StartFetching( - Callback1<const std::list<FileSystemInfo>& >::Type* callback); - virtual void CancelNotification(); - virtual void DeleteFileSystemOrigin(const GURL& origin); + virtual void StartFetching(const base::Callback< + void(const std::list<FileSystemInfo>&)>& callback) OVERRIDE; + virtual void CancelNotification() OVERRIDE; + virtual void DeleteFileSystemOrigin(const GURL& origin) OVERRIDE; private: virtual ~BrowsingDataFileSystemHelperImpl(); @@ -57,8 +58,7 @@ class BrowsingDataFileSystemHelperImpl : public BrowsingDataFileSystemHelper { // Holds the callback passed in at the beginning of the StartFetching workflow // so that it can be triggered via NotifyOnUIThread. This only mutates on the // UI thread. - scoped_ptr<Callback1<const std::list<FileSystemInfo>& >::Type > - completion_callback_; + base::Callback<void(const std::list<FileSystemInfo>&)> completion_callback_; // Indicates whether or not we're currently fetching information: set to true // when StartFetching is called on the UI thread, and reset to false when @@ -80,12 +80,12 @@ BrowsingDataFileSystemHelperImpl::~BrowsingDataFileSystemHelperImpl() { } void BrowsingDataFileSystemHelperImpl::StartFetching( - Callback1<const std::list<FileSystemInfo>& >::Type* callback) { + const base::Callback<void(const std::list<FileSystemInfo>&)>& 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::FILE, FROM_HERE, base::Bind( @@ -95,7 +95,7 @@ void BrowsingDataFileSystemHelperImpl::StartFetching( void BrowsingDataFileSystemHelperImpl::CancelNotification() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - completion_callback_.reset(); + completion_callback_.Reset(); } void BrowsingDataFileSystemHelperImpl::DeleteFileSystemOrigin( @@ -152,9 +152,9 @@ void BrowsingDataFileSystemHelperImpl::NotifyOnUIThread() { DCHECK(is_fetching_); // completion_callback_ mutates only in the UI thread, so we're safe to test // it here. - if (completion_callback_ != NULL) { - completion_callback_->Run(file_system_info_); - completion_callback_.reset(); + if (!completion_callback_.is_null()) { + completion_callback_.Run(file_system_info_); + completion_callback_.Reset(); } is_fetching_ = false; } @@ -254,12 +254,12 @@ bool CannedBrowsingDataFileSystemHelper::empty() const { } void CannedBrowsingDataFileSystemHelper::StartFetching( - Callback1<const std::list<FileSystemInfo>& >::Type* callback) { + const base::Callback<void(const std::list<FileSystemInfo>&)>& 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::UI, FROM_HERE, @@ -269,14 +269,14 @@ void CannedBrowsingDataFileSystemHelper::StartFetching( void CannedBrowsingDataFileSystemHelper::NotifyOnUIThread() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(is_fetching_); - if (completion_callback_ != NULL) { - completion_callback_->Run(file_system_info_); - completion_callback_.reset(); + if (!completion_callback_.is_null()) { + completion_callback_.Run(file_system_info_); + completion_callback_.Reset(); } is_fetching_ = false; } void CannedBrowsingDataFileSystemHelper::CancelNotification() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - completion_callback_.reset(); + completion_callback_.Reset(); } diff --git a/chrome/browser/browsing_data_file_system_helper.h b/chrome/browser/browsing_data_file_system_helper.h index 1bfdc26..e00db12 100644 --- a/chrome/browser/browsing_data_file_system_helper.h +++ b/chrome/browser/browsing_data_file_system_helper.h @@ -9,7 +9,8 @@ #include <list> #include <string> -#include "base/callback_old.h" +#include "base/callback.h" +#include "base/compiler_specific.h" #include "base/file_path.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" @@ -82,8 +83,8 @@ class BrowsingDataFileSystemHelper // // BrowsingDataFileSystemHelper takes ownership of the Callback1, and is // responsible for deleting it once it's no longer needed. - virtual void StartFetching( - Callback1<const std::list<FileSystemInfo>& >::Type* callback) = 0; + virtual void StartFetching(const base::Callback< + void(const std::list<FileSystemInfo>&)>& callback) = 0; // Cancels the notification callback associated with StartFetching. Clients // that are destroyed before the callback is triggered must call this, and @@ -136,16 +137,16 @@ class CannedBrowsingDataFileSystemHelper // True if no filesystems are currently stored. bool empty() const; - // BrowsingDataFileSystemHelper methods. - virtual void StartFetching( - Callback1<const std::list<FileSystemInfo>& >::Type* callback); - virtual void CancelNotification(); + // BrowsingDataFileSystemHelper implementation. + virtual void StartFetching(const base::Callback< + void(const std::list<FileSystemInfo>&)>& callback) OVERRIDE; + virtual void CancelNotification() OVERRIDE; // Note that this doesn't actually have an implementation for this canned // class. It hasn't been necessary for anything that uses the canned // implementation, as the canned class is only used in tests, or in read-only // contexts (like the non-modal cookie dialog). - virtual void DeleteFileSystemOrigin(const GURL& origin) {} + virtual void DeleteFileSystemOrigin(const GURL& origin) OVERRIDE {} private: // Used by Clone() to create an object without a Profile @@ -160,10 +161,9 @@ class CannedBrowsingDataFileSystemHelper // StartFetching is called. std::list<FileSystemInfo> file_system_info_; - // Holds the callback passed in at the beginning of the StartFetching workflow - // so that it can be triggered via NotifyOnUIThread. - scoped_ptr<Callback1<const std::list<FileSystemInfo>& >::Type > - completion_callback_; + // The callback passed in at the beginning of the StartFetching workflow so + // that it can be triggered via NotifyOnUIThread. + base::Callback<void(const std::list<FileSystemInfo>&)> completion_callback_; // Indicates whether or not we're currently fetching information: set to true // when StartFetching is called on the UI thread, and reset to false when diff --git a/chrome/browser/browsing_data_file_system_helper_unittest.cc b/chrome/browser/browsing_data_file_system_helper_unittest.cc index b28f552..30c3be6 100644 --- a/chrome/browser/browsing_data_file_system_helper_unittest.cc +++ b/chrome/browser/browsing_data_file_system_helper_unittest.cc @@ -111,16 +111,18 @@ class BrowsingDataFileSystemHelperTest : public testing::Test { // Calls StartFetching() on the test's BrowsingDataFileSystemHelper // object, then blocks until the callback is executed. void FetchFileSystems() { - helper_->StartFetching(NewCallback(this, - &BrowsingDataFileSystemHelperTest::CallbackStartFetching)); + helper_->StartFetching( + base::Bind(&BrowsingDataFileSystemHelperTest::CallbackStartFetching, + base::Unretained(this))); BlockUntilNotified(); } // Calls StartFetching() on the test's CannedBrowsingDataFileSystemHelper // object, then blocks until the callback is executed. void FetchCannedFileSystems() { - canned_helper_->StartFetching(NewCallback(this, - &BrowsingDataFileSystemHelperTest::CallbackStartFetching)); + canned_helper_->StartFetching( + base::Bind(&BrowsingDataFileSystemHelperTest::CallbackStartFetching, + base::Unretained(this))); BlockUntilNotified(); } diff --git a/chrome/browser/cookies_tree_model.cc b/chrome/browser/cookies_tree_model.cc index 90fbdaa..d1c24d0 100644 --- a/chrome/browser/cookies_tree_model.cc +++ b/chrome/browser/cookies_tree_model.cc @@ -655,8 +655,9 @@ CookiesTreeModel::CookiesTreeModel( } if (file_system_helper_) { - file_system_helper_->StartFetching(NewCallback( - this, &CookiesTreeModel::OnFileSystemModelInfoLoaded)); + file_system_helper_->StartFetching( + base::Bind(&CookiesTreeModel::OnFileSystemModelInfoLoaded, + base::Unretained(this))); } if (quota_helper_) { diff --git a/chrome/browser/mock_browsing_data_file_system_helper.cc b/chrome/browser/mock_browsing_data_file_system_helper.cc index 7194362..3ecc344 100644 --- a/chrome/browser/mock_browsing_data_file_system_helper.cc +++ b/chrome/browser/mock_browsing_data_file_system_helper.cc @@ -15,12 +15,12 @@ MockBrowsingDataFileSystemHelper::~MockBrowsingDataFileSystemHelper() { } void MockBrowsingDataFileSystemHelper::StartFetching( - Callback1<const std::list<FileSystemInfo>& >::Type* callback) { - callback_.reset(callback); + const base::Callback<void(const std::list<FileSystemInfo>&)>& callback) { + callback_ = callback; } void MockBrowsingDataFileSystemHelper::CancelNotification() { - callback_.reset(NULL); + callback_.Reset(); } void MockBrowsingDataFileSystemHelper::DeleteFileSystemOrigin( @@ -45,8 +45,8 @@ void MockBrowsingDataFileSystemHelper::AddFileSystemSamples() { } void MockBrowsingDataFileSystemHelper::Notify() { - CHECK(callback_.get()); - callback_->Run(response_); + CHECK_EQ(false, callback_.is_null()); + callback_.Run(response_); } void MockBrowsingDataFileSystemHelper::Reset() { diff --git a/chrome/browser/mock_browsing_data_file_system_helper.h b/chrome/browser/mock_browsing_data_file_system_helper.h index 6e172ee..15dac27 100644 --- a/chrome/browser/mock_browsing_data_file_system_helper.h +++ b/chrome/browser/mock_browsing_data_file_system_helper.h @@ -10,6 +10,7 @@ #include <map> #include "base/callback.h" +#include "base/compiler_specific.h" #include "chrome/browser/browsing_data_file_system_helper.h" #include "webkit/fileapi/file_system_types.h" @@ -20,12 +21,11 @@ class MockBrowsingDataFileSystemHelper : public BrowsingDataFileSystemHelper { public: explicit MockBrowsingDataFileSystemHelper(Profile* profile); - virtual void StartFetching( - Callback1<const std::list<FileSystemInfo>& >::Type* callback); - - virtual void CancelNotification(); - - virtual void DeleteFileSystemOrigin(const GURL& origin); + // BrowsingDataFileSystemHelper implementation. + virtual void StartFetching(const base::Callback< + void(const std::list<FileSystemInfo>&)>& callback) OVERRIDE; + virtual void CancelNotification() OVERRIDE; + virtual void DeleteFileSystemOrigin(const GURL& origin) OVERRIDE; // Adds a specific filesystem. void AddFileSystem(const GURL& origin, @@ -41,7 +41,7 @@ class MockBrowsingDataFileSystemHelper : public BrowsingDataFileSystemHelper { // Marks all filesystems as existing. void Reset(); - // Returns true if all filesystemss since the last Reset() invokation were + // Returns true if all filesystemss since the last Reset() invocation were // deleted. bool AllDeleted(); @@ -52,8 +52,7 @@ class MockBrowsingDataFileSystemHelper : public BrowsingDataFileSystemHelper { Profile* profile_; - scoped_ptr<Callback1<const std::list<FileSystemInfo>& >::Type > - callback_; + base::Callback<void(const std::list<FileSystemInfo>&)> callback_; // Stores which filesystems exist. std::map<const std::string, bool> file_systems_; |