diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-07 23:15:32 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-07 23:15:32 +0000 |
commit | 5f294031db12d64ea7eb1788c9aabf001a90653c (patch) | |
tree | 456ab18e2c22e31d75d7055db85f2cd8a2fde590 /chrome | |
parent | a1b7a0fdd7d3f33cbaeefd2f41b0c2ee86449394 (diff) | |
download | chromium_src-5f294031db12d64ea7eb1788c9aabf001a90653c.zip chromium_src-5f294031db12d64ea7eb1788c9aabf001a90653c.tar.gz chromium_src-5f294031db12d64ea7eb1788c9aabf001a90653c.tar.bz2 |
base::Bind: Complete cleanup of history/.
BUG=none
TEST=none
R=csilv@chromium.org
Review URL: http://codereview.chromium.org/8163005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104597 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
57 files changed, 397 insertions, 362 deletions
diff --git a/chrome/browser/autocomplete/history_contents_provider.cc b/chrome/browser/autocomplete/history_contents_provider.cc index 7061daf..6ec694c 100644 --- a/chrome/browser/autocomplete/history_contents_provider.cc +++ b/chrome/browser/autocomplete/history_contents_provider.cc @@ -4,7 +4,8 @@ #include "chrome/browser/autocomplete/history_contents_provider.h" -#include "base/callback.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/metrics/histogram.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" @@ -137,7 +138,8 @@ void HistoryContentsProvider::Start(const AutocompleteInput& input, options.max_count = kMaxMatches; history->QueryHistory(input.text(), options, &request_consumer_, - NewCallback(this, &HistoryContentsProvider::QueryComplete)); + base::Bind(&HistoryContentsProvider::QueryComplete, + base::Unretained(this))); } } } diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc index cb6b2ec..21e47b6 100644 --- a/chrome/browser/automation/automation_provider_observers.cc +++ b/chrome/browser/automation/automation_provider_observers.cc @@ -1737,8 +1737,8 @@ void PasswordStoreLoginsChangedObserver::Init() { BrowserThread::PostTask( BrowserThread::DB, FROM_HERE, - NewRunnableMethod( - this, &PasswordStoreLoginsChangedObserver::RegisterObserversTask)); + base::Bind(&PasswordStoreLoginsChangedObserver::RegisterObserversTask, + this)); done_event_.Wait(); } @@ -1764,8 +1764,8 @@ void PasswordStoreLoginsChangedObserver::Observe( BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, - NewRunnableMethod( - this, &PasswordStoreLoginsChangedObserver::IndicateError, error)); + base::Bind(&PasswordStoreLoginsChangedObserver::IndicateError, this, + error)); return; } @@ -1775,8 +1775,7 @@ void PasswordStoreLoginsChangedObserver::Observe( BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, - NewRunnableMethod( - this, &PasswordStoreLoginsChangedObserver::IndicateDone)); + base::Bind(&PasswordStoreLoginsChangedObserver::IndicateDone, this)); } void PasswordStoreLoginsChangedObserver::IndicateDone() { @@ -1909,8 +1908,8 @@ void PageSnapshotTaker::OnDomOperationCompleted(const std::string& json) { ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator(); - ThumbnailGenerator::ThumbnailReadyCallback* callback = - NewCallback(this, &PageSnapshotTaker::OnSnapshotTaken); + ThumbnailGenerator::ThumbnailReadyCallback callback = + base::Bind(&PageSnapshotTaker::OnSnapshotTaken, base::Unretained(this)); // Don't actually start the thumbnail generator, this leads to crashes on // Mac, crbug.com/62986. Instead, just hook the generator to the // RenderViewHost manually. @@ -2273,7 +2272,7 @@ void AutofillChangedObserver::Init() { BrowserThread::PostTask( BrowserThread::DB, FROM_HERE, - NewRunnableMethod(this, &AutofillChangedObserver::RegisterObserversTask)); + base::Bind(&AutofillChangedObserver::RegisterObserversTask, this)); done_event_.Wait(); } @@ -2308,7 +2307,7 @@ void AutofillChangedObserver::Observe( BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, - NewRunnableMethod(this, &AutofillChangedObserver::IndicateDone)); + base::Bind(&AutofillChangedObserver::IndicateDone, this)); } } @@ -2690,10 +2689,10 @@ WaitForProcessLauncherThreadToGoIdleObserver( AddRef(); BrowserThread::PostTask( BrowserThread::PROCESS_LAUNCHER, FROM_HERE, - NewRunnableMethod( - this, + base::Bind( &WaitForProcessLauncherThreadToGoIdleObserver:: - RunOnProcessLauncherThread)); + RunOnProcessLauncherThread, + this)); } WaitForProcessLauncherThreadToGoIdleObserver:: @@ -2705,10 +2704,10 @@ RunOnProcessLauncherThread() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::PROCESS_LAUNCHER)); BrowserThread::PostTask( BrowserThread::PROCESS_LAUNCHER, FROM_HERE, - NewRunnableMethod( - this, + base::Bind( &WaitForProcessLauncherThreadToGoIdleObserver:: - RunOnProcessLauncherThread2)); + RunOnProcessLauncherThread2, + this)); } void WaitForProcessLauncherThreadToGoIdleObserver:: @@ -2716,9 +2715,8 @@ RunOnProcessLauncherThread2() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::PROCESS_LAUNCHER)); BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, - NewRunnableMethod( - this, - &WaitForProcessLauncherThreadToGoIdleObserver::RunOnUIThread)); + base::Bind(&WaitForProcessLauncherThreadToGoIdleObserver::RunOnUIThread, + this)); } void WaitForProcessLauncherThreadToGoIdleObserver::RunOnUIThread() { diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index 2a0739a..4c0a523 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -10,6 +10,7 @@ #include <vector> #include "base/bind.h" +#include "base/bind_helpers.h" #include "base/command_line.h" #include "base/file_path.h" #include "base/json/json_reader.h" @@ -738,8 +739,8 @@ void TestingAutomationProvider::GetRedirectsFrom(int tab_handle, // that it's done: OnRedirectQueryComplete. redirect_query_ = history_service->QueryRedirectsFrom( source_url, &consumer_, - NewCallback(this, - &TestingAutomationProvider::OnRedirectQueryComplete)); + base::Bind(&TestingAutomationProvider::OnRedirectQueryComplete, + base::Unretained(this))); return; // Response will be sent when query completes. } } @@ -3021,8 +3022,8 @@ void TestingAutomationProvider::GetHistoryInfo(Browser* browser, search_text, options, &consumer_, - NewCallback(history_observer, - &AutomationProviderHistoryObserver::HistoryQueryComplete)); + base::Bind(&AutomationProviderHistoryObserver::HistoryQueryComplete, + base::Unretained(history_observer))); } // Sample json input: { "command": "AddHistoryItem", diff --git a/chrome/browser/bookmarks/bookmark_html_writer.cc b/chrome/browser/bookmarks/bookmark_html_writer.cc index 8952d65..c6065ac 100644 --- a/chrome/browser/bookmarks/bookmark_html_writer.cc +++ b/chrome/browser/bookmarks/bookmark_html_writer.cc @@ -5,6 +5,8 @@ #include "chrome/browser/bookmarks/bookmark_html_writer.h" #include "base/base64.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/callback.h" #include "base/file_path.h" #include "base/memory/scoped_ptr.h" @@ -448,7 +450,8 @@ bool BookmarkFaviconFetcher::FetchNextFavicon() { profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); favicon_service->GetFaviconForURL(GURL(url), history::FAVICON, &favicon_consumer_, - NewCallback(this, &BookmarkFaviconFetcher::OnFaviconDataAvailable)); + base::Bind(&BookmarkFaviconFetcher::OnFaviconDataAvailable, + base::Unretained(this))); return true; } else { bookmark_urls_.pop_front(); diff --git a/chrome/browser/bookmarks/bookmark_model.cc b/chrome/browser/bookmarks/bookmark_model.cc index 18bb942..b9db127 100644 --- a/chrome/browser/bookmarks/bookmark_model.cc +++ b/chrome/browser/bookmarks/bookmark_model.cc @@ -7,7 +7,8 @@ #include <algorithm> #include <functional> -#include "base/callback.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/command_line.h" #include "base/memory/scoped_vector.h" #include "build/build_config.h" @@ -749,7 +750,8 @@ void BookmarkModel::LoadFavicon(BookmarkNode* node) { return; FaviconService::Handle handle = favicon_service->GetFaviconForURL( node->url(), history::FAVICON, &load_consumer_, - NewCallback(this, &BookmarkModel::OnFaviconDataAvailable)); + base::Bind(&BookmarkModel::OnFaviconDataAvailable, + base::Unretained(this))); load_consumer_.SetClientData(favicon_service, handle, node); node->set_favicon_load_handle(handle); } diff --git a/chrome/browser/browsing_data_remover.cc b/chrome/browser/browsing_data_remover.cc index 0d7f021..0cfc15d 100644 --- a/chrome/browser/browsing_data_remover.cc +++ b/chrome/browser/browsing_data_remover.cc @@ -8,6 +8,7 @@ #include <set> #include "base/bind.h" +#include "base/bind_helpers.h" #include "base/callback.h" #include "base/file_util.h" #include "base/logging.h" @@ -136,7 +137,8 @@ void BrowsingDataRemover::Remove(int remove_mask) { history_service->ExpireHistoryBetween(restrict_urls, delete_begin_, delete_end_, &request_consumer_, - NewCallback(this, &BrowsingDataRemover::OnHistoryDeletionDone)); + base::Bind(&BrowsingDataRemover::OnHistoryDeletionDone, + base::Unretained(this))); } // Need to clear the host cache and accumulated speculative data, as it also diff --git a/chrome/browser/custom_home_pages_table_model.cc b/chrome/browser/custom_home_pages_table_model.cc index 9f09f92..e1e2ab7 100644 --- a/chrome/browser/custom_home_pages_table_model.cc +++ b/chrome/browser/custom_home_pages_table_model.cc @@ -226,7 +226,8 @@ void CustomHomePagesTableModel::LoadTitleAndFavicon(Entry* entry) { if (favicon_service) { entry->favicon_handle = favicon_service->GetFaviconForURL(entry->url, history::FAVICON, &favicon_query_consumer_, - NewCallback(this, &CustomHomePagesTableModel::OnGotFavicon)); + base::Bind(&CustomHomePagesTableModel::OnGotFavicon, + base::Unretained(this))); } } diff --git a/chrome/browser/download/chrome_download_manager_delegate.cc b/chrome/browser/download/chrome_download_manager_delegate.cc index 80c6dbc..08f7265 100644 --- a/chrome/browser/download/chrome_download_manager_delegate.cc +++ b/chrome/browser/download/chrome_download_manager_delegate.cc @@ -4,6 +4,8 @@ #include "chrome/browser/download/chrome_download_manager_delegate.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/callback.h" #include "base/file_util.h" #include "base/path_service.h" @@ -59,9 +61,11 @@ void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) { download_manager_ = dm; download_history_.reset(new DownloadHistory(profile_)); download_history_->Load( - NewCallback(dm, &DownloadManager::OnPersistentStoreQueryComplete)); + base::Bind(&DownloadManager::OnPersistentStoreQueryComplete, + base::Unretained(dm))); download_history_->GetNextId( - NewCallback(dm, &DownloadManager::OnPersistentStoreGetNextId)); + base::Bind(&DownloadManager::OnPersistentStoreGetNextId, + base::Unretained(dm))); } void ChromeDownloadManagerDelegate::Shutdown() { @@ -206,8 +210,8 @@ void ChromeDownloadManagerDelegate::OnResponseCompleted( void ChromeDownloadManagerDelegate::AddItemToPersistentStore( DownloadItem* item) { download_history_->AddEntry(item, - NewCallback(this, - &ChromeDownloadManagerDelegate::OnItemAddedToPersistentStore)); + base::Bind(&ChromeDownloadManagerDelegate::OnItemAddedToPersistentStore, + base::Unretained(this))); } void ChromeDownloadManagerDelegate::UpdateItemInPersistentStore( @@ -293,8 +297,10 @@ void ChromeDownloadManagerDelegate::CheckDownloadUrlDone( if (is_dangerous_url) download->MarkUrlDangerous(); - download_history_->CheckVisitedReferrerBefore(download_id, - download->referrer_url(), NewCallback(this, + download_history_->CheckVisitedReferrerBefore( + download_id, download->referrer_url(), + NewCallback( + this, &ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone)); } @@ -380,12 +386,9 @@ void ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone( // now and pass the value to the FILE thread. BrowserThread::PostTask( BrowserThread::FILE, FROM_HERE, - NewRunnableMethod( - this, - &ChromeDownloadManagerDelegate::CheckIfSuggestedPathExists, - download->id(), - state, - download_prefs_->download_path())); + base::Bind(&ChromeDownloadManagerDelegate::CheckIfSuggestedPathExists, + this, download->id(), state, + download_prefs_->download_path())); } void ChromeDownloadManagerDelegate::CheckIfSuggestedPathExists( @@ -472,11 +475,8 @@ void ChromeDownloadManagerDelegate::CheckIfSuggestedPathExists( BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, - NewRunnableMethod( - this, - &ChromeDownloadManagerDelegate::OnPathExistenceAvailable, - download_id, - state)); + base::Bind(&ChromeDownloadManagerDelegate::OnPathExistenceAvailable, + this, download_id, state)); } void ChromeDownloadManagerDelegate::OnPathExistenceAvailable( diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc index f613b27..a6265d5 100644 --- a/chrome/browser/download/download_browsertest.cc +++ b/chrome/browser/download/download_browsertest.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "base/bind.h" +#include "base/bind_helpers.h" #include "base/file_path.h" #include "base/file_util.h" #include "base/memory/ref_counted.h" @@ -521,8 +522,8 @@ class DownloadsHistoryDataCollector { DCHECK(hs); hs->QueryDownloads( &callback_consumer_, - NewCallback(this, - &DownloadsHistoryDataCollector::OnQueryDownloadsComplete)); + base::Bind(&DownloadsHistoryDataCollector::OnQueryDownloadsComplete, + base::Unretained(this))); // TODO(rdsmith): Move message loop out of constructor. // Cannot complete immediately because the history backend runs on a diff --git a/chrome/browser/download/download_history.cc b/chrome/browser/download/download_history.cc index 426a434..0398a3c 100644 --- a/chrome/browser/download/download_history.cc +++ b/chrome/browser/download/download_history.cc @@ -28,23 +28,20 @@ DownloadHistory::~DownloadHistory() { } void DownloadHistory::GetNextId( - HistoryService::DownloadNextIdCallback* callback) { - DCHECK(callback); + const HistoryService::DownloadNextIdCallback& callback) { HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); - if (!hs) { - delete callback; + if (!hs) return; - } + hs->GetNextDownloadId(&history_consumer_, callback); } -void DownloadHistory::Load(HistoryService::DownloadQueryCallback* callback) { - DCHECK(callback); +void DownloadHistory::Load( + const HistoryService::DownloadQueryCallback& callback) { HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); - if (!hs) { - delete callback; + if (!hs) return; - } + hs->QueryDownloads(&history_consumer_, callback); // This is the initial load, so do a cleanup of corrupt in-progress entries. @@ -62,7 +59,8 @@ void DownloadHistory::CheckVisitedReferrerBefore( if (hs) { HistoryService::Handle handle = hs->GetVisibleVisitCountToHost(referrer_url, &history_consumer_, - NewCallback(this, &DownloadHistory::OnGotVisitCountToHost)); + base::Bind(&DownloadHistory::OnGotVisitCountToHost, + base::Unretained(this))); visited_before_requests_[handle] = std::make_pair(download_id, callback); return; } @@ -73,7 +71,7 @@ void DownloadHistory::CheckVisitedReferrerBefore( void DownloadHistory::AddEntry( DownloadItem* download_item, - HistoryService::DownloadCreateCallback* callback) { + const HistoryService::DownloadCreateCallback& callback) { DCHECK(download_item); // Do not store the download in the history database for a few special cases: // - incognito mode (that is the point of this mode) @@ -88,10 +86,7 @@ void DownloadHistory::AddEntry( if (download_item->is_otr() || ChromeDownloadManagerDelegate::IsExtensionDownload(download_item) || download_item->is_temporary() || !hs) { - callback->RunWithParams( - history::DownloadCreateRequest::TupleType(download_item->id(), - GetNextFakeDbHandle())); - delete callback; + callback.Run(download_item->id(), GetNextFakeDbHandle()); return; } diff --git a/chrome/browser/download/download_history.h b/chrome/browser/download/download_history.h index 45f978b..06c7df9 100644 --- a/chrome/browser/download/download_history.h +++ b/chrome/browser/download/download_history.h @@ -9,6 +9,7 @@ #include <map> #include "base/basictypes.h" +#include "base/callback_old.h" #include "chrome/browser/history/history.h" #include "content/browser/cancelable_request.h" @@ -30,10 +31,10 @@ class DownloadHistory { // Retrieves the next_id counter from the sql meta_table. // Should be much faster than Load so that we may delay downloads until after // this call with minimal performance penalty. - void GetNextId(HistoryService::DownloadNextIdCallback* callback); + void GetNextId(const HistoryService::DownloadNextIdCallback& callback); // Retrieves DownloadCreateInfos saved in the history. - void Load(HistoryService::DownloadQueryCallback* callback); + void Load(const HistoryService::DownloadQueryCallback& callback); // Checks whether |referrer_url| has been visited before today. This takes // ownership of |callback|. @@ -43,7 +44,7 @@ class DownloadHistory { // Adds a new entry for a download to the history database. void AddEntry(DownloadItem* download_item, - HistoryService::DownloadCreateCallback* callback); + const HistoryService::DownloadCreateCallback& callback); // Updates the history entry for |download_item|. void UpdateEntry(DownloadItem* download_item); diff --git a/chrome/browser/download/save_page_browsertest.cc b/chrome/browser/download/save_page_browsertest.cc index b7ae2fb..8709b1e 100644 --- a/chrome/browser/download/save_page_browsertest.cc +++ b/chrome/browser/download/save_page_browsertest.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "base/bind.h" +#include "base/bind_helpers.h" #include "base/file_path.h" #include "base/file_util.h" #include "base/path_service.h" @@ -133,8 +134,8 @@ class SavePageBrowserTest : public InProcessBrowserTest { static_cast<ChromeDownloadManagerDelegate*>( GetDownloadManager()->delegate()); delegate->download_history()->Load( - NewCallback(this, - &SavePageBrowserTest::OnQueryDownloadEntriesComplete)); + base::Bind(&SavePageBrowserTest::OnQueryDownloadEntriesComplete, + base::Unretained(this))); // Run message loop until a quit message is sent from // OnQueryDownloadEntriesComplete(). diff --git a/chrome/browser/extensions/extension_history_api.cc b/chrome/browser/extensions/extension_history_api.cc index 3f4dda7..e6c6a8a 100644 --- a/chrome/browser/extensions/extension_history_api.cc +++ b/chrome/browser/extensions/extension_history_api.cc @@ -272,7 +272,8 @@ bool SearchHistoryFunction::RunAsyncImpl() { HistoryService* hs = profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); hs->QueryHistory(search_text, options, &cancelable_consumer_, - NewCallback(this, &SearchHistoryFunction::SearchComplete)); + base::Bind(&SearchHistoryFunction::SearchComplete, + base::Unretained(this))); return true; } @@ -349,7 +350,8 @@ bool DeleteRangeHistoryFunction::RunAsyncImpl() { begin_time, end_time, &cancelable_consumer_, - NewCallback(this, &DeleteRangeHistoryFunction::DeleteComplete)); + base::Bind(&DeleteRangeHistoryFunction::DeleteComplete, + base::Unretained(this))); return true; } @@ -366,7 +368,8 @@ bool DeleteAllHistoryFunction::RunAsyncImpl() { base::Time::UnixEpoch(), // From the beginning of the epoch. base::Time::Now(), // To the current time. &cancelable_consumer_, - NewCallback(this, &DeleteAllHistoryFunction::DeleteComplete)); + base::Bind(&DeleteAllHistoryFunction::DeleteComplete, + base::Unretained(this))); return true; } diff --git a/chrome/browser/extensions/extension_web_ui.cc b/chrome/browser/extensions/extension_web_ui.cc index ccb77d5..eeca442 100644 --- a/chrome/browser/extensions/extension_web_ui.cc +++ b/chrome/browser/extensions/extension_web_ui.cc @@ -108,9 +108,7 @@ class ExtensionWebUIImageLoadingTracker : public ImageLoadingTracker::Observer { favicon.known_icon = icon_data.get() != NULL && icon_data->size() > 0; favicon.image_data = icon_data; favicon.icon_type = history::FAVICON; - request_->ForwardResultAsync( - FaviconService::FaviconDataCallback::TupleType(request_->handle(), - favicon)); + request_->ForwardResultAsync(request_->handle(), favicon); delete this; } diff --git a/chrome/browser/favicon/favicon_handler.cc b/chrome/browser/favicon/favicon_handler.cc index b14bf9b..9385c39 100644 --- a/chrome/browser/favicon/favicon_handler.cc +++ b/chrome/browser/favicon/favicon_handler.cc @@ -8,6 +8,8 @@ #include <vector> +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/callback.h" #include "base/memory/ref_counted_memory.h" #include "chrome/browser/bookmarks/bookmark_model.h" @@ -101,7 +103,8 @@ void FaviconHandler::FetchFavicon(const GURL& url) { // available. if (GetFaviconService()) { GetFaviconForURL(url_, icon_types_, &cancelable_consumer_, - NewCallback(this, &FaviconHandler::OnFaviconDataForInitialURL)); + base::Bind(&FaviconHandler::OnFaviconDataForInitialURL, + base::Unretained(this))); } } @@ -267,7 +270,7 @@ void FaviconHandler::UpdateFaviconMappingAndFetch( const GURL& icon_url, history::IconType icon_type, CancelableRequestConsumerBase* consumer, - FaviconService::FaviconDataCallback* callback) { + const FaviconService::FaviconDataCallback& callback) { GetFaviconService()->UpdateFaviconMappingAndFetch(page_url, icon_url, icon_type, consumer, callback); } @@ -276,7 +279,7 @@ void FaviconHandler::GetFavicon( const GURL& icon_url, history::IconType icon_type, CancelableRequestConsumerBase* consumer, - FaviconService::FaviconDataCallback* callback) { + const FaviconService::FaviconDataCallback& callback) { GetFaviconService()->GetFavicon(icon_url, icon_type, consumer, callback); } @@ -284,7 +287,7 @@ void FaviconHandler::GetFaviconForURL( const GURL& page_url, int icon_types, CancelableRequestConsumerBase* consumer, - FaviconService::FaviconDataCallback* callback) { + const FaviconService::FaviconDataCallback& callback) { GetFaviconService()->GetFaviconForURL(page_url, icon_types, consumer, callback); } @@ -368,7 +371,7 @@ void FaviconHandler::DownloadFaviconOrAskHistory( // favicon given the favicon URL. if (profile_->IsOffTheRecord()) { GetFavicon(icon_url, icon_type, &cancelable_consumer_, - NewCallback(this, &FaviconHandler::OnFaviconData)); + base::Bind(&FaviconHandler::OnFaviconData, base::Unretained(this))); } else { // Ask the history service for the icon. This does two things: // 1. Attempts to fetch the favicon data from the database. @@ -378,7 +381,7 @@ void FaviconHandler::DownloadFaviconOrAskHistory( // Issue the request and associate the current page ID with it. UpdateFaviconMappingAndFetch(page_url, icon_url, icon_type, &cancelable_consumer_, - NewCallback(this, &FaviconHandler::OnFaviconData)); + base::Bind(&FaviconHandler::OnFaviconData, base::Unretained(this))); } } } diff --git a/chrome/browser/favicon/favicon_handler.h b/chrome/browser/favicon/favicon_handler.h index ccdae05..da979f9 100644 --- a/chrome/browser/favicon/favicon_handler.h +++ b/chrome/browser/favicon/favicon_handler.h @@ -127,19 +127,19 @@ class FaviconHandler { const GURL& icon_url, history::IconType icon_type, CancelableRequestConsumerBase* consumer, - FaviconService::FaviconDataCallback* callback); + const FaviconService::FaviconDataCallback& callback); virtual void GetFavicon( const GURL& icon_url, history::IconType icon_type, CancelableRequestConsumerBase* consumer, - FaviconService::FaviconDataCallback* callback); + const FaviconService::FaviconDataCallback& callback); virtual void GetFaviconForURL( const GURL& page_url, int icon_types, CancelableRequestConsumerBase* consumer, - FaviconService::FaviconDataCallback* callback); + const FaviconService::FaviconDataCallback& callback); virtual void SetHistoryFavicon(const GURL& page_url, const GURL& icon_url, diff --git a/chrome/browser/favicon/favicon_handler_unittest.cc b/chrome/browser/favicon/favicon_handler_unittest.cc index 3eba39a..bdf05d8 100644 --- a/chrome/browser/favicon/favicon_handler_unittest.cc +++ b/chrome/browser/favicon/favicon_handler_unittest.cc @@ -86,7 +86,7 @@ class HistoryRequestHandler { HistoryRequestHandler(const GURL& page_url, const GURL& icon_url, int icon_type, - FaviconService::FaviconDataCallback* callback) + const FaviconService::FaviconDataCallback& callback) : page_url_(page_url), icon_url_(icon_url), icon_type_(icon_type), @@ -97,7 +97,7 @@ class HistoryRequestHandler { const GURL& icon_url, int icon_type, const std::vector<unsigned char>& image_data, - FaviconService::FaviconDataCallback* callback) + const FaviconService::FaviconDataCallback& callback) : page_url_(page_url), icon_url_(icon_url), icon_type_(icon_type), @@ -105,9 +105,7 @@ class HistoryRequestHandler { callback_(callback) { } - virtual ~HistoryRequestHandler() { - delete callback_; - } + virtual ~HistoryRequestHandler() {} void InvokeCallback(); const GURL page_url_; @@ -115,7 +113,7 @@ class HistoryRequestHandler { const int icon_type_; const std::vector<unsigned char> image_data_; history::FaviconData favicon_data_; - FaviconService::FaviconDataCallback* callback_; + FaviconService::FaviconDataCallback callback_; private: DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler); @@ -219,7 +217,7 @@ class TestFaviconHandler : public FaviconHandler { const GURL& icon_url, history::IconType icon_type, CancelableRequestConsumerBase* consumer, - FaviconService::FaviconDataCallback* callback) OVERRIDE { + const FaviconService::FaviconDataCallback& callback) OVERRIDE { history_handler_.reset(new HistoryRequestHandler(page_url, icon_url, icon_type, callback)); } @@ -228,7 +226,7 @@ class TestFaviconHandler : public FaviconHandler { const GURL& icon_url, history::IconType icon_type, CancelableRequestConsumerBase* consumer, - FaviconService::FaviconDataCallback* callback) OVERRIDE { + const FaviconService::FaviconDataCallback& callback) OVERRIDE { history_handler_.reset(new HistoryRequestHandler(GURL(), icon_url, icon_type, callback)); } @@ -237,7 +235,7 @@ class TestFaviconHandler : public FaviconHandler { const GURL& page_url, int icon_types, CancelableRequestConsumerBase* consumer, - FaviconService::FaviconDataCallback* callback) OVERRIDE { + const FaviconService::FaviconDataCallback& callback) OVERRIDE { history_handler_.reset(new HistoryRequestHandler(page_url, GURL(), icon_types, callback)); } @@ -253,8 +251,9 @@ class TestFaviconHandler : public FaviconHandler { const GURL& icon_url, const std::vector<unsigned char>& image_data, history::IconType icon_type) OVERRIDE { - history_handler_.reset(new HistoryRequestHandler(page_url, icon_url, - icon_type, image_data, NULL)); + history_handler_.reset(new HistoryRequestHandler( + page_url, icon_url,icon_type, image_data, + FaviconService::FaviconDataCallback())); } virtual FaviconService* GetFaviconService() OVERRIDE { @@ -302,7 +301,7 @@ void DownloadHandler::InvokeCallback() { } void HistoryRequestHandler::InvokeCallback() { - callback_->Run(0, favicon_data_); + callback_.Run(0, favicon_data_); } class FaviconHandlerTest : public ChromeRenderViewHostTestHarness { @@ -786,19 +785,17 @@ TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { // Reset the history_handler to verify whether favicon is request from // history. // Save the callback for late use. - FaviconService::FaviconDataCallback* callback = history_handler->callback_; - // Prevent the callback from being released. - history_handler->callback_ = NULL; + FaviconService::FaviconDataCallback callback = history_handler->callback_; helper.set_history_handler(NULL); - // Smulates download succeed. + // Simulates download succeed. download_handler->InvokeCallback(); - // The downloaded icon should be thrown away as there is faviocn update. + // The downloaded icon should be thrown away as there is favicon update. EXPECT_FALSE(helper.history_handler()); helper.set_download_handler(NULL); - // Smulates getting the icon from history. + // Simulates getting the icon from history. scoped_ptr<HistoryRequestHandler> handler; handler.reset(new HistoryRequestHandler(page_url, latest_icon_url, history::TOUCH_ICON, callback)); diff --git a/chrome/browser/favicon/favicon_service.cc b/chrome/browser/favicon/favicon_service.cc index a276c7c..5efd081 100644 --- a/chrome/browser/favicon/favicon_service.cc +++ b/chrome/browser/favicon/favicon_service.cc @@ -17,7 +17,7 @@ FaviconService::Handle FaviconService::GetFavicon( const GURL& icon_url, history::IconType icon_type, CancelableRequestConsumerBase* consumer, - FaviconDataCallback* callback) { + const FaviconDataCallback& callback) { GetFaviconRequest* request = new GetFaviconRequest(callback); AddRequest(request, consumer); HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); @@ -33,7 +33,7 @@ FaviconService::Handle FaviconService::UpdateFaviconMappingAndFetch( const GURL& icon_url, history::IconType icon_type, CancelableRequestConsumerBase* consumer, - FaviconService::FaviconDataCallback* callback) { + const FaviconDataCallback& callback) { GetFaviconRequest* request = new GetFaviconRequest(callback); AddRequest(request, consumer); HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); @@ -48,7 +48,7 @@ FaviconService::Handle FaviconService::GetFaviconForURL( const GURL& page_url, int icon_types, CancelableRequestConsumerBase* consumer, - FaviconDataCallback* callback) { + const FaviconDataCallback& callback) { GetFaviconRequest* request = new GetFaviconRequest(callback); AddRequest(request, consumer); FaviconService::Handle handle = request->handle(); @@ -92,6 +92,5 @@ FaviconService::~FaviconService() { } void FaviconService::ForwardEmptyResultAsync(GetFaviconRequest* request) { - request->ForwardResultAsync(FaviconDataCallback::TupleType( - request->handle(), history::FaviconData())); + request->ForwardResultAsync(request->handle(), history::FaviconData()); } diff --git a/chrome/browser/favicon/favicon_service.h b/chrome/browser/favicon/favicon_service.h index 2062239..4fb313b 100644 --- a/chrome/browser/favicon/favicon_service.h +++ b/chrome/browser/favicon/favicon_service.h @@ -8,7 +8,7 @@ #include <vector> -#include "base/callback_old.h" +#include "base/callback.h" #include "base/memory/ref_counted.h" #include "base/memory/ref_counted_memory.h" #include "base/task.h" @@ -40,9 +40,10 @@ class FaviconService : public CancelableRequestProvider { // opposed to not knowing anything). |expired| will be set to true if we // refreshed the favicon "too long" ago and should be updated if the page // is visited again. - typedef Callback2<Handle, // handle - history::FaviconData>::Type // the type of favicon - FaviconDataCallback; + typedef base::Callback< + void(Handle, // handle + history::FaviconData)> // the type of favicon + FaviconDataCallback; typedef CancelableRequest<FaviconDataCallback> GetFaviconRequest; @@ -52,7 +53,7 @@ class FaviconService : public CancelableRequestProvider { Handle GetFavicon(const GURL& icon_url, history::IconType icon_type, CancelableRequestConsumerBase* consumer, - FaviconDataCallback* callback); + const FaviconDataCallback& callback); // Fetches the |icon_type| of favicon at |icon_url|, sending the results to // the given |callback|. If the favicon has previously been set via @@ -63,7 +64,7 @@ class FaviconService : public CancelableRequestProvider { const GURL& icon_url, history::IconType icon_type, CancelableRequestConsumerBase* consumer, - FaviconDataCallback* callback); + const FaviconDataCallback& callback); // Requests any |icon_types| of favicon for a web page URL. |consumer| is // notified when the bits have been fetched. |icon_types| can be any @@ -76,7 +77,7 @@ class FaviconService : public CancelableRequestProvider { Handle GetFaviconForURL(const GURL& page_url, int icon_types, CancelableRequestConsumerBase* consumer, - FaviconDataCallback* callback); + const FaviconDataCallback& callback); // Marks all types of favicon for the page as being out of date. void SetFaviconOutOfDateForPage(const GURL& page_url); diff --git a/chrome/browser/favicon/favicon_tab_helper.h b/chrome/browser/favicon/favicon_tab_helper.h index c236f75..97e8d63 100644 --- a/chrome/browser/favicon/favicon_tab_helper.h +++ b/chrome/browser/favicon/favicon_tab_helper.h @@ -7,7 +7,7 @@ #pragma once #include "base/basictypes.h" -#include "base/callback.h" +#include "base/callback_old.h" #include "chrome/browser/favicon/favicon_handler_delegate.h" #include "chrome/browser/favicon/favicon_service.h" #include "chrome/common/favicon_url.h" diff --git a/chrome/browser/history/expire_history_backend.cc b/chrome/browser/history/expire_history_backend.cc index 0542ab8..0149646 100644 --- a/chrome/browser/history/expire_history_backend.cc +++ b/chrome/browser/history/expire_history_backend.cc @@ -7,6 +7,7 @@ #include <algorithm> #include <limits> +#include "base/bind.h" #include "base/compiler_specific.h" #include "base/file_util.h" #include "base/message_loop.h" @@ -168,7 +169,7 @@ ExpireHistoryBackend::ExpireHistoryBackend( archived_db_(NULL), thumb_db_(NULL), text_db_(NULL), - ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)), + ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), bookmark_service_(bookmark_service) { } @@ -573,8 +574,11 @@ void ExpireHistoryBackend::ScheduleArchive() { delay = TimeDelta::FromSeconds(kExpirationDelaySec); } - MessageLoop::current()->PostDelayedTask(FROM_HERE, factory_.NewRunnableMethod( - &ExpireHistoryBackend::DoArchiveIteration), delay.InMilliseconds()); + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&ExpireHistoryBackend::DoArchiveIteration, + weak_factory_.GetWeakPtr()), + delay.InMilliseconds()); } void ExpireHistoryBackend::DoArchiveIteration() { @@ -666,8 +670,9 @@ void ExpireHistoryBackend::ScheduleExpireHistoryIndexFiles() { TimeDelta delay = TimeDelta::FromMinutes(kIndexExpirationDelayMin); MessageLoop::current()->PostDelayedTask( - FROM_HERE, factory_.NewRunnableMethod( - &ExpireHistoryBackend::DoExpireHistoryIndexFiles), + FROM_HERE, + base::Bind(&ExpireHistoryBackend::DoExpireHistoryIndexFiles, + weak_factory_.GetWeakPtr()), delay.InMilliseconds()); } diff --git a/chrome/browser/history/expire_history_backend.h b/chrome/browser/history/expire_history_backend.h index 753331a..babb829 100644 --- a/chrome/browser/history/expire_history_backend.h +++ b/chrome/browser/history/expire_history_backend.h @@ -13,6 +13,7 @@ #include "base/basictypes.h" #include "base/gtest_prod_util.h" #include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" #include "base/task.h" #include "base/time.h" #include "chrome/browser/history/history_types.h" @@ -260,7 +261,7 @@ class ExpireHistoryBackend { // Used to generate runnable methods to do timers on this class. They will be // automatically canceled when this class is deleted. - ScopedRunnableMethodFactory<ExpireHistoryBackend> factory_; + base::WeakPtrFactory<ExpireHistoryBackend> weak_factory_; // The threshold for "old" history where we will automatically expire it to // the archived database. diff --git a/chrome/browser/history/history.cc b/chrome/browser/history/history.cc index d7508d3..d736f2a 100644 --- a/chrome/browser/history/history.cc +++ b/chrome/browser/history/history.cc @@ -263,7 +263,7 @@ HistoryService::Handle HistoryService::GetMostRecentKeywordSearchTerms( const string16& prefix, int max_count, CancelableRequestConsumerBase* consumer, - GetMostRecentKeywordSearchTermsCallback* callback) { + const GetMostRecentKeywordSearchTermsCallback& callback) { return Schedule(PRIORITY_UI, &HistoryBackend::GetMostRecentKeywordSearchTerms, consumer, new history::GetMostRecentKeywordSearchTermsRequest(callback), @@ -275,21 +275,19 @@ void HistoryService::URLsNoLongerBookmarked(const std::set<GURL>& urls) { urls); } -HistoryService::Handle HistoryService::ScheduleDBTask( - HistoryDBTask* task, - CancelableRequestConsumerBase* consumer) { +void HistoryService::ScheduleDBTask(HistoryDBTask* task, + CancelableRequestConsumerBase* consumer) { history::HistoryDBTaskRequest* request = new history::HistoryDBTaskRequest( - NewCallback(task, &HistoryDBTask::DoneRunOnMainThread)); + base::Bind(&HistoryDBTask::DoneRunOnMainThread, task)); request->value = task; // The value is the task to execute. - return Schedule(PRIORITY_UI, &HistoryBackend::ProcessDBTask, consumer, - request); + Schedule(PRIORITY_UI, &HistoryBackend::ProcessDBTask, consumer, request); } HistoryService::Handle HistoryService::QuerySegmentUsageSince( CancelableRequestConsumerBase* consumer, const Time from_time, int max_result_count, - SegmentQueryCallback* callback) { + const SegmentQueryCallback& callback) { return Schedule(PRIORITY_UI, &HistoryBackend::QuerySegmentUsage, consumer, new history::QuerySegmentUsageRequest(callback), from_time, max_result_count); @@ -436,7 +434,7 @@ void HistoryService::SetPageContents(const GURL& url, HistoryService::Handle HistoryService::GetPageThumbnail( const GURL& page_url, CancelableRequestConsumerBase* consumer, - ThumbnailDataCallback* callback) { + const ThumbnailDataCallback& callback) { return Schedule(PRIORITY_NORMAL, &HistoryBackend::GetPageThumbnail, consumer, new history::GetPageThumbnailRequest(callback), page_url); } @@ -510,7 +508,7 @@ HistoryService::Handle HistoryService::CreateDownload( int32 id, const DownloadPersistentStoreInfo& create_info, CancelableRequestConsumerBase* consumer, - HistoryService::DownloadCreateCallback* callback) { + const HistoryService::DownloadCreateCallback& callback) { return Schedule(PRIORITY_NORMAL, &HistoryBackend::CreateDownload, consumer, new history::DownloadCreateRequest(callback), id, create_info); @@ -518,7 +516,7 @@ HistoryService::Handle HistoryService::CreateDownload( HistoryService::Handle HistoryService::GetNextDownloadId( CancelableRequestConsumerBase* consumer, - DownloadNextIdCallback* callback) { + const DownloadNextIdCallback& callback) { return Schedule(PRIORITY_NORMAL, &HistoryBackend::GetNextDownloadId, consumer, new history::DownloadNextIdRequest(callback)); } @@ -527,7 +525,7 @@ HistoryService::Handle HistoryService::GetNextDownloadId( // 'downloads' table. HistoryService::Handle HistoryService::QueryDownloads( CancelableRequestConsumerBase* consumer, - DownloadQueryCallback* callback) { + const DownloadQueryCallback& callback) { return Schedule(PRIORITY_NORMAL, &HistoryBackend::QueryDownloads, consumer, new history::DownloadQueryRequest(callback)); } @@ -571,7 +569,7 @@ HistoryService::Handle HistoryService::QueryHistory( const string16& text_query, const history::QueryOptions& options, CancelableRequestConsumerBase* consumer, - QueryHistoryCallback* callback) { + const QueryHistoryCallback& callback) { return Schedule(PRIORITY_UI, &HistoryBackend::QueryHistory, consumer, new history::QueryHistoryRequest(callback), text_query, options); @@ -580,7 +578,7 @@ HistoryService::Handle HistoryService::QueryHistory( HistoryService::Handle HistoryService::QueryRedirectsFrom( const GURL& from_url, CancelableRequestConsumerBase* consumer, - QueryRedirectsCallback* callback) { + const QueryRedirectsCallback& callback) { return Schedule(PRIORITY_UI, &HistoryBackend::QueryRedirectsFrom, consumer, new history::QueryRedirectsRequest(callback), from_url); } @@ -588,7 +586,7 @@ HistoryService::Handle HistoryService::QueryRedirectsFrom( HistoryService::Handle HistoryService::QueryRedirectsTo( const GURL& to_url, CancelableRequestConsumerBase* consumer, - QueryRedirectsCallback* callback) { + const QueryRedirectsCallback& callback) { return Schedule(PRIORITY_NORMAL, &HistoryBackend::QueryRedirectsTo, consumer, new history::QueryRedirectsRequest(callback), to_url); } @@ -596,7 +594,7 @@ HistoryService::Handle HistoryService::QueryRedirectsTo( HistoryService::Handle HistoryService::GetVisibleVisitCountToHost( const GURL& url, CancelableRequestConsumerBase* consumer, - GetVisibleVisitCountToHostCallback* callback) { + const GetVisibleVisitCountToHostCallback& callback) { return Schedule(PRIORITY_UI, &HistoryBackend::GetVisibleVisitCountToHost, consumer, new history::GetVisibleVisitCountToHostRequest(callback), url); } @@ -604,7 +602,7 @@ HistoryService::Handle HistoryService::GetVisibleVisitCountToHost( HistoryService::Handle HistoryService::QueryTopURLsAndRedirects( int result_count, CancelableRequestConsumerBase* consumer, - QueryTopURLsAndRedirectsCallback* callback) { + const QueryTopURLsAndRedirectsCallback& callback) { return Schedule(PRIORITY_NORMAL, &HistoryBackend::QueryTopURLsAndRedirects, consumer, new history::QueryTopURLsAndRedirectsRequest(callback), result_count); @@ -614,7 +612,7 @@ HistoryService::Handle HistoryService::QueryMostVisitedURLs( int result_count, int days_back, CancelableRequestConsumerBase* consumer, - QueryMostVisitedURLsCallback* callback) { + const QueryMostVisitedURLsCallback& callback) { return Schedule(PRIORITY_NORMAL, &HistoryBackend::QueryMostVisitedURLs, consumer, new history::QueryMostVisitedURLsRequest(callback), @@ -747,11 +745,11 @@ void HistoryService::ExpireHistoryBetween( const std::set<GURL>& restrict_urls, Time begin_time, Time end_time, CancelableRequestConsumerBase* consumer, - ExpireHistoryCallback* callback) { + const base::Closure& callback) { // We will update the visited links when we observe the delete notifications. Schedule(PRIORITY_UI, &HistoryBackend::ExpireHistoryBetween, consumer, - new history::ExpireHistoryRequest(callback), + new CancelableRequest<base::Closure>(callback), restrict_urls, begin_time, end_time); } diff --git a/chrome/browser/history/history.h b/chrome/browser/history/history.h index af513c2..7b9d219 100644 --- a/chrome/browser/history/history.h +++ b/chrome/browser/history/history.h @@ -10,7 +10,7 @@ #include <vector> #include "base/basictypes.h" -#include "base/callback_old.h" +#include "base/callback.h" #include "base/file_path.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" @@ -284,7 +284,7 @@ class HistoryService : public CancelableRequestProvider, // Provides the result of a query. See QueryResults in history_types.h. // The common use will be to use QueryResults.Swap to suck the contents of // the results out of the passed in parameter and take ownership of them. - typedef Callback2<Handle, history::QueryResults*>::Type + typedef base::Callback<void(Handle, history::QueryResults*)> QueryHistoryCallback; // Queries all history with the given options (see QueryOptions in @@ -297,7 +297,7 @@ class HistoryService : public CancelableRequestProvider, Handle QueryHistory(const string16& text_query, const history::QueryOptions& options, CancelableRequestConsumerBase* consumer, - QueryHistoryCallback* callback); + const QueryHistoryCallback& callback); // Called when the results of QueryRedirectsFrom are available. // The given vector will contain a list of all redirects, not counting @@ -308,30 +308,30 @@ class HistoryService : public CancelableRequestProvider, // redirect, the vector will be empty. If the history system failed for // some reason, success will additionally be false. If the given page // has redirected to multiple destinations, this will pick a random one. - typedef Callback4<Handle, - GURL, // from_url - bool, // success - history::RedirectList*>::Type - QueryRedirectsCallback; + typedef base::Callback<void(Handle, + GURL, // from_url + bool, // success + history::RedirectList*)> QueryRedirectsCallback; // Schedules a query for the most recent redirect coming out of the given // URL. See the RedirectQuerySource above, which is guaranteed to be called // if the request is not canceled. Handle QueryRedirectsFrom(const GURL& from_url, CancelableRequestConsumerBase* consumer, - QueryRedirectsCallback* callback); + const QueryRedirectsCallback& callback); // Schedules a query to get the most recent redirects ending at the given // URL. Handle QueryRedirectsTo(const GURL& to_url, CancelableRequestConsumerBase* consumer, - QueryRedirectsCallback* callback); - - typedef Callback4<Handle, - bool, // Were we able to determine the # of visits? - int, // Number of visits. - base::Time>::Type // Time of first visit. Only set if bool - // is true and int is > 0. + const QueryRedirectsCallback& callback); + + typedef base::Callback< + void(Handle, + bool, // Were we able to determine the # of visits? + int, // Number of visits. + base::Time)> // Time of first visit. Only set if bool + // is true and int is > 0. GetVisibleVisitCountToHostCallback; // Requests the number of user-visible visits (i.e. no redirects or subframes) @@ -340,35 +340,37 @@ class HistoryService : public CancelableRequestProvider, Handle GetVisibleVisitCountToHost( const GURL& url, CancelableRequestConsumerBase* consumer, - GetVisibleVisitCountToHostCallback* callback); + const GetVisibleVisitCountToHostCallback& callback); // Called when QueryTopURLsAndRedirects completes. The vector contains a list // of the top |result_count| URLs. For each of these URLs, there is an entry // in the map containing redirects from the URL. For example, if we have the // redirect chain A -> B -> C and A is a top visited URL, then A will be in // the vector and "A => {B -> C}" will be in the map. - typedef Callback4<Handle, - bool, // Did we get the top urls and redirects? - std::vector<GURL>*, // List of top URLs. - history::RedirectMap*>::Type // Redirects for top URLs. + typedef base::Callback< + void(Handle, + bool, // Did we get the top urls and redirects? + std::vector<GURL>*, // List of top URLs. + history::RedirectMap*)> // Redirects for top URLs. QueryTopURLsAndRedirectsCallback; // Request the top |result_count| most visited URLs and the chain of redirects // leading to each of these URLs. // TODO(Nik): remove this. Use QueryMostVisitedURLs instead. - Handle QueryTopURLsAndRedirects(int result_count, - CancelableRequestConsumerBase* consumer, - QueryTopURLsAndRedirectsCallback* callback); + Handle QueryTopURLsAndRedirects( + int result_count, + CancelableRequestConsumerBase* consumer, + const QueryTopURLsAndRedirectsCallback& callback); - typedef Callback2<Handle, history::MostVisitedURLList>::Type - QueryMostVisitedURLsCallback; + typedef base::Callback<void(Handle, history::MostVisitedURLList)> + QueryMostVisitedURLsCallback; // Request the |result_count| most visited URLs and the chain of // redirects leading to each of these URLs. |days_back| is the // number of days of history to use. Used by TopSites. Handle QueryMostVisitedURLs(int result_count, int days_back, CancelableRequestConsumerBase* consumer, - QueryMostVisitedURLsCallback* callback); + const QueryMostVisitedURLsCallback& callback); // Thumbnails ---------------------------------------------------------------- @@ -378,23 +380,19 @@ class HistoryService : public CancelableRequestProvider, // // This function will be called even on error conditions or if there is no // thumbnail for that page. In these cases, the data pointer will be NULL. - typedef Callback2<Handle, scoped_refptr<RefCountedBytes> >::Type + typedef base::Callback<void(Handle, scoped_refptr<RefCountedBytes>)> ThumbnailDataCallback; // Requests a page thumbnail. See ThumbnailDataCallback definition above. Handle GetPageThumbnail(const GURL& page_url, CancelableRequestConsumerBase* consumer, - ThumbnailDataCallback* callback); + const ThumbnailDataCallback& callback); // Database management operations -------------------------------------------- // Delete all the information related to a single url. void DeleteURL(const GURL& url); - // Implemented by the caller of ExpireHistoryBetween, and - // is called when the history service has deleted the history. - typedef Callback0::Type ExpireHistoryCallback; - // Removes all visits in the selected time range (including the start time), // updating the URLs accordingly. This deletes the associated data, including // the full text index. This function also deletes the associated favicons, @@ -406,14 +404,13 @@ class HistoryService : public CancelableRequestProvider, void ExpireHistoryBetween(const std::set<GURL>& restrict_urls, base::Time begin_time, base::Time end_time, CancelableRequestConsumerBase* consumer, - ExpireHistoryCallback* callback); + const base::Closure& callback); // Downloads ----------------------------------------------------------------- // Implemented by the caller of 'CreateDownload' below, and is called when the // history service has created a new entry for a download in the history db. - typedef Callback2<int32, int64>::Type - DownloadCreateCallback; + typedef base::Callback<void(int32, int64)> DownloadCreateCallback; // Begins a history request to create a new persistent entry for a download. // 'info' contains all the download's creation state, and 'callback' runs @@ -421,18 +418,18 @@ class HistoryService : public CancelableRequestProvider, Handle CreateDownload(int32 id, const DownloadPersistentStoreInfo& info, CancelableRequestConsumerBase* consumer, - DownloadCreateCallback* callback); + const DownloadCreateCallback& callback); // Implemented by the caller of 'GetNextDownloadId' below. - typedef Callback1<int/*next_download_id*/>::Type DownloadNextIdCallback; + typedef base::Callback<void(int)> DownloadNextIdCallback; // Runs the callback with the next available download id. Handle GetNextDownloadId(CancelableRequestConsumerBase* consumer, - DownloadNextIdCallback* callback); + const DownloadNextIdCallback& callback); // Implemented by the caller of 'QueryDownloads' below, and is called when the // history service has retrieved a list of all download state. The call - typedef Callback1<std::vector<DownloadPersistentStoreInfo>*>::Type + typedef base::Callback<void(std::vector<DownloadPersistentStoreInfo>*)> DownloadQueryCallback; // Begins a history request to retrieve the state of all downloads in the @@ -440,7 +437,7 @@ class HistoryService : public CancelableRequestProvider, // at which point 'info' contains an array of DownloadPersistentStoreInfo, one // per download. Handle QueryDownloads(CancelableRequestConsumerBase* consumer, - DownloadQueryCallback* callback); + const DownloadQueryCallback& callback); // Begins a request to clean up entries that has been corrupted (because of // the crash, for example). @@ -468,7 +465,7 @@ class HistoryService : public CancelableRequestProvider, // Visit Segments ------------------------------------------------------------ - typedef Callback2<Handle, std::vector<PageUsageData*>*>::Type + typedef base::Callback<void(Handle, std::vector<PageUsageData*>*)> SegmentQueryCallback; // Query usage data for all visit segments since the provided time. @@ -487,7 +484,7 @@ class HistoryService : public CancelableRequestProvider, Handle QuerySegmentUsageSince(CancelableRequestConsumerBase* consumer, const base::Time from_time, int max_result_count, - SegmentQueryCallback* callback); + const SegmentQueryCallback& callback); // Set the presentation index for the segment identified by |segment_id|. void SetSegmentPresentationIndex(int64 segment_id, int index); @@ -503,8 +500,9 @@ class HistoryService : public CancelableRequestProvider, // Deletes all search terms for the specified keyword. void DeleteAllSearchTermsForKeyword(TemplateURLID keyword_id); - typedef Callback2<Handle, std::vector<history::KeywordSearchTermVisit>*>::Type - GetMostRecentKeywordSearchTermsCallback; + typedef base::Callback< + void(Handle, std::vector<history::KeywordSearchTermVisit>*)> + GetMostRecentKeywordSearchTermsCallback; // Returns up to max_count of the most recent search terms starting with the // specified text. The matching is case insensitive. The results are ordered @@ -515,7 +513,7 @@ class HistoryService : public CancelableRequestProvider, const string16& prefix, int max_count, CancelableRequestConsumerBase* consumer, - GetMostRecentKeywordSearchTermsCallback* callback); + const GetMostRecentKeywordSearchTermsCallback& callback); // Bookmarks ----------------------------------------------------------------- @@ -524,12 +522,10 @@ class HistoryService : public CancelableRequestProvider, // Generic Stuff ------------------------------------------------------------- - typedef Callback0::Type HistoryDBTaskCallback; - // Schedules a HistoryDBTask for running on the history backend thread. See // HistoryDBTask for details on what this does. - virtual Handle ScheduleDBTask(HistoryDBTask* task, - CancelableRequestConsumerBase* consumer); + virtual void ScheduleDBTask(HistoryDBTask* task, + CancelableRequestConsumerBase* consumer); // Returns true if top sites needs to be migrated out of history into its own // db. diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc index d9cac45..f9ef759 100644 --- a/chrome/browser/history/history_backend.cc +++ b/chrome/browser/history/history_backend.cc @@ -28,6 +28,7 @@ #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/url_constants.h" +#include "content/browser/cancelable_request.h" #include "content/browser/download/download_persistent_store_info.h" #include "googleurl/src/gurl.h" #include "grit/chromium_strings.h" @@ -1024,9 +1025,7 @@ void HistoryBackend::QuerySegmentUsage( NewRunnableMethod(this, &HistoryBackend::DeleteOldSegmentData)); } } - request->ForwardResult( - QuerySegmentUsageRequest::TupleType(request->handle(), - &request->value.get())); + request->ForwardResult(request->handle(), &request->value.get()); } // Keyword visits -------------------------------------------------------------- @@ -1079,9 +1078,7 @@ void HistoryBackend::GetMostRecentKeywordSearchTerms( db_->GetMostRecentKeywordSearchTerms(keyword_id, prefix, max_count, &(request->value)); } - request->ForwardResult( - GetMostRecentKeywordSearchTermsRequest::TupleType(request->handle(), - &request->value)); + request->ForwardResult(request->handle(), &request->value); } // Downloads ------------------------------------------------------------------- @@ -1094,7 +1091,7 @@ void HistoryBackend::GetNextDownloadId( } else { request->value = 0; } - request->ForwardResult(DownloadNextIdRequest::TupleType(request->value)); + request->ForwardResult(request->value); } // Get all the download entries from the database. @@ -1104,7 +1101,7 @@ void HistoryBackend::QueryDownloads( return; if (db_.get()) db_->QueryDownloads(&request->value); - request->ForwardResult(DownloadQueryRequest::TupleType(&request->value)); + request->ForwardResult(&request->value); } // Clean up entries that has been corrupted (because of the crash, for example). @@ -1140,7 +1137,7 @@ void HistoryBackend::CreateDownload( if (!request->canceled()) { if (db_.get()) db_handle = db_->CreateDownload(history_info); - request->ForwardResult(DownloadCreateRequest::TupleType(id, db_handle)); + request->ForwardResult(id, db_handle); } } @@ -1181,8 +1178,7 @@ void HistoryBackend::QueryHistory(scoped_refptr<QueryHistoryRequest> request, } } - request->ForwardResult(QueryHistoryRequest::TupleType(request->handle(), - &request->value)); + request->ForwardResult(request->handle(), &request->value); UMA_HISTOGRAM_TIMES("History.QueryHistory", TimeTicks::Now() - beginning_time); @@ -1300,8 +1296,7 @@ void HistoryBackend::QueryRedirectsFrom( if (request->canceled()) return; bool success = GetMostRecentRedirectsFrom(url, &request->value); - request->ForwardResult(QueryRedirectsRequest::TupleType( - request->handle(), url, success, &request->value)); + request->ForwardResult(request->handle(), url, success, &request->value); } void HistoryBackend::QueryRedirectsTo( @@ -1310,8 +1305,7 @@ void HistoryBackend::QueryRedirectsTo( if (request->canceled()) return; bool success = GetMostRecentRedirectsTo(url, &request->value); - request->ForwardResult(QueryRedirectsRequest::TupleType( - request->handle(), url, success, &request->value)); + request->ForwardResult(request->handle(), url, success, &request->value); } void HistoryBackend::GetVisibleVisitCountToHost( @@ -1323,8 +1317,7 @@ void HistoryBackend::GetVisibleVisitCountToHost( Time first_visit; const bool success = db_.get() && db_->GetVisibleVisitCountToHost(url, &count, &first_visit); - request->ForwardResult(GetVisibleVisitCountToHostRequest::TupleType( - request->handle(), success, count, first_visit)); + request->ForwardResult(request->handle(), success, count, first_visit); } void HistoryBackend::QueryTopURLsAndRedirects( @@ -1334,8 +1327,7 @@ void HistoryBackend::QueryTopURLsAndRedirects( return; if (!db_.get()) { - request->ForwardResult(QueryTopURLsAndRedirectsRequest::TupleType( - request->handle(), false, NULL, NULL)); + request->ForwardResult(request->handle(), false, NULL, NULL); return; } @@ -1353,8 +1345,7 @@ void HistoryBackend::QueryTopURLsAndRedirects( (*redirects)[top_urls->back()] = list; } - request->ForwardResult(QueryTopURLsAndRedirectsRequest::TupleType( - request->handle(), true, top_urls, redirects)); + request->ForwardResult(request->handle(), true, top_urls, redirects); } // Will replace QueryTopURLsAndRedirectsRequest. @@ -1367,15 +1358,13 @@ void HistoryBackend::QueryMostVisitedURLs( if (!db_.get()) { // No History Database - return an empty list. - request->ForwardResult(QueryMostVisitedURLsRequest::TupleType( - request->handle(), MostVisitedURLList())); + request->ForwardResult(request->handle(), MostVisitedURLList()); return; } MostVisitedURLList* result = &request->value; QueryMostVisitedURLsImpl(result_count, days_back, result); - request->ForwardResult(QueryMostVisitedURLsRequest::TupleType( - request->handle(), *result)); + request->ForwardResult(request->handle(), *result); } void HistoryBackend::QueryMostVisitedURLsImpl(int result_count, @@ -1510,8 +1499,7 @@ void HistoryBackend::GetPageThumbnail( scoped_refptr<RefCountedBytes> data; GetPageThumbnailDirectly(page_url, &data); - request->ForwardResult(GetPageThumbnailRequest::TupleType( - request->handle(), data)); + request->ForwardResult(request->handle(), data); } void HistoryBackend::GetPageThumbnailDirectly( @@ -1727,8 +1715,7 @@ void HistoryBackend::UpdateFaviconMappingAndFetchImpl( // else case, haven't cached entry yet. Caller is responsible for // downloading the favicon and invoking SetFavicon. } - request->ForwardResult(GetFaviconRequest::TupleType( - request->handle(), favicon)); + request->ForwardResult(request->handle(), favicon); } void HistoryBackend::GetFaviconForURL( @@ -1743,8 +1730,7 @@ void HistoryBackend::GetFaviconForURL( // Get the favicon from DB. GetFaviconFromDB(page_url, icon_types, &favicon); - request->ForwardResult( - GetFaviconRequest::TupleType(request->handle(), favicon)); + request->ForwardResult(request->handle(), favicon); } void HistoryBackend::SetFavicon( @@ -1927,7 +1913,7 @@ void HistoryBackend::ProcessDBTaskImpl() { db_task_requests_.pop_front(); if (request->value->RunOnDBThread(this, db_.get())) { // The task is done. Notify the callback. - request->ForwardResult(HistoryDBTaskRequest::TupleType()); + request->ForwardResult(); // We AddRef'd the request before adding, need to release it now. request->Release(); } else { @@ -1975,7 +1961,7 @@ void HistoryBackend::DeleteURL(const GURL& url) { } void HistoryBackend::ExpireHistoryBetween( - scoped_refptr<ExpireHistoryRequest> request, + scoped_refptr<CancelableRequest<base::Closure> > request, const std::set<GURL>& restrict_urls, Time begin_time, Time end_time) { @@ -2000,7 +1986,7 @@ void HistoryBackend::ExpireHistoryBetween( if (begin_time <= first_recorded_time_) db_->GetStartDate(&first_recorded_time_); - request->ForwardResult(ExpireHistoryRequest::TupleType()); + request->ForwardResult(); if (history_publisher_.get() && restrict_urls.empty()) history_publisher_->DeleteUserHistoryBetween(begin_time, end_time); diff --git a/chrome/browser/history/history_backend.h b/chrome/browser/history/history_backend.h index 5d43bed..f9625c2 100644 --- a/chrome/browser/history/history_backend.h +++ b/chrome/browser/history/history_backend.h @@ -22,6 +22,7 @@ #include "chrome/browser/history/thumbnail_database.h" #include "chrome/browser/history/visit_tracker.h" #include "chrome/browser/search_engines/template_url_id.h" +#include "content/browser/cancelable_request.h" #include "sql/init_status.h" class BookmarkService; @@ -309,10 +310,11 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>, virtual void DeleteURL(const GURL& url); // Calls ExpireHistoryBackend::ExpireHistoryBetween and commits the change. - void ExpireHistoryBetween(scoped_refptr<ExpireHistoryRequest> request, - const std::set<GURL>& restrict_urls, - base::Time begin_time, - base::Time end_time); + void ExpireHistoryBetween( + scoped_refptr<CancelableRequest<base::Closure> > request, + const std::set<GURL>& restrict_urls, + base::Time begin_time, + base::Time end_time); // Bookmarks ----------------------------------------------------------------- diff --git a/chrome/browser/history/history_browsertest.cc b/chrome/browser/history/history_browsertest.cc index 82cbb99..a2dc9f3 100644 --- a/chrome/browser/history/history_browsertest.cc +++ b/chrome/browser/history/history_browsertest.cc @@ -4,6 +4,7 @@ #include <vector> +#include "base/bind.h" #include "base/message_loop.h" #include "chrome/browser/history/history.h" #include "chrome/browser/prefs/pref_service.h" @@ -54,7 +55,7 @@ class HistoryEnumerator : public HistoryService::URLEnumerator { BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, - NewRunnableMethod(history, &HistoryService::IterateURLs, this)); + base::Bind(&HistoryService::IterateURLs, history, this)); ui_test_utils::RunMessageLoop(); } @@ -108,10 +109,8 @@ class HistoryBrowserTest : public InProcessBrowserTest { HistoryService* history = GetHistoryService(); BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, - NewRunnableMethod(history, - &HistoryService::ScheduleDBTask, - task, - &request_consumer)); + base::Bind(&HistoryService::ScheduleDBTask, + history, task, &request_consumer)); ui_test_utils::RunMessageLoop(); } diff --git a/chrome/browser/history/history_marshaling.h b/chrome/browser/history/history_marshaling.h index 845ea9c..ac3a702 100644 --- a/chrome/browser/history/history_marshaling.h +++ b/chrome/browser/history/history_marshaling.h @@ -67,11 +67,6 @@ typedef CancelableRequest1<HistoryService::DownloadQueryCallback, typedef CancelableRequest<HistoryService::DownloadCreateCallback> DownloadCreateRequest; -// Deletion -------------------------------------------------------------------- - -typedef CancelableRequest<HistoryService::ExpireHistoryCallback> - ExpireHistoryRequest; - // Segment usage -------------------------------------------------------------- typedef CancelableRequest1<HistoryService::SegmentQueryCallback, @@ -90,8 +85,7 @@ typedef // The argument here is an input value, which is the task to run on the // background thread. The callback is used to execute the portion of the task // that executes on the main thread. -typedef CancelableRequest1<HistoryService::HistoryDBTaskCallback, - scoped_refptr<HistoryDBTask> > +typedef CancelableRequest1<base::Closure, scoped_refptr<HistoryDBTask> > HistoryDBTaskRequest; } // namespace history diff --git a/chrome/browser/history/history_querying_unittest.cc b/chrome/browser/history/history_querying_unittest.cc index 609f78a..7c11dc4 100644 --- a/chrome/browser/history/history_querying_unittest.cc +++ b/chrome/browser/history/history_querying_unittest.cc @@ -3,7 +3,8 @@ // found in the LICENSE file. #include "base/basictypes.h" -#include "base/callback.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/file_path.h" #include "base/file_util.h" #include "base/path_service.h" @@ -76,8 +77,10 @@ class HistoryQueryTest : public testing::Test { void QueryHistory(const std::string& text_query, const QueryOptions& options, QueryResults* results) { - history_->QueryHistory(UTF8ToUTF16(text_query), options, &consumer_, - NewCallback(this, &HistoryQueryTest::QueryHistoryComplete)); + history_->QueryHistory( + UTF8ToUTF16(text_query), options, &consumer_, + base::Bind(&HistoryQueryTest::QueryHistoryComplete, + base::Unretained(this))); MessageLoop::current()->Run(); // Will go until ...Complete calls Quit. results->Swap(&last_query_results_); } diff --git a/chrome/browser/history/history_unittest.cc b/chrome/browser/history/history_unittest.cc index 2cd7a2d..ac38745 100644 --- a/chrome/browser/history/history_unittest.cc +++ b/chrome/browser/history/history_unittest.cc @@ -231,7 +231,8 @@ class HistoryTest : public testing::Test { // returning true on success. False means the URL was not found. bool QueryRedirectsFrom(HistoryService* history, const GURL& url) { history->QueryRedirectsFrom(url, &consumer_, - NewCallback(this, &HistoryTest::OnRedirectQueryComplete)); + base::Bind(&HistoryTest::OnRedirectQueryComplete, + base::Unretained(this))); MessageLoop::current()->Run(); // Will be exited in *QueryComplete. return redirect_query_success_; } @@ -628,8 +629,8 @@ TEST_F(HistoryTest, Segments) { // Make sure a segment was created. history->QuerySegmentUsageSince( &consumer_, Time::Now() - TimeDelta::FromDays(1), 10, - NewCallback(static_cast<HistoryTest*>(this), - &HistoryTest::OnSegmentUsageAvailable)); + base::Bind(&HistoryTest::OnSegmentUsageAvailable, + base::Unretained(this))); // Wait for processing. MessageLoop::current()->Run(); @@ -647,8 +648,8 @@ TEST_F(HistoryTest, Segments) { // Query again history->QuerySegmentUsageSince( &consumer_, Time::Now() - TimeDelta::FromDays(1), 10, - NewCallback(static_cast<HistoryTest*>(this), - &HistoryTest::OnSegmentUsageAvailable)); + base::Bind(&HistoryTest::OnSegmentUsageAvailable, + base::Unretained(this))); // Wait for processing. MessageLoop::current()->Run(); @@ -665,8 +666,8 @@ TEST_F(HistoryTest, Segments) { // Query again history->QuerySegmentUsageSince( &consumer_, Time::Now() - TimeDelta::FromDays(1), 10, - NewCallback(static_cast<HistoryTest*>(this), - &HistoryTest::OnSegmentUsageAvailable)); + base::Bind(&HistoryTest::OnSegmentUsageAvailable, + base::Unretained(this))); // Wait for processing. MessageLoop::current()->Run(); @@ -700,8 +701,9 @@ TEST_F(HistoryTest, MostVisitedURLs) { PageTransition::TYPED, history::RedirectList(), history::SOURCE_BROWSED, false); history->QueryMostVisitedURLs(20, 90, &consumer_, - NewCallback(static_cast<HistoryTest*>(this), - &HistoryTest::OnMostVisitedURLsAvailable)); + base::Bind( + &HistoryTest::OnMostVisitedURLsAvailable, + base::Unretained(this))); MessageLoop::current()->Run(); EXPECT_EQ(2U, most_visited_urls_.size()); @@ -713,8 +715,9 @@ TEST_F(HistoryTest, MostVisitedURLs) { PageTransition::TYPED, history::RedirectList(), history::SOURCE_BROWSED, false); history->QueryMostVisitedURLs(20, 90, &consumer_, - NewCallback(static_cast<HistoryTest*>(this), - &HistoryTest::OnMostVisitedURLsAvailable)); + base::Bind( + &HistoryTest::OnMostVisitedURLsAvailable, + base::Unretained(this))); MessageLoop::current()->Run(); EXPECT_EQ(3U, most_visited_urls_.size()); @@ -727,8 +730,9 @@ TEST_F(HistoryTest, MostVisitedURLs) { PageTransition::TYPED, history::RedirectList(), history::SOURCE_BROWSED, false); history->QueryMostVisitedURLs(20, 90, &consumer_, - NewCallback(static_cast<HistoryTest*>(this), - &HistoryTest::OnMostVisitedURLsAvailable)); + base::Bind( + &HistoryTest::OnMostVisitedURLsAvailable, + base::Unretained(this))); MessageLoop::current()->Run(); EXPECT_EQ(3U, most_visited_urls_.size()); @@ -741,8 +745,9 @@ TEST_F(HistoryTest, MostVisitedURLs) { PageTransition::TYPED, history::RedirectList(), history::SOURCE_BROWSED, false); history->QueryMostVisitedURLs(20, 90, &consumer_, - NewCallback(static_cast<HistoryTest*>(this), - &HistoryTest::OnMostVisitedURLsAvailable)); + base::Bind( + &HistoryTest::OnMostVisitedURLsAvailable, + base::Unretained(this))); MessageLoop::current()->Run(); EXPECT_EQ(3U, most_visited_urls_.size()); @@ -760,8 +765,9 @@ TEST_F(HistoryTest, MostVisitedURLs) { PageTransition::TYPED, redirects, history::SOURCE_BROWSED, false); history->QueryMostVisitedURLs(20, 90, &consumer_, - NewCallback(static_cast<HistoryTest*>(this), - &HistoryTest::OnMostVisitedURLsAvailable)); + base::Bind( + &HistoryTest::OnMostVisitedURLsAvailable, + base::Unretained(this))); MessageLoop::current()->Run(); EXPECT_EQ(4U, most_visited_urls_.size()); diff --git a/chrome/browser/history/text_database_manager.cc b/chrome/browser/history/text_database_manager.cc index 09a79cf..98e5990 100644 --- a/chrome/browser/history/text_database_manager.cc +++ b/chrome/browser/history/text_database_manager.cc @@ -4,6 +4,7 @@ #include "chrome/browser/history/text_database_manager.h" +#include "base/bind.h" #include "base/compiler_specific.h" #include "base/file_util.h" #include "base/metrics/histogram.h" @@ -85,7 +86,7 @@ TextDatabaseManager::TextDatabaseManager(const FilePath& dir, transaction_nesting_(0), db_cache_(DBCache::NO_AUTO_EVICT), present_databases_loaded_(false), - ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)), + ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), history_publisher_(NULL) { } @@ -532,9 +533,11 @@ TextDatabase* TextDatabaseManager::GetDBForTime(Time time, } void TextDatabaseManager::ScheduleFlushOldChanges() { - factory_.RevokeAll(); - MessageLoop::current()->PostDelayedTask(FROM_HERE, factory_.NewRunnableMethod( - &TextDatabaseManager::FlushOldChanges), + weak_factory_.InvalidateWeakPtrs(); + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&TextDatabaseManager::FlushOldChanges, + weak_factory_.GetWeakPtr()), kExpirationSec * Time::kMillisecondsPerSecond); } diff --git a/chrome/browser/history/text_database_manager.h b/chrome/browser/history/text_database_manager.h index 120f4b1..89b750a 100644 --- a/chrome/browser/history/text_database_manager.h +++ b/chrome/browser/history/text_database_manager.h @@ -12,6 +12,7 @@ #include "base/basictypes.h" #include "base/file_path.h" #include "base/gtest_prod_util.h" +#include "base/memory/weak_ptr.h" #include "base/string16.h" #include "base/task.h" #include "base/memory/mru_cache.h" @@ -32,7 +33,7 @@ class VisitDatabase; // It will also keep a list of partial changes, such as page adds and title and // body sets, all of which come in at different times for a given page. When // all data is received or enough time has elapsed since adding, the indexed -// data will be comitted. +// data will be committed. // // This allows us to minimize inserts and modifications, which are slow for the // full text database, since each page's information is added exactly once. @@ -126,7 +127,7 @@ class TextDatabaseManager { // The text database manager keeps a list of changes that are made to the // file AddPageURL/Title/Body that may not be committed to the database yet. - // This function removes entires from this list happening between the given + // This function removes entries from this list happening between the given // time range. It is called when the user clears their history for a time // range, and we don't want any of our data to "leak." If restrict_urls is // not empty, only changes on those URLs are deleted. @@ -277,7 +278,7 @@ class TextDatabaseManager { DBCache db_cache_; // Tells us about the existence of database files on disk. All existing - // databases will be in here, and non-existant ones will not, so we don't + // databases will be in here, and non-existent ones will not, so we don't // have to check the disk every time. // // This set is populated LAZILY by InitDBList(), you should call that function @@ -296,7 +297,7 @@ class TextDatabaseManager { QueryParser query_parser_; // Generates tasks for our periodic checking of expired "recent changes". - ScopedRunnableMethodFactory<TextDatabaseManager> factory_; + base::WeakPtrFactory<TextDatabaseManager> weak_factory_; // This object is created and managed by the history backend. We maintain an // opaque pointer to the object for our use. diff --git a/chrome/browser/history/top_sites.cc b/chrome/browser/history/top_sites.cc index 17c8940..9228217 100644 --- a/chrome/browser/history/top_sites.cc +++ b/chrome/browser/history/top_sites.cc @@ -7,6 +7,8 @@ #include <algorithm> #include <set> +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/logging.h" #include "base/md5.h" #include "base/string_util.h" @@ -175,7 +177,8 @@ void TopSites::Init(const FilePath& db_name) { backend_->Init(db_name); backend_->GetMostVisitedThumbnails( &top_sites_consumer_, - NewCallback(this, &TopSites::OnGotMostVisitedThumbnails)); + base::Bind(&TopSites::OnGotMostVisitedThumbnails, + base::Unretained(this))); // History may have already finished loading by the time we're created. HistoryService* history = profile_->GetHistoryServiceWithoutCreating(); @@ -329,7 +332,8 @@ void TopSites::FinishHistoryMigration(const ThumbnailMigration& data) { // we can tell history to finish its part of migration. backend_->DoEmptyRequest( &top_sites_consumer_, - NewCallback(this, &TopSites::OnHistoryMigrationWrittenToDisk)); + base::Bind(&TopSites::OnHistoryMigrationWrittenToDisk, + base::Unretained(this))); } void TopSites::HistoryLoaded() { @@ -531,7 +535,8 @@ CancelableRequestProvider::Handle TopSites::StartQueryForMostVisited() { num_results_to_request_from_history(), kDaysOfHistory, &history_consumer_, - NewCallback(this, &TopSites::OnTopSitesAvailableFromHistory)); + base::Bind(&TopSites::OnTopSitesAvailableFromHistory, + base::Unretained(this))); } return 0; } diff --git a/chrome/browser/history/top_sites_backend.cc b/chrome/browser/history/top_sites_backend.cc index bb25e1f..94355cc 100644 --- a/chrome/browser/history/top_sites_backend.cc +++ b/chrome/browser/history/top_sites_backend.cc @@ -4,8 +4,10 @@ #include "chrome/browser/history/top_sites_backend.h" +#include "base/bind.h" #include "base/file_path.h" #include "base/file_util.h" +#include "base/memory/ref_counted.h" #include "chrome/browser/history/top_sites_database.h" #include "content/browser/browser_thread.h" @@ -18,62 +20,60 @@ TopSitesBackend::TopSitesBackend() void TopSitesBackend::Init(const FilePath& path) { db_path_ = path; BrowserThread::PostTask( - BrowserThread::DB, FROM_HERE, NewRunnableMethod( - this, &TopSitesBackend::InitDBOnDBThread, path)); + BrowserThread::DB, FROM_HERE, + base::Bind(&TopSitesBackend::InitDBOnDBThread, this, path)); } void TopSitesBackend::Shutdown() { BrowserThread::PostTask( - BrowserThread::DB, FROM_HERE, NewRunnableMethod( - this, &TopSitesBackend::ShutdownDBOnDBThread)); + BrowserThread::DB, FROM_HERE, + base::Bind(&TopSitesBackend::ShutdownDBOnDBThread, this)); } TopSitesBackend::Handle TopSitesBackend::GetMostVisitedThumbnails( CancelableRequestConsumerBase* consumer, - GetMostVisitedThumbnailsCallback* callback) { + const GetMostVisitedThumbnailsCallback& callback) { GetMostVisitedThumbnailsRequest* request = new GetMostVisitedThumbnailsRequest(callback); request->value = new MostVisitedThumbnails; AddRequest(request, consumer); BrowserThread::PostTask( - BrowserThread::DB, FROM_HERE, NewRunnableMethod( - this, - &TopSitesBackend::GetMostVisitedThumbnailsOnDBThread, - scoped_refptr<GetMostVisitedThumbnailsRequest>(request))); + BrowserThread::DB, FROM_HERE, + base::Bind(&TopSitesBackend::GetMostVisitedThumbnailsOnDBThread, this, + make_scoped_refptr(request))); return request->handle(); } void TopSitesBackend::UpdateTopSites(const TopSitesDelta& delta) { BrowserThread::PostTask( - BrowserThread::DB, FROM_HERE, NewRunnableMethod( - this, &TopSitesBackend::UpdateTopSitesOnDBThread, delta)); + BrowserThread::DB, FROM_HERE, + base::Bind(&TopSitesBackend::UpdateTopSitesOnDBThread, this, delta)); } void TopSitesBackend::SetPageThumbnail(const MostVisitedURL& url, int url_rank, const Images& thumbnail) { BrowserThread::PostTask( - BrowserThread::DB, FROM_HERE, NewRunnableMethod( - this, &TopSitesBackend::SetPageThumbnailOnDBThread, url, - url_rank, thumbnail)); + BrowserThread::DB, FROM_HERE, + base::Bind(&TopSitesBackend::SetPageThumbnailOnDBThread, this, url, + url_rank, thumbnail)); } void TopSitesBackend::ResetDatabase() { BrowserThread::PostTask( - BrowserThread::DB, FROM_HERE, NewRunnableMethod( - this, &TopSitesBackend::ResetDatabaseOnDBThread, db_path_)); + BrowserThread::DB, FROM_HERE, + base::Bind(&TopSitesBackend::ResetDatabaseOnDBThread, this, db_path_)); } TopSitesBackend::Handle TopSitesBackend::DoEmptyRequest( CancelableRequestConsumerBase* consumer, - EmptyRequestCallback* callback) { + const EmptyRequestCallback& callback) { EmptyRequestRequest* request = new EmptyRequestRequest(callback); AddRequest(request, consumer); BrowserThread::PostTask( - BrowserThread::DB, FROM_HERE, NewRunnableMethod( - this, - &TopSitesBackend::DoEmptyRequestOnDBThread, - scoped_refptr<EmptyRequestRequest>(request))); + BrowserThread::DB, FROM_HERE, + base::Bind(&TopSitesBackend::DoEmptyRequestOnDBThread, this, + make_scoped_refptr(request))); return request->handle(); } @@ -108,10 +108,8 @@ void TopSitesBackend::GetMostVisitedThumbnailsOnDBThread( &(request->value->url_to_images_map)); may_need_history_migration = db_->may_need_history_migration(); } - request->ForwardResult(GetMostVisitedThumbnailsRequest::TupleType( - request->handle(), - request->value, - may_need_history_migration)); + request->ForwardResult(request->handle(), request->value, + may_need_history_migration); } void TopSitesBackend::UpdateTopSitesOnDBThread(const TopSitesDelta& delta) { @@ -147,7 +145,7 @@ void TopSitesBackend::ResetDatabaseOnDBThread(const FilePath& file_path) { void TopSitesBackend::DoEmptyRequestOnDBThread( scoped_refptr<EmptyRequestRequest> request) { - request->ForwardResult(EmptyRequestRequest::TupleType(request->handle())); + request->ForwardResult(request->handle()); } } // namespace history diff --git a/chrome/browser/history/top_sites_backend.h b/chrome/browser/history/top_sites_backend.h index a2a5b61..95ff242 100644 --- a/chrome/browser/history/top_sites_backend.h +++ b/chrome/browser/history/top_sites_backend.h @@ -6,7 +6,7 @@ #define CHROME_BROWSER_HISTORY_TOP_SITES_BACKEND_H_ #pragma once -#include "base/callback_old.h" +#include "base/callback.h" #include "base/file_path.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" @@ -35,15 +35,17 @@ class TopSitesBackend // The boolean parameter indicates if the DB existed on disk or needs to be // migrated. - typedef Callback3<Handle, scoped_refptr<MostVisitedThumbnails>, bool >::Type - GetMostVisitedThumbnailsCallback; + typedef base::Callback< + void(Handle, scoped_refptr<MostVisitedThumbnails>, bool)> + GetMostVisitedThumbnailsCallback; typedef CancelableRequest1<TopSitesBackend::GetMostVisitedThumbnailsCallback, scoped_refptr<MostVisitedThumbnails> > GetMostVisitedThumbnailsRequest; // Fetches MostVisitedThumbnails. - Handle GetMostVisitedThumbnails(CancelableRequestConsumerBase* consumer, - GetMostVisitedThumbnailsCallback* callback); + Handle GetMostVisitedThumbnails( + CancelableRequestConsumerBase* consumer, + const GetMostVisitedThumbnailsCallback& callback); // Updates top sites database from the specified delta. void UpdateTopSites(const TopSitesDelta& delta); @@ -56,7 +58,7 @@ class TopSitesBackend // Deletes the database and recreates it. void ResetDatabase(); - typedef Callback1<Handle>::Type EmptyRequestCallback; + typedef base::Callback<void(Handle)> EmptyRequestCallback; typedef CancelableRequest<TopSitesBackend::EmptyRequestCallback> EmptyRequestRequest; @@ -64,7 +66,7 @@ class TopSitesBackend // the callback on the calling thread. This is used to make sure the db has // finished processing a request. Handle DoEmptyRequest(CancelableRequestConsumerBase* consumer, - EmptyRequestCallback* callback); + const EmptyRequestCallback& callback); private: friend class base::RefCountedThreadSafe<TopSitesBackend>; diff --git a/chrome/browser/history/top_sites_unittest.cc b/chrome/browser/history/top_sites_unittest.cc index 5d6ef8f..df81625 100644 --- a/chrome/browser/history/top_sites_unittest.cc +++ b/chrome/browser/history/top_sites_unittest.cc @@ -194,7 +194,8 @@ class TopSitesTest : public HistoryUnitTestBase { void WaitForTopSites() { top_sites()->backend_->DoEmptyRequest( &consumer_, - NewCallback(this, &TopSitesTest::QuitCallback)); + base::Bind(&TopSitesTest::QuitCallback, + base::Unretained(this))); MessageLoop::current()->Run(); } @@ -895,8 +896,8 @@ TEST_F(TopSitesTest, PinnedURLsDeleted) { history_service()->ExpireHistoryBetween( std::set<GURL>(), base::Time(), base::Time(), - consumer(), NewCallback(static_cast<TopSitesTest*>(this), - &TopSitesTest::EmptyCallback)), + consumer(), base::Bind(&TopSitesTest::EmptyCallback, + base::Unretained(this))), WaitForHistory(); { diff --git a/chrome/browser/jumplist_win.cc b/chrome/browser/jumplist_win.cc index a032e9f..cc797b9 100644 --- a/chrome/browser/jumplist_win.cc +++ b/chrome/browser/jumplist_win.cc @@ -14,7 +14,6 @@ #include "base/bind.h" #include "base/bind_helpers.h" -#include "base/callback.h" #include "base/command_line.h" #include "base/file_util.h" #include "base/path_service.h" @@ -713,7 +712,7 @@ bool JumpList::StartLoadingFavicon() { profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); handle_ = favicon_service->GetFaviconForURL( url, history::FAVICON, &favicon_consumer_, - NewCallback(this, &JumpList::OnFaviconDataAvailable)); + base::Bind(&JumpList::OnFaviconDataAvailable, base::Unretained(this))); return true; } diff --git a/chrome/browser/page_info_model.cc b/chrome/browser/page_info_model.cc index 9e4394d..de4b4c2 100644 --- a/chrome/browser/page_info_model.cc +++ b/chrome/browser/page_info_model.cc @@ -6,6 +6,8 @@ #include <string> +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/command_line.h" #include "base/i18n/time_formatting.h" #include "base/string_number_conversions.h" @@ -284,7 +286,8 @@ PageInfoModel::PageInfoModel(Profile* profile, history->GetVisibleVisitCountToHost( url, &request_consumer_, - NewCallback(this, &PageInfoModel::OnGotVisitCountToHost)); + base::Bind(&PageInfoModel::OnGotVisitCountToHost, + base::Unretained(this))); } } diff --git a/chrome/browser/safe_browsing/browser_feature_extractor.cc b/chrome/browser/safe_browsing/browser_feature_extractor.cc index 9333b9f..b0fd195 100644 --- a/chrome/browser/safe_browsing/browser_feature_extractor.cc +++ b/chrome/browser/safe_browsing/browser_feature_extractor.cc @@ -324,7 +324,8 @@ void BrowserFeatureExtractor::QueryUrlHistoryDone( history->GetVisibleVisitCountToHost( GURL(request->url()), &request_consumer_, - NewCallback(this, &BrowserFeatureExtractor::QueryHttpHostVisitsDone)); + base::Bind(&BrowserFeatureExtractor::QueryHttpHostVisitsDone, + base::Unretained(this))); StorePendingQuery(next_handle, request, callback); } @@ -361,8 +362,8 @@ void BrowserFeatureExtractor::QueryHttpHostVisitsDone( history->GetVisibleVisitCountToHost( GURL(https_url.replace(0, 5, "https:")), &request_consumer_, - NewCallback(this, - &BrowserFeatureExtractor::QueryHttpsHostVisitsDone)); + base::Bind(&BrowserFeatureExtractor::QueryHttpsHostVisitsDone, + base::Unretained(this))); StorePendingQuery(next_handle, request, callback); } diff --git a/chrome/browser/safe_browsing/malware_details_history.cc b/chrome/browser/safe_browsing/malware_details_history.cc index ed5e36a..11a0d4c 100644 --- a/chrome/browser/safe_browsing/malware_details_history.cc +++ b/chrome/browser/safe_browsing/malware_details_history.cc @@ -7,6 +7,7 @@ #include "chrome/browser/safe_browsing/malware_details_history.h" #include "base/bind.h" +#include "base/bind_helpers.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/safe_browsing/malware_details.h" #include "chrome/common/chrome_notification_types.h" @@ -78,8 +79,8 @@ void MalwareDetailsRedirectsCollector::GetRedirects(const GURL& url) { history->QueryRedirectsTo( url, &request_consumer_, - NewCallback(this, - &MalwareDetailsRedirectsCollector::OnGotQueryRedirectsTo)); + base::Bind(&MalwareDetailsRedirectsCollector::OnGotQueryRedirectsTo, + base::Unretained(this))); } void MalwareDetailsRedirectsCollector::OnGotQueryRedirectsTo( diff --git a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc index 2460b1e..8586958 100644 --- a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc @@ -98,8 +98,8 @@ class HistoryBackendMock : public HistoryBackend { class HistoryServiceMock : public HistoryService { public: HistoryServiceMock() {} - MOCK_METHOD2(ScheduleDBTask, Handle(HistoryDBTask*, - CancelableRequestConsumerBase*)); + MOCK_METHOD2(ScheduleDBTask, void(HistoryDBTask*, + CancelableRequestConsumerBase*)); }; class RunOnDBThreadTask : public Task { @@ -119,7 +119,6 @@ ACTION_P2(RunTaskOnDBThread, thread, backend) { thread->message_loop()->PostTask( FROM_HERE, new RunOnDBThreadTask(backend, arg0)); - return 0; } ACTION_P4(MakeTypedUrlSyncComponents, profile, service, hb, dtc) { diff --git a/chrome/browser/tab_contents/thumbnail_generator.cc b/chrome/browser/tab_contents/thumbnail_generator.cc index f7c16ba..1f431ba 100644 --- a/chrome/browser/tab_contents/thumbnail_generator.cc +++ b/chrome/browser/tab_contents/thumbnail_generator.cc @@ -130,7 +130,7 @@ SkBitmap GetBitmapForBackingStore( } // namespace struct ThumbnailGenerator::AsyncRequestInfo { - scoped_ptr<ThumbnailReadyCallback> callback; + ThumbnailReadyCallback callback; scoped_ptr<TransportDIB> thumbnail_dib; RenderWidgetHost* renderer; // Not owned. }; @@ -195,11 +195,9 @@ void ThumbnailGenerator::MonitorRenderer(RenderWidgetHost* renderer, void ThumbnailGenerator::AskForSnapshot(RenderWidgetHost* renderer, bool prefer_backing_store, - ThumbnailReadyCallback* callback, + const ThumbnailReadyCallback& callback, gfx::Size page_size, gfx::Size desired_size) { - scoped_ptr<ThumbnailReadyCallback> callback_deleter(callback); - if (prefer_backing_store) { BackingStore* backing_store = renderer->GetBackingStore(false); if (backing_store) { @@ -210,7 +208,7 @@ void ThumbnailGenerator::AskForSnapshot(RenderWidgetHost* renderer, desired_size.height(), kNoOptions, NULL); - callback->Run(first_try); + callback.Run(first_try); return; } @@ -249,7 +247,7 @@ void ThumbnailGenerator::AskForSnapshot(RenderWidgetHost* renderer, #endif linked_ptr<AsyncRequestInfo> request_info(new AsyncRequestInfo); - request_info->callback.reset(callback_deleter.release()); + request_info->callback = callback; request_info->thumbnail_dib.reset(thumbnail_dib.release()); request_info->renderer = renderer; ThumbnailCallbackMap::value_type new_value(sequence_num, request_info); @@ -318,7 +316,7 @@ void ThumbnailGenerator::WidgetDidReceivePaintAtSizeAck( // TODO: Figure out a way to avoid this copy? non_owned_bitmap.copyTo(&result, SkBitmap::kARGB_8888_Config); - item->second->callback->Run(result); + item->second->callback.Run(result); // We're done with the callback, and with the DIB, so delete both. callback_map_.erase(item); diff --git a/chrome/browser/tab_contents/thumbnail_generator.h b/chrome/browser/tab_contents/thumbnail_generator.h index 0c0e588..8329f29 100644 --- a/chrome/browser/tab_contents/thumbnail_generator.h +++ b/chrome/browser/tab_contents/thumbnail_generator.h @@ -32,7 +32,7 @@ class TopSites; class ThumbnailGenerator : public NotificationObserver, public TabContentsObserver { public: - typedef Callback1<const SkBitmap&>::Type ThumbnailReadyCallback; + typedef base::Callback<void(const SkBitmap&)> ThumbnailReadyCallback; // The result of clipping. This can be used to determine if the // generated thumbnail is good or not. enum ClipResult { @@ -80,7 +80,7 @@ class ThumbnailGenerator : public NotificationObserver, // dimensions, but might not be the exact size requested. void AskForSnapshot(RenderWidgetHost* renderer, bool prefer_backing_store, - ThumbnailReadyCallback* callback, + const ThumbnailReadyCallback& callback, gfx::Size page_size, gfx::Size desired_size); diff --git a/chrome/browser/tabs/tab_finder.cc b/chrome/browser/tabs/tab_finder.cc index af32e1f..5bf2c59 100644 --- a/chrome/browser/tabs/tab_finder.cc +++ b/chrome/browser/tabs/tab_finder.cc @@ -4,6 +4,8 @@ #include "chrome/browser/tabs/tab_finder.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/command_line.h" #include "base/stl_util.h" #include "chrome/browser/history/history.h" @@ -216,7 +218,8 @@ void TabFinder::FetchRedirectStart(TabContents* tab) { history->QueryRedirectsTo( committed_entry->url(), &callback_consumer_, - NewCallback(this, &TabFinder::QueryRedirectsToComplete)); + base::Bind(&TabFinder::QueryRedirectsToComplete, + base::Unretained(this))); callback_consumer_.SetClientData(history, request_handle, tab); } } diff --git a/chrome/browser/ui/cocoa/history_menu_bridge.mm b/chrome/browser/ui/cocoa/history_menu_bridge.mm index fa68650..6c54b81 100644 --- a/chrome/browser/ui/cocoa/history_menu_bridge.mm +++ b/chrome/browser/ui/cocoa/history_menu_bridge.mm @@ -4,7 +4,8 @@ #include "chrome/browser/ui/cocoa/history_menu_bridge.h" -#include "base/callback.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/stl_util.h" #include "base/string_number_conversions.h" #include "base/string_util.h" @@ -386,7 +387,8 @@ void HistoryMenuBridge::CreateMenu() { &cancelable_request_consumer_, base::Time::Now() - base::TimeDelta::FromDays(kMostVisitedScope), kMostVisitedCount, - NewCallback(this, &HistoryMenuBridge::OnVisitedHistoryResults)); + base::Bind(&HistoryMenuBridge::OnVisitedHistoryResults, + base::Unretained(this))); } void HistoryMenuBridge::OnVisitedHistoryResults( @@ -444,9 +446,9 @@ HistoryMenuBridge::HistoryItem* HistoryMenuBridge::HistoryItemForTab( void HistoryMenuBridge::GetFaviconForHistoryItem(HistoryItem* item) { FaviconService* service = profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); - FaviconService::Handle handle = service->GetFaviconForURL(item->url, - history::FAVICON, &favicon_consumer_, - NewCallback(this, &HistoryMenuBridge::GotFaviconData)); + FaviconService::Handle handle = service->GetFaviconForURL( + item->url, history::FAVICON, &favicon_consumer_, + base::Bind(&HistoryMenuBridge::GotFaviconData, base::Unretained(this))); favicon_consumer_.SetClientData(service, handle, item); item->icon_handle = handle; item->icon_requested = true; diff --git a/chrome/browser/ui/cocoa/tabpose_window.mm b/chrome/browser/ui/cocoa/tabpose_window.mm index 6a07d23..3a75527 100644 --- a/chrome/browser/ui/cocoa/tabpose_window.mm +++ b/chrome/browser/ui/cocoa/tabpose_window.mm @@ -10,7 +10,7 @@ #include "base/mac/mac_util.h" #include "base/mac/scoped_cftyperef.h" -#include "base/memory/scoped_callback_factory.h" +#include "base/memory/weak_ptr.h" #include "base/sys_string_conversions.h" #include "chrome/app/chrome_command_ids.h" #include "chrome/browser/browser_process.h" @@ -136,7 +136,7 @@ namespace tabpose { class ThumbnailLoader : public base::RefCountedThreadSafe<ThumbnailLoader> { public: ThumbnailLoader(gfx::Size size, RenderWidgetHost* rwh, ThumbnailLayer* layer) - : size_(size), rwh_(rwh), layer_(layer), factory_(this) {} + : size_(size), rwh_(rwh), layer_(layer), weak_factory_(this) {} // Starts the fetch. void LoadThumbnail(); @@ -160,7 +160,7 @@ class ThumbnailLoader : public base::RefCountedThreadSafe<ThumbnailLoader> { gfx::Size size_; RenderWidgetHost* rwh_; // weak ThumbnailLayer* layer_; // weak, owns us - base::ScopedCallbackFactory<ThumbnailLoader> factory_; + base::WeakPtrFactory<ThumbnailLoader> weak_factory_; DISALLOW_COPY_AND_ASSIGN(ThumbnailLoader); }; @@ -185,7 +185,8 @@ void ThumbnailLoader::LoadThumbnail() { generator->AskForSnapshot( rwh_, /*prefer_backing_store=*/false, - factory_.NewCallback(&ThumbnailLoader::DidReceiveBitmap), + base::Bind(&ThumbnailLoader::DidReceiveBitmap, + weak_factory_.GetWeakPtr()), page_size, pixel_size); } diff --git a/chrome/browser/ui/intents/web_intent_picker_controller.cc b/chrome/browser/ui/intents/web_intent_picker_controller.cc index cbc02ce..dc89ccf 100644 --- a/chrome/browser/ui/intents/web_intent_picker_controller.cc +++ b/chrome/browser/ui/intents/web_intent_picker_controller.cc @@ -6,6 +6,8 @@ #include <vector> +#include "base/bind.h" +#include "base/bind_helpers.h" #include "chrome/browser/favicon/favicon_service.h" #include "chrome/browser/intents/web_intents_registry.h" #include "chrome/browser/intents/web_intents_registry_factory.h" @@ -259,8 +261,9 @@ void WebIntentPickerController::FaviconFetcher::Fetch( urls[index], history::FAVICON, &load_consumer_, - NewCallback(this, &WebIntentPickerController::FaviconFetcher:: - OnFaviconDataAvailable)); + base::Bind( + &WebIntentPickerController::FaviconFetcher::OnFaviconDataAvailable, + base::Unretained(this))); load_consumer_.SetClientData(favicon_service_, handle, index); } } diff --git a/chrome/browser/ui/search_engines/template_url_table_model.cc b/chrome/browser/ui/search_engines/template_url_table_model.cc index df098cd..30151c9 100644 --- a/chrome/browser/ui/search_engines/template_url_table_model.cc +++ b/chrome/browser/ui/search_engines/template_url_table_model.cc @@ -4,7 +4,8 @@ #include "chrome/browser/ui/search_engines/template_url_table_model.h" -#include "base/callback.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/i18n/rtl.h" #include "base/stl_util.h" #include "base/utf_string_conversions.h" @@ -92,7 +93,8 @@ class ModelEntry { load_state_ = LOADING; favicon_service->GetFavicon(favicon_url, history::FAVICON, &request_consumer_, - NewCallback(this, &ModelEntry::OnFaviconDataAvailable)); + base::Bind(&ModelEntry::OnFaviconDataAvailable, + base::Unretained(this))); } void OnFaviconDataAvailable( diff --git a/chrome/browser/ui/toolbar/back_forward_menu_model.cc b/chrome/browser/ui/toolbar/back_forward_menu_model.cc index b634544..c9a9f7e 100644 --- a/chrome/browser/ui/toolbar/back_forward_menu_model.cc +++ b/chrome/browser/ui/toolbar/back_forward_menu_model.cc @@ -6,6 +6,8 @@ #include "chrome/browser/ui/toolbar/back_forward_menu_model.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/string_number_conversions.h" #include "chrome/browser/event_disposition.h" #include "chrome/browser/prefs/pref_service.h" @@ -231,7 +233,8 @@ void BackForwardMenuModel::FetchFavicon(NavigationEntry* entry) { return; FaviconService::Handle handle = favicon_service->GetFaviconForURL( entry->url(), history::FAVICON, &load_consumer_, - NewCallback(this, &BackForwardMenuModel::OnFavIconDataAvailable)); + base::Bind(&BackForwardMenuModel::OnFavIconDataAvailable, + base::Unretained(this))); load_consumer_.SetClientData(favicon_service, handle, entry->unique_id()); } diff --git a/chrome/browser/ui/webui/chrome_web_ui_factory.cc b/chrome/browser/ui/webui/chrome_web_ui_factory.cc index 09f06cb..bcf2008 100644 --- a/chrome/browser/ui/webui/chrome_web_ui_factory.cc +++ b/chrome/browser/ui/webui/chrome_web_ui_factory.cc @@ -340,9 +340,7 @@ void ChromeWebUIFactory::GetFaviconForURL( favicon.known_icon = favicon.image_data.get() != NULL && favicon.image_data->size() > 0; favicon.icon_type = history::FAVICON; - request->ForwardResultAsync( - FaviconService::FaviconDataCallback::TupleType(request->handle(), - favicon)); + request->ForwardResultAsync(request->handle(), favicon); } } diff --git a/chrome/browser/ui/webui/extension_icon_source.cc b/chrome/browser/ui/webui/extension_icon_source.cc index f896457..81b0c833 100644 --- a/chrome/browser/ui/webui/extension_icon_source.cc +++ b/chrome/browser/ui/webui/extension_icon_source.cc @@ -4,7 +4,8 @@ #include "chrome/browser/ui/webui/extension_icon_source.h" -#include "base/callback.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/memory/ref_counted_memory.h" #include "base/stl_util.h" #include "base/string_number_conversions.h" @@ -241,7 +242,8 @@ void ExtensionIconSource::LoadFaviconImage(int request_id) { favicon_url, history::FAVICON, &cancelable_consumer_, - NewCallback(this, &ExtensionIconSource::OnFaviconDataAvailable)); + base::Bind(&ExtensionIconSource::OnFaviconDataAvailable, + base::Unretained(this))); cancelable_consumer_.SetClientData(favicon_service, handle, request_id); } diff --git a/chrome/browser/ui/webui/favicon_source.cc b/chrome/browser/ui/webui/favicon_source.cc index 7b66fb7..480c2f5 100644 --- a/chrome/browser/ui/webui/favicon_source.cc +++ b/chrome/browser/ui/webui/favicon_source.cc @@ -4,7 +4,8 @@ #include "chrome/browser/ui/webui/favicon_source.h" -#include "base/callback.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/url_constants.h" #include "grit/ui_resources.h" @@ -41,7 +42,8 @@ void FaviconSource::StartDataRequest(const std::string& path, GURL(path.substr(8)), history::FAVICON, &cancelable_consumer_, - NewCallback(this, &FaviconSource::OnFaviconDataAvailable)); + base::Bind(&FaviconSource::OnFaviconDataAvailable, + base::Unretained(this))); } else { GURL url; @@ -63,7 +65,8 @@ void FaviconSource::StartDataRequest(const std::string& path, url, icon_types_, &cancelable_consumer_, - NewCallback(this, &FaviconSource::OnFaviconDataAvailable)); + base::Bind(&FaviconSource::OnFaviconDataAvailable, + base::Unretained(this))); } // Attach the ChromeURLDataManager request ID to the history request. cancelable_consumer_.SetClientData(favicon_service, handle, request_id); diff --git a/chrome/browser/ui/webui/history2_ui.cc b/chrome/browser/ui/webui/history2_ui.cc index 7b80a82..48cb4fa 100644 --- a/chrome/browser/ui/webui/history2_ui.cc +++ b/chrome/browser/ui/webui/history2_ui.cc @@ -150,7 +150,8 @@ void BrowsingHistoryHandler2::HandleGetHistory(const ListValue* args) { hs->QueryHistory(search_text_, options, &cancelable_search_consumer_, - NewCallback(this, &BrowsingHistoryHandler2::QueryComplete)); + base::Bind(&BrowsingHistoryHandler2::QueryComplete, + base::Unretained(this))); } void BrowsingHistoryHandler2::HandleSearchHistory(const ListValue* args) { @@ -175,7 +176,8 @@ void BrowsingHistoryHandler2::HandleSearchHistory(const ListValue* args) { hs->QueryHistory(search_text_, options, &cancelable_search_consumer_, - NewCallback(this, &BrowsingHistoryHandler2::QueryComplete)); + base::Bind(&BrowsingHistoryHandler2::QueryComplete, + base::Unretained(this))); } void BrowsingHistoryHandler2::HandleRemoveURLsOnOneDay(const ListValue* args) { @@ -216,7 +218,8 @@ void BrowsingHistoryHandler2::HandleRemoveURLsOnOneDay(const ListValue* args) { Profile::FromWebUI(web_ui_)->GetHistoryService(Profile::EXPLICIT_ACCESS); hs->ExpireHistoryBetween( urls_to_be_deleted_, begin_time, end_time, &cancelable_delete_consumer_, - NewCallback(this, &BrowsingHistoryHandler2::RemoveComplete)); + base::Bind(&BrowsingHistoryHandler2::RemoveComplete, + base::Unretained(this))); } void BrowsingHistoryHandler2::HandleClearBrowsingData(const ListValue* args) { diff --git a/chrome/browser/ui/webui/history_ui.cc b/chrome/browser/ui/webui/history_ui.cc index f88d4db..ba1a648 100644 --- a/chrome/browser/ui/webui/history_ui.cc +++ b/chrome/browser/ui/webui/history_ui.cc @@ -181,7 +181,8 @@ void BrowsingHistoryHandler::HandleGetHistory(const ListValue* args) { hs->QueryHistory(search_text_, options, &cancelable_search_consumer_, - NewCallback(this, &BrowsingHistoryHandler::QueryComplete)); + base::Bind(&BrowsingHistoryHandler::QueryComplete, + base::Unretained(this))); } void BrowsingHistoryHandler::HandleSearchHistory(const ListValue* args) { @@ -206,7 +207,8 @@ void BrowsingHistoryHandler::HandleSearchHistory(const ListValue* args) { hs->QueryHistory(search_text_, options, &cancelable_search_consumer_, - NewCallback(this, &BrowsingHistoryHandler::QueryComplete)); + base::Bind(&BrowsingHistoryHandler::QueryComplete, + base::Unretained(this))); } void BrowsingHistoryHandler::HandleRemoveURLsOnOneDay(const ListValue* args) { @@ -242,7 +244,8 @@ void BrowsingHistoryHandler::HandleRemoveURLsOnOneDay(const ListValue* args) { Profile::FromWebUI(web_ui_)->GetHistoryService(Profile::EXPLICIT_ACCESS); hs->ExpireHistoryBetween( urls, begin_time, end_time, &cancelable_delete_consumer_, - NewCallback(this, &BrowsingHistoryHandler::RemoveComplete)); + base::Bind(&BrowsingHistoryHandler::RemoveComplete, + base::Unretained(this))); } void BrowsingHistoryHandler::HandleClearBrowsingData(const ListValue* args) { diff --git a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc index 111f9a7..3651009 100644 --- a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc +++ b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc @@ -792,7 +792,7 @@ void AppLauncherHandler::HandleGenerateAppForLink(const ListValue* args) { FaviconService::Handle h = favicon_service->GetFaviconForURL( launch_url, history::FAVICON, &favicon_consumer_, - NewCallback(this, &AppLauncherHandler::OnFaviconForApp)); + base::Bind(&AppLauncherHandler::OnFaviconForApp, base::Unretained(this))); favicon_consumer_.SetClientData(favicon_service, h, install_info.release()); } diff --git a/chrome/browser/ui/webui/ntp/favicon_webui_handler.cc b/chrome/browser/ui/webui/ntp/favicon_webui_handler.cc index f4e9688..0ae6443 100644 --- a/chrome/browser/ui/webui/ntp/favicon_webui_handler.cc +++ b/chrome/browser/ui/webui/ntp/favicon_webui_handler.cc @@ -5,7 +5,7 @@ #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h" #include "base/bind.h" -#include "base/callback_old.h" +#include "base/bind_helpers.h" #include "base/string_split.h" #include "base/string_util.h" #include "base/stringprintf.h" @@ -77,7 +77,8 @@ void FaviconWebUIHandler::HandleGetFaviconDominantColor(const ListValue* args) { GURL(path), history::FAVICON, &consumer_, - NewCallback(this, &FaviconWebUIHandler::OnFaviconDataAvailable)); + base::Bind(&FaviconWebUIHandler::OnFaviconDataAvailable, + base::Unretained(this))); consumer_.SetClientData(favicon_service, handle, id_++); } diff --git a/chrome/test/base/ui_test_utils.cc b/chrome/test/base/ui_test_utils.cc index c664f77..f2e6f8a 100644 --- a/chrome/test/base/ui_test_utils.cc +++ b/chrome/test/base/ui_test_utils.cc @@ -6,6 +6,8 @@ #include <vector> +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/callback.h" #include "base/command_line.h" #include "base/file_path.h" @@ -929,7 +931,7 @@ class SnapshotTaker { generator->AskForSnapshot( rwh, false, // don't use backing_store - NewCallback(this, &SnapshotTaker::OnSnapshotTaken), + base::Bind(&SnapshotTaker::OnSnapshotTaken, base::Unretained(this)), page_size, desired_size); ui_test_utils::RunMessageLoop(); |