| OLD | NEW |
| 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_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/hash_tables.h" | 9 #include "base/hash_tables.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 } | 108 } |
| 109 | 109 |
| 110 PhishingDOMFeatureExtractor::~PhishingDOMFeatureExtractor() { | 110 PhishingDOMFeatureExtractor::~PhishingDOMFeatureExtractor() { |
| 111 // The RenderView should have called CancelPendingExtraction() before | 111 // The RenderView should have called CancelPendingExtraction() before |
| 112 // we are destroyed. | 112 // we are destroyed. |
| 113 CheckNoPendingExtraction(); | 113 CheckNoPendingExtraction(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void PhishingDOMFeatureExtractor::ExtractFeatures( | 116 void PhishingDOMFeatureExtractor::ExtractFeatures( |
| 117 FeatureMap* features, | 117 FeatureMap* features, |
| 118 DoneCallback* done_callback) { | 118 const DoneCallback& done_callback) { |
| 119 // The RenderView should have called CancelPendingExtraction() before | 119 // The RenderView should have called CancelPendingExtraction() before |
| 120 // starting a new extraction, so DCHECK this. | 120 // starting a new extraction, so DCHECK this. |
| 121 CheckNoPendingExtraction(); | 121 CheckNoPendingExtraction(); |
| 122 // However, in an opt build, we will go ahead and clean up the pending | 122 // However, in an opt build, we will go ahead and clean up the pending |
| 123 // extraction so that we can start in a known state. | 123 // extraction so that we can start in a known state. |
| 124 CancelPendingExtraction(); | 124 CancelPendingExtraction(); |
| 125 | 125 |
| 126 features_ = features; | 126 features_ = features; |
| 127 done_callback_.reset(done_callback); | 127 done_callback_ = done_callback; |
| 128 | 128 |
| 129 page_feature_state_.reset(new PageFeatureState(clock_->Now())); | 129 page_feature_state_.reset(new PageFeatureState(clock_->Now())); |
| 130 WebKit::WebView* web_view = render_view_->GetWebView(); | 130 WebKit::WebView* web_view = render_view_->GetWebView(); |
| 131 if (web_view && web_view->mainFrame()) { | 131 if (web_view && web_view->mainFrame()) { |
| 132 cur_document_ = web_view->mainFrame()->document(); | 132 cur_document_ = web_view->mainFrame()->document(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 MessageLoop::current()->PostTask( | 135 MessageLoop::current()->PostTask( |
| 136 FROM_HERE, | 136 FROM_HERE, |
| 137 base::Bind(&PhishingDOMFeatureExtractor::ExtractFeaturesWithTimeout, | 137 base::Bind(&PhishingDOMFeatureExtractor::ExtractFeaturesWithTimeout, |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 ++page_feature_state_->num_text_inputs; | 341 ++page_feature_state_->num_text_inputs; |
| 342 } | 342 } |
| 343 } | 343 } |
| 344 | 344 |
| 345 void PhishingDOMFeatureExtractor::HandleScript( | 345 void PhishingDOMFeatureExtractor::HandleScript( |
| 346 const WebKit::WebElement& element) { | 346 const WebKit::WebElement& element) { |
| 347 ++page_feature_state_->num_script_tags; | 347 ++page_feature_state_->num_script_tags; |
| 348 } | 348 } |
| 349 | 349 |
| 350 void PhishingDOMFeatureExtractor::CheckNoPendingExtraction() { | 350 void PhishingDOMFeatureExtractor::CheckNoPendingExtraction() { |
| 351 DCHECK(!done_callback_.get()); | 351 DCHECK(done_callback_.is_null()); |
| 352 DCHECK(!cur_frame_data_.get()); | 352 DCHECK(!cur_frame_data_.get()); |
| 353 DCHECK(cur_document_.isNull()); | 353 DCHECK(cur_document_.isNull()); |
| 354 if (done_callback_.get() || cur_frame_data_.get() || | 354 if (!done_callback_.is_null() || cur_frame_data_.get() || |
| 355 !cur_document_.isNull()) { | 355 !cur_document_.isNull()) { |
| 356 LOG(ERROR) << "Extraction in progress, missing call to " | 356 LOG(ERROR) << "Extraction in progress, missing call to " |
| 357 << "CancelPendingExtraction"; | 357 << "CancelPendingExtraction"; |
| 358 } | 358 } |
| 359 } | 359 } |
| 360 | 360 |
| 361 void PhishingDOMFeatureExtractor::RunCallback(bool success) { | 361 void PhishingDOMFeatureExtractor::RunCallback(bool success) { |
| 362 // Record some timing stats that we can use to evaluate feature extraction | 362 // Record some timing stats that we can use to evaluate feature extraction |
| 363 // performance. These include both successful and failed extractions. | 363 // performance. These include both successful and failed extractions. |
| 364 DCHECK(page_feature_state_.get()); | 364 DCHECK(page_feature_state_.get()); |
| 365 UMA_HISTOGRAM_COUNTS("SBClientPhishing.DOMFeatureIterations", | 365 UMA_HISTOGRAM_COUNTS("SBClientPhishing.DOMFeatureIterations", |
| 366 page_feature_state_->num_iterations); | 366 page_feature_state_->num_iterations); |
| 367 UMA_HISTOGRAM_TIMES("SBClientPhishing.DOMFeatureTotalTime", | 367 UMA_HISTOGRAM_TIMES("SBClientPhishing.DOMFeatureTotalTime", |
| 368 clock_->Now() - page_feature_state_->start_time); | 368 clock_->Now() - page_feature_state_->start_time); |
| 369 | 369 |
| 370 DCHECK(done_callback_.get()); | 370 DCHECK(!done_callback_.is_null()); |
| 371 done_callback_->Run(success); | 371 done_callback_.Run(success); |
| 372 Clear(); | 372 Clear(); |
| 373 } | 373 } |
| 374 | 374 |
| 375 void PhishingDOMFeatureExtractor::Clear() { | 375 void PhishingDOMFeatureExtractor::Clear() { |
| 376 features_ = NULL; | 376 features_ = NULL; |
| 377 done_callback_.reset(NULL); | 377 done_callback_.Reset(); |
| 378 cur_frame_data_.reset(NULL); | 378 cur_frame_data_.reset(NULL); |
| 379 cur_document_.reset(); | 379 cur_document_.reset(); |
| 380 } | 380 } |
| 381 | 381 |
| 382 void PhishingDOMFeatureExtractor::ResetFrameData() { | 382 void PhishingDOMFeatureExtractor::ResetFrameData() { |
| 383 DCHECK(!cur_document_.isNull()); | 383 DCHECK(!cur_document_.isNull()); |
| 384 DCHECK(!cur_frame_data_.get()); | 384 DCHECK(!cur_frame_data_.get()); |
| 385 | 385 |
| 386 cur_frame_data_.reset(new FrameData()); | 386 cur_frame_data_.reset(new FrameData()); |
| 387 cur_frame_data_->elements = cur_document_.all(); | 387 cur_frame_data_->elements = cur_document_.all(); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 // Record number of script tags (discretized for numerical stability.) | 490 // Record number of script tags (discretized for numerical stability.) |
| 491 if (page_feature_state_->num_script_tags > 1) { | 491 if (page_feature_state_->num_script_tags > 1) { |
| 492 features_->AddBooleanFeature(features::kPageNumScriptTagsGTOne); | 492 features_->AddBooleanFeature(features::kPageNumScriptTagsGTOne); |
| 493 if (page_feature_state_->num_script_tags > 6) { | 493 if (page_feature_state_->num_script_tags > 6) { |
| 494 features_->AddBooleanFeature(features::kPageNumScriptTagsGTSix); | 494 features_->AddBooleanFeature(features::kPageNumScriptTagsGTSix); |
| 495 } | 495 } |
| 496 } | 496 } |
| 497 } | 497 } |
| 498 | 498 |
| 499 } // namespace safe_browsing | 499 } // namespace safe_browsing |
| OLD | NEW |