Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: chrome/renderer/safe_browsing/phishing_term_feature_extractor_unittest.cc

Issue 8573018: Convert to base::Callback in safe_browsing client-side-detection code. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Don't call Run() on null callbacks. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/renderer/safe_browsing/phishing_term_feature_extractor.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/safe_browsing/phishing_term_feature_extractor.h" 5 #include "chrome/renderer/safe_browsing/phishing_term_feature_extractor.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 &clock_)); 76 &clock_));
77 } 77 }
78 78
79 // Runs the TermFeatureExtractor on |page_text|, waiting for the 79 // Runs the TermFeatureExtractor on |page_text|, waiting for the
80 // completion callback. Returns the success boolean from the callback. 80 // completion callback. Returns the success boolean from the callback.
81 bool ExtractFeatures(const string16* page_text, FeatureMap* features) { 81 bool ExtractFeatures(const string16* page_text, FeatureMap* features) {
82 success_ = false; 82 success_ = false;
83 extractor_->ExtractFeatures( 83 extractor_->ExtractFeatures(
84 page_text, 84 page_text,
85 features, 85 features,
86 NewCallback(this, &PhishingTermFeatureExtractorTest::ExtractionDone)); 86 base::Bind(&PhishingTermFeatureExtractorTest::ExtractionDone,
87 base::Unretained(this)));
87 msg_loop_.Run(); 88 msg_loop_.Run();
88 return success_; 89 return success_;
89 } 90 }
90 91
91 void PartialExtractFeatures(const string16* page_text, FeatureMap* features) { 92 void PartialExtractFeatures(const string16* page_text, FeatureMap* features) {
92 extractor_->ExtractFeatures( 93 extractor_->ExtractFeatures(
93 page_text, 94 page_text,
94 features, 95 features,
95 NewCallback(this, &PhishingTermFeatureExtractorTest::ExtractionDone)); 96 base::Bind(&PhishingTermFeatureExtractorTest::ExtractionDone,
97 base::Unretained(this)));
96 msg_loop_.PostTask( 98 msg_loop_.PostTask(
97 FROM_HERE, 99 FROM_HERE,
98 base::Bind(&PhishingTermFeatureExtractorTest::QuitExtraction, 100 base::Bind(&PhishingTermFeatureExtractorTest::QuitExtraction,
99 base::Unretained(this))); 101 base::Unretained(this)));
100 msg_loop_.RunAllPending(); 102 msg_loop_.RunAllPending();
101 } 103 }
102 104
103 // Completion callback for feature extraction. 105 // Completion callback for feature extraction.
104 void ExtractionDone(bool success) { 106 void ExtractionDone(bool success) {
105 success_ = success; 107 success_ = success;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 // Now extract normally and make sure nothing breaks. 306 // Now extract normally and make sure nothing breaks.
305 EXPECT_TRUE(ExtractFeatures(page_text.get(), &features)); 307 EXPECT_TRUE(ExtractFeatures(page_text.get(), &features));
306 308
307 FeatureMap expected_features; 309 FeatureMap expected_features;
308 expected_features.AddBooleanFeature(features::kPageTerm + 310 expected_features.AddBooleanFeature(features::kPageTerm +
309 std::string("multi word test")); 311 std::string("multi word test"));
310 EXPECT_THAT(features.features(), ContainerEq(expected_features.features())); 312 EXPECT_THAT(features.features(), ContainerEq(expected_features.features()));
311 } 313 }
312 314
313 } // namespace safe_browsing 315 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/renderer/safe_browsing/phishing_term_feature_extractor.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698