diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/download/chrome_download_manager_delegate.cc | 11 | ||||
-rw-r--r-- | chrome/browser/download/download_browsertest.cc | 28 | ||||
-rw-r--r-- | chrome/browser/download/download_history.cc | 22 | ||||
-rw-r--r-- | chrome/browser/download/download_history.h | 8 | ||||
-rw-r--r-- | chrome/browser/download/download_manager_unittest.cc | 7 | ||||
-rw-r--r-- | chrome/browser/download/download_prefs.cc | 3 | ||||
-rw-r--r-- | chrome/browser/download/download_request_limiter.cc | 10 | ||||
-rw-r--r-- | chrome/browser/download/download_safe_browsing_client.cc | 44 | ||||
-rw-r--r-- | chrome/browser/download/download_safe_browsing_client.h | 29 |
9 files changed, 70 insertions, 92 deletions
diff --git a/chrome/browser/download/chrome_download_manager_delegate.cc b/chrome/browser/download/chrome_download_manager_delegate.cc index 08f7265..6bd11fa 100644 --- a/chrome/browser/download/chrome_download_manager_delegate.cc +++ b/chrome/browser/download/chrome_download_manager_delegate.cc @@ -93,7 +93,8 @@ bool ChromeDownloadManagerDelegate::ShouldStartDownload(int32 download_id) { download_id, download->url_chain(), download->referrer_url(), profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)); sb_client->CheckDownloadUrl( - NewCallback(this, &ChromeDownloadManagerDelegate::CheckDownloadUrlDone)); + base::Bind(&ChromeDownloadManagerDelegate::CheckDownloadUrlDone, + base::Unretained(this))); #else CheckDownloadUrlDone(download_id, false); #endif @@ -203,7 +204,8 @@ void ChromeDownloadManagerDelegate::OnResponseCompleted( prefs::kSafeBrowsingEnabled)); sb_client->CheckDownloadHash( hash, - NewCallback(this, &ChromeDownloadManagerDelegate::CheckDownloadHashDone)); + base::Bind(&ChromeDownloadManagerDelegate::CheckDownloadHashDone, + base::Unretained(this))); #endif } @@ -299,9 +301,8 @@ void ChromeDownloadManagerDelegate::CheckDownloadUrlDone( download_history_->CheckVisitedReferrerBefore( download_id, download->referrer_url(), - NewCallback( - this, - &ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone)); + base::Bind(&ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone, + base::Unretained(this))); } // NotificationObserver implementation. diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc index a6265d5..dbb681a 100644 --- a/chrome/browser/download/download_browsertest.cc +++ b/chrome/browser/download/download_browsertest.cc @@ -176,10 +176,8 @@ class DownloadsObserver : public DownloadManager::Observer, // real UI would. BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, - NewRunnableFunction( - &AcceptDangerousDownload, - download_manager_, - download->id())); + base::Bind(&AcceptDangerousDownload, download_manager_, + download->id())); break; case ON_DANGEROUS_DOWNLOAD_DENY: @@ -187,10 +185,8 @@ class DownloadsObserver : public DownloadManager::Observer, // real UI would. BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, - NewRunnableFunction( - &DenyDangerousDownload, - download_manager_, - download->id())); + base::Bind(&DenyDangerousDownload, download_manager_, + download->id())); break; case ON_DANGEROUS_DOWNLOAD_FAIL: @@ -202,9 +198,8 @@ class DownloadsObserver : public DownloadManager::Observer, } } - if (download->state() == download_finished_state_) { + if (download->state() == download_finished_state_) DownloadInFinalState(download); - } } virtual void OnDownloadOpened(DownloadItem* download) {} @@ -409,8 +404,7 @@ class DownloadsFlushObserver // there's a self-task posting in the IO thread cancel path. BrowserThread::PostTask( BrowserThread::FILE, FROM_HERE, - NewRunnableMethod(this, - &DownloadsFlushObserver::PingFileThread, 2)); + base::Bind(&DownloadsFlushObserver::PingFileThread, this, 2)); } } } @@ -418,16 +412,14 @@ class DownloadsFlushObserver void PingFileThread(int cycle) { BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, - NewRunnableMethod(this, &DownloadsFlushObserver::PingIOThread, - cycle)); + base::Bind(&DownloadsFlushObserver::PingIOThread, this, cycle)); } void PingIOThread(int cycle) { if (--cycle) { BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, - NewRunnableMethod(this, &DownloadsFlushObserver::PingFileThread, - cycle)); + base::Bind(&DownloadsFlushObserver::PingFileThread, this, cycle)); } else { BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, new MessageLoop::QuitTask()); @@ -458,7 +450,7 @@ class CancelTestDataCollector DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, - NewRunnableMethod(this, &CancelTestDataCollector::IOInfoCollector)); + base::Bind(&CancelTestDataCollector::IOInfoCollector, this)); ui_test_utils::RunMessageLoop(); } @@ -477,7 +469,7 @@ class CancelTestDataCollector rdh_pending_requests_ = resource_dispatcher_host_->pending_requests(); BrowserThread::PostTask( BrowserThread::FILE, FROM_HERE, - NewRunnableMethod(this, &CancelTestDataCollector::FileInfoCollector)); + base::Bind(&CancelTestDataCollector::FileInfoCollector, this)); } void FileInfoCollector() { diff --git a/chrome/browser/download/download_history.cc b/chrome/browser/download/download_history.cc index 0398a3c..9ac6c1a 100644 --- a/chrome/browser/download/download_history.cc +++ b/chrome/browser/download/download_history.cc @@ -17,15 +17,7 @@ DownloadHistory::DownloadHistory(Profile* profile) DCHECK(profile); } -DownloadHistory::~DownloadHistory() { - // For any outstanding requests to - // HistoryService::GetVisibleVisitCountToHost(), since they'll be cancelled - // and thus not call back to OnGotVisitCountToHost(), we need to delete the - // associated VisitedBeforeDoneCallbacks. - for (VisitedBeforeRequestsMap::iterator i(visited_before_requests_.begin()); - i != visited_before_requests_.end(); ++i) - delete i->second.second; -} +DownloadHistory::~DownloadHistory() {} void DownloadHistory::GetNextId( const HistoryService::DownloadNextIdCallback& callback) { @@ -51,9 +43,7 @@ void DownloadHistory::Load( void DownloadHistory::CheckVisitedReferrerBefore( int32 download_id, const GURL& referrer_url, - VisitedBeforeDoneCallback* callback) { - DCHECK(callback); - + const VisitedBeforeDoneCallback& callback) { if (referrer_url.is_valid()) { HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); if (hs) { @@ -65,8 +55,7 @@ void DownloadHistory::CheckVisitedReferrerBefore( return; } } - callback->Run(download_id, false); - delete callback; + callback.Run(download_id, false); } void DownloadHistory::AddEntry( @@ -151,9 +140,8 @@ void DownloadHistory::OnGotVisitCountToHost(HistoryService::Handle handle, visited_before_requests_.find(handle); DCHECK(request != visited_before_requests_.end()); int32 download_id = request->second.first; - VisitedBeforeDoneCallback* callback = request->second.second; + VisitedBeforeDoneCallback callback = request->second.second; visited_before_requests_.erase(request); - callback->Run(download_id, found_visits && count && + callback.Run(download_id, found_visits && count && (first_visit.LocalMidnight() < base::Time::Now().LocalMidnight())); - delete callback; } diff --git a/chrome/browser/download/download_history.h b/chrome/browser/download/download_history.h index 06c7df9..be0c28d 100644 --- a/chrome/browser/download/download_history.h +++ b/chrome/browser/download/download_history.h @@ -9,7 +9,7 @@ #include <map> #include "base/basictypes.h" -#include "base/callback_old.h" +#include "base/callback.h" #include "chrome/browser/history/history.h" #include "content/browser/cancelable_request.h" @@ -23,7 +23,7 @@ class Time; // Interacts with the HistoryService on behalf of the download subsystem. class DownloadHistory { public: - typedef Callback2<int32, bool>::Type VisitedBeforeDoneCallback; + typedef base::Callback<void(int32, bool)> VisitedBeforeDoneCallback; explicit DownloadHistory(Profile* profile); ~DownloadHistory(); @@ -40,7 +40,7 @@ class DownloadHistory { // ownership of |callback|. void CheckVisitedReferrerBefore(int32 download_id, const GURL& referrer_url, - VisitedBeforeDoneCallback* callback); + const VisitedBeforeDoneCallback& callback); // Adds a new entry for a download to the history database. void AddEntry(DownloadItem* download_item, @@ -65,7 +65,7 @@ class DownloadHistory { private: typedef std::map<HistoryService::Handle, - std::pair<int32, VisitedBeforeDoneCallback*> > + std::pair<int32, VisitedBeforeDoneCallback> > VisitedBeforeRequestsMap; void OnGotVisitCountToHost(HistoryService::Handle handle, diff --git a/chrome/browser/download/download_manager_unittest.cc b/chrome/browser/download/download_manager_unittest.cc index f93c140..db1a1f0 100644 --- a/chrome/browser/download/download_manager_unittest.cc +++ b/chrome/browser/download/download_manager_unittest.cc @@ -5,6 +5,7 @@ #include <string> #include <set> +#include "base/bind.h" #include "base/file_util.h" #include "base/i18n/number_formatting.h" #include "base/i18n/rtl.h" @@ -99,10 +100,8 @@ class DownloadManagerTest : public testing::Test { BrowserThread::PostTask( BrowserThread::FILE, FROM_HERE, - NewRunnableMethod(file_manager_.get(), - &DownloadFileManager::UpdateDownload, - DownloadId(download_manager_.get(), id), - &download_buffer_)); + base::Bind(&DownloadFileManager::UpdateDownload, file_manager_.get(), + DownloadId(download_manager_.get(), id), &download_buffer_)); message_loop_.RunAllPending(); } diff --git a/chrome/browser/download/download_prefs.cc b/chrome/browser/download/download_prefs.cc index e037012..0e74b30 100644 --- a/chrome/browser/download/download_prefs.cc +++ b/chrome/browser/download/download_prefs.cc @@ -4,6 +4,7 @@ #include "chrome/browser/download/download_prefs.h" +#include "base/bind.h" #include "base/file_util.h" #include "base/logging.h" #include "base/string_split.h" @@ -73,7 +74,7 @@ void DownloadPrefs::RegisterUserPrefs(PrefService* prefs) { // Ensure that the download directory specified in the preferences exists. BrowserThread::PostTask( BrowserThread::FILE, FROM_HERE, - NewRunnableFunction(&file_util::CreateDirectory, default_download_path)); + base::Bind(&file_util::CreateDirectory, default_download_path)); #endif // defined(OS_CHROMEOS) // If the download path is dangerous we forcefully reset it. But if we do diff --git a/chrome/browser/download/download_request_limiter.cc b/chrome/browser/download/download_request_limiter.cc index b3e24414..3b6b42c 100644 --- a/chrome/browser/download/download_request_limiter.cc +++ b/chrome/browser/download/download_request_limiter.cc @@ -4,6 +4,7 @@ #include "chrome/browser/download/download_request_limiter.h" +#include "base/bind.h" #include "base/stl_util.h" #include "chrome/browser/download/download_request_infobar_delegate.h" #include "chrome/browser/infobars/infobar_tab_helper.h" @@ -204,9 +205,8 @@ void DownloadRequestLimiter::CanDownloadOnIOThread(int render_process_host_id, DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, - NewRunnableMethod(this, &DownloadRequestLimiter::CanDownload, - render_process_host_id, render_view_id, request_id, - callback)); + base::Bind(&DownloadRequestLimiter::CanDownload, this, + render_process_host_id, render_view_id, request_id, callback)); } void DownloadRequestLimiter::OnUserGesture(TabContents* tab) { @@ -317,8 +317,8 @@ void DownloadRequestLimiter::ScheduleNotification(Callback* callback, bool allow) { BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, - NewRunnableMethod( - this, &DownloadRequestLimiter::NotifyCallback, callback, allow)); + base::Bind(&DownloadRequestLimiter::NotifyCallback, this, callback, + allow)); } void DownloadRequestLimiter::NotifyCallback(Callback* callback, bool allow) { diff --git a/chrome/browser/download/download_safe_browsing_client.cc b/chrome/browser/download/download_safe_browsing_client.cc index 15966b5..1cfced0 100644 --- a/chrome/browser/download/download_safe_browsing_client.cc +++ b/chrome/browser/download/download_safe_browsing_client.cc @@ -5,6 +5,7 @@ #include "chrome/browser/download/download_safe_browsing_client.h" +#include "base/bind.h" #include "base/command_line.h" #include "base/logging.h" #include "base/metrics/histogram.h" @@ -38,35 +39,30 @@ DownloadSBClient::DownloadSBClient(int32 download_id, DownloadSBClient::~DownloadSBClient() {} -void DownloadSBClient::CheckDownloadUrl(UrlDoneCallback* callback) { +void DownloadSBClient::CheckDownloadUrl(const UrlDoneCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); // It is not allowed to call this method twice. - CHECK(!url_done_callback_.get() && !hash_done_callback_.get()); - CHECK(callback); + CHECK(url_done_callback_.is_null() && hash_done_callback_.is_null()); start_time_ = base::TimeTicks::Now(); - url_done_callback_.reset(callback); + url_done_callback_ = callback; BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, - NewRunnableMethod(this, - &DownloadSBClient::CheckDownloadUrlOnIOThread, - url_chain_)); + base::Bind(&DownloadSBClient::CheckDownloadUrlOnIOThread, this, + url_chain_)); } void DownloadSBClient::CheckDownloadHash(const std::string& hash, - HashDoneCallback* callback) { + const HashDoneCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); // It is not allowed to call this method twice. - CHECK(!url_done_callback_.get() && !hash_done_callback_.get()); - CHECK(callback); + CHECK(url_done_callback_.is_null() && hash_done_callback_.is_null()); start_time_ = base::TimeTicks::Now(); - hash_done_callback_.reset(callback); + hash_done_callback_ = callback; BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, - NewRunnableMethod(this, - &DownloadSBClient::CheckDownloadHashOnIOThread, - hash)); + base::Bind(&DownloadSBClient::CheckDownloadHashOnIOThread, this, hash)); } void DownloadSBClient::CheckDownloadUrlOnIOThread( @@ -89,10 +85,9 @@ void DownloadSBClient::OnDownloadUrlCheckResult( const std::vector<GURL>& url_chain, SafeBrowsingService::UrlCheckResult result) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, - NewRunnableMethod(this, - &DownloadSBClient::SafeBrowsingCheckUrlDone, - result)); + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + base::Bind(&DownloadSBClient::SafeBrowsingCheckUrlDone, this, result)); Release(); } @@ -113,11 +108,10 @@ void DownloadSBClient::CheckDownloadHashOnIOThread(const std::string& hash) { void DownloadSBClient::OnDownloadHashCheckResult( const std::string& hash, SafeBrowsingService::UrlCheckResult result) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, - NewRunnableMethod(this, - &DownloadSBClient::SafeBrowsingCheckHashDone, - result, - hash)); + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + base::Bind(&DownloadSBClient::SafeBrowsingCheckHashDone, this, result, + hash)); Release(); } @@ -127,7 +121,7 @@ void DownloadSBClient::SafeBrowsingCheckUrlDone( DVLOG(1) << "SafeBrowsingCheckUrlDone with result: " << result; bool is_dangerous = result != SafeBrowsingService::SAFE; - url_done_callback_->Run(download_id_, is_dangerous); + url_done_callback_.Run(download_id_, is_dangerous); if (sb_service_.get() && sb_service_->download_protection_enabled()) { UMA_HISTOGRAM_TIMES("SB2.DownloadUrlCheckDuration", @@ -147,7 +141,7 @@ void DownloadSBClient::SafeBrowsingCheckHashDone( DVLOG(1) << "SafeBrowsingCheckHashDone with result: " << result; bool is_dangerous = result != SafeBrowsingService::SAFE; - hash_done_callback_->Run(download_id_, is_dangerous); + hash_done_callback_.Run(download_id_, is_dangerous); if (sb_service_.get() && sb_service_->download_protection_enabled()) { UMA_HISTOGRAM_TIMES("SB2.DownloadHashCheckDuration", diff --git a/chrome/browser/download/download_safe_browsing_client.h b/chrome/browser/download/download_safe_browsing_client.h index 5aa44b5..3b4d14b9 100644 --- a/chrome/browser/download/download_safe_browsing_client.h +++ b/chrome/browser/download/download_safe_browsing_client.h @@ -6,22 +6,24 @@ #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SAFE_BROWSING_CLIENT_H_ #pragma once -#include "base/callback_old.h" +#include "base/callback.h" #include "base/memory/ref_counted.h" #include "base/time.h" #include "chrome/browser/safe_browsing/safe_browsing_service.h" // This is a helper class used by DownloadManager to check a download URL with -// SafeBrowsingService. The client is refcounted and will be released once -// there is no reference to it. +// SafeBrowsingService. The client is refcounted and will be released once there +// is no reference to it. // Usage: // { // scoped_refptr<DownloadSBClient> client_ = new DownloadSBClient(...); -// client_->CheckDownloadUrl(..., NewCallback(this, -// &DownloadManager::UrlCallBack)); +// client_->CheckDownloadUrl( +// ..., base::Bind(&DownloadManager::UrlCallBack, +// base::Unretained(this))); // or -// client_->CheckDownloadHash(..., NewCallback(this, -// &DownloadManager::HashCallBack)); +// client_->CheckDownloadHash( +// ..., base::Bind(&DownloadManager::HashCallBack, +// base::Unretained(this))); // } // DownloadManager::UrlCallBack(...) or HashCallCall { // // After this, the |client_| is gone. @@ -30,8 +32,8 @@ class DownloadSBClient : public SafeBrowsingService::Client, public base::RefCountedThreadSafe<DownloadSBClient> { public: - typedef Callback2<int32, bool>::Type UrlDoneCallback; - typedef Callback2<int32, bool>::Type HashDoneCallback; + typedef base::Callback<void(int32, bool)> UrlDoneCallback; + typedef base::Callback<void(int32, bool)> HashDoneCallback; DownloadSBClient(int32 download_id, const std::vector<GURL>& url_chain, @@ -42,8 +44,9 @@ class DownloadSBClient // For each DownloadSBClient instance, either CheckDownloadUrl or // CheckDownloadHash can be called, and be called only once. // DownloadSBClient instance. - void CheckDownloadUrl(UrlDoneCallback* callback); - void CheckDownloadHash(const std::string& hash, HashDoneCallback* callback); + void CheckDownloadUrl(const UrlDoneCallback& callback); + void CheckDownloadHash(const std::string& hash, + const HashDoneCallback& callback); private: // Call SafeBrowsingService on IO thread to verify the download URL or @@ -99,8 +102,8 @@ class DownloadSBClient // Update the UMA stats. void UpdateDownloadCheckStats(SBStatsType stat_type); - scoped_ptr<UrlDoneCallback> url_done_callback_; - scoped_ptr<HashDoneCallback> hash_done_callback_; + UrlDoneCallback url_done_callback_; + HashDoneCallback hash_done_callback_; int32 download_id_; scoped_refptr<SafeBrowsingService> sb_service_; |