From 4f1b97d5191ba6d5674b4d3ee4e851d18018d731 Mon Sep 17 00:00:00 2001 From: "shess@chromium.org" Date: Fri, 30 Sep 2011 19:37:50 +0000 Subject: [PATCH] Convert SafeBrowsingBlockingPage and test to new Bind/Callback system. Includes malware_details*. BUG=none TEST=none Review URL: http://codereview.chromium.org/8082011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103519 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/safe_browsing/malware_details.cc | 9 ++++----- chrome/browser/safe_browsing/malware_details_cache.cc | 9 ++++----- chrome/browser/safe_browsing/malware_details_cache.h | 5 +++-- chrome/browser/safe_browsing/malware_details_history.cc | 8 ++++---- chrome/browser/safe_browsing/malware_details_history.h | 5 +++-- chrome/browser/safe_browsing/malware_details_unittest.cc | 11 +++++------ chrome/browser/safe_browsing/safe_browsing_blocking_page.cc | 9 ++++----- .../safe_browsing/safe_browsing_blocking_page_test.cc | 12 ++++++------ 8 files changed, 33 insertions(+), 35 deletions(-) diff --git a/chrome/browser/safe_browsing/malware_details.cc b/chrome/browser/safe_browsing/malware_details.cc index d8edb233a186..09a7304d3efe 100644 --- a/chrome/browser/safe_browsing/malware_details.cc +++ b/chrome/browser/safe_browsing/malware_details.cc @@ -6,7 +6,7 @@ #include "chrome/browser/safe_browsing/malware_details.h" -#include "base/callback.h" +#include "base/bind.h" #include "base/lazy_instance.h" #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/profiles/profile.h" @@ -219,8 +219,7 @@ void MalwareDetails::OnReceivedMalwareDOMDetails( // of our data structures (eg GetSerializedReport). BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, - NewRunnableMethod( - this, &MalwareDetails::AddDOMDetails, params)); + base::Bind(&MalwareDetails::AddDOMDetails, this, params)); } void MalwareDetails::AddDOMDetails( @@ -262,7 +261,7 @@ void MalwareDetails::FinishCollection() { } redirects_collector_->StartHistoryCollection( urls, - NewRunnableMethod(this, &MalwareDetails::OnRedirectionCollectionReady)); + base::Bind(&MalwareDetails::OnRedirectionCollectionReady, this)); } void MalwareDetails::OnRedirectionCollectionReady() { @@ -278,7 +277,7 @@ void MalwareDetails::OnRedirectionCollectionReady() { request_context_getter_, &resources_, &cache_result_, - NewRunnableMethod(this, &MalwareDetails::OnCacheCollectionReady)); + base::Bind(&MalwareDetails::OnCacheCollectionReady, this)); } void MalwareDetails::AddRedirectUrlList(const std::vector& urls) { diff --git a/chrome/browser/safe_browsing/malware_details_cache.cc b/chrome/browser/safe_browsing/malware_details_cache.cc index 6836e9711072..40c7933bb895 100644 --- a/chrome/browser/safe_browsing/malware_details_cache.cc +++ b/chrome/browser/safe_browsing/malware_details_cache.cc @@ -6,7 +6,7 @@ #include "chrome/browser/safe_browsing/malware_details.h" -#include "base/callback.h" +#include "base/bind.h" #include "base/lazy_instance.h" #include "base/md5.h" #include "base/string_util.h" @@ -30,7 +30,6 @@ static const uint32 kMaxBodySizeBytes = 1024; MalwareDetailsCacheCollector::MalwareDetailsCacheCollector() : resources_(NULL), result_(NULL), - callback_(NULL), has_started_(false), current_fetch_(NULL) { } @@ -42,7 +41,7 @@ void MalwareDetailsCacheCollector::StartCacheCollection( net::URLRequestContextGetter* request_context_getter, safe_browsing::ResourceMap* resources, bool* result, - Task* callback) { + const base::Closure& callback) { // Start the data collection from the HTTP cache. We use a URLFetcher // and set the right flags so we only hit the cache. DVLOG(1) << "Getting cache data for all urls..."; @@ -57,7 +56,7 @@ void MalwareDetailsCacheCollector::StartCacheCollection( // check if we call their callback immediately. BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, - NewRunnableMethod(this, &MalwareDetailsCacheCollector::OpenEntry)); + base::Bind(&MalwareDetailsCacheCollector::OpenEntry, this)); } bool MalwareDetailsCacheCollector::HasStarted() { @@ -201,7 +200,7 @@ void MalwareDetailsCacheCollector::AdvanceEntry() { // Create a task so we don't take over the IO thread for too long. BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, - NewRunnableMethod(this, &MalwareDetailsCacheCollector::OpenEntry)); + base::Bind(&MalwareDetailsCacheCollector::OpenEntry, this)); } void MalwareDetailsCacheCollector::AllDone(bool success) { diff --git a/chrome/browser/safe_browsing/malware_details_cache.h b/chrome/browser/safe_browsing/malware_details_cache.h index 2b1a5ba2dbf3..33f6391db940 100644 --- a/chrome/browser/safe_browsing/malware_details_cache.h +++ b/chrome/browser/safe_browsing/malware_details_cache.h @@ -12,6 +12,7 @@ #include #include +#include "base/callback.h" #include "base/hash_tables.h" #include "base/memory/linked_ptr.h" #include "base/memory/ref_counted.h" @@ -48,7 +49,7 @@ class MalwareDetailsCacheCollector net::URLRequestContextGetter* request_context_getter, safe_browsing::ResourceMap* resources, bool* result, - Task* callback); + const base::Closure& callback); // Returns whether or not StartCacheCollection has been called. bool HasStarted(); @@ -76,7 +77,7 @@ class MalwareDetailsCacheCollector // Method we call when we are done. The caller must be alive for the // whole time, we are modifying its state (see above). - Task* callback_; + base::Closure callback_; // Set to true as soon as StartCacheCollection is called. bool has_started_; diff --git a/chrome/browser/safe_browsing/malware_details_history.cc b/chrome/browser/safe_browsing/malware_details_history.cc index 000a59bc7cca..df78385b2e92 100644 --- a/chrome/browser/safe_browsing/malware_details_history.cc +++ b/chrome/browser/safe_browsing/malware_details_history.cc @@ -6,6 +6,7 @@ #include "chrome/browser/safe_browsing/malware_details_history.h" +#include "base/bind.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/safe_browsing/malware_details.h" #include "chrome/common/chrome_notification_types.h" @@ -20,7 +21,6 @@ MalwareDetailsRedirectsCollector::MalwareDetailsRedirectsCollector( Profile* profile) : profile_(profile), - callback_(NULL), has_started_(false) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); if (profile) { @@ -34,7 +34,7 @@ MalwareDetailsRedirectsCollector::~MalwareDetailsRedirectsCollector() { void MalwareDetailsRedirectsCollector::StartHistoryCollection( const std::vector& urls, - Task* callback) { + const base::Closure& callback) { DVLOG(1) << "Num of urls to check in history service: " << urls.size(); has_started_ = true; callback_ = callback; @@ -46,8 +46,8 @@ void MalwareDetailsRedirectsCollector::StartHistoryCollection( BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, - NewRunnableMethod( - this, &MalwareDetailsRedirectsCollector::StartGetRedirects, urls)); + base::Bind(&MalwareDetailsRedirectsCollector::StartGetRedirects, + this, urls)); } void MalwareDetailsRedirectsCollector::StartGetRedirects( diff --git a/chrome/browser/safe_browsing/malware_details_history.h b/chrome/browser/safe_browsing/malware_details_history.h index 74d03faf3e6e..59ccdf84ebbd 100644 --- a/chrome/browser/safe_browsing/malware_details_history.h +++ b/chrome/browser/safe_browsing/malware_details_history.h @@ -11,6 +11,7 @@ #include #include +#include "base/callback.h" #include "base/hash_tables.h" #include "base/memory/linked_ptr.h" #include "base/memory/ref_counted.h" @@ -39,7 +40,7 @@ class MalwareDetailsRedirectsCollector // We get access to history service via tab_contents in UI thread. // Notice the callback will be posted to the IO thread. void StartHistoryCollection(const std::vector& urls, - Task* callback); + const base::Closure& callback); // Returns whether or not StartCacheCollection has been called. bool HasStarted() const; @@ -56,7 +57,7 @@ class MalwareDetailsRedirectsCollector // Method we call when we are done. The caller must be alive for the // whole time, we are modifying its state (see above). - Task* callback_; + base::Closure callback_; // Sets to true once StartHistoryCollection is called bool has_started_; diff --git a/chrome/browser/safe_browsing/malware_details_unittest.cc b/chrome/browser/safe_browsing/malware_details_unittest.cc index 8050a14054e9..7439d6b38c64 100644 --- a/chrome/browser/safe_browsing/malware_details_unittest.cc +++ b/chrome/browser/safe_browsing/malware_details_unittest.cc @@ -4,6 +4,7 @@ #include +#include "base/bind.h" #include "base/pickle.h" #include "base/time.h" #include "chrome/browser/history/history.h" @@ -149,7 +150,7 @@ class MockSafeBrowsingService : public SafeBrowsingService { // Notify WaitForSerializedReport. BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, - NewRunnableFunction(&QuitUIMessageLoop)); + base::Bind(&QuitUIMessageLoop)); serialized_ = serialized; } @@ -197,8 +198,7 @@ class MalwareDetailsTest : public ChromeRenderViewHostTestHarness { BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, - NewRunnableMethod( - report, &MalwareDetails::FinishCollection)); + base::Bind(&MalwareDetails::FinishCollection, report)); // Wait for the callback (SendSerializedMalwareDetails). DVLOG(1) << "Waiting for SendSerializedMalwareDetails"; MessageLoop::current()->Run(); @@ -528,9 +528,8 @@ TEST_F(MalwareDetailsTest, HTTPCache) { BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, - NewRunnableFunction( - &FillCache, - make_scoped_refptr(profile()->GetRequestContext()))); + base::Bind(&FillCache, + make_scoped_refptr(profile()->GetRequestContext()))); // The cache collection starts after the IPC from the DOM is fired. std::vector params; diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc index 8396ffedacc0..f2e0b92c04e0 100644 --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc @@ -8,6 +8,7 @@ #include +#include "base/bind.h" #include "base/i18n/rtl.h" #include "base/lazy_instance.h" #include "base/string_number_conversions.h" @@ -637,8 +638,7 @@ void SafeBrowsingBlockingPage::FinishMalwareDetails(int64 delay_ms) { // Finish the malware details collection, send it over. BrowserThread::PostDelayedTask( BrowserThread::IO, FROM_HERE, - NewRunnableMethod( - malware_details_.get(), &MalwareDetails::FinishCollection), + base::Bind(&MalwareDetails::FinishCollection, malware_details_.get()), delay_ms); } } @@ -650,9 +650,8 @@ void SafeBrowsingBlockingPage::NotifySafeBrowsingService( bool proceed) { BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, - NewRunnableMethod( - sb_service, &SafeBrowsingService::OnBlockingPageDone, - unsafe_resources, proceed)); + base::Bind(&SafeBrowsingService::OnBlockingPageDone, + sb_service, unsafe_resources, proceed)); } // static diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc index 2ff62b41fe6c..dc64322d9a08 100644 --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc @@ -7,6 +7,7 @@ // these urls, and sends "goback" or "proceed" commands and verifies // they work. +#include "base/bind.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" @@ -43,8 +44,8 @@ class FakeSafeBrowsingService : public SafeBrowsingService { BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, - NewRunnableMethod(this, &FakeSafeBrowsingService::OnCheckBrowseURLDone, - gurl, client)); + base::Bind(&FakeSafeBrowsingService::OnCheckBrowseURLDone, + this, gurl, client)); return false; } @@ -66,8 +67,7 @@ class FakeSafeBrowsingService : public SafeBrowsingService { // Notify the UI thread that we got a report. BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, - NewRunnableMethod(this, - &FakeSafeBrowsingService::OnMalwareDetailsDone)); + base::Bind(&FakeSafeBrowsingService::OnMalwareDetailsDone, this)); } void OnMalwareDetailsDone() { @@ -114,8 +114,8 @@ class FakeMalwareDetails : public MalwareDetails { // Notify the UI thread that we got the dom details. BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, - NewRunnableMethod(this, - &FakeMalwareDetails::OnDOMDetailsDone)); + base::Bind(&FakeMalwareDetails::OnDOMDetailsDone, + this)); } void OnDOMDetailsDone() { -- 2.11.4.GIT