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

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

Issue 1167163002: chrome: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added some missing message_loop.h includes. Created 5 years, 6 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <list> 7 #include <list>
8 #include <map> 8 #include <map>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/i18n/break_iterator.h" 12 #include "base/i18n/break_iterator.h"
13 #include "base/i18n/case_conversion.h" 13 #include "base/i18n/case_conversion.h"
14 #include "base/location.h"
14 #include "base/logging.h" 15 #include "base/logging.h"
15 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
16 #include "base/message_loop/message_loop.h"
17 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
18 #include "base/single_thread_task_runner.h"
18 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
20 #include "base/thread_task_runner_handle.h"
19 #include "base/time/time.h" 21 #include "base/time/time.h"
20 #include "chrome/renderer/safe_browsing/feature_extractor_clock.h" 22 #include "chrome/renderer/safe_browsing/feature_extractor_clock.h"
21 #include "chrome/renderer/safe_browsing/features.h" 23 #include "chrome/renderer/safe_browsing/features.h"
22 #include "chrome/renderer/safe_browsing/murmurhash3_util.h" 24 #include "chrome/renderer/safe_browsing/murmurhash3_util.h"
23 #include "crypto/sha2.h" 25 #include "crypto/sha2.h"
24 26
25 namespace safe_browsing { 27 namespace safe_browsing {
26 28
27 // This time should be short enough that it doesn't noticeably disrupt the 29 // This time should be short enough that it doesn't noticeably disrupt the
28 // user's interaction with the page. 30 // user's interaction with the page.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // However, in an opt build, we will go ahead and clean up the pending 118 // However, in an opt build, we will go ahead and clean up the pending
117 // extraction so that we can start in a known state. 119 // extraction so that we can start in a known state.
118 CancelPendingExtraction(); 120 CancelPendingExtraction();
119 121
120 page_text_ = page_text; 122 page_text_ = page_text;
121 features_ = features; 123 features_ = features;
122 shingle_hashes_ = shingle_hashes, 124 shingle_hashes_ = shingle_hashes,
123 done_callback_ = done_callback; 125 done_callback_ = done_callback;
124 126
125 state_.reset(new ExtractionState(*page_text_, clock_->Now())); 127 state_.reset(new ExtractionState(*page_text_, clock_->Now()));
126 base::MessageLoop::current()->PostTask( 128 base::ThreadTaskRunnerHandle::Get()->PostTask(
127 FROM_HERE, 129 FROM_HERE,
128 base::Bind(&PhishingTermFeatureExtractor::ExtractFeaturesWithTimeout, 130 base::Bind(&PhishingTermFeatureExtractor::ExtractFeaturesWithTimeout,
129 weak_factory_.GetWeakPtr())); 131 weak_factory_.GetWeakPtr()));
130 } 132 }
131 133
132 void PhishingTermFeatureExtractor::CancelPendingExtraction() { 134 void PhishingTermFeatureExtractor::CancelPendingExtraction() {
133 // Cancel any pending callbacks, and clear our state. 135 // Cancel any pending callbacks, and clear our state.
134 weak_factory_.InvalidateWeakPtrs(); 136 weak_factory_.InvalidateWeakPtrs();
135 Clear(); 137 Clear();
136 } 138 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 if (chunk_elapsed >= 173 if (chunk_elapsed >=
172 base::TimeDelta::FromMilliseconds(kMaxTimePerChunkMs)) { 174 base::TimeDelta::FromMilliseconds(kMaxTimePerChunkMs)) {
173 // The time limit for the current chunk is up, so post a task to 175 // The time limit for the current chunk is up, so post a task to
174 // continue extraction. 176 // continue extraction.
175 // 177 //
176 // Record how much time we actually spent on the chunk. If this is 178 // Record how much time we actually spent on the chunk. If this is
177 // much higher than kMaxTimePerChunkMs, we may need to adjust the 179 // much higher than kMaxTimePerChunkMs, we may need to adjust the
178 // clock granularity. 180 // clock granularity.
179 UMA_HISTOGRAM_TIMES("SBClientPhishing.TermFeatureChunkTime", 181 UMA_HISTOGRAM_TIMES("SBClientPhishing.TermFeatureChunkTime",
180 chunk_elapsed); 182 chunk_elapsed);
181 base::MessageLoop::current()->PostTask( 183 base::ThreadTaskRunnerHandle::Get()->PostTask(
182 FROM_HERE, 184 FROM_HERE,
183 base::Bind( 185 base::Bind(
184 &PhishingTermFeatureExtractor::ExtractFeaturesWithTimeout, 186 &PhishingTermFeatureExtractor::ExtractFeaturesWithTimeout,
185 weak_factory_.GetWeakPtr())); 187 weak_factory_.GetWeakPtr()));
186 return; 188 return;
187 } 189 }
188 // Otherwise, continue. 190 // Otherwise, continue.
189 } 191 }
190 } 192 }
191 RunCallback(true); 193 RunCallback(true);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 290
289 void PhishingTermFeatureExtractor::Clear() { 291 void PhishingTermFeatureExtractor::Clear() {
290 page_text_ = NULL; 292 page_text_ = NULL;
291 features_ = NULL; 293 features_ = NULL;
292 shingle_hashes_ = NULL; 294 shingle_hashes_ = NULL;
293 done_callback_.Reset(); 295 done_callback_.Reset();
294 state_.reset(NULL); 296 state_.reset(NULL);
295 } 297 }
296 298
297 } // namespace safe_browsing 299 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698