Chromium Code Reviews| 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 DOWNLOAD_URL_CHECKS_MALWARE, | 107 DOWNLOAD_URL_CHECKS_MALWARE, |
| 108 | 108 |
| 109 DOWNLOAD_HASH_CHECKS_TOTAL, | 109 DOWNLOAD_HASH_CHECKS_TOTAL, |
| 110 DOWNLOAD_HASH_CHECKS_MALWARE, | 110 DOWNLOAD_HASH_CHECKS_MALWARE, |
| 111 | 111 |
| 112 // Memory space for histograms is determined by the max. | 112 // Memory space for histograms is determined by the max. |
| 113 // ALWAYS ADD NEW VALUES BEFORE THIS ONE. | 113 // ALWAYS ADD NEW VALUES BEFORE THIS ONE. |
| 114 DOWNLOAD_CHECKS_MAX | 114 DOWNLOAD_CHECKS_MAX |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 // Prepares URLs to be put into a ping message. Currently this just shortens | |
| 118 // data: URIs, other URLs are included verbatim. | |
| 119 std::string SanitizeUrl(const GURL& url) { | |
| 120 std::string spec = url.spec(); | |
| 121 if (url.SchemeIs(url::kDataScheme)) { | |
| 122 size_t comma_pos = spec.find(','); | |
| 123 if (comma_pos != std::string::npos && comma_pos != spec.size() - 1) { | |
| 124 std::string hash_value = crypto::SHA256HashString(spec); | |
| 125 spec.erase(comma_pos + 1); | |
| 126 spec += base::HexEncode(hash_value.data(), hash_value.size()); | |
| 127 } | |
| 128 } | |
| 129 return spec; | |
| 130 } | |
| 131 | |
| 132 } // namespace | 117 } // namespace |
| 133 | 118 |
| 134 // Parent SafeBrowsing::Client class used to lookup the bad binary | 119 // Parent SafeBrowsing::Client class used to lookup the bad binary |
| 135 // URL and digest list. There are two sub-classes (one for each list). | 120 // URL and digest list. There are two sub-classes (one for each list). |
| 136 class DownloadSBClient | 121 class DownloadSBClient |
| 137 : public SafeBrowsingDatabaseManager::Client, | 122 : public SafeBrowsingDatabaseManager::Client, |
| 138 public base::RefCountedThreadSafe<DownloadSBClient> { | 123 public base::RefCountedThreadSafe<DownloadSBClient> { |
| 139 public: | 124 public: |
| 140 DownloadSBClient( | 125 DownloadSBClient( |
| 141 const content::DownloadItem& item, | 126 const content::DownloadItem& item, |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 type_(ClientDownloadRequest::WIN_EXECUTABLE), | 287 type_(ClientDownloadRequest::WIN_EXECUTABLE), |
| 303 start_time_(base::TimeTicks::Now()), | 288 start_time_(base::TimeTicks::Now()), |
| 304 skipped_url_whitelist_(false), | 289 skipped_url_whitelist_(false), |
| 305 skipped_certificate_whitelist_(false), | 290 skipped_certificate_whitelist_(false), |
| 306 is_extended_reporting_(false), | 291 is_extended_reporting_(false), |
| 307 is_incognito_(false), | 292 is_incognito_(false), |
| 308 weakptr_factory_(this) { | 293 weakptr_factory_(this) { |
| 309 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 294 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 310 item_->AddObserver(this); | 295 item_->AddObserver(this); |
| 311 } | 296 } |
| 297 bool ShouldSampleUnsupportedFile(const base::FilePath filename) { | |
|
asanka
2016/06/20 18:15:46
Nit: Use 'const base::FilePath&'. We aren't benefi
Nathan Parker
2016/06/20 22:47:31
Done.
| |
| 298 // If this extension is specifically marked as SAMPLED_PING (as are | |
| 299 // all "unknown" extensions), we may want to sample it. Sampling it means | |
| 300 // we'll send a "light ping" with private info removed, and we won't | |
| 301 // use the verdict. | |
| 302 const FileTypePolicies* policies = FileTypePolicies::GetInstance(); | |
| 303 return service_ && is_extended_reporting_ && !is_incognito_ && | |
| 304 base::RandDouble() < policies->SampledPingProbability() && | |
| 305 policies->PingSettingForFile(filename) == | |
| 306 DownloadFileType::SAMPLED_PING; | |
| 307 } | |
| 312 | 308 |
| 313 void Start() { | 309 void Start() { |
| 314 DVLOG(2) << "Starting SafeBrowsing download check for: " | 310 DVLOG(2) << "Starting SafeBrowsing download check for: " |
| 315 << item_->DebugString(true); | 311 << item_->DebugString(true); |
| 316 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 312 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 317 if (item_->GetBrowserContext()) { | 313 if (item_->GetBrowserContext()) { |
| 318 Profile* profile = | 314 Profile* profile = |
| 319 Profile::FromBrowserContext(item_->GetBrowserContext()); | 315 Profile::FromBrowserContext(item_->GetBrowserContext()); |
| 320 is_extended_reporting_ = profile && | 316 is_extended_reporting_ = profile && |
| 321 profile->GetPrefs()->GetBoolean( | 317 profile->GetPrefs()->GetBoolean( |
| 322 prefs::kSafeBrowsingExtendedReportingEnabled); | 318 prefs::kSafeBrowsingExtendedReportingEnabled); |
| 323 is_incognito_ = item_->GetBrowserContext()->IsOffTheRecord(); | 319 is_incognito_ = item_->GetBrowserContext()->IsOffTheRecord(); |
| 324 } | 320 } |
| 325 // TODO(noelutz): implement some cache to make sure we don't issue the same | 321 |
| 326 // request over and over again if a user downloads the same binary multiple | |
| 327 // times. | |
| 328 DownloadCheckResultReason reason = REASON_MAX; | 322 DownloadCheckResultReason reason = REASON_MAX; |
| 329 if (!IsSupportedDownload( | 323 if (!IsSupportedDownload( |
| 330 *item_, item_->GetTargetFilePath(), &reason, &type_)) { | 324 *item_, item_->GetTargetFilePath(), &reason, &type_)) { |
| 331 switch (reason) { | 325 switch (reason) { |
| 332 case REASON_EMPTY_URL_CHAIN: | 326 case REASON_EMPTY_URL_CHAIN: |
| 333 case REASON_INVALID_URL: | 327 case REASON_INVALID_URL: |
| 334 case REASON_UNSUPPORTED_URL_SCHEME: | 328 case REASON_UNSUPPORTED_URL_SCHEME: |
| 335 PostFinishTask(UNKNOWN, reason); | 329 PostFinishTask(UNKNOWN, reason); |
|
asanka
2016/06/20 18:15:46
Can we do some sort of incomplete ping for these c
Nathan Parker
2016/06/20 22:47:31
I don't really know what these are, other than fil
| |
| 336 return; | 330 return; |
| 337 | 331 |
| 338 case REASON_NOT_BINARY_FILE: | 332 case REASON_NOT_BINARY_FILE: |
| 339 RecordFileExtensionType(item_->GetTargetFilePath()); | 333 if (ShouldSampleUnsupportedFile(item_->GetTargetFilePath())) { |
| 340 PostFinishTask(UNKNOWN, reason); | 334 // Send a "light ping" and don't use the verdict. |
| 341 return; | 335 type_ = ClientDownloadRequest::SAMPLED_UNSUPPORTED_FILE; |
| 336 break; | |
| 337 } else { | |
|
asanka
2016/06/20 18:15:46
Nit: else { unnecessary.
Nathan Parker
2016/06/20 22:47:31
Done.
| |
| 338 RecordFileExtensionType(item_->GetTargetFilePath()); | |
| 339 PostFinishTask(UNKNOWN, reason); | |
| 340 return; | |
| 341 } | |
| 342 | 342 |
| 343 default: | 343 default: |
| 344 // We only expect the reasons explicitly handled above. | 344 // We only expect the reasons explicitly handled above. |
| 345 NOTREACHED(); | 345 NOTREACHED(); |
| 346 } | 346 } |
| 347 } | 347 } |
| 348 RecordFileExtensionType(item_->GetTargetFilePath()); | 348 RecordFileExtensionType(item_->GetTargetFilePath()); |
| 349 | 349 |
| 350 // Compute features from the file contents. Note that we record histograms | 350 // Compute features from the file contents. Note that we record histograms |
| 351 // based on the result, so this runs regardless of whether the pingbacks | 351 // based on the result, so this runs regardless of whether the pingbacks |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 457 std::string token; | 457 std::string token; |
| 458 if (source->GetStatus().is_success() && | 458 if (source->GetStatus().is_success() && |
| 459 net::HTTP_OK == source->GetResponseCode()) { | 459 net::HTTP_OK == source->GetResponseCode()) { |
| 460 ClientDownloadResponse response; | 460 ClientDownloadResponse response; |
| 461 std::string data; | 461 std::string data; |
| 462 bool got_data = source->GetResponseAsString(&data); | 462 bool got_data = source->GetResponseAsString(&data); |
| 463 DCHECK(got_data); | 463 DCHECK(got_data); |
| 464 if (!response.ParseFromString(data)) { | 464 if (!response.ParseFromString(data)) { |
| 465 reason = REASON_INVALID_RESPONSE_PROTO; | 465 reason = REASON_INVALID_RESPONSE_PROTO; |
| 466 result = UNKNOWN; | 466 result = UNKNOWN; |
| 467 } else if (type_ == ClientDownloadRequest::SAMPLED_UNSUPPORTED_FILE) { | |
| 468 // Ignore the verdict because we were just reporting a sampled file. | |
| 469 reason = REASON_SAMPLED_UNSUPPORTED_FILE; | |
| 470 result = UNKNOWN; | |
| 467 } else if (response.verdict() == ClientDownloadResponse::SAFE) { | 471 } else if (response.verdict() == ClientDownloadResponse::SAFE) { |
| 468 reason = REASON_DOWNLOAD_SAFE; | 472 reason = REASON_DOWNLOAD_SAFE; |
| 469 result = SAFE; | 473 result = SAFE; |
| 470 } else if (service_ && !service_->IsSupportedDownload( | 474 } else if (service_ && !service_->IsSupportedDownload( |
| 471 *item_, item_->GetTargetFilePath())) { | 475 *item_, item_->GetTargetFilePath())) { |
| 472 // The client of the download protection service assumes that we don't | 476 // TODO(nparker): Remove this check since it should be impossible. |
| 473 // support this download so we cannot return any other verdict than | |
| 474 // UNKNOWN even if the server says it's dangerous to download this file. | |
| 475 // Note: if service_ is NULL we already cancelled the request and | |
| 476 // returned UNKNOWN. | |
| 477 reason = REASON_DOWNLOAD_NOT_SUPPORTED; | 477 reason = REASON_DOWNLOAD_NOT_SUPPORTED; |
| 478 result = UNKNOWN; | 478 result = UNKNOWN; |
| 479 } else if (response.verdict() == ClientDownloadResponse::DANGEROUS) { | 479 } else if (response.verdict() == ClientDownloadResponse::DANGEROUS) { |
| 480 reason = REASON_DOWNLOAD_DANGEROUS; | 480 reason = REASON_DOWNLOAD_DANGEROUS; |
| 481 result = DANGEROUS; | 481 result = DANGEROUS; |
| 482 token = response.token(); | 482 token = response.token(); |
| 483 } else if (response.verdict() == ClientDownloadResponse::UNCOMMON) { | 483 } else if (response.verdict() == ClientDownloadResponse::UNCOMMON) { |
| 484 reason = REASON_DOWNLOAD_UNCOMMON; | 484 reason = REASON_DOWNLOAD_UNCOMMON; |
| 485 result = UNCOMMON; | 485 result = UNCOMMON; |
| 486 token = response.token(); | 486 token = response.token(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 521 ClientDownloadRequest::DownloadType* type) { | 521 ClientDownloadRequest::DownloadType* type) { |
| 522 if (item.GetUrlChain().empty()) { | 522 if (item.GetUrlChain().empty()) { |
| 523 *reason = REASON_EMPTY_URL_CHAIN; | 523 *reason = REASON_EMPTY_URL_CHAIN; |
| 524 return false; | 524 return false; |
| 525 } | 525 } |
| 526 const GURL& final_url = item.GetUrlChain().back(); | 526 const GURL& final_url = item.GetUrlChain().back(); |
| 527 if (!final_url.is_valid() || final_url.is_empty()) { | 527 if (!final_url.is_valid() || final_url.is_empty()) { |
| 528 *reason = REASON_INVALID_URL; | 528 *reason = REASON_INVALID_URL; |
| 529 return false; | 529 return false; |
| 530 } | 530 } |
| 531 if (!FileTypePolicies::GetInstance()->IsCheckedBinaryFile(target_path)) { | |
| 532 *reason = REASON_NOT_BINARY_FILE; | |
| 533 return false; | |
| 534 } | |
| 535 if ((!final_url.IsStandard() && !final_url.SchemeIsBlob() && | 531 if ((!final_url.IsStandard() && !final_url.SchemeIsBlob() && |
| 536 !final_url.SchemeIs(url::kDataScheme)) || | 532 !final_url.SchemeIs(url::kDataScheme)) || |
| 537 final_url.SchemeIsFile()) { | 533 final_url.SchemeIsFile()) { |
| 538 *reason = REASON_UNSUPPORTED_URL_SCHEME; | 534 *reason = REASON_UNSUPPORTED_URL_SCHEME; |
| 539 return false; | 535 return false; |
| 540 } | 536 } |
| 537 // This check should be last, so we know the earlier checks passed. | |
| 538 if (!FileTypePolicies::GetInstance()->IsCheckedBinaryFile(target_path)) { | |
| 539 *reason = REASON_NOT_BINARY_FILE; | |
| 540 return false; | |
| 541 } | |
| 541 *type = download_protection_util::GetDownloadType(target_path); | 542 *type = download_protection_util::GetDownloadType(target_path); |
| 542 return true; | 543 return true; |
| 543 } | 544 } |
| 544 | 545 |
| 545 private: | 546 private: |
| 546 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; | 547 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; |
| 547 friend class base::DeleteHelper<CheckClientDownloadRequest>; | 548 friend class base::DeleteHelper<CheckClientDownloadRequest>; |
| 548 | 549 |
| 549 ~CheckClientDownloadRequest() override { | 550 ~CheckClientDownloadRequest() override { |
| 550 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 551 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 872 if (service_->IsHashManuallyBlacklisted(request.digests().sha256())) | 873 if (service_->IsHashManuallyBlacklisted(request.digests().sha256())) |
| 873 return true; | 874 return true; |
| 874 | 875 |
| 875 for (auto bin_itr : request.archived_binary()) { | 876 for (auto bin_itr : request.archived_binary()) { |
| 876 if (service_->IsHashManuallyBlacklisted(bin_itr.digests().sha256())) | 877 if (service_->IsHashManuallyBlacklisted(bin_itr.digests().sha256())) |
| 877 return true; | 878 return true; |
| 878 } | 879 } |
| 879 return false; | 880 return false; |
| 880 } | 881 } |
| 881 | 882 |
| 883 // Prepares URLs to be put into a ping message. Currently this just shortens | |
| 884 // data: URIs, other URLs are included verbatim. If this is a sampled binary, | |
| 885 // we'll send a lite-ping which strips all PII. | |
| 886 std::string SanitizeUrl(const GURL& url) const { | |
| 887 if (type_ == ClientDownloadRequest::SAMPLED_UNSUPPORTED_FILE) | |
| 888 return url.GetOrigin().spec(); | |
| 889 | |
| 890 std::string spec = url.spec(); | |
| 891 if (url.SchemeIs(url::kDataScheme)) { | |
| 892 size_t comma_pos = spec.find(','); | |
| 893 if (comma_pos != std::string::npos && comma_pos != spec.size() - 1) { | |
| 894 std::string hash_value = crypto::SHA256HashString(spec); | |
| 895 spec.erase(comma_pos + 1); | |
| 896 spec += base::HexEncode(hash_value.data(), hash_value.size()); | |
| 897 } | |
| 898 } | |
| 899 return spec; | |
| 900 } | |
| 901 | |
| 902 | |
|
asanka
2016/06/20 18:15:46
Nit: Extra blank line.
Nathan Parker
2016/06/20 22:47:31
Done.
| |
| 882 void SendRequest() { | 903 void SendRequest() { |
| 883 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 904 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 884 | 905 |
| 885 // This is our last chance to check whether the request has been canceled | 906 // This is our last chance to check whether the request has been canceled |
| 886 // before sending it. | 907 // before sending it. |
| 887 if (!service_) | 908 if (!service_) |
| 888 return; | 909 return; |
| 889 | 910 |
| 890 ClientDownloadRequest request; | 911 ClientDownloadRequest request; |
| 891 if (is_extended_reporting_) { | 912 if (is_extended_reporting_) { |
| 892 request.mutable_population()->set_user_population( | 913 request.mutable_population()->set_user_population( |
| 893 ChromeUserPopulation::EXTENDED_REPORTING); | 914 ChromeUserPopulation::EXTENDED_REPORTING); |
| 894 } else { | 915 } else { |
| 895 request.mutable_population()->set_user_population( | 916 request.mutable_population()->set_user_population( |
| 896 ChromeUserPopulation::SAFE_BROWSING); | 917 ChromeUserPopulation::SAFE_BROWSING); |
| 897 } | 918 } |
| 919 | |
| 898 request.set_url(SanitizeUrl(item_->GetUrlChain().back())); | 920 request.set_url(SanitizeUrl(item_->GetUrlChain().back())); |
| 899 request.mutable_digests()->set_sha256(item_->GetHash()); | 921 request.mutable_digests()->set_sha256(item_->GetHash()); |
| 900 request.set_length(item_->GetReceivedBytes()); | 922 request.set_length(item_->GetReceivedBytes()); |
| 901 request.set_skipped_url_whitelist(skipped_url_whitelist_); | 923 request.set_skipped_url_whitelist(skipped_url_whitelist_); |
| 902 request.set_skipped_certificate_whitelist(skipped_certificate_whitelist_); | 924 request.set_skipped_certificate_whitelist(skipped_certificate_whitelist_); |
| 903 for (size_t i = 0; i < item_->GetUrlChain().size(); ++i) { | 925 for (size_t i = 0; i < item_->GetUrlChain().size(); ++i) { |
| 904 ClientDownloadRequest::Resource* resource = request.add_resources(); | 926 ClientDownloadRequest::Resource* resource = request.add_resources(); |
| 905 resource->set_url(SanitizeUrl(item_->GetUrlChain()[i])); | 927 resource->set_url(SanitizeUrl(item_->GetUrlChain()[i])); |
| 906 if (i == item_->GetUrlChain().size() - 1) { | 928 if (i == item_->GetUrlChain().size() - 1) { |
| 907 // The last URL in the chain is the download URL. | 929 // The last URL in the chain is the download URL. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 931 resource->set_url(SanitizeUrl(tab_url_)); | 953 resource->set_url(SanitizeUrl(tab_url_)); |
| 932 DVLOG(2) << "tab url " << resource->url(); | 954 DVLOG(2) << "tab url " << resource->url(); |
| 933 resource->set_type(ClientDownloadRequest::TAB_URL); | 955 resource->set_type(ClientDownloadRequest::TAB_URL); |
| 934 if (tab_referrer_url_.is_valid()) { | 956 if (tab_referrer_url_.is_valid()) { |
| 935 resource->set_referrer(SanitizeUrl(tab_referrer_url_)); | 957 resource->set_referrer(SanitizeUrl(tab_referrer_url_)); |
| 936 DVLOG(2) << "tab referrer " << resource->referrer(); | 958 DVLOG(2) << "tab referrer " << resource->referrer(); |
| 937 } | 959 } |
| 938 } | 960 } |
| 939 | 961 |
| 940 request.set_user_initiated(item_->HasUserGesture()); | 962 request.set_user_initiated(item_->HasUserGesture()); |
| 941 request.set_file_basename( | 963 if (type_ == ClientDownloadRequest::SAMPLED_UNSUPPORTED_FILE) { |
| 964 request.set_file_basename( | |
| 965 base::FilePath(item_->GetTargetFilePath().Extension()) | |
| 966 .AsUTF8Unsafe()); | |
| 967 } else { | |
| 968 request.set_file_basename( | |
| 942 item_->GetTargetFilePath().BaseName().AsUTF8Unsafe()); | 969 item_->GetTargetFilePath().BaseName().AsUTF8Unsafe()); |
| 970 } | |
| 943 request.set_download_type(type_); | 971 request.set_download_type(type_); |
| 944 if (archive_is_valid_ != ArchiveValid::UNSET) | 972 if (archive_is_valid_ != ArchiveValid::UNSET) |
| 945 request.set_archive_valid(archive_is_valid_ == ArchiveValid::VALID); | 973 request.set_archive_valid(archive_is_valid_ == ArchiveValid::VALID); |
| 946 request.mutable_signature()->CopyFrom(signature_info_); | 974 request.mutable_signature()->CopyFrom(signature_info_); |
| 947 if (image_headers_) | 975 if (image_headers_) |
| 948 request.set_allocated_image_headers(image_headers_.release()); | 976 request.set_allocated_image_headers(image_headers_.release()); |
| 949 if (archived_executable_) | 977 if (archived_executable_) |
| 950 request.mutable_archived_binary()->Swap(&archived_binary_); | 978 request.mutable_archived_binary()->Swap(&archived_binary_); |
| 951 if (!request.SerializeToString(&client_download_request_data_)) { | 979 if (!request.SerializeToString(&client_download_request_data_)) { |
| 952 FinishRequest(UNKNOWN, REASON_INVALID_REQUEST_PROTO); | 980 FinishRequest(UNKNOWN, REASON_INVALID_REQUEST_PROTO); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1013 REASON_MAX); | 1041 REASON_MAX); |
| 1014 if (reason != REASON_REQUEST_CANCELED) { | 1042 if (reason != REASON_REQUEST_CANCELED) { |
| 1015 UMA_HISTOGRAM_TIMES("SBClientDownload.DownloadRequestTimeoutDuration", | 1043 UMA_HISTOGRAM_TIMES("SBClientDownload.DownloadRequestTimeoutDuration", |
| 1016 base::TimeTicks::Now() - timeout_start_time_); | 1044 base::TimeTicks::Now() - timeout_start_time_); |
| 1017 } | 1045 } |
| 1018 } | 1046 } |
| 1019 if (service_) { | 1047 if (service_) { |
| 1020 DVLOG(2) << "SafeBrowsing download verdict for: " | 1048 DVLOG(2) << "SafeBrowsing download verdict for: " |
| 1021 << item_->DebugString(true) << " verdict:" << reason | 1049 << item_->DebugString(true) << " verdict:" << reason |
| 1022 << " result:" << result; | 1050 << " result:" << result; |
| 1023 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckDownloadStats", | 1051 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckDownloadStats", reason, |
| 1024 reason, | |
| 1025 REASON_MAX); | 1052 REASON_MAX); |
| 1026 callback_.Run(result); | 1053 callback_.Run(result); |
| 1027 item_->RemoveObserver(this); | 1054 item_->RemoveObserver(this); |
| 1028 item_ = NULL; | 1055 item_ = NULL; |
| 1029 DownloadProtectionService* service = service_; | 1056 DownloadProtectionService* service = service_; |
| 1030 service_ = NULL; | 1057 service_ = NULL; |
| 1031 service->RequestFinished(this); | 1058 service->RequestFinished(this); |
| 1032 // DownloadProtectionService::RequestFinished will decrement our refcount, | 1059 // DownloadProtectionService::RequestFinished will decrement our refcount, |
| 1033 // so we may be deleted now. | 1060 // so we may be deleted now. |
| 1034 } else { | 1061 } else { |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1361 case ClientDownloadResponse::DANGEROUS: | 1388 case ClientDownloadResponse::DANGEROUS: |
| 1362 return DANGEROUS; | 1389 return DANGEROUS; |
| 1363 case ClientDownloadResponse::DANGEROUS_HOST: | 1390 case ClientDownloadResponse::DANGEROUS_HOST: |
| 1364 return DANGEROUS_HOST; | 1391 return DANGEROUS_HOST; |
| 1365 } | 1392 } |
| 1366 return UNKNOWN; | 1393 return UNKNOWN; |
| 1367 } | 1394 } |
| 1368 | 1395 |
| 1369 // Given a |default_file_path| and a list of |alternate_extensions|, | 1396 // Given a |default_file_path| and a list of |alternate_extensions|, |
| 1370 // constructs a FilePath with each possible extension and returns one that | 1397 // constructs a FilePath with each possible extension and returns one that |
| 1371 // satisfies download_protection_util::IsSupportedBinaryFile(). If none are | 1398 // satisfies IsCheckedBinaryFile(). If none are supported, returns an |
| 1372 // supported, returns an empty FilePath. | 1399 // empty FilePath. |
| 1373 static base::FilePath GetSupportedFilePath( | 1400 static base::FilePath GetSupportedFilePath( |
| 1374 const base::FilePath& default_file_path, | 1401 const base::FilePath& default_file_path, |
| 1375 const std::vector<base::FilePath::StringType>& alternate_extensions) { | 1402 const std::vector<base::FilePath::StringType>& alternate_extensions) { |
| 1376 const FileTypePolicies* file_type_policies = | 1403 const FileTypePolicies* file_type_policies = |
| 1377 FileTypePolicies::GetInstance(); | 1404 FileTypePolicies::GetInstance(); |
| 1378 if (file_type_policies->IsCheckedBinaryFile(default_file_path)) | 1405 if (file_type_policies->IsCheckedBinaryFile(default_file_path)) |
| 1379 return default_file_path; | 1406 return default_file_path; |
| 1380 | 1407 |
| 1381 for (const auto& extension : alternate_extensions) { | 1408 for (const auto& extension : alternate_extensions) { |
| 1382 base::FilePath alternative_file_path = | 1409 base::FilePath alternative_file_path = |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1405 CheckDownloadCallback callback_; | 1432 CheckDownloadCallback callback_; |
| 1406 | 1433 |
| 1407 DownloadProtectionService* service_; | 1434 DownloadProtectionService* service_; |
| 1408 const scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; | 1435 const scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; |
| 1409 | 1436 |
| 1410 // Time request was started. | 1437 // Time request was started. |
| 1411 const base::TimeTicks start_time_; | 1438 const base::TimeTicks start_time_; |
| 1412 | 1439 |
| 1413 // A download path that is supported by SafeBrowsing. This is determined by | 1440 // A download path that is supported by SafeBrowsing. This is determined by |
| 1414 // invoking GetSupportedFilePath(). If non-empty, | 1441 // invoking GetSupportedFilePath(). If non-empty, |
| 1415 // safe_browsing::IsSupportedBinaryFile(supported_path_) is always true. This | 1442 // IsCheckedBinaryFile(supported_path_) is always true. This |
| 1416 // path is therefore used as the download target when sending the SafeBrowsing | 1443 // path is therefore used as the download target when sending the SafeBrowsing |
| 1417 // ping. | 1444 // ping. |
| 1418 const base::FilePath supported_path_; | 1445 const base::FilePath supported_path_; |
| 1419 | 1446 |
| 1420 base::WeakPtrFactory<PPAPIDownloadRequest> weakptr_factory_; | 1447 base::WeakPtrFactory<PPAPIDownloadRequest> weakptr_factory_; |
| 1421 | 1448 |
| 1422 DISALLOW_COPY_AND_ASSIGN(PPAPIDownloadRequest); | 1449 DISALLOW_COPY_AND_ASSIGN(PPAPIDownloadRequest); |
| 1423 }; | 1450 }; |
| 1424 | 1451 |
| 1425 DownloadProtectionService::DownloadProtectionService( | 1452 DownloadProtectionService::DownloadProtectionService( |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1504 FROM_HERE, | 1531 FROM_HERE, |
| 1505 base::Bind(&DownloadUrlSBClient::StartCheck, client)); | 1532 base::Bind(&DownloadUrlSBClient::StartCheck, client)); |
| 1506 } | 1533 } |
| 1507 | 1534 |
| 1508 bool DownloadProtectionService::IsSupportedDownload( | 1535 bool DownloadProtectionService::IsSupportedDownload( |
| 1509 const content::DownloadItem& item, | 1536 const content::DownloadItem& item, |
| 1510 const base::FilePath& target_path) const { | 1537 const base::FilePath& target_path) const { |
| 1511 DownloadCheckResultReason reason = REASON_MAX; | 1538 DownloadCheckResultReason reason = REASON_MAX; |
| 1512 ClientDownloadRequest::DownloadType type = | 1539 ClientDownloadRequest::DownloadType type = |
| 1513 ClientDownloadRequest::WIN_EXECUTABLE; | 1540 ClientDownloadRequest::WIN_EXECUTABLE; |
| 1541 // TODO(nparker): Remove the CRX check here once can support | |
| 1542 // UNKNOWN types properly. http://crbug.com/581044 | |
| 1514 return (CheckClientDownloadRequest::IsSupportedDownload( | 1543 return (CheckClientDownloadRequest::IsSupportedDownload( |
| 1515 item, target_path, &reason, &type) && | 1544 item, target_path, &reason, &type) && |
| 1516 (ClientDownloadRequest::CHROME_EXTENSION != type)); | 1545 (ClientDownloadRequest::CHROME_EXTENSION != type)); |
| 1517 } | 1546 } |
| 1518 | 1547 |
| 1519 void DownloadProtectionService::CheckPPAPIDownloadRequest( | 1548 void DownloadProtectionService::CheckPPAPIDownloadRequest( |
| 1520 const GURL& requestor_url, | 1549 const GURL& requestor_url, |
| 1521 const base::FilePath& default_file_path, | 1550 const base::FilePath& default_file_path, |
| 1522 const std::vector<base::FilePath::StringType>& alternate_extensions, | 1551 const std::vector<base::FilePath::StringType>& alternate_extensions, |
| 1523 const CheckDownloadCallback& callback) { | 1552 const CheckDownloadCallback& callback) { |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1682 GURL DownloadProtectionService::GetDownloadRequestUrl() { | 1711 GURL DownloadProtectionService::GetDownloadRequestUrl() { |
| 1683 GURL url(kDownloadRequestUrl); | 1712 GURL url(kDownloadRequestUrl); |
| 1684 std::string api_key = google_apis::GetAPIKey(); | 1713 std::string api_key = google_apis::GetAPIKey(); |
| 1685 if (!api_key.empty()) | 1714 if (!api_key.empty()) |
| 1686 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); | 1715 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); |
| 1687 | 1716 |
| 1688 return url; | 1717 return url; |
| 1689 } | 1718 } |
| 1690 | 1719 |
| 1691 } // namespace safe_browsing | 1720 } // namespace safe_browsing |
| OLD | NEW |