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..bae81c412639c1c61df061786d7e9246571a2c88 100644 |
| --- a/chrome/browser/safe_browsing/client_side_detection_host.cc |
| +++ b/chrome/browser/safe_browsing/client_side_detection_host.cc |
| @@ -250,6 +250,12 @@ ClientSideDetectionHost* ClientSideDetectionHost::Create( |
| return new ClientSideDetectionHost(tab); |
| } |
| +ClientSideDetectionHost::ClientSideDetectionHost( |
| + SafeBrowsingDatabaseManager* database_manager) |
| + : content::WebContentsObserver(), |
| + database_manager_(database_manager), |
| + weak_factory_(this) { } |
|
mattm
2013/10/29 01:11:47
It looks like this constructor doesn't initialize
noé
2013/10/31 02:41:12
Done.
|
| + |
| ClientSideDetectionHost::ClientSideDetectionHost(WebContents* tab) |
| : content::WebContentsObserver(tab), |
| csd_service_(NULL), |
| @@ -260,7 +266,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 +367,11 @@ void ClientSideDetectionHost::OnSafeBrowsingHit( |
| } |
| } |
| +scoped_refptr<SafeBrowsingDatabaseManager> |
| +ClientSideDetectionHost::database_manager() { |
| + return database_manager_; |
| +} |
| + |
| void ClientSideDetectionHost::WebContentsDestroyed(WebContents* tab) { |
| DCHECK(tab); |
| // Tell any pending classification request that it is being canceled. |
| @@ -399,9 +410,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 browse_info_ to stay around after this |
| + // function returns. |
| feature_extractor_->ExtractMalwareFeatures( |
| - browse_info_.get(), malware_verdict.get()); |
| - MalwareFeatureExtractionDone(malware_verdict.Pass()); |
| + browse_info_.get(), |
| + malware_verdict.release(), |
| + base::Bind(&ClientSideDetectionHost::MalwareFeatureExtractionDone, |
| + weak_factory_.GetWeakPtr())); |
| } |
| // We only send phishing verdict to the server if the verdict is phishing or |
| @@ -490,10 +505,7 @@ void ClientSideDetectionHost::MaybeShowMalwareWarning(GURL original_url, |
| void ClientSideDetectionHost::FeatureExtractionDone( |
| bool success, |
| ClientPhishingRequest* request) { |
| - if (!request) { |
| - DLOG(FATAL) << "Invalid request object in FeatureExtractionDone"; |
| - return; |
| - } |
| + DCHECK(request); |
| VLOG(2) << "Feature extraction done (success:" << success << ") for URL: " |
| << request->url() << ". Start sending client phishing request."; |
| ClientSideDetectionService::ClientReportPhishingRequestCallback callback; |
| @@ -510,23 +522,19 @@ void ClientSideDetectionHost::FeatureExtractionDone( |
| } |
| void ClientSideDetectionHost::MalwareFeatureExtractionDone( |
| + bool feature_extraction_success, |
| scoped_ptr<ClientMalwareRequest> request) { |
| - if (!request) { |
| - DLOG(FATAL) << "Invalid request object in MalwareFeatureExtractionDone"; |
| - return; |
| - } |
| + DCHECK(request.get()); |
| 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.release(), callback); |
| } |
| } |