diff options
author | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-10 20:42:51 +0000 |
---|---|---|
committer | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-10 20:42:51 +0000 |
commit | c3c4197c1b80f82d5887af8acf962a05565c4d28 (patch) | |
tree | 44429cc32f12204a011b8a5f110b85317ce64069 /chrome/renderer | |
parent | e88485cab6969203a71321dde29373ca13f229dd (diff) | |
download | chromium_src-c3c4197c1b80f82d5887af8acf962a05565c4d28.zip chromium_src-c3c4197c1b80f82d5887af8acf962a05565c4d28.tar.gz chromium_src-c3c4197c1b80f82d5887af8acf962a05565c4d28.tar.bz2 |
Convert safe-browsing ScopedRunnableMethodFactory.
ScopedRunnableMethodFactory<> -> base::WeakPtrFactory<> in
chrome/browser/safe_browsing/ and
chrome/renderer/safe_browsing/
There are other conversions to be done in this code, this CL attempts
to focus on a single isolated conversion to make it easy to review.
Review URL: http://codereview.chromium.org/8503036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109498 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
6 files changed, 30 insertions, 25 deletions
diff --git a/chrome/renderer/safe_browsing/phishing_classifier.cc b/chrome/renderer/safe_browsing/phishing_classifier.cc index 2c5f70a..886889a 100644 --- a/chrome/renderer/safe_browsing/phishing_classifier.cc +++ b/chrome/renderer/safe_browsing/phishing_classifier.cc @@ -6,6 +6,7 @@ #include <string> +#include "base/bind.h" #include "base/callback.h" #include "base/compiler_specific.h" #include "base/logging.h" @@ -40,7 +41,7 @@ PhishingClassifier::PhishingClassifier(content::RenderView* render_view, : render_view_(render_view), scorer_(NULL), clock_(clock), - ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { + ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { Clear(); } @@ -96,8 +97,8 @@ void PhishingClassifier::BeginClassification(const string16* page_text, // iteration of the message loop. MessageLoop::current()->PostTask( FROM_HERE, - method_factory_.NewRunnableMethod( - &PhishingClassifier::BeginFeatureExtraction)); + base::Bind(&PhishingClassifier::BeginFeatureExtraction, + weak_factory_.GetWeakPtr())); } void PhishingClassifier::BeginFeatureExtraction() { @@ -146,7 +147,7 @@ void PhishingClassifier::CancelPendingClassification() { DCHECK(is_ready()); dom_extractor_->CancelPendingExtraction(); term_extractor_->CancelPendingExtraction(); - method_factory_.RevokeAll(); + weak_factory_.InvalidateWeakPtrs(); Clear(); } diff --git a/chrome/renderer/safe_browsing/phishing_classifier.h b/chrome/renderer/safe_browsing/phishing_classifier.h index b3b8fce..64d1d26 100644 --- a/chrome/renderer/safe_browsing/phishing_classifier.h +++ b/chrome/renderer/safe_browsing/phishing_classifier.h @@ -138,9 +138,9 @@ class PhishingClassifier { const string16* page_text_; // owned by the caller scoped_ptr<DoneCallback> done_callback_; - // Used to create BeginFeatureExtraction tasks. - // These tasks are revoked if classification is cancelled. - ScopedRunnableMethodFactory<PhishingClassifier> method_factory_; + // Used in scheduling BeginFeatureExtraction tasks. + // These pointers are invalidated if classification is cancelled. + base::WeakPtrFactory<PhishingClassifier> weak_factory_; DISALLOW_COPY_AND_ASSIGN(PhishingClassifier); }; diff --git a/chrome/renderer/safe_browsing/phishing_dom_feature_extractor.cc b/chrome/renderer/safe_browsing/phishing_dom_feature_extractor.cc index 15779a8..7037754 100644 --- a/chrome/renderer/safe_browsing/phishing_dom_feature_extractor.cc +++ b/chrome/renderer/safe_browsing/phishing_dom_feature_extractor.cc @@ -4,6 +4,7 @@ #include "chrome/renderer/safe_browsing/phishing_dom_feature_extractor.h" +#include "base/bind.h" #include "base/compiler_specific.h" #include "base/hash_tables.h" #include "base/logging.h" @@ -102,7 +103,7 @@ PhishingDOMFeatureExtractor::PhishingDOMFeatureExtractor( FeatureExtractorClock* clock) : render_view_(render_view), clock_(clock), - ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { + ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { Clear(); } @@ -133,13 +134,13 @@ void PhishingDOMFeatureExtractor::ExtractFeatures( MessageLoop::current()->PostTask( FROM_HERE, - method_factory_.NewRunnableMethod( - &PhishingDOMFeatureExtractor::ExtractFeaturesWithTimeout)); + base::Bind(&PhishingDOMFeatureExtractor::ExtractFeaturesWithTimeout, + weak_factory_.GetWeakPtr())); } void PhishingDOMFeatureExtractor::CancelPendingExtraction() { // Cancel any pending callbacks, and clear our state. - method_factory_.RevokeAll(); + weak_factory_.InvalidateWeakPtrs(); Clear(); } @@ -216,8 +217,9 @@ void PhishingDOMFeatureExtractor::ExtractFeaturesWithTimeout() { chunk_elapsed); MessageLoop::current()->PostTask( FROM_HERE, - method_factory_.NewRunnableMethod( - &PhishingDOMFeatureExtractor::ExtractFeaturesWithTimeout)); + base::Bind( + &PhishingDOMFeatureExtractor::ExtractFeaturesWithTimeout, + weak_factory_.GetWeakPtr())); return; } // Otherwise, continue. diff --git a/chrome/renderer/safe_browsing/phishing_dom_feature_extractor.h b/chrome/renderer/safe_browsing/phishing_dom_feature_extractor.h index 887e66d..785f607 100644 --- a/chrome/renderer/safe_browsing/phishing_dom_feature_extractor.h +++ b/chrome/renderer/safe_browsing/phishing_dom_feature_extractor.h @@ -145,9 +145,9 @@ class PhishingDOMFeatureExtractor { // accumulated across all frames in the RenderView. scoped_ptr<PageFeatureState> page_feature_state_; - // Used to create ExtractFeaturesWithTimeout tasks. - // These tasks are revoked if extraction is cancelled. - ScopedRunnableMethodFactory<PhishingDOMFeatureExtractor> method_factory_; + // Used in scheduling ExtractFeaturesWithTimeout tasks. + // These pointers are invalidated if extraction is cancelled. + base::WeakPtrFactory<PhishingDOMFeatureExtractor> weak_factory_; DISALLOW_COPY_AND_ASSIGN(PhishingDOMFeatureExtractor); }; diff --git a/chrome/renderer/safe_browsing/phishing_term_feature_extractor.cc b/chrome/renderer/safe_browsing/phishing_term_feature_extractor.cc index ff3a50e8..47161b9 100644 --- a/chrome/renderer/safe_browsing/phishing_term_feature_extractor.cc +++ b/chrome/renderer/safe_browsing/phishing_term_feature_extractor.cc @@ -7,6 +7,7 @@ #include <list> #include <map> +#include "base/bind.h" #include "base/compiler_specific.h" #include "base/i18n/case_conversion.h" #include "base/logging.h" @@ -101,7 +102,7 @@ PhishingTermFeatureExtractor::PhishingTermFeatureExtractor( murmurhash3_seed_(murmurhash3_seed), negative_word_cache_(kMaxNegativeWordCacheSize), clock_(clock), - ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { + ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { Clear(); } @@ -129,13 +130,13 @@ void PhishingTermFeatureExtractor::ExtractFeatures( state_.reset(new ExtractionState(*page_text_, clock_->Now())); MessageLoop::current()->PostTask( FROM_HERE, - method_factory_.NewRunnableMethod( - &PhishingTermFeatureExtractor::ExtractFeaturesWithTimeout)); + base::Bind(&PhishingTermFeatureExtractor::ExtractFeaturesWithTimeout, + weak_factory_.GetWeakPtr())); } void PhishingTermFeatureExtractor::CancelPendingExtraction() { // Cancel any pending callbacks, and clear our state. - method_factory_.RevokeAll(); + weak_factory_.InvalidateWeakPtrs(); Clear(); } @@ -196,8 +197,9 @@ void PhishingTermFeatureExtractor::ExtractFeaturesWithTimeout() { chunk_elapsed); MessageLoop::current()->PostTask( FROM_HERE, - method_factory_.NewRunnableMethod( - &PhishingTermFeatureExtractor::ExtractFeaturesWithTimeout)); + base::Bind( + &PhishingTermFeatureExtractor::ExtractFeaturesWithTimeout, + weak_factory_.GetWeakPtr())); return; } // Otherwise, continue. diff --git a/chrome/renderer/safe_browsing/phishing_term_feature_extractor.h b/chrome/renderer/safe_browsing/phishing_term_feature_extractor.h index 4fb26c1..969af79 100644 --- a/chrome/renderer/safe_browsing/phishing_term_feature_extractor.h +++ b/chrome/renderer/safe_browsing/phishing_term_feature_extractor.h @@ -153,9 +153,9 @@ class PhishingTermFeatureExtractor { // Stores the current state of term extraction from |page_text_|. scoped_ptr<ExtractionState> state_; - // Used to create ExtractFeaturesWithTimeout tasks. - // These tasks are revoked if extraction is cancelled. - ScopedRunnableMethodFactory<PhishingTermFeatureExtractor> method_factory_; + // Used in scheduling ExtractFeaturesWithTimeout tasks. + // These pointers are invalidated if extraction is cancelled. + base::WeakPtrFactory<PhishingTermFeatureExtractor> weak_factory_; DISALLOW_COPY_AND_ASSIGN(PhishingTermFeatureExtractor); }; |