| 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/download_protection_service.h" | 5 #include "chrome/browser/safe_browsing/download_protection_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 SBStatsType dangerous_type) | 170 SBStatsType dangerous_type) |
| 171 : sha256_hash_(item.GetHash()), | 171 : sha256_hash_(item.GetHash()), |
| 172 url_chain_(item.GetUrlChain()), | 172 url_chain_(item.GetUrlChain()), |
| 173 referrer_url_(item.GetReferrerUrl()), | 173 referrer_url_(item.GetReferrerUrl()), |
| 174 callback_(callback), | 174 callback_(callback), |
| 175 ui_manager_(ui_manager), | 175 ui_manager_(ui_manager), |
| 176 start_time_(base::TimeTicks::Now()), | 176 start_time_(base::TimeTicks::Now()), |
| 177 total_type_(total_type), | 177 total_type_(total_type), |
| 178 dangerous_type_(dangerous_type) { | 178 dangerous_type_(dangerous_type) { |
| 179 Profile* profile = Profile::FromBrowserContext(item.GetBrowserContext()); | 179 Profile* profile = Profile::FromBrowserContext(item.GetBrowserContext()); |
| 180 is_extended_reporting_ = | 180 extended_reporting_level_ = |
| 181 profile && IsExtendedReportingEnabled(*profile->GetPrefs()); | 181 profile ? GetExtendedReportingLevel(*profile->GetPrefs()) |
| 182 : SBER_LEVEL_OFF; |
| 182 } | 183 } |
| 183 | 184 |
| 184 virtual void StartCheck() = 0; | 185 virtual void StartCheck() = 0; |
| 185 virtual bool IsDangerous(SBThreatType threat_type) const = 0; | 186 virtual bool IsDangerous(SBThreatType threat_type) const = 0; |
| 186 | 187 |
| 187 protected: | 188 protected: |
| 188 friend class base::RefCountedThreadSafe<DownloadSBClient>; | 189 friend class base::RefCountedThreadSafe<DownloadSBClient>; |
| 189 ~DownloadSBClient() override {} | 190 ~DownloadSBClient() override {} |
| 190 | 191 |
| 191 void CheckDone(SBThreatType threat_type) { | 192 void CheckDone(SBThreatType threat_type) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 219 safe_browsing::HitReport hit_report; | 220 safe_browsing::HitReport hit_report; |
| 220 hit_report.malicious_url = url_chain_.back(); | 221 hit_report.malicious_url = url_chain_.back(); |
| 221 hit_report.page_url = url_chain_.front(); | 222 hit_report.page_url = url_chain_.front(); |
| 222 hit_report.referrer_url = referrer_url_; | 223 hit_report.referrer_url = referrer_url_; |
| 223 hit_report.is_subresource = true; | 224 hit_report.is_subresource = true; |
| 224 hit_report.threat_type = threat_type; | 225 hit_report.threat_type = threat_type; |
| 225 // TODO(nparker) Replace this with database_manager_->GetThreatSource(); | 226 // TODO(nparker) Replace this with database_manager_->GetThreatSource(); |
| 226 hit_report.threat_source = safe_browsing::ThreatSource::LOCAL_PVER3; | 227 hit_report.threat_source = safe_browsing::ThreatSource::LOCAL_PVER3; |
| 227 // TODO(nparker) Populate hit_report.population_id once Pver4 is used here. | 228 // TODO(nparker) Populate hit_report.population_id once Pver4 is used here. |
| 228 hit_report.post_data = post_data; | 229 hit_report.post_data = post_data; |
| 229 hit_report.is_extended_reporting = is_extended_reporting_; | 230 hit_report.extended_reporting_level = extended_reporting_level_; |
| 230 hit_report.is_metrics_reporting_active = | 231 hit_report.is_metrics_reporting_active = |
| 231 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); | 232 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); |
| 232 | 233 |
| 233 ui_manager_->MaybeReportSafeBrowsingHit(hit_report); | 234 ui_manager_->MaybeReportSafeBrowsingHit(hit_report); |
| 234 } | 235 } |
| 235 | 236 |
| 236 void UpdateDownloadCheckStats(SBStatsType stat_type) { | 237 void UpdateDownloadCheckStats(SBStatsType stat_type) { |
| 237 UMA_HISTOGRAM_ENUMERATION("SB2.DownloadChecks", | 238 UMA_HISTOGRAM_ENUMERATION("SB2.DownloadChecks", |
| 238 stat_type, | 239 stat_type, |
| 239 DOWNLOAD_CHECKS_MAX); | 240 DOWNLOAD_CHECKS_MAX); |
| 240 } | 241 } |
| 241 | 242 |
| 242 std::string sha256_hash_; | 243 std::string sha256_hash_; |
| 243 std::vector<GURL> url_chain_; | 244 std::vector<GURL> url_chain_; |
| 244 GURL referrer_url_; | 245 GURL referrer_url_; |
| 245 DownloadProtectionService::CheckDownloadCallback callback_; | 246 DownloadProtectionService::CheckDownloadCallback callback_; |
| 246 scoped_refptr<SafeBrowsingUIManager> ui_manager_; | 247 scoped_refptr<SafeBrowsingUIManager> ui_manager_; |
| 247 base::TimeTicks start_time_; | 248 base::TimeTicks start_time_; |
| 248 | 249 |
| 249 private: | 250 private: |
| 250 const SBStatsType total_type_; | 251 const SBStatsType total_type_; |
| 251 const SBStatsType dangerous_type_; | 252 const SBStatsType dangerous_type_; |
| 252 bool is_extended_reporting_; | 253 ExtendedReportingLevel extended_reporting_level_; |
| 253 | 254 |
| 254 DISALLOW_COPY_AND_ASSIGN(DownloadSBClient); | 255 DISALLOW_COPY_AND_ASSIGN(DownloadSBClient); |
| 255 }; | 256 }; |
| 256 | 257 |
| 257 class DownloadUrlSBClient : public DownloadSBClient { | 258 class DownloadUrlSBClient : public DownloadSBClient { |
| 258 public: | 259 public: |
| 259 DownloadUrlSBClient( | 260 DownloadUrlSBClient( |
| 260 const content::DownloadItem& item, | 261 const content::DownloadItem& item, |
| 261 const DownloadProtectionService::CheckDownloadCallback& callback, | 262 const DownloadProtectionService::CheckDownloadCallback& callback, |
| 262 const scoped_refptr<SafeBrowsingUIManager>& ui_manager, | 263 const scoped_refptr<SafeBrowsingUIManager>& ui_manager, |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 } | 795 } |
| 795 | 796 |
| 796 OnFileFeatureExtractionDone(); | 797 OnFileFeatureExtractionDone(); |
| 797 } | 798 } |
| 798 #endif // defined(OS_MACOSX) | 799 #endif // defined(OS_MACOSX) |
| 799 | 800 |
| 800 bool ShouldSampleWhitelistedDownload() { | 801 bool ShouldSampleWhitelistedDownload() { |
| 801 // We currently sample 1% whitelisted downloads from users who opted | 802 // We currently sample 1% whitelisted downloads from users who opted |
| 802 // in extended reporting and are not in incognito mode. | 803 // in extended reporting and are not in incognito mode. |
| 803 return service_ && is_extended_reporting_ && !is_incognito_ && | 804 return service_ && is_extended_reporting_ && !is_incognito_ && |
| 804 base::RandDouble() < service_->whitelist_sample_rate(); | 805 base::RandDouble() < service_->whitelist_sample_rate(); |
| 805 } | 806 } |
| 806 | 807 |
| 807 void CheckWhitelists() { | 808 void CheckWhitelists() { |
| 808 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 809 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 809 | 810 |
| 810 if (!database_manager_.get()) { | 811 if (!database_manager_.get()) { |
| 811 PostFinishTask(UNKNOWN, REASON_SB_DISABLED); | 812 PostFinishTask(UNKNOWN, REASON_SB_DISABLED); |
| 812 return; | 813 return; |
| 813 } | 814 } |
| 814 | 815 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 void SendRequest() { | 939 void SendRequest() { |
| 939 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 940 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 940 | 941 |
| 941 // This is our last chance to check whether the request has been canceled | 942 // This is our last chance to check whether the request has been canceled |
| 942 // before sending it. | 943 // before sending it. |
| 943 if (!service_) | 944 if (!service_) |
| 944 return; | 945 return; |
| 945 | 946 |
| 946 ClientDownloadRequest request; | 947 ClientDownloadRequest request; |
| 947 auto population = is_extended_reporting_ | 948 auto population = is_extended_reporting_ |
| 948 ? ChromeUserPopulation::EXTENDED_REPORTING | 949 ? ChromeUserPopulation::EXTENDED_REPORTING |
| 949 : ChromeUserPopulation::SAFE_BROWSING; | 950 : ChromeUserPopulation::SAFE_BROWSING; |
| 950 request.mutable_population()->set_user_population(population); | 951 request.mutable_population()->set_user_population(population); |
| 951 | 952 |
| 952 request.set_url(SanitizeUrl(item_->GetUrlChain().back())); | 953 request.set_url(SanitizeUrl(item_->GetUrlChain().back())); |
| 953 request.mutable_digests()->set_sha256(item_->GetHash()); | 954 request.mutable_digests()->set_sha256(item_->GetHash()); |
| 954 request.set_length(item_->GetReceivedBytes()); | 955 request.set_length(item_->GetReceivedBytes()); |
| 955 request.set_skipped_url_whitelist(skipped_url_whitelist_); | 956 request.set_skipped_url_whitelist(skipped_url_whitelist_); |
| 956 request.set_skipped_certificate_whitelist(skipped_certificate_whitelist_); | 957 request.set_skipped_certificate_whitelist(skipped_certificate_whitelist_); |
| 957 for (size_t i = 0; i < item_->GetUrlChain().size(); ++i) { | 958 for (size_t i = 0; i < item_->GetUrlChain().size(); ++i) { |
| 958 ClientDownloadRequest::Resource* resource = request.add_resources(); | 959 ClientDownloadRequest::Resource* resource = request.add_resources(); |
| 959 resource->set_url(SanitizeUrl(item_->GetUrlChain()[i])); | 960 resource->set_url(SanitizeUrl(item_->GetUrlChain()[i])); |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1319 // backend. | 1320 // backend. |
| 1320 SendRequest(); | 1321 SendRequest(); |
| 1321 } | 1322 } |
| 1322 | 1323 |
| 1323 void SendRequest() { | 1324 void SendRequest() { |
| 1324 DVLOG(2) << __func__; | 1325 DVLOG(2) << __func__; |
| 1325 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1326 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1326 | 1327 |
| 1327 ClientDownloadRequest request; | 1328 ClientDownloadRequest request; |
| 1328 auto population = is_extended_reporting_ | 1329 auto population = is_extended_reporting_ |
| 1329 ? ChromeUserPopulation::EXTENDED_REPORTING | 1330 ? ChromeUserPopulation::EXTENDED_REPORTING |
| 1330 : ChromeUserPopulation::SAFE_BROWSING; | 1331 : ChromeUserPopulation::SAFE_BROWSING; |
| 1331 request.mutable_population()->set_user_population(population); | 1332 request.mutable_population()->set_user_population(population); |
| 1332 request.set_download_type(ClientDownloadRequest::PPAPI_SAVE_REQUEST); | 1333 request.set_download_type(ClientDownloadRequest::PPAPI_SAVE_REQUEST); |
| 1333 ClientDownloadRequest::Resource* resource = request.add_resources(); | 1334 ClientDownloadRequest::Resource* resource = request.add_resources(); |
| 1334 resource->set_type(ClientDownloadRequest::PPAPI_DOCUMENT); | 1335 resource->set_type(ClientDownloadRequest::PPAPI_DOCUMENT); |
| 1335 resource->set_url(requestor_url_.spec()); | 1336 resource->set_url(requestor_url_.spec()); |
| 1336 request.set_url(requestor_url_.spec()); | 1337 request.set_url(requestor_url_.spec()); |
| 1337 request.set_file_basename(supported_path_.BaseName().AsUTF8Unsafe()); | 1338 request.set_file_basename(supported_path_.BaseName().AsUTF8Unsafe()); |
| 1338 request.set_length(0); | 1339 request.set_length(0); |
| 1339 request.mutable_digests()->set_md5(std::string()); | 1340 request.mutable_digests()->set_md5(std::string()); |
| 1340 for (const auto& alternate_extension : alternate_extensions_) { | 1341 for (const auto& alternate_extension : alternate_extensions_) { |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1771 GURL DownloadProtectionService::GetDownloadRequestUrl() { | 1772 GURL DownloadProtectionService::GetDownloadRequestUrl() { |
| 1772 GURL url(kDownloadRequestUrl); | 1773 GURL url(kDownloadRequestUrl); |
| 1773 std::string api_key = google_apis::GetAPIKey(); | 1774 std::string api_key = google_apis::GetAPIKey(); |
| 1774 if (!api_key.empty()) | 1775 if (!api_key.empty()) |
| 1775 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); | 1776 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); |
| 1776 | 1777 |
| 1777 return url; | 1778 return url; |
| 1778 } | 1779 } |
| 1779 | 1780 |
| 1780 } // namespace safe_browsing | 1781 } // namespace safe_browsing |
| OLD | NEW |