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