| 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/browser/safe_browsing/client_side_detection_host.h" | 5 #include "chrome/browser/safe_browsing/client_side_detection_host.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 database_manager_->MatchCsdWhitelistUrl(url)) { | 169 database_manager_->MatchCsdWhitelistUrl(url)) { |
| 170 // We're done. There is no point in going back to the UI thread. | 170 // We're done. There is no point in going back to the UI thread. |
| 171 VLOG(1) << "Skipping phishing classification for URL: " << url | 171 VLOG(1) << "Skipping phishing classification for URL: " << url |
| 172 << " because it matches the csd whitelist"; | 172 << " because it matches the csd whitelist"; |
| 173 UMA_HISTOGRAM_ENUMERATION("SBClientPhishing.PreClassificationCheckFail", | 173 UMA_HISTOGRAM_ENUMERATION("SBClientPhishing.PreClassificationCheckFail", |
| 174 NO_CLASSIFY_MATCH_CSD_WHITELIST, | 174 NO_CLASSIFY_MATCH_CSD_WHITELIST, |
| 175 NO_CLASSIFY_MAX); | 175 NO_CLASSIFY_MAX); |
| 176 return; | 176 return; |
| 177 } | 177 } |
| 178 | 178 |
| 179 bool malware_killswitch = database_manager_->MalwareKillSwitchOn(); |
| 180 |
| 179 BrowserThread::PostTask( | 181 BrowserThread::PostTask( |
| 180 BrowserThread::UI, | 182 BrowserThread::UI, |
| 181 FROM_HERE, | 183 FROM_HERE, |
| 182 base::Bind(&ShouldClassifyUrlRequest::CheckCache, this)); | 184 base::Bind(&ShouldClassifyUrlRequest::CheckCache, this, |
| 185 malware_killswitch)); |
| 183 } | 186 } |
| 184 | 187 |
| 185 void CheckCache() { | 188 void CheckCache(bool malware_killswitch) { |
| 186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 187 if (canceled_) { | 190 if (canceled_) { |
| 188 return; | 191 return; |
| 189 } | 192 } |
| 190 | 193 |
| 194 // Whether enable the malware IP matching feature |
| 195 csd_service_->SetMalwareEnabled(malware_killswitch); |
| 196 |
| 191 // If result is cached, we don't want to run classification again | 197 // If result is cached, we don't want to run classification again |
| 192 bool is_phishing; | 198 bool is_phishing; |
| 193 if (csd_service_->GetValidCachedResult(params_.url, &is_phishing)) { | 199 if (csd_service_->GetValidCachedResult(params_.url, &is_phishing)) { |
| 194 VLOG(1) << "Satisfying request for " << params_.url << " from cache"; | 200 VLOG(1) << "Satisfying request for " << params_.url << " from cache"; |
| 195 UMA_HISTOGRAM_COUNTS("SBClientPhishing.RequestSatisfiedFromCache", 1); | 201 UMA_HISTOGRAM_COUNTS("SBClientPhishing.RequestSatisfiedFromCache", 1); |
| 196 // Since we are already on the UI thread, this is safe. | 202 // Since we are already on the UI thread, this is safe. |
| 197 host_->MaybeShowPhishingWarning(params_.url, is_phishing); | 203 host_->MaybeShowPhishingWarning(params_.url, is_phishing); |
| 198 return; | 204 return; |
| 199 } | 205 } |
| 200 | 206 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 DCHECK(browse_info_.get()); | 379 DCHECK(browse_info_.get()); |
| 374 | 380 |
| 375 // We parse the protocol buffer here. If we're unable to parse it we won't | 381 // We parse the protocol buffer here. If we're unable to parse it we won't |
| 376 // send the verdict further. | 382 // send the verdict further. |
| 377 scoped_ptr<ClientPhishingRequest> verdict(new ClientPhishingRequest); | 383 scoped_ptr<ClientPhishingRequest> verdict(new ClientPhishingRequest); |
| 378 if (csd_service_ && | 384 if (csd_service_ && |
| 379 !weak_factory_.HasWeakPtrs() && | 385 !weak_factory_.HasWeakPtrs() && |
| 380 browse_info_.get() && | 386 browse_info_.get() && |
| 381 verdict->ParseFromString(verdict_str) && | 387 verdict->ParseFromString(verdict_str) && |
| 382 verdict->IsInitialized()) { | 388 verdict->IsInitialized()) { |
| 383 scoped_ptr<ClientMalwareRequest> malware_verdict(new ClientMalwareRequest); | 389 // We do the malware IP matching and request sending if the feature |
| 384 // Start browser-side malware feature extraction. Once we're done it will | 390 // is enabled |
| 385 // send the malware client verdict request. | 391 if (csd_service_->MalwareEnabled()) { |
| 386 malware_verdict->set_url(verdict->url()); | 392 scoped_ptr<ClientMalwareRequest> malware_verdict( |
| 387 feature_extractor_->ExtractMalwareFeatures( | 393 new ClientMalwareRequest); |
| 388 browse_info_.get(), | 394 // Start browser-side malware feature extraction. Once we're done it will |
| 389 malware_verdict.get()); | 395 // send the malware client verdict request. |
| 390 MalwareFeatureExtractionDone(malware_verdict.Pass()); | 396 malware_verdict->set_url(verdict->url()); |
| 397 feature_extractor_->ExtractMalwareFeatures( |
| 398 browse_info_.get(), malware_verdict.get()); |
| 399 MalwareFeatureExtractionDone(malware_verdict.Pass()); |
| 400 } |
| 391 | 401 |
| 392 // We only send phishing verdict to the server if the verdict is phishing or | 402 // We only send phishing verdict to the server if the verdict is phishing or |
| 393 // if a SafeBrowsing interstitial was already shown for this site. E.g., a | 403 // if a SafeBrowsing interstitial was already shown for this site. E.g., a |
| 394 // malware or phishing interstitial was shown but the user clicked | 404 // malware or phishing interstitial was shown but the user clicked |
| 395 // through. | 405 // through. |
| 396 if (verdict->is_phishing() || DidShowSBInterstitial()) { | 406 if (verdict->is_phishing() || DidShowSBInterstitial()) { |
| 397 if (DidShowSBInterstitial()) { | 407 if (DidShowSBInterstitial()) { |
| 398 browse_info_->unsafe_resource.reset(unsafe_resource_.release()); | 408 browse_info_->unsafe_resource.reset(unsafe_resource_.release()); |
| 399 } | 409 } |
| 400 // Start browser-side feature extraction. Once we're done it will send | 410 // Start browser-side feature extraction. Once we're done it will send |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 ui_manager_->RemoveObserver(this); | 540 ui_manager_->RemoveObserver(this); |
| 531 | 541 |
| 532 ui_manager_ = ui_manager; | 542 ui_manager_ = ui_manager; |
| 533 if (ui_manager) | 543 if (ui_manager) |
| 534 ui_manager_->AddObserver(this); | 544 ui_manager_->AddObserver(this); |
| 535 | 545 |
| 536 database_manager_ = database_manager; | 546 database_manager_ = database_manager; |
| 537 } | 547 } |
| 538 | 548 |
| 539 } // namespace safe_browsing | 549 } // namespace safe_browsing |
| OLD | NEW |