Chromium Code Reviews| Index: chrome/browser/safe_browsing/download_protection_service.cc |
| diff --git a/chrome/browser/safe_browsing/download_protection_service.cc b/chrome/browser/safe_browsing/download_protection_service.cc |
| index f5c82c7e83e35119809606e2c1fc8d6f008f74ce..978b53172583ac9edd5f7af4c55df9918882b957 100644 |
| --- a/chrome/browser/safe_browsing/download_protection_service.cc |
| +++ b/chrome/browser/safe_browsing/download_protection_service.cc |
| @@ -82,6 +82,9 @@ namespace safe_browsing { |
| const char DownloadProtectionService::kDownloadRequestUrl[] = |
| "https://sb-ssl.google.com/safebrowsing/clientreport/download"; |
| +const void* const DownloadProtectionService::kDownloadPingTokenKey |
| + = &kDownloadPingTokenKey; |
|
asanka
2016/06/07 20:26:44
Interesting. Have you seen this pattern before?
Jialiu Lin
2016/06/07 20:34:01
I copied from the download feedback example you ga
Nathan Parker
2016/06/07 23:00:53
I suppose it is guaranteed to be unique in this pr
Jialiu Lin
2016/06/08 00:06:16
I suppose so.
|
| + |
| namespace { |
| void RecordFileExtensionType(const base::FilePath& file) { |
| UMA_HISTOGRAM_SPARSE_SLOWLY( |
| @@ -451,6 +454,7 @@ class DownloadProtectionService::CheckClientDownloadRequest |
| -source->GetStatus().error()); |
| DownloadCheckResultReason reason = REASON_SERVER_PING_FAILED; |
| DownloadCheckResult result = UNKNOWN; |
| + std::string token; |
| if (source->GetStatus().is_success() && |
| net::HTTP_OK == source->GetResponseCode()) { |
| ClientDownloadResponse response; |
| @@ -475,22 +479,29 @@ class DownloadProtectionService::CheckClientDownloadRequest |
| } else if (response.verdict() == ClientDownloadResponse::DANGEROUS) { |
| reason = REASON_DOWNLOAD_DANGEROUS; |
| result = DANGEROUS; |
| + token = response.has_token() ? response.token() : std::string(); |
|
Nathan Parker
2016/06/07 23:00:53
nit: Could this be just
token = response.token()
Jialiu Lin
2016/06/08 00:06:16
Fixed. Thanks!
|
| } else if (response.verdict() == ClientDownloadResponse::UNCOMMON) { |
| reason = REASON_DOWNLOAD_UNCOMMON; |
| result = UNCOMMON; |
| + token = response.has_token() ? response.token() : std::string(); |
| } else if (response.verdict() == ClientDownloadResponse::DANGEROUS_HOST) { |
| reason = REASON_DOWNLOAD_DANGEROUS_HOST; |
| result = DANGEROUS_HOST; |
| + token = response.has_token() ? response.token() : std::string(); |
| } else if ( |
| response.verdict() == ClientDownloadResponse::POTENTIALLY_UNWANTED) { |
| reason = REASON_DOWNLOAD_POTENTIALLY_UNWANTED; |
| result = POTENTIALLY_UNWANTED; |
| + token = response.has_token() ? response.token() : std::string(); |
| } else { |
| LOG(DFATAL) << "Unknown download response verdict: " |
| << response.verdict(); |
| reason = REASON_INVALID_RESPONSE_VERDICT; |
| result = UNKNOWN; |
| } |
| + if (!token.empty()) |
| + SetDownloadPingToken(item_, token); |
| + |
| DownloadFeedbackService::MaybeStorePingsForDownload( |
| result, item_, client_download_request_data_, data); |
| } |
| @@ -1570,6 +1581,22 @@ void DownloadProtectionService::ShowDetailsForDownload( |
| false)); |
| } |
| +void DownloadProtectionService::SetDownloadPingToken( |
| + content::DownloadItem* item, const std::string& token) { |
| + if (item) |
| + item->SetUserData(kDownloadPingTokenKey, new DownloadPingToken(token)); |
| +} |
| + |
| +std::string DownloadProtectionService::GetDownloadPingToken( |
| + const content::DownloadItem* item) { |
| + base::SupportsUserData::Data* token_data = |
| + item->GetUserData(kDownloadPingTokenKey); |
| + if (token_data) |
| + return static_cast<DownloadPingToken*>(token_data)->token_string(); |
| + else |
| + return std::string(); |
| +} |
| + |
| namespace { |
| // Escapes a certificate attribute so that it can be used in a whitelist |
| // entry. Currently, we only escape slashes, since they are used as a |