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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 const int64_t kDownloadRequestTimeoutMs = 7000; | 81 const int64_t kDownloadRequestTimeoutMs = 7000; |
| 82 // We sample 1% of whitelisted downloads to still send out download pings. | 82 // We sample 1% of whitelisted downloads to still send out download pings. |
| 83 const double kWhitelistDownloadSampleRate = 0.01; | 83 const double kWhitelistDownloadSampleRate = 0.01; |
| 84 | 84 |
| 85 // The number of user gestures we trace back for download attribution. | 85 // The number of user gestures we trace back for download attribution. |
| 86 const int kDownloadAttributionUserGestureLimit = 2; | 86 const int kDownloadAttributionUserGestureLimit = 2; |
| 87 | 87 |
| 88 const char kDownloadExtensionUmaName[] = "SBClientDownload.DownloadExtensions"; | 88 const char kDownloadExtensionUmaName[] = "SBClientDownload.DownloadExtensions"; |
| 89 const char kUnsupportedSchemeUmaPrefix[] = "SBClientDownload.UnsupportedScheme"; | 89 const char kUnsupportedSchemeUmaPrefix[] = "SBClientDownload.UnsupportedScheme"; |
| 90 | 90 |
| 91 const void* const kDownloadReferrerChainDataKey = | |
| 92 &kDownloadReferrerChainDataKey; | |
| 93 | |
| 91 enum WhitelistType { | 94 enum WhitelistType { |
| 92 NO_WHITELIST_MATCH, | 95 NO_WHITELIST_MATCH, |
| 93 URL_WHITELIST, | 96 URL_WHITELIST, |
| 94 SIGNATURE_WHITELIST, | 97 SIGNATURE_WHITELIST, |
| 95 WHITELIST_TYPE_MAX | 98 WHITELIST_TYPE_MAX |
| 96 }; | 99 }; |
| 97 | 100 |
| 98 void RecordCountOfWhitelistedDownload(WhitelistType type) { | 101 void RecordCountOfWhitelistedDownload(WhitelistType type) { |
| 99 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckWhitelistResult", type, | 102 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckWhitelistResult", type, |
| 100 WHITELIST_TYPE_MAX); | 103 WHITELIST_TYPE_MAX); |
| 101 } | 104 } |
| 102 | 105 |
| 103 } // namespace | 106 } // namespace |
| 104 | 107 |
| 105 const char DownloadProtectionService::kDownloadRequestUrl[] = | 108 const char DownloadProtectionService::kDownloadRequestUrl[] = |
| 106 "https://sb-ssl.google.com/safebrowsing/clientreport/download"; | 109 "https://sb-ssl.google.com/safebrowsing/clientreport/download"; |
| 107 | 110 |
| 108 const void* const DownloadProtectionService::kDownloadPingTokenKey | 111 const void* const DownloadProtectionService::kDownloadPingTokenKey |
| 109 = &kDownloadPingTokenKey; | 112 = &kDownloadPingTokenKey; |
| 110 | 113 |
| 114 | |
|
Nathan Parker
2017/01/26 19:29:10
nit: 3 blank lines
Jialiu Lin
2017/01/26 22:51:26
Done.
| |
| 115 | |
| 111 namespace { | 116 namespace { |
| 112 void RecordFileExtensionType(const std::string& metric_name, | 117 void RecordFileExtensionType(const std::string& metric_name, |
| 113 const base::FilePath& file) { | 118 const base::FilePath& file) { |
| 114 UMA_HISTOGRAM_SPARSE_SLOWLY( | 119 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 115 metric_name, FileTypePolicies::GetInstance()->UmaValueForFile(file)); | 120 metric_name, FileTypePolicies::GetInstance()->UmaValueForFile(file)); |
| 116 } | 121 } |
| 117 | 122 |
| 118 void RecordArchivedArchiveFileExtensionType(const base::FilePath& file) { | 123 void RecordArchivedArchiveFileExtensionType(const base::FilePath& file) { |
| 119 UMA_HISTOGRAM_SPARSE_SLOWLY( | 124 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 120 "SBClientDownload.ArchivedArchiveExtensions", | 125 "SBClientDownload.ArchivedArchiveExtensions", |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 | 164 |
| 160 } // namespace | 165 } // namespace |
| 161 | 166 |
| 162 // Parent SafeBrowsing::Client class used to lookup the bad binary | 167 // Parent SafeBrowsing::Client class used to lookup the bad binary |
| 163 // URL and digest list. There are two sub-classes (one for each list). | 168 // URL and digest list. There are two sub-classes (one for each list). |
| 164 class DownloadSBClient | 169 class DownloadSBClient |
| 165 : public SafeBrowsingDatabaseManager::Client, | 170 : public SafeBrowsingDatabaseManager::Client, |
| 166 public base::RefCountedThreadSafe<DownloadSBClient> { | 171 public base::RefCountedThreadSafe<DownloadSBClient> { |
| 167 public: | 172 public: |
| 168 DownloadSBClient( | 173 DownloadSBClient( |
| 169 const content::DownloadItem& item, | 174 content::DownloadItem* item, |
| 175 const base::WeakPtr<DownloadProtectionService>& service, | |
| 170 const DownloadProtectionService::CheckDownloadCallback& callback, | 176 const DownloadProtectionService::CheckDownloadCallback& callback, |
| 171 const scoped_refptr<SafeBrowsingUIManager>& ui_manager, | 177 const scoped_refptr<SafeBrowsingUIManager>& ui_manager, |
| 172 SBStatsType total_type, | 178 SBStatsType total_type, |
| 173 SBStatsType dangerous_type) | 179 SBStatsType dangerous_type) |
| 174 : sha256_hash_(item.GetHash()), | 180 : item_(item), |
| 175 url_chain_(item.GetUrlChain()), | 181 sha256_hash_(item->GetHash()), |
| 176 referrer_url_(item.GetReferrerUrl()), | 182 url_chain_(item->GetUrlChain()), |
| 183 referrer_url_(item->GetReferrerUrl()), | |
| 184 service_(service), | |
| 177 callback_(callback), | 185 callback_(callback), |
| 178 ui_manager_(ui_manager), | 186 ui_manager_(ui_manager), |
| 179 start_time_(base::TimeTicks::Now()), | 187 start_time_(base::TimeTicks::Now()), |
| 180 total_type_(total_type), | 188 total_type_(total_type), |
| 181 dangerous_type_(dangerous_type) { | 189 dangerous_type_(dangerous_type) { |
| 182 Profile* profile = Profile::FromBrowserContext(item.GetBrowserContext()); | 190 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 191 Profile* profile = Profile::FromBrowserContext(item->GetBrowserContext()); | |
| 183 extended_reporting_level_ = | 192 extended_reporting_level_ = |
| 184 profile ? GetExtendedReportingLevel(*profile->GetPrefs()) | 193 profile ? GetExtendedReportingLevel(*profile->GetPrefs()) |
| 185 : SBER_LEVEL_OFF; | 194 : SBER_LEVEL_OFF; |
| 186 } | 195 } |
| 187 | 196 |
| 188 virtual void StartCheck() = 0; | 197 virtual void StartCheck() = 0; |
| 189 virtual bool IsDangerous(SBThreatType threat_type) const = 0; | 198 virtual bool IsDangerous(SBThreatType threat_type) const = 0; |
| 190 | 199 |
| 191 protected: | 200 protected: |
| 192 friend class base::RefCountedThreadSafe<DownloadSBClient>; | 201 friend class base::RefCountedThreadSafe<DownloadSBClient>; |
| 193 ~DownloadSBClient() override {} | 202 ~DownloadSBClient() override {} |
| 194 | 203 |
| 195 void CheckDone(SBThreatType threat_type) { | 204 void CheckDone(SBThreatType threat_type) { |
| 196 DownloadProtectionService::DownloadCheckResult result = | 205 DownloadProtectionService::DownloadCheckResult result = |
| 197 IsDangerous(threat_type) ? | 206 IsDangerous(threat_type) ? |
| 198 DownloadProtectionService::DANGEROUS : | 207 DownloadProtectionService::DANGEROUS : |
| 199 DownloadProtectionService::SAFE; | 208 DownloadProtectionService::SAFE; |
| 200 BrowserThread::PostTask(BrowserThread::UI, | 209 BrowserThread::PostTask(BrowserThread::UI, |
| 201 FROM_HERE, | 210 FROM_HERE, |
| 202 base::Bind(callback_, result)); | 211 base::Bind(callback_, result)); |
| 203 UpdateDownloadCheckStats(total_type_); | 212 UpdateDownloadCheckStats(total_type_); |
| 204 if (threat_type != SB_THREAT_TYPE_SAFE) { | 213 if (threat_type != SB_THREAT_TYPE_SAFE) { |
| 205 UpdateDownloadCheckStats(dangerous_type_); | 214 UpdateDownloadCheckStats(dangerous_type_); |
| 206 BrowserThread::PostTask( | 215 BrowserThread::PostTask( |
| 207 BrowserThread::UI, | 216 BrowserThread::UI, |
| 208 FROM_HERE, | 217 FROM_HERE, |
| 209 base::Bind(&DownloadSBClient::ReportMalware, | 218 base::Bind(&DownloadSBClient::ReportMalware, |
| 210 this, threat_type)); | 219 this, threat_type)); |
| 220 } else if (service_ && service_->navigation_observer_manager() && | |
| 221 base::FeatureList::IsEnabled( | |
| 222 SafeBrowsingNavigationObserverManager::kDownloadAttribution)) { | |
| 223 // Identify download referrer chain, which will be used in | |
| 224 // ClientDownloadRequest. | |
| 225 BrowserThread::PostTask( | |
| 226 BrowserThread::UI, | |
| 227 FROM_HERE, | |
| 228 base::Bind(&DownloadSBClient::IdentifyReferrerChain, | |
| 229 this)); | |
| 211 } | 230 } |
| 212 } | 231 } |
| 213 | 232 |
| 214 void ReportMalware(SBThreatType threat_type) { | 233 void ReportMalware(SBThreatType threat_type) { |
| 215 std::string post_data; | 234 std::string post_data; |
| 216 if (!sha256_hash_.empty()) | 235 if (!sha256_hash_.empty()) { |
| 217 post_data += base::HexEncode(sha256_hash_.data(), | 236 post_data += base::HexEncode(sha256_hash_.data(), |
| 218 sha256_hash_.size()) + "\n"; | 237 sha256_hash_.size()) + "\n"; |
| 238 } | |
| 219 for (size_t i = 0; i < url_chain_.size(); ++i) { | 239 for (size_t i = 0; i < url_chain_.size(); ++i) { |
| 220 post_data += url_chain_[i].spec() + "\n"; | 240 post_data += url_chain_[i].spec() + "\n"; |
| 221 } | 241 } |
| 222 | 242 |
| 223 safe_browsing::HitReport hit_report; | 243 safe_browsing::HitReport hit_report; |
| 224 hit_report.malicious_url = url_chain_.back(); | 244 hit_report.malicious_url = url_chain_.back(); |
| 225 hit_report.page_url = url_chain_.front(); | 245 hit_report.page_url = url_chain_.front(); |
| 226 hit_report.referrer_url = referrer_url_; | 246 hit_report.referrer_url = referrer_url_; |
| 227 hit_report.is_subresource = true; | 247 hit_report.is_subresource = true; |
| 228 hit_report.threat_type = threat_type; | 248 hit_report.threat_type = threat_type; |
| 229 // TODO(nparker) Replace this with database_manager_->GetThreatSource(); | 249 // TODO(nparker) Replace this with database_manager_->GetThreatSource(); |
| 230 hit_report.threat_source = safe_browsing::ThreatSource::LOCAL_PVER3; | 250 hit_report.threat_source = safe_browsing::ThreatSource::LOCAL_PVER3; |
| 231 // TODO(nparker) Populate hit_report.population_id once Pver4 is used here. | 251 // TODO(nparker) Populate hit_report.population_id once Pver4 is used here. |
| 232 hit_report.post_data = post_data; | 252 hit_report.post_data = post_data; |
| 233 hit_report.extended_reporting_level = extended_reporting_level_; | 253 hit_report.extended_reporting_level = extended_reporting_level_; |
| 234 hit_report.is_metrics_reporting_active = | 254 hit_report.is_metrics_reporting_active = |
| 235 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); | 255 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); |
| 236 | 256 |
| 237 ui_manager_->MaybeReportSafeBrowsingHit(hit_report); | 257 ui_manager_->MaybeReportSafeBrowsingHit(hit_report); |
| 238 } | 258 } |
| 239 | 259 |
| 260 void IdentifyReferrerChain() { | |
| 261 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 262 if (service_) { | |
|
asanka
2017/01/26 18:54:47
The DownloadProtectionService and the SafeBrowsing
Jialiu Lin
2017/01/26 22:51:26
Thanks for confirming this. Removed checking for s
| |
| 263 std::unique_ptr<ReferrerChain> referrer_chain | |
| 264 = base::MakeUnique<ReferrerChain>(); | |
| 265 service_->IdentifyReferrerChain( | |
| 266 item_->GetURL(), item_->GetWebContents(), | |
| 267 referrer_chain.get()); | |
| 268 if (!referrer_chain->empty()) { | |
| 269 item_->SetUserData( | |
|
asanka
2017/01/26 18:54:47
DownloadItem can go away abruptly for a number of
Nathan Parker
2017/01/26 19:29:10
The CheckDone() method above is called on the IO t
Jialiu Lin
2017/01/26 22:51:26
Done.
Jialiu Lin
2017/01/26 22:51:26
Thanks for checking this out!
| |
| 270 kDownloadReferrerChainDataKey, | |
| 271 new ReferrerChainData(std::move(referrer_chain))); | |
| 272 } | |
| 273 } | |
| 274 } | |
| 275 | |
| 240 void UpdateDownloadCheckStats(SBStatsType stat_type) { | 276 void UpdateDownloadCheckStats(SBStatsType stat_type) { |
| 241 UMA_HISTOGRAM_ENUMERATION("SB2.DownloadChecks", | 277 UMA_HISTOGRAM_ENUMERATION("SB2.DownloadChecks", |
| 242 stat_type, | 278 stat_type, |
| 243 DOWNLOAD_CHECKS_MAX); | 279 DOWNLOAD_CHECKS_MAX); |
| 244 } | 280 } |
| 245 | 281 // The DownloadItem we are checking. Must be accessed only on UI thread. |
| 282 content::DownloadItem* item_; | |
| 283 // Copies of data from |item_| for access on other threads. | |
| 246 std::string sha256_hash_; | 284 std::string sha256_hash_; |
| 247 std::vector<GURL> url_chain_; | 285 std::vector<GURL> url_chain_; |
| 248 GURL referrer_url_; | 286 GURL referrer_url_; |
| 287 base::WeakPtr<DownloadProtectionService> service_; | |
| 249 DownloadProtectionService::CheckDownloadCallback callback_; | 288 DownloadProtectionService::CheckDownloadCallback callback_; |
| 250 scoped_refptr<SafeBrowsingUIManager> ui_manager_; | 289 scoped_refptr<SafeBrowsingUIManager> ui_manager_; |
| 251 base::TimeTicks start_time_; | 290 base::TimeTicks start_time_; |
| 252 | 291 |
| 253 private: | 292 private: |
| 254 const SBStatsType total_type_; | 293 const SBStatsType total_type_; |
| 255 const SBStatsType dangerous_type_; | 294 const SBStatsType dangerous_type_; |
| 256 ExtendedReportingLevel extended_reporting_level_; | 295 ExtendedReportingLevel extended_reporting_level_; |
| 257 | 296 |
| 258 DISALLOW_COPY_AND_ASSIGN(DownloadSBClient); | 297 DISALLOW_COPY_AND_ASSIGN(DownloadSBClient); |
| 259 }; | 298 }; |
| 260 | 299 |
| 261 class DownloadUrlSBClient : public DownloadSBClient { | 300 class DownloadUrlSBClient : public DownloadSBClient { |
| 262 public: | 301 public: |
| 263 DownloadUrlSBClient( | 302 DownloadUrlSBClient( |
| 264 const content::DownloadItem& item, | 303 content::DownloadItem* item, |
| 304 const base::WeakPtr<DownloadProtectionService>& service, | |
| 265 const DownloadProtectionService::CheckDownloadCallback& callback, | 305 const DownloadProtectionService::CheckDownloadCallback& callback, |
| 266 const scoped_refptr<SafeBrowsingUIManager>& ui_manager, | 306 const scoped_refptr<SafeBrowsingUIManager>& ui_manager, |
| 267 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager) | 307 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager) |
| 268 : DownloadSBClient(item, callback, ui_manager, | 308 : DownloadSBClient(item, service, callback, ui_manager, |
| 269 DOWNLOAD_URL_CHECKS_TOTAL, | 309 DOWNLOAD_URL_CHECKS_TOTAL, |
| 270 DOWNLOAD_URL_CHECKS_MALWARE), | 310 DOWNLOAD_URL_CHECKS_MALWARE), |
| 271 database_manager_(database_manager) { } | 311 database_manager_(database_manager) { } |
| 272 | 312 |
| 273 void StartCheck() override { | 313 void StartCheck() override { |
| 274 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 314 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 275 if (!database_manager_.get() || | 315 if (!database_manager_.get() || |
| 276 database_manager_->CheckDownloadUrl(url_chain_, this)) { | 316 database_manager_->CheckDownloadUrl(item_->GetUrlChain(), this)) { |
| 277 CheckDone(SB_THREAT_TYPE_SAFE); | 317 CheckDone(SB_THREAT_TYPE_SAFE); |
| 278 } else { | 318 } else { |
| 279 AddRef(); // SafeBrowsingService takes a pointer not a scoped_refptr. | 319 AddRef(); // SafeBrowsingService takes a pointer not a scoped_refptr. |
| 280 } | 320 } |
| 281 } | 321 } |
| 282 | 322 |
| 283 bool IsDangerous(SBThreatType threat_type) const override { | 323 bool IsDangerous(SBThreatType threat_type) const override { |
| 284 return threat_type == SB_THREAT_TYPE_BINARY_MALWARE_URL; | 324 return threat_type == SB_THREAT_TYPE_BINARY_MALWARE_URL; |
| 285 } | 325 } |
| 286 | 326 |
| (...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 999 if (type_ == ClientDownloadRequest::SAMPLED_UNSUPPORTED_FILE) { | 1039 if (type_ == ClientDownloadRequest::SAMPLED_UNSUPPORTED_FILE) { |
| 1000 request.set_file_basename( | 1040 request.set_file_basename( |
| 1001 base::FilePath(item_->GetTargetFilePath().Extension()) | 1041 base::FilePath(item_->GetTargetFilePath().Extension()) |
| 1002 .AsUTF8Unsafe()); | 1042 .AsUTF8Unsafe()); |
| 1003 } else { | 1043 } else { |
| 1004 request.set_file_basename( | 1044 request.set_file_basename( |
| 1005 item_->GetTargetFilePath().BaseName().AsUTF8Unsafe()); | 1045 item_->GetTargetFilePath().BaseName().AsUTF8Unsafe()); |
| 1006 } | 1046 } |
| 1007 request.set_download_type(type_); | 1047 request.set_download_type(type_); |
| 1008 | 1048 |
| 1009 service_->AddReferrerChainToClientDownloadRequest( | 1049 ReferrerChainData* referrer_chain_data = |
| 1010 item_->GetURL(), | 1050 static_cast<ReferrerChainData*>( |
| 1011 item_->GetWebContents(), | 1051 item_->GetUserData(kDownloadReferrerChainDataKey)); |
| 1012 &request); | 1052 if (referrer_chain_data && |
| 1053 !referrer_chain_data->GetReferrerChain()->empty()) { | |
| 1054 request.mutable_referrer_chain()->Swap( | |
| 1055 referrer_chain_data->GetReferrerChain()); | |
| 1056 } | |
| 1013 | 1057 |
| 1014 if (archive_is_valid_ != ArchiveValid::UNSET) | 1058 if (archive_is_valid_ != ArchiveValid::UNSET) |
| 1015 request.set_archive_valid(archive_is_valid_ == ArchiveValid::VALID); | 1059 request.set_archive_valid(archive_is_valid_ == ArchiveValid::VALID); |
| 1016 request.mutable_signature()->CopyFrom(signature_info_); | 1060 request.mutable_signature()->CopyFrom(signature_info_); |
| 1017 if (image_headers_) | 1061 if (image_headers_) |
| 1018 request.set_allocated_image_headers(image_headers_.release()); | 1062 request.set_allocated_image_headers(image_headers_.release()); |
| 1019 if (archived_executable_) | 1063 if (archived_executable_) |
| 1020 request.mutable_archived_binary()->Swap(&archived_binary_); | 1064 request.mutable_archived_binary()->Swap(&archived_binary_); |
| 1021 if (!request.SerializeToString(&client_download_request_data_)) { | 1065 if (!request.SerializeToString(&client_download_request_data_)) { |
| 1022 FinishRequest(UNKNOWN, REASON_INVALID_REQUEST_PROTO); | 1066 FinishRequest(UNKNOWN, REASON_INVALID_REQUEST_PROTO); |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1543 DownloadProtectionService::DownloadProtectionService( | 1587 DownloadProtectionService::DownloadProtectionService( |
| 1544 SafeBrowsingService* sb_service) | 1588 SafeBrowsingService* sb_service) |
| 1545 : request_context_getter_(sb_service ? sb_service->url_request_context() | 1589 : request_context_getter_(sb_service ? sb_service->url_request_context() |
| 1546 : nullptr), | 1590 : nullptr), |
| 1547 enabled_(false), | 1591 enabled_(false), |
| 1548 binary_feature_extractor_(new BinaryFeatureExtractor()), | 1592 binary_feature_extractor_(new BinaryFeatureExtractor()), |
| 1549 download_request_timeout_ms_(kDownloadRequestTimeoutMs), | 1593 download_request_timeout_ms_(kDownloadRequestTimeoutMs), |
| 1550 feedback_service_( | 1594 feedback_service_( |
| 1551 new DownloadFeedbackService(request_context_getter_.get(), | 1595 new DownloadFeedbackService(request_context_getter_.get(), |
| 1552 BrowserThread::GetBlockingPool())), | 1596 BrowserThread::GetBlockingPool())), |
| 1553 whitelist_sample_rate_(kWhitelistDownloadSampleRate) { | 1597 whitelist_sample_rate_(kWhitelistDownloadSampleRate), |
| 1598 weak_ptr_factory_(this) { | |
| 1554 if (sb_service) { | 1599 if (sb_service) { |
| 1555 ui_manager_ = sb_service->ui_manager(); | 1600 ui_manager_ = sb_service->ui_manager(); |
| 1556 database_manager_ = sb_service->database_manager(); | 1601 database_manager_ = sb_service->database_manager(); |
| 1557 navigation_observer_manager_ = sb_service->navigation_observer_manager(); | 1602 navigation_observer_manager_ = sb_service->navigation_observer_manager(); |
| 1558 ParseManualBlacklistFlag(); | 1603 ParseManualBlacklistFlag(); |
| 1559 } | 1604 } |
| 1560 } | 1605 } |
| 1561 | 1606 |
| 1562 DownloadProtectionService::~DownloadProtectionService() { | 1607 DownloadProtectionService::~DownloadProtectionService() { |
| 1563 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1608 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1606 const CheckDownloadCallback& callback) { | 1651 const CheckDownloadCallback& callback) { |
| 1607 scoped_refptr<CheckClientDownloadRequest> request( | 1652 scoped_refptr<CheckClientDownloadRequest> request( |
| 1608 new CheckClientDownloadRequest(item, callback, this, | 1653 new CheckClientDownloadRequest(item, callback, this, |
| 1609 database_manager_, | 1654 database_manager_, |
| 1610 binary_feature_extractor_.get())); | 1655 binary_feature_extractor_.get())); |
| 1611 download_requests_.insert(request); | 1656 download_requests_.insert(request); |
| 1612 request->Start(); | 1657 request->Start(); |
| 1613 } | 1658 } |
| 1614 | 1659 |
| 1615 void DownloadProtectionService::CheckDownloadUrl( | 1660 void DownloadProtectionService::CheckDownloadUrl( |
| 1616 const content::DownloadItem& item, | 1661 content::DownloadItem* item, |
| 1617 const CheckDownloadCallback& callback) { | 1662 const CheckDownloadCallback& callback) { |
| 1618 DCHECK(!item.GetUrlChain().empty()); | 1663 DCHECK(!item->GetUrlChain().empty()); |
| 1619 scoped_refptr<DownloadUrlSBClient> client( | 1664 scoped_refptr<DownloadUrlSBClient> client( |
| 1620 new DownloadUrlSBClient(item, callback, ui_manager_, database_manager_)); | 1665 new DownloadUrlSBClient(item, weak_ptr_factory_.GetWeakPtr(), callback, |
| 1666 ui_manager_, database_manager_)); | |
| 1621 // The client will release itself once it is done. | 1667 // The client will release itself once it is done. |
| 1622 BrowserThread::PostTask( | 1668 BrowserThread::PostTask( |
| 1623 BrowserThread::IO, | 1669 BrowserThread::IO, |
| 1624 FROM_HERE, | 1670 FROM_HERE, |
| 1625 base::Bind(&DownloadUrlSBClient::StartCheck, client)); | 1671 base::Bind(&DownloadUrlSBClient::StartCheck, client)); |
| 1626 } | 1672 } |
| 1627 | 1673 |
| 1628 bool DownloadProtectionService::IsSupportedDownload( | 1674 bool DownloadProtectionService::IsSupportedDownload( |
| 1629 const content::DownloadItem& item, | 1675 const content::DownloadItem& item, |
| 1630 const base::FilePath& target_path) const { | 1676 const base::FilePath& target_path) const { |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1813 // static | 1859 // static |
| 1814 GURL DownloadProtectionService::GetDownloadRequestUrl() { | 1860 GURL DownloadProtectionService::GetDownloadRequestUrl() { |
| 1815 GURL url(kDownloadRequestUrl); | 1861 GURL url(kDownloadRequestUrl); |
| 1816 std::string api_key = google_apis::GetAPIKey(); | 1862 std::string api_key = google_apis::GetAPIKey(); |
| 1817 if (!api_key.empty()) | 1863 if (!api_key.empty()) |
| 1818 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); | 1864 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); |
| 1819 | 1865 |
| 1820 return url; | 1866 return url; |
| 1821 } | 1867 } |
| 1822 | 1868 |
| 1823 void DownloadProtectionService::AddReferrerChainToClientDownloadRequest( | 1869 void DownloadProtectionService::IdentifyReferrerChain( |
| 1824 const GURL& download_url, | 1870 const GURL& download_url, |
| 1825 content::WebContents* web_contents, | 1871 content::WebContents* web_contents, |
| 1826 ClientDownloadRequest* out_request) { | 1872 ReferrerChain* out_referrer_chain) { |
| 1827 if (!base::FeatureList::IsEnabled( | 1873 if (!base::FeatureList::IsEnabled( |
| 1828 SafeBrowsingNavigationObserverManager::kDownloadAttribution) || | 1874 SafeBrowsingNavigationObserverManager::kDownloadAttribution) || |
| 1829 !navigation_observer_manager_) { | 1875 !navigation_observer_manager_) { |
| 1830 return; | 1876 return; |
| 1831 } | 1877 } |
| 1832 | 1878 |
| 1833 int download_tab_id = SessionTabHelper::IdForTab(web_contents); | 1879 int download_tab_id = SessionTabHelper::IdForTab(web_contents); |
| 1834 UMA_HISTOGRAM_BOOLEAN( | 1880 UMA_HISTOGRAM_BOOLEAN( |
| 1835 "SafeBrowsing.ReferrerHasInvalidTabID.DownloadAttribution", | 1881 "SafeBrowsing.ReferrerHasInvalidTabID.DownloadAttribution", |
| 1836 download_tab_id == -1); | 1882 download_tab_id == -1); |
| 1837 SafeBrowsingNavigationObserverManager::ReferrerChain attribution_chain; | |
| 1838 SafeBrowsingNavigationObserverManager::AttributionResult result = | 1883 SafeBrowsingNavigationObserverManager::AttributionResult result = |
| 1839 navigation_observer_manager_->IdentifyReferrerChainForDownload( | 1884 navigation_observer_manager_->IdentifyReferrerChainForDownload( |
| 1840 download_url, | 1885 download_url, |
| 1841 download_tab_id, | 1886 download_tab_id, |
| 1842 kDownloadAttributionUserGestureLimit, | 1887 kDownloadAttributionUserGestureLimit, |
| 1843 &attribution_chain); | 1888 out_referrer_chain); |
| 1844 UMA_HISTOGRAM_COUNTS_100( | 1889 UMA_HISTOGRAM_COUNTS_100( |
| 1845 "SafeBrowsing.ReferrerURLChainSize.DownloadAttribution", | 1890 "SafeBrowsing.ReferrerURLChainSize.DownloadAttribution", |
| 1846 attribution_chain.size()); | 1891 out_referrer_chain->size()); |
| 1847 UMA_HISTOGRAM_ENUMERATION( | 1892 UMA_HISTOGRAM_ENUMERATION( |
| 1848 "SafeBrowsing.ReferrerAttributionResult.DownloadAttribution", result, | 1893 "SafeBrowsing.ReferrerAttributionResult.DownloadAttribution", result, |
| 1849 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX); | 1894 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX); |
| 1850 for (auto& entry : attribution_chain) | |
| 1851 out_request->add_referrer_chain()->Swap(entry.get()); | |
| 1852 } | 1895 } |
| 1853 | 1896 |
| 1854 void DownloadProtectionService::AddReferrerChainToPPAPIClientDownloadRequest( | 1897 void DownloadProtectionService::AddReferrerChainToPPAPIClientDownloadRequest( |
| 1855 const GURL& initiating_frame_url, | 1898 const GURL& initiating_frame_url, |
| 1856 int tab_id, | 1899 int tab_id, |
| 1857 bool has_user_gesture, | 1900 bool has_user_gesture, |
| 1858 ClientDownloadRequest* out_request) { | 1901 ClientDownloadRequest* out_request) { |
| 1859 if (!base::FeatureList::IsEnabled( | 1902 if (!base::FeatureList::IsEnabled( |
| 1860 SafeBrowsingNavigationObserverManager::kDownloadAttribution) || | 1903 SafeBrowsingNavigationObserverManager::kDownloadAttribution) || |
| 1861 !navigation_observer_manager_) { | 1904 !navigation_observer_manager_) { |
| 1862 return; | 1905 return; |
| 1863 } | 1906 } |
| 1864 | 1907 |
| 1865 UMA_HISTOGRAM_BOOLEAN( | 1908 UMA_HISTOGRAM_BOOLEAN( |
| 1866 "SafeBrowsing.ReferrerHasInvalidTabID.DownloadAttribution", | 1909 "SafeBrowsing.ReferrerHasInvalidTabID.DownloadAttribution", |
| 1867 tab_id == -1); | 1910 tab_id == -1); |
| 1868 SafeBrowsingNavigationObserverManager::ReferrerChain attribution_chain; | |
| 1869 SafeBrowsingNavigationObserverManager::AttributionResult result = | 1911 SafeBrowsingNavigationObserverManager::AttributionResult result = |
| 1870 navigation_observer_manager_->IdentifyReferrerChainForPPAPIDownload( | 1912 navigation_observer_manager_->IdentifyReferrerChainForPPAPIDownload( |
| 1871 initiating_frame_url, | 1913 initiating_frame_url, |
| 1872 tab_id, | 1914 tab_id, |
| 1873 has_user_gesture, | 1915 has_user_gesture, |
| 1874 kDownloadAttributionUserGestureLimit, | 1916 kDownloadAttributionUserGestureLimit, |
| 1875 &attribution_chain); | 1917 out_request->mutable_referrer_chain()); |
| 1876 UMA_HISTOGRAM_COUNTS_100( | 1918 UMA_HISTOGRAM_COUNTS_100( |
| 1877 "SafeBrowsing.ReferrerURLChainSize.PPAPIDownloadAttribution", | 1919 "SafeBrowsing.ReferrerURLChainSize.PPAPIDownloadAttribution", |
| 1878 attribution_chain.size()); | 1920 out_request->referrer_chain_size()); |
| 1879 UMA_HISTOGRAM_ENUMERATION( | 1921 UMA_HISTOGRAM_ENUMERATION( |
| 1880 "SafeBrowsing.ReferrerAttributionResult.PPAPIDownloadAttribution", result, | 1922 "SafeBrowsing.ReferrerAttributionResult.PPAPIDownloadAttribution", result, |
| 1881 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX); | 1923 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX); |
| 1882 for (auto& entry : attribution_chain) | |
| 1883 out_request->add_referrer_chain()->Swap(entry.get()); | |
| 1884 } | 1924 } |
| 1885 | 1925 |
| 1886 } // namespace safe_browsing | 1926 } // namespace safe_browsing |
| OLD | NEW |