diff options
10 files changed, 113 insertions, 80 deletions
diff --git a/chrome/browser/geolocation/access_token_store_browsertest.cc b/chrome/browser/geolocation/access_token_store_browsertest.cc index 7ef5a4e..c6792c5 100644 --- a/chrome/browser/geolocation/access_token_store_browsertest.cc +++ b/chrome/browser/geolocation/access_token_store_browsertest.cc @@ -2,6 +2,8 @@ // 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/bind_helpers.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "chrome/browser/geolocation/chrome_access_token_store.h" @@ -43,7 +45,7 @@ class GeolocationAccessTokenStoreTest void StartTestStepFromClientThread( scoped_refptr<AccessTokenStore>* store, CancelableRequestConsumerBase* consumer, - AccessTokenStore::LoadAccessTokensCallbackType* callback) { + const AccessTokenStore::LoadAccessTokensCallbackType& callback) { ASSERT_TRUE(BrowserThread::CurrentlyOn(kExpectedClientThreadId)); if (*store == NULL) (*store) = new ChromeAccessTokenStore(); @@ -65,8 +67,10 @@ void RunCancelTestInClientTread() { // Single request, canceled explicitly CancelableRequestProvider::Handle first_handle = - store->LoadAccessTokens(&consumer, NewCallback( - &load_client, &TokenLoadClientForTest::NotReachedCallback)); + store->LoadAccessTokens( + &consumer, + base::Bind(&TokenLoadClientForTest::NotReachedCallback, + base::Unretained(&load_client))); EXPECT_TRUE(consumer.HasPendingRequests()); // Test this handle is valid. consumer.GetClientData(store.get(), first_handle); @@ -74,10 +78,14 @@ void RunCancelTestInClientTread() { EXPECT_FALSE(consumer.HasPendingRequests()); // 2 requests, canceled globally. - store->LoadAccessTokens(&consumer, NewCallback( - &load_client, &TokenLoadClientForTest::NotReachedCallback)); - store->LoadAccessTokens(&consumer, NewCallback( - &load_client, &TokenLoadClientForTest::NotReachedCallback)); + store->LoadAccessTokens( + &consumer, + base::Bind(&TokenLoadClientForTest::NotReachedCallback, + base::Unretained(&load_client))); + store->LoadAccessTokens( + &consumer, + base::Bind(&TokenLoadClientForTest::NotReachedCallback, + base::Unretained(&load_client))); EXPECT_TRUE(consumer.HasPendingRequests()); EXPECT_EQ(2u, consumer.PendingRequestCount()); consumer.CancelAllRequests(); @@ -96,10 +104,11 @@ void GeolocationAccessTokenStoreTest::DoTestStepAndWaitForResults( token_to_set_ = token_to_set; BrowserThread::PostTask( - kExpectedClientThreadId, FROM_HERE, NewRunnableFunction( - &StartTestStepFromClientThread, &token_store_, &request_consumer_, - NewCallback(this, - &GeolocationAccessTokenStoreTest::OnAccessTokenStoresLoaded))); + kExpectedClientThreadId, FROM_HERE, + base::Bind(&StartTestStepFromClientThread, &token_store_, + &request_consumer_, + base::Bind(&GeolocationAccessTokenStoreTest:: + OnAccessTokenStoresLoaded, base::Unretained(this)))); ui_test_utils::RunMessageLoop(); } @@ -159,9 +168,8 @@ IN_PROC_BROWSER_TEST_F(GeolocationAccessTokenStoreTest, OldUrlRemoval) { } IN_PROC_BROWSER_TEST_F(GeolocationAccessTokenStoreTest, CancelRequest) { - BrowserThread::PostTask( - kExpectedClientThreadId, FROM_HERE, NewRunnableFunction( - RunCancelTestInClientTread)); + BrowserThread::PostTask(kExpectedClientThreadId, FROM_HERE, + base::Bind(&RunCancelTestInClientTread)); ui_test_utils::RunMessageLoop(); } diff --git a/chrome/browser/geolocation/chrome_access_token_store.cc b/chrome/browser/geolocation/chrome_access_token_store.cc index 15f9020..702e0dd 100644 --- a/chrome/browser/geolocation/chrome_access_token_store.cc +++ b/chrome/browser/geolocation/chrome_access_token_store.cc @@ -4,6 +4,7 @@ #include "chrome/browser/geolocation/chrome_access_token_store.h" +#include "base/bind.h" #include "base/string_piece.h" #include "base/utf_string_conversions.h" #include "base/values.h" @@ -56,15 +57,16 @@ void ChromeAccessTokenStore::LoadDictionaryStoreInUIThread( token_dictionary->RemoveWithoutPathExpansion( kOldDefaultNetworkProviderUrl, NULL); } - request->ForwardResultAsync(MakeTuple( - access_token_set, g_browser_process->system_request_context())); + request->ForwardResultAsync(access_token_set, + g_browser_process->system_request_context()); } void ChromeAccessTokenStore::DoLoadAccessTokens( scoped_refptr<CancelableRequest<LoadAccessTokensCallbackType> > request) { - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, NewRunnableMethod( - this, &ChromeAccessTokenStore::LoadDictionaryStoreInUIThread, - request)); + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + base::Bind(&ChromeAccessTokenStore::LoadDictionaryStoreInUIThread, this, + request)); } void SetAccessTokenOnUIThread(const GURL& server_url, const string16& token) { @@ -78,6 +80,7 @@ void SetAccessTokenOnUIThread(const GURL& server_url, const string16& token) { void ChromeAccessTokenStore::SaveAccessToken(const GURL& server_url, const string16& access_token) { - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, NewRunnableFunction( - &SetAccessTokenOnUIThread, server_url, access_token)); + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + base::Bind(&SetAccessTokenOnUIThread, server_url, access_token)); } diff --git a/chrome/browser/geolocation/chrome_geolocation_permission_context.cc b/chrome/browser/geolocation/chrome_geolocation_permission_context.cc index b766435..3624793 100644 --- a/chrome/browser/geolocation/chrome_geolocation_permission_context.cc +++ b/chrome/browser/geolocation/chrome_geolocation_permission_context.cc @@ -8,6 +8,7 @@ #include <string> #include <vector> +#include "base/bind.h" #include "base/utf_string_conversions.h" #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/content_settings/tab_specific_content_settings.h" @@ -511,9 +512,12 @@ void ChromeGeolocationPermissionContext::RequestGeolocationPermission( int render_process_id, int render_view_id, int bridge_id, const GURL& requesting_frame) { if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, NewRunnableMethod( - this, &ChromeGeolocationPermissionContext::RequestGeolocationPermission, - render_process_id, render_view_id, bridge_id, requesting_frame)); + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + base::Bind( + &ChromeGeolocationPermissionContext::RequestGeolocationPermission, + this, render_process_id, render_view_id, bridge_id, + requesting_frame)); return; } DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -609,10 +613,11 @@ void ChromeGeolocationPermissionContext::NotifyPermissionSet( allowed); if (allowed) { - BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, NewRunnableMethod( - this, - &ChromeGeolocationPermissionContext::NotifyArbitratorPermissionGranted, - requesting_frame)); + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind( + &ChromeGeolocationPermissionContext:: + NotifyArbitratorPermissionGranted, this, requesting_frame)); } } @@ -627,9 +632,11 @@ void ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest( int render_view_id, int bridge_id) { if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, NewRunnableMethod( - this, &ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest, - render_process_id, render_view_id, bridge_id)); + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + base::Bind( + &ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest, + this, render_process_id, render_view_id, bridge_id)); return; } DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); diff --git a/chrome/browser/geolocation/wifi_data_provider_chromeos.cc b/chrome/browser/geolocation/wifi_data_provider_chromeos.cc index 7950972..3abb2d9 100644 --- a/chrome/browser/geolocation/wifi_data_provider_chromeos.cc +++ b/chrome/browser/geolocation/wifi_data_provider_chromeos.cc @@ -6,6 +6,7 @@ #include "chrome/browser/geolocation/wifi_data_provider_chromeos.h" +#include "base/bind.h" #include "base/utf_string_conversions.h" #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/cros/network_library.h" @@ -140,8 +141,8 @@ void WifiDataProviderChromeOs::DoStartTaskOnUIThread() { CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); wlan_api_.reset(NewWlanApi()); if (wlan_api_ == NULL) { - client_loop()->PostTask(FROM_HERE, NewRunnableMethod( - this, &WifiDataProviderChromeOs::DidStartFailed)); + client_loop()->PostTask( + FROM_HERE, base::Bind(&WifiDataProviderChromeOs::DidStartFailed, this)); return; } DoWifiScanTaskOnUIThread(); @@ -168,12 +169,13 @@ void WifiDataProviderChromeOs::DoWifiScanTaskOnUIThread() { WifiData new_data; if (!wlan_api_->GetAccessPointData(&new_data.access_point_data)) { - client_loop()->PostTask(FROM_HERE, NewRunnableMethod( - this, &WifiDataProviderChromeOs::DidWifiScanTaskNoResults)); + client_loop()->PostTask( + FROM_HERE, + base::Bind(&WifiDataProviderChromeOs::DidWifiScanTaskNoResults, this)); } else { - client_loop()->PostTask(FROM_HERE, NewRunnableMethod( - this, &WifiDataProviderChromeOs::DidWifiScanTask, - new_data)); + client_loop()->PostTask( + FROM_HERE, + base::Bind(&WifiDataProviderChromeOs::DidWifiScanTask, this, new_data)); } } @@ -212,8 +214,7 @@ void WifiDataProviderChromeOs::ScheduleNextScan(int interval) { BrowserThread::PostDelayedTask( BrowserThread::UI, FROM_HERE, - NewRunnableMethod(this, - &WifiDataProviderChromeOs::DoWifiScanTaskOnUIThread), + base::Bind(&WifiDataProviderChromeOs::DoWifiScanTaskOnUIThread, this), interval); } @@ -224,8 +225,7 @@ void WifiDataProviderChromeOs::ScheduleStop() { BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, - NewRunnableMethod(this, - &WifiDataProviderChromeOs::DoStopTaskOnUIThread)); + base::Bind(&WifiDataProviderChromeOs::DoStopTaskOnUIThread, this)); } void WifiDataProviderChromeOs::ScheduleStart() { @@ -237,6 +237,5 @@ void WifiDataProviderChromeOs::ScheduleStart() { BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, - NewRunnableMethod(this, - &WifiDataProviderChromeOs::DoStartTaskOnUIThread)); + base::Bind(&WifiDataProviderChromeOs::DoStartTaskOnUIThread, this)); } diff --git a/chrome/browser/google/google_update.cc b/chrome/browser/google/google_update.cc index aa571b9..b3f69ba 100644 --- a/chrome/browser/google/google_update.cc +++ b/chrome/browser/google/google_update.cc @@ -7,6 +7,7 @@ #include <atlbase.h> #include <atlcom.h> +#include "base/bind.h" #include "base/file_path.h" #include "base/message_loop.h" #include "base/path_service.h" @@ -231,22 +232,20 @@ void GoogleUpdate::CheckForUpdate(bool install_if_newer, // it run in the file thread. BrowserThread::PostTask( BrowserThread::FILE, FROM_HERE, - NewRunnableMethod( - this, &GoogleUpdate::InitiateGoogleUpdateCheck, install_if_newer, - window, MessageLoop::current())); + base::Bind(&GoogleUpdate::InitiateGoogleUpdateCheck, this, + install_if_newer, window, MessageLoop::current())); } //////////////////////////////////////////////////////////////////////////////// // GoogleUpdate, private: -bool GoogleUpdate::InitiateGoogleUpdateCheck(bool install_if_newer, +void GoogleUpdate::InitiateGoogleUpdateCheck(bool install_if_newer, views::Widget* window, MessageLoop* main_loop) { FilePath chrome_exe_path; - if (!PathService::Get(base::DIR_EXE, &chrome_exe_path)) { + if (!PathService::Get(base::DIR_EXE, &chrome_exe_path)) NOTREACHED(); - return false; - } + std::wstring chrome_exe = chrome_exe_path.value(); std::transform(chrome_exe.begin(), chrome_exe.end(), @@ -254,17 +253,19 @@ bool GoogleUpdate::InitiateGoogleUpdateCheck(bool install_if_newer, GoogleUpdateErrorCode error_code = CanUpdateCurrentChrome(chrome_exe); if (error_code != GOOGLE_UPDATE_NO_ERROR) { - main_loop->PostTask(FROM_HERE, NewRunnableMethod(this, - &GoogleUpdate::ReportResults, UPGRADE_ERROR, error_code)); - return false; + main_loop->PostTask( + FROM_HERE, + base::Bind(&GoogleUpdate::ReportResults, this, + UPGRADE_ERROR, error_code)); + return; } CComObject<GoogleUpdateJobObserver>* job_observer; HRESULT hr = CComObject<GoogleUpdateJobObserver>::CreateInstance(&job_observer); if (hr != S_OK) { - return ReportFailure(hr, GOOGLE_UPDATE_JOB_SERVER_CREATION_FAILED, - main_loop); + ReportFailure(hr, GOOGLE_UPDATE_JOB_SERVER_CREATION_FAILED, main_loop); + return; } base::win::ScopedComPtr<IJobObserver> job_holder(job_observer); @@ -294,8 +295,10 @@ bool GoogleUpdate::InitiateGoogleUpdateCheck(bool install_if_newer, system_level = true; } - if (hr != S_OK) - return ReportFailure(hr, GOOGLE_UPDATE_ONDEMAND_CLASS_NOT_FOUND, main_loop); + if (hr != S_OK) { + ReportFailure(hr, GOOGLE_UPDATE_ONDEMAND_CLASS_NOT_FOUND, main_loop); + return; + } std::wstring app_guid = installer::GetAppGuidForUpdates(system_level); DCHECK(!app_guid.empty()); @@ -305,9 +308,10 @@ bool GoogleUpdate::InitiateGoogleUpdateCheck(bool install_if_newer, else hr = on_demand->Update(app_guid.c_str(), job_observer); - if (hr != S_OK) - return ReportFailure(hr, GOOGLE_UPDATE_ONDEMAND_CLASS_REPORTED_ERROR, - main_loop); + if (hr != S_OK) { + ReportFailure(hr, GOOGLE_UPDATE_ONDEMAND_CLASS_REPORTED_ERROR, main_loop); + return; + } // We need to spin the message loop while Google Update is running so that it // can report back to us through GoogleUpdateJobObserver. This message loop @@ -317,21 +321,28 @@ bool GoogleUpdate::InitiateGoogleUpdateCheck(bool install_if_newer, GoogleUpdateUpgradeResult results; hr = job_observer->GetResult(&results); - if (hr != S_OK) - return ReportFailure(hr, GOOGLE_UPDATE_GET_RESULT_CALL_FAILED, main_loop); + if (hr != S_OK) { + ReportFailure(hr, GOOGLE_UPDATE_GET_RESULT_CALL_FAILED, main_loop); + return; + } - if (results == UPGRADE_ERROR) - return ReportFailure(hr, GOOGLE_UPDATE_ERROR_UPDATING, main_loop); + if (results == UPGRADE_ERROR) { + ReportFailure(hr, GOOGLE_UPDATE_ERROR_UPDATING, main_loop); + return; + } hr = job_observer->GetVersionInfo(&version_available_); - if (hr != S_OK) - return ReportFailure(hr, GOOGLE_UPDATE_GET_VERSION_INFO_FAILED, main_loop); + if (hr != S_OK) { + ReportFailure(hr, GOOGLE_UPDATE_GET_VERSION_INFO_FAILED, main_loop); + return; + } - main_loop->PostTask(FROM_HERE, NewRunnableMethod(this, - &GoogleUpdate::ReportResults, results, GOOGLE_UPDATE_NO_ERROR)); + main_loop->PostTask( + FROM_HERE, + base::Bind(&GoogleUpdate::ReportResults, this, + results, GOOGLE_UPDATE_NO_ERROR)); job_holder = NULL; on_demand = NULL; - return true; } void GoogleUpdate::ReportResults(GoogleUpdateUpgradeResult results, @@ -347,7 +358,9 @@ bool GoogleUpdate::ReportFailure(HRESULT hr, GoogleUpdateErrorCode error_code, MessageLoop* main_loop) { NOTREACHED() << "Communication with Google Update failed: " << hr << " error: " << error_code; - main_loop->PostTask(FROM_HERE, NewRunnableMethod(this, - &GoogleUpdate::ReportResults, UPGRADE_ERROR, error_code)); + main_loop->PostTask( + FROM_HERE, + base::Bind(&GoogleUpdate::ReportResults, this, + UPGRADE_ERROR, error_code)); return false; } diff --git a/chrome/browser/google/google_update.h b/chrome/browser/google/google_update.h index 293f2ca..a5e59a5 100644 --- a/chrome/browser/google/google_update.h +++ b/chrome/browser/google/google_update.h @@ -123,7 +123,7 @@ class GoogleUpdate : public base::RefCountedThreadSafe<GoogleUpdate> { // to the message loop that we want the response to come from. // |window| should point to a foreground window. This is needed to ensure that // Vista/Windows 7 UAC prompts show up in the foreground. It may also be null. - bool InitiateGoogleUpdateCheck(bool install_if_newer, views::Widget* window, + void InitiateGoogleUpdateCheck(bool install_if_newer, views::Widget* window, MessageLoop* main_loop); // This function reports the results of the GoogleUpdate operation to the diff --git a/content/browser/geolocation/access_token_store.cc b/content/browser/geolocation/access_token_store.cc index be1e578..45d0203 100644 --- a/content/browser/geolocation/access_token_store.cc +++ b/content/browser/geolocation/access_token_store.cc @@ -12,7 +12,7 @@ AccessTokenStore::~AccessTokenStore() { AccessTokenStore::Handle AccessTokenStore::LoadAccessTokens( CancelableRequestConsumerBase* consumer, - LoadAccessTokensCallbackType* callback) { + const LoadAccessTokensCallbackType& callback) { scoped_refptr<CancelableRequest<LoadAccessTokensCallbackType> > request( new CancelableRequest<LoadAccessTokensCallbackType>(callback)); AddRequest(request, consumer); diff --git a/content/browser/geolocation/access_token_store.h b/content/browser/geolocation/access_token_store.h index 804f22b..2089dfb 100644 --- a/content/browser/geolocation/access_token_store.h +++ b/content/browser/geolocation/access_token_store.h @@ -16,7 +16,7 @@ #include <map> -#include "base/callback_old.h" +#include "base/callback.h" #include "base/memory/ref_counted.h" #include "base/string16.h" #include "content/browser/cancelable_request.h" @@ -36,8 +36,9 @@ class AccessTokenStore : public base::RefCountedThreadSafe<AccessTokenStore>, // Map of server URLs to associated access token. typedef std::map<GURL, string16> AccessTokenSet; - typedef Callback2<AccessTokenSet, net::URLRequestContextGetter*>::Type + typedef base::Callback<void(AccessTokenSet, net::URLRequestContextGetter*)> LoadAccessTokensCallbackType; + // |callback| will be invoked once per LoadAccessTokens call, after existing // access tokens have been loaded from persistent store. As a convenience the // URLRequestContextGetter is also supplied as an argument in |callback|, as @@ -47,7 +48,7 @@ class AccessTokenStore : public base::RefCountedThreadSafe<AccessTokenStore>, // Returns a handle which can subsequently be used with CancelRequest(). CONTENT_EXPORT Handle LoadAccessTokens( CancelableRequestConsumerBase* consumer, - LoadAccessTokensCallbackType* callback); + const LoadAccessTokensCallbackType& callback); virtual void SaveAccessToken( const GURL& server_url, const string16& access_token) = 0; diff --git a/content/browser/geolocation/fake_access_token_store.cc b/content/browser/geolocation/fake_access_token_store.cc index 548c127..4b2dc53 100644 --- a/content/browser/geolocation/fake_access_token_store.cc +++ b/content/browser/geolocation/fake_access_token_store.cc @@ -19,7 +19,7 @@ FakeAccessTokenStore::FakeAccessTokenStore() { void FakeAccessTokenStore::NotifyDelegateTokensLoaded() { CHECK(request_ != NULL); net::URLRequestContextGetter* context_getter = NULL; - request_->ForwardResult(MakeTuple(access_token_set_, context_getter)); + request_->ForwardResult(access_token_set_, context_getter); request_ = NULL; } diff --git a/content/browser/geolocation/location_arbitrator.cc b/content/browser/geolocation/location_arbitrator.cc index 0160e4e..2765cdc 100644 --- a/content/browser/geolocation/location_arbitrator.cc +++ b/content/browser/geolocation/location_arbitrator.cc @@ -6,6 +6,8 @@ #include <map> +#include "base/bind.h" +#include "base/bind_helpers.h" #include "content/browser/geolocation/arbitrator_dependency_factory.h" namespace { @@ -63,8 +65,8 @@ void GeolocationArbitrator::StartProviders( DCHECK(GURL(kDefaultNetworkProviderUrl).is_valid()); access_token_store_->LoadAccessTokens( &request_consumer_, - NewCallback(this, - &GeolocationArbitrator::OnAccessTokenStoresLoaded)); + base::Bind(&GeolocationArbitrator::OnAccessTokenStoresLoaded, + base::Unretained(this))); } else { DoStartProviders(); } |