Chromium Code Reviews| Index: chrome/browser/safe_browsing/client_side_detection_host.cc |
| diff --git a/chrome/browser/safe_browsing/client_side_detection_host.cc b/chrome/browser/safe_browsing/client_side_detection_host.cc |
| index eace117d9e6bf90f4f36fa6e3d77b663588d6d61..3dbf28c17ed8fb56560598a9541471e059aa8638 100644 |
| --- a/chrome/browser/safe_browsing/client_side_detection_host.cc |
| +++ b/chrome/browser/safe_browsing/client_side_detection_host.cc |
| @@ -250,6 +250,10 @@ ClientSideDetectionHost* ClientSideDetectionHost::Create( |
| return new ClientSideDetectionHost(tab); |
| } |
| +ClientSideDetectionHost::ClientSideDetectionHost() |
| + : content::WebContentsObserver(), |
| + weak_factory_(this) { } |
| + |
| ClientSideDetectionHost::ClientSideDetectionHost(WebContents* tab) |
| : content::WebContentsObserver(tab), |
| csd_service_(NULL), |
| @@ -260,7 +264,7 @@ ClientSideDetectionHost::ClientSideDetectionHost(WebContents* tab) |
| DCHECK(tab); |
| // Note: csd_service_ and sb_service will be NULL here in testing. |
| csd_service_ = g_browser_process->safe_browsing_detection_service(); |
| - feature_extractor_.reset(new BrowserFeatureExtractor(tab, csd_service_)); |
| + feature_extractor_.reset(new BrowserFeatureExtractor(tab, this)); |
| registrar_.Add(this, content::NOTIFICATION_RESOURCE_RESPONSE_STARTED, |
| content::Source<WebContents>(tab)); |
| @@ -361,6 +365,12 @@ void ClientSideDetectionHost::OnSafeBrowsingHit( |
| } |
| } |
| +bool ClientSideDetectionHost::IsBadIpAddress(const std::string& ip_address) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + return (database_manager_.get() && |
| + database_manager_->MatchMalwareIP(ip_address)); |
| +} |
| + |
| void ClientSideDetectionHost::WebContentsDestroyed(WebContents* tab) { |
| DCHECK(tab); |
| // Tell any pending classification request that it is being canceled. |
| @@ -399,9 +409,13 @@ void ClientSideDetectionHost::OnPhishingDetectionDone( |
| // Start browser-side malware feature extraction. Once we're done it will |
| // send the malware client verdict request. |
| malware_verdict->set_url(verdict->url()); |
| + // This function doesn't expect brose_info_ to stay around after this |
|
mattm
2013/10/25 06:28:12
browse_info_
noé
2013/10/28 23:39:26
Done.
|
| + // function returns. |
| feature_extractor_->ExtractMalwareFeatures( |
| - browse_info_.get(), malware_verdict.get()); |
| - MalwareFeatureExtractionDone(malware_verdict.Pass()); |
| + *browse_info_, |
| + malware_verdict.release(), |
| + base::Bind(&ClientSideDetectionHost::MalwareFeatureExtractionDone, |
| + weak_factory_.GetWeakPtr())); |
| } |
| // We only send phishing verdict to the server if the verdict is phishing or |
| @@ -510,23 +524,20 @@ void ClientSideDetectionHost::FeatureExtractionDone( |
| } |
| void ClientSideDetectionHost::MalwareFeatureExtractionDone( |
| - scoped_ptr<ClientMalwareRequest> request) { |
| - if (!request) { |
| - DLOG(FATAL) << "Invalid request object in MalwareFeatureExtractionDone"; |
| - return; |
| - } |
| + bool feature_extraction_success, |
| + ClientMalwareRequest* request) { |
| VLOG(2) << "Malware Feature extraction done for URL: " << request->url() |
| << ", with features count:" << request->feature_map_size(); |
| // Send ping if there is matching features. |
| - if (request->feature_map_size() > 0) { |
| + if (feature_extraction_success && request->feature_map_size() > 0) { |
| VLOG(1) << "Start sending client malware request."; |
| ClientSideDetectionService::ClientReportMalwareRequestCallback callback; |
| callback = base::Bind(&ClientSideDetectionHost::MaybeShowMalwareWarning, |
| weak_factory_.GetWeakPtr()); |
| - csd_service_->SendClientReportMalwareRequest( |
| - request.release(), // The service takes ownership of the request object |
| - callback); |
| + csd_service_->SendClientReportMalwareRequest(request, callback); |
| + } else { |
| + delete request; |
| } |
| } |