OLD | NEW |
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_dom_feature_extractor.h" | 5 #include "chrome/renderer/safe_browsing/phishing_dom_feature_extractor.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
| 10 #include "base/location.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/message_loop/message_loop.h" | |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/single_thread_task_runner.h" |
13 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/thread_task_runner_handle.h" |
14 #include "base/time/time.h" | 16 #include "base/time/time.h" |
15 #include "chrome/renderer/safe_browsing/feature_extractor_clock.h" | 17 #include "chrome/renderer/safe_browsing/feature_extractor_clock.h" |
16 #include "chrome/renderer/safe_browsing/features.h" | 18 #include "chrome/renderer/safe_browsing/features.h" |
17 #include "content/public/renderer/render_view.h" | 19 #include "content/public/renderer/render_view.h" |
18 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 20 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
19 #include "third_party/WebKit/public/platform/WebString.h" | 21 #include "third_party/WebKit/public/platform/WebString.h" |
20 #include "third_party/WebKit/public/web/WebElement.h" | 22 #include "third_party/WebKit/public/web/WebElement.h" |
21 #include "third_party/WebKit/public/web/WebElementCollection.h" | 23 #include "third_party/WebKit/public/web/WebElementCollection.h" |
22 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 24 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
23 #include "third_party/WebKit/public/web/WebView.h" | 25 #include "third_party/WebKit/public/web/WebView.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 | 128 |
127 features_ = features; | 129 features_ = features; |
128 done_callback_ = done_callback; | 130 done_callback_ = done_callback; |
129 | 131 |
130 page_feature_state_.reset(new PageFeatureState(clock_->Now())); | 132 page_feature_state_.reset(new PageFeatureState(clock_->Now())); |
131 blink::WebView* web_view = render_view_->GetWebView(); | 133 blink::WebView* web_view = render_view_->GetWebView(); |
132 if (web_view && web_view->mainFrame()) { | 134 if (web_view && web_view->mainFrame()) { |
133 cur_document_ = web_view->mainFrame()->document(); | 135 cur_document_ = web_view->mainFrame()->document(); |
134 } | 136 } |
135 | 137 |
136 base::MessageLoop::current()->PostTask( | 138 base::ThreadTaskRunnerHandle::Get()->PostTask( |
137 FROM_HERE, | 139 FROM_HERE, |
138 base::Bind(&PhishingDOMFeatureExtractor::ExtractFeaturesWithTimeout, | 140 base::Bind(&PhishingDOMFeatureExtractor::ExtractFeaturesWithTimeout, |
139 weak_factory_.GetWeakPtr())); | 141 weak_factory_.GetWeakPtr())); |
140 } | 142 } |
141 | 143 |
142 void PhishingDOMFeatureExtractor::CancelPendingExtraction() { | 144 void PhishingDOMFeatureExtractor::CancelPendingExtraction() { |
143 // Cancel any pending callbacks, and clear our state. | 145 // Cancel any pending callbacks, and clear our state. |
144 weak_factory_.InvalidateWeakPtrs(); | 146 weak_factory_.InvalidateWeakPtrs(); |
145 Clear(); | 147 Clear(); |
146 } | 148 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 if (chunk_elapsed >= | 208 if (chunk_elapsed >= |
207 base::TimeDelta::FromMilliseconds(kMaxTimePerChunkMs)) { | 209 base::TimeDelta::FromMilliseconds(kMaxTimePerChunkMs)) { |
208 // The time limit for the current chunk is up, so post a task to | 210 // The time limit for the current chunk is up, so post a task to |
209 // continue extraction. | 211 // continue extraction. |
210 // | 212 // |
211 // Record how much time we actually spent on the chunk. If this is | 213 // Record how much time we actually spent on the chunk. If this is |
212 // much higher than kMaxTimePerChunkMs, we may need to adjust the | 214 // much higher than kMaxTimePerChunkMs, we may need to adjust the |
213 // clock granularity. | 215 // clock granularity. |
214 UMA_HISTOGRAM_TIMES("SBClientPhishing.DOMFeatureChunkTime", | 216 UMA_HISTOGRAM_TIMES("SBClientPhishing.DOMFeatureChunkTime", |
215 chunk_elapsed); | 217 chunk_elapsed); |
216 base::MessageLoop::current()->PostTask( | 218 base::ThreadTaskRunnerHandle::Get()->PostTask( |
217 FROM_HERE, | 219 FROM_HERE, |
218 base::Bind( | 220 base::Bind( |
219 &PhishingDOMFeatureExtractor::ExtractFeaturesWithTimeout, | 221 &PhishingDOMFeatureExtractor::ExtractFeaturesWithTimeout, |
220 weak_factory_.GetWeakPtr())); | 222 weak_factory_.GetWeakPtr())); |
221 return; | 223 return; |
222 } | 224 } |
223 // Otherwise, continue. | 225 // Otherwise, continue. |
224 } | 226 } |
225 } | 227 } |
226 | 228 |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 // Record number of script tags (discretized for numerical stability.) | 497 // Record number of script tags (discretized for numerical stability.) |
496 if (page_feature_state_->num_script_tags > 1) { | 498 if (page_feature_state_->num_script_tags > 1) { |
497 features_->AddBooleanFeature(features::kPageNumScriptTagsGTOne); | 499 features_->AddBooleanFeature(features::kPageNumScriptTagsGTOne); |
498 if (page_feature_state_->num_script_tags > 6) { | 500 if (page_feature_state_->num_script_tags > 6) { |
499 features_->AddBooleanFeature(features::kPageNumScriptTagsGTSix); | 501 features_->AddBooleanFeature(features::kPageNumScriptTagsGTSix); |
500 } | 502 } |
501 } | 503 } |
502 } | 504 } |
503 | 505 |
504 } // namespace safe_browsing | 506 } // namespace safe_browsing |
OLD | NEW |