Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(707)

Side by Side Diff: chrome/browser/safe_browsing/download_protection_service.cc

Issue 2647323004: Move download attribution right after CheckDownloadUrl (Closed)
Patch Set: nit Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 // ALWAYS ADD NEW VALUES BEFORE THIS ONE. 159 // ALWAYS ADD NEW VALUES BEFORE THIS ONE.
157 DOWNLOAD_CHECKS_MAX 160 DOWNLOAD_CHECKS_MAX
158 }; 161 };
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,
169 public content::DownloadItem::Observer,
166 public base::RefCountedThreadSafe<DownloadSBClient> { 170 public base::RefCountedThreadSafe<DownloadSBClient> {
167 public: 171 public:
168 DownloadSBClient( 172 DownloadSBClient(
169 const content::DownloadItem& item, 173 content::DownloadItem* item,
174 DownloadProtectionService* service,
170 const DownloadProtectionService::CheckDownloadCallback& callback, 175 const DownloadProtectionService::CheckDownloadCallback& callback,
171 const scoped_refptr<SafeBrowsingUIManager>& ui_manager, 176 const scoped_refptr<SafeBrowsingUIManager>& ui_manager,
172 SBStatsType total_type, 177 SBStatsType total_type,
173 SBStatsType dangerous_type) 178 SBStatsType dangerous_type)
174 : sha256_hash_(item.GetHash()), 179 : item_(item),
175 url_chain_(item.GetUrlChain()), 180 sha256_hash_(item->GetHash()),
176 referrer_url_(item.GetReferrerUrl()), 181 url_chain_(item->GetUrlChain()),
182 referrer_url_(item->GetReferrerUrl()),
183 service_(service),
177 callback_(callback), 184 callback_(callback),
178 ui_manager_(ui_manager), 185 ui_manager_(ui_manager),
179 start_time_(base::TimeTicks::Now()), 186 start_time_(base::TimeTicks::Now()),
180 total_type_(total_type), 187 total_type_(total_type),
181 dangerous_type_(dangerous_type) { 188 dangerous_type_(dangerous_type) {
182 Profile* profile = Profile::FromBrowserContext(item.GetBrowserContext()); 189 DCHECK_CURRENTLY_ON(BrowserThread::UI);
190 if (item_)
asanka 2017/01/27 00:10:48 |item_| had better be true here :-). For cases lik
Jialiu Lin 2017/01/27 01:29:46 You're right. DCHECK makes more sense.
191 item_->AddObserver(this);
192 Profile* profile = Profile::FromBrowserContext(item_->GetBrowserContext());
183 extended_reporting_level_ = 193 extended_reporting_level_ =
184 profile ? GetExtendedReportingLevel(*profile->GetPrefs()) 194 profile ? GetExtendedReportingLevel(*profile->GetPrefs())
185 : SBER_LEVEL_OFF; 195 : SBER_LEVEL_OFF;
186 } 196 }
187 197
188 virtual void StartCheck() = 0; 198 virtual void StartCheck() = 0;
189 virtual bool IsDangerous(SBThreatType threat_type) const = 0; 199 virtual bool IsDangerous(SBThreatType threat_type) const = 0;
190 200
201 // Implements DownloadItem::Observer.
202 void OnDownloadDestroyed(content::DownloadItem* download) override {
203 download->RemoveObserver(this);
204 item_ = nullptr;
205 }
206
191 protected: 207 protected:
192 friend class base::RefCountedThreadSafe<DownloadSBClient>; 208 friend class base::RefCountedThreadSafe<DownloadSBClient>;
193 ~DownloadSBClient() override {} 209 ~DownloadSBClient() override {
210 if (item_)
asanka 2017/01/27 00:10:48 FYI: This is totally fine. But another way to do t
Jialiu Lin 2017/01/27 01:29:46 ScopedObserver is much cleaner. Thanks!
211 item_->RemoveObserver(this);
212 }
194 213
195 void CheckDone(SBThreatType threat_type) { 214 void CheckDone(SBThreatType threat_type) {
196 DownloadProtectionService::DownloadCheckResult result = 215 DownloadProtectionService::DownloadCheckResult result =
197 IsDangerous(threat_type) ? 216 IsDangerous(threat_type) ?
198 DownloadProtectionService::DANGEROUS : 217 DownloadProtectionService::DANGEROUS :
199 DownloadProtectionService::SAFE; 218 DownloadProtectionService::SAFE;
200 BrowserThread::PostTask(BrowserThread::UI, 219 BrowserThread::PostTask(BrowserThread::UI,
201 FROM_HERE, 220 FROM_HERE,
202 base::Bind(callback_, result)); 221 base::Bind(callback_, result));
asanka 2017/01/27 00:10:49 This is racy. |callback_| will be scheduled on the
Jialiu Lin 2017/01/27 01:29:46 You're right. Moved callback to the end of this fu
203 UpdateDownloadCheckStats(total_type_); 222 UpdateDownloadCheckStats(total_type_);
204 if (threat_type != SB_THREAT_TYPE_SAFE) { 223 if (threat_type != SB_THREAT_TYPE_SAFE) {
205 UpdateDownloadCheckStats(dangerous_type_); 224 UpdateDownloadCheckStats(dangerous_type_);
206 BrowserThread::PostTask( 225 BrowserThread::PostTask(
207 BrowserThread::UI, 226 BrowserThread::UI,
208 FROM_HERE, 227 FROM_HERE,
209 base::Bind(&DownloadSBClient::ReportMalware, 228 base::Bind(&DownloadSBClient::ReportMalware,
210 this, threat_type)); 229 this, threat_type));
230 } else if (service_ && service_->navigation_observer_manager() &&
asanka 2017/01/27 00:10:49 There's a race here because CheckDone() could exec
Jialiu Lin 2017/01/27 01:29:45 Moved navigation_observer_manager() and feature ch
231 base::FeatureList::IsEnabled(
232 SafeBrowsingNavigationObserverManager::kDownloadAttribution)) {
233 // Identify download referrer chain, which will be used in
234 // ClientDownloadRequest.
235 BrowserThread::PostTask(
236 BrowserThread::UI,
237 FROM_HERE,
238 base::Bind(&DownloadSBClient::IdentifyReferrerChain,
239 this));
211 } 240 }
212 } 241 }
213 242
214 void ReportMalware(SBThreatType threat_type) { 243 void ReportMalware(SBThreatType threat_type) {
215 std::string post_data; 244 std::string post_data;
216 if (!sha256_hash_.empty()) 245 if (!sha256_hash_.empty()) {
217 post_data += base::HexEncode(sha256_hash_.data(), 246 post_data += base::HexEncode(sha256_hash_.data(),
218 sha256_hash_.size()) + "\n"; 247 sha256_hash_.size()) + "\n";
248 }
219 for (size_t i = 0; i < url_chain_.size(); ++i) { 249 for (size_t i = 0; i < url_chain_.size(); ++i) {
220 post_data += url_chain_[i].spec() + "\n"; 250 post_data += url_chain_[i].spec() + "\n";
221 } 251 }
222 252
223 safe_browsing::HitReport hit_report; 253 safe_browsing::HitReport hit_report;
224 hit_report.malicious_url = url_chain_.back(); 254 hit_report.malicious_url = url_chain_.back();
225 hit_report.page_url = url_chain_.front(); 255 hit_report.page_url = url_chain_.front();
226 hit_report.referrer_url = referrer_url_; 256 hit_report.referrer_url = referrer_url_;
227 hit_report.is_subresource = true; 257 hit_report.is_subresource = true;
228 hit_report.threat_type = threat_type; 258 hit_report.threat_type = threat_type;
229 // TODO(nparker) Replace this with database_manager_->GetThreatSource(); 259 // TODO(nparker) Replace this with database_manager_->GetThreatSource();
230 hit_report.threat_source = safe_browsing::ThreatSource::LOCAL_PVER3; 260 hit_report.threat_source = safe_browsing::ThreatSource::LOCAL_PVER3;
231 // TODO(nparker) Populate hit_report.population_id once Pver4 is used here. 261 // TODO(nparker) Populate hit_report.population_id once Pver4 is used here.
232 hit_report.post_data = post_data; 262 hit_report.post_data = post_data;
233 hit_report.extended_reporting_level = extended_reporting_level_; 263 hit_report.extended_reporting_level = extended_reporting_level_;
234 hit_report.is_metrics_reporting_active = 264 hit_report.is_metrics_reporting_active =
235 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); 265 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled();
236 266
237 ui_manager_->MaybeReportSafeBrowsingHit(hit_report); 267 ui_manager_->MaybeReportSafeBrowsingHit(hit_report);
238 } 268 }
239 269
270 void IdentifyReferrerChain() {
271 DCHECK_CURRENTLY_ON(BrowserThread::UI);
272 if (item_) {
asanka 2017/01/27 00:10:49 Nit: return early if !item_. That way you'll have
Jialiu Lin 2017/01/27 01:29:45 Done.
273 std::unique_ptr<ReferrerChain> referrer_chain
274 = base::MakeUnique<ReferrerChain>();
275 service_->IdentifyReferrerChain(
asanka 2017/01/27 00:10:49 Minor nit: Something nice to have would be for DPS
Jialiu Lin 2017/01/27 01:29:46 Done.
276 item_->GetURL(), item_->GetWebContents(),
277 referrer_chain.get());
278 if (!referrer_chain->empty()) {
279 item_->SetUserData(
280 kDownloadReferrerChainDataKey,
281 new ReferrerChainData(std::move(referrer_chain)));
282 }
283 }
284 }
285
240 void UpdateDownloadCheckStats(SBStatsType stat_type) { 286 void UpdateDownloadCheckStats(SBStatsType stat_type) {
241 UMA_HISTOGRAM_ENUMERATION("SB2.DownloadChecks", 287 UMA_HISTOGRAM_ENUMERATION("SB2.DownloadChecks",
242 stat_type, 288 stat_type,
243 DOWNLOAD_CHECKS_MAX); 289 DOWNLOAD_CHECKS_MAX);
244 } 290 }
245 291 // The DownloadItem we are checking. Must be accessed only on UI thread.
292 content::DownloadItem* item_;
293 // Copies of data from |item_| for access on other threads.
246 std::string sha256_hash_; 294 std::string sha256_hash_;
247 std::vector<GURL> url_chain_; 295 std::vector<GURL> url_chain_;
248 GURL referrer_url_; 296 GURL referrer_url_;
297 DownloadProtectionService* service_;
249 DownloadProtectionService::CheckDownloadCallback callback_; 298 DownloadProtectionService::CheckDownloadCallback callback_;
250 scoped_refptr<SafeBrowsingUIManager> ui_manager_; 299 scoped_refptr<SafeBrowsingUIManager> ui_manager_;
251 base::TimeTicks start_time_; 300 base::TimeTicks start_time_;
252 301
253 private: 302 private:
254 const SBStatsType total_type_; 303 const SBStatsType total_type_;
255 const SBStatsType dangerous_type_; 304 const SBStatsType dangerous_type_;
256 ExtendedReportingLevel extended_reporting_level_; 305 ExtendedReportingLevel extended_reporting_level_;
257 306
258 DISALLOW_COPY_AND_ASSIGN(DownloadSBClient); 307 DISALLOW_COPY_AND_ASSIGN(DownloadSBClient);
259 }; 308 };
260 309
261 class DownloadUrlSBClient : public DownloadSBClient { 310 class DownloadUrlSBClient : public DownloadSBClient {
262 public: 311 public:
263 DownloadUrlSBClient( 312 DownloadUrlSBClient(
264 const content::DownloadItem& item, 313 content::DownloadItem* item,
314 DownloadProtectionService* service,
265 const DownloadProtectionService::CheckDownloadCallback& callback, 315 const DownloadProtectionService::CheckDownloadCallback& callback,
266 const scoped_refptr<SafeBrowsingUIManager>& ui_manager, 316 const scoped_refptr<SafeBrowsingUIManager>& ui_manager,
267 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager) 317 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager)
268 : DownloadSBClient(item, callback, ui_manager, 318 : DownloadSBClient(item, service, callback, ui_manager,
269 DOWNLOAD_URL_CHECKS_TOTAL, 319 DOWNLOAD_URL_CHECKS_TOTAL,
270 DOWNLOAD_URL_CHECKS_MALWARE), 320 DOWNLOAD_URL_CHECKS_MALWARE),
271 database_manager_(database_manager) { } 321 database_manager_(database_manager) { }
272 322
273 void StartCheck() override { 323 void StartCheck() override {
274 DCHECK_CURRENTLY_ON(BrowserThread::IO); 324 DCHECK_CURRENTLY_ON(BrowserThread::IO);
275 if (!database_manager_.get() || 325 if (!database_manager_.get() ||
276 database_manager_->CheckDownloadUrl(url_chain_, this)) { 326 database_manager_->CheckDownloadUrl(url_chain_, this)) {
277 CheckDone(SB_THREAT_TYPE_SAFE); 327 CheckDone(SB_THREAT_TYPE_SAFE);
278 } else { 328 } else {
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 if (type_ == ClientDownloadRequest::SAMPLED_UNSUPPORTED_FILE) { 1049 if (type_ == ClientDownloadRequest::SAMPLED_UNSUPPORTED_FILE) {
1000 request.set_file_basename( 1050 request.set_file_basename(
1001 base::FilePath(item_->GetTargetFilePath().Extension()) 1051 base::FilePath(item_->GetTargetFilePath().Extension())
1002 .AsUTF8Unsafe()); 1052 .AsUTF8Unsafe());
1003 } else { 1053 } else {
1004 request.set_file_basename( 1054 request.set_file_basename(
1005 item_->GetTargetFilePath().BaseName().AsUTF8Unsafe()); 1055 item_->GetTargetFilePath().BaseName().AsUTF8Unsafe());
1006 } 1056 }
1007 request.set_download_type(type_); 1057 request.set_download_type(type_);
1008 1058
1009 service_->AddReferrerChainToClientDownloadRequest( 1059 ReferrerChainData* referrer_chain_data =
1010 item_->GetURL(), 1060 static_cast<ReferrerChainData*>(
1011 item_->GetWebContents(), 1061 item_->GetUserData(kDownloadReferrerChainDataKey));
1012 &request); 1062 if (referrer_chain_data &&
1063 !referrer_chain_data->GetReferrerChain()->empty()) {
1064 request.mutable_referrer_chain()->Swap(
1065 referrer_chain_data->GetReferrerChain());
1066 }
1013 1067
1014 if (archive_is_valid_ != ArchiveValid::UNSET) 1068 if (archive_is_valid_ != ArchiveValid::UNSET)
1015 request.set_archive_valid(archive_is_valid_ == ArchiveValid::VALID); 1069 request.set_archive_valid(archive_is_valid_ == ArchiveValid::VALID);
1016 request.mutable_signature()->CopyFrom(signature_info_); 1070 request.mutable_signature()->CopyFrom(signature_info_);
1017 if (image_headers_) 1071 if (image_headers_)
1018 request.set_allocated_image_headers(image_headers_.release()); 1072 request.set_allocated_image_headers(image_headers_.release());
1019 if (archived_executable_) 1073 if (archived_executable_)
1020 request.mutable_archived_binary()->Swap(&archived_binary_); 1074 request.mutable_archived_binary()->Swap(&archived_binary_);
1021 if (!request.SerializeToString(&client_download_request_data_)) { 1075 if (!request.SerializeToString(&client_download_request_data_)) {
1022 FinishRequest(UNKNOWN, REASON_INVALID_REQUEST_PROTO); 1076 FinishRequest(UNKNOWN, REASON_INVALID_REQUEST_PROTO);
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
1606 const CheckDownloadCallback& callback) { 1660 const CheckDownloadCallback& callback) {
1607 scoped_refptr<CheckClientDownloadRequest> request( 1661 scoped_refptr<CheckClientDownloadRequest> request(
1608 new CheckClientDownloadRequest(item, callback, this, 1662 new CheckClientDownloadRequest(item, callback, this,
1609 database_manager_, 1663 database_manager_,
1610 binary_feature_extractor_.get())); 1664 binary_feature_extractor_.get()));
1611 download_requests_.insert(request); 1665 download_requests_.insert(request);
1612 request->Start(); 1666 request->Start();
1613 } 1667 }
1614 1668
1615 void DownloadProtectionService::CheckDownloadUrl( 1669 void DownloadProtectionService::CheckDownloadUrl(
1616 const content::DownloadItem& item, 1670 content::DownloadItem* item,
1617 const CheckDownloadCallback& callback) { 1671 const CheckDownloadCallback& callback) {
1618 DCHECK(!item.GetUrlChain().empty()); 1672 DCHECK(!item->GetUrlChain().empty());
1619 scoped_refptr<DownloadUrlSBClient> client( 1673 scoped_refptr<DownloadUrlSBClient> client(
1620 new DownloadUrlSBClient(item, callback, ui_manager_, database_manager_)); 1674 new DownloadUrlSBClient(item, this, callback, ui_manager_,
1675 database_manager_));
1621 // The client will release itself once it is done. 1676 // The client will release itself once it is done.
1622 BrowserThread::PostTask( 1677 BrowserThread::PostTask(
1623 BrowserThread::IO, 1678 BrowserThread::IO,
1624 FROM_HERE, 1679 FROM_HERE,
1625 base::Bind(&DownloadUrlSBClient::StartCheck, client)); 1680 base::Bind(&DownloadUrlSBClient::StartCheck, client));
1626 } 1681 }
1627 1682
1628 bool DownloadProtectionService::IsSupportedDownload( 1683 bool DownloadProtectionService::IsSupportedDownload(
1629 const content::DownloadItem& item, 1684 const content::DownloadItem& item,
1630 const base::FilePath& target_path) const { 1685 const base::FilePath& target_path) const {
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1813 // static 1868 // static
1814 GURL DownloadProtectionService::GetDownloadRequestUrl() { 1869 GURL DownloadProtectionService::GetDownloadRequestUrl() {
1815 GURL url(kDownloadRequestUrl); 1870 GURL url(kDownloadRequestUrl);
1816 std::string api_key = google_apis::GetAPIKey(); 1871 std::string api_key = google_apis::GetAPIKey();
1817 if (!api_key.empty()) 1872 if (!api_key.empty())
1818 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); 1873 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true));
1819 1874
1820 return url; 1875 return url;
1821 } 1876 }
1822 1877
1823 void DownloadProtectionService::AddReferrerChainToClientDownloadRequest( 1878 void DownloadProtectionService::IdentifyReferrerChain(
1824 const GURL& download_url, 1879 const GURL& download_url,
1825 content::WebContents* web_contents, 1880 content::WebContents* web_contents,
1826 ClientDownloadRequest* out_request) { 1881 ReferrerChain* out_referrer_chain) {
1827 if (!base::FeatureList::IsEnabled( 1882 if (!base::FeatureList::IsEnabled(
1828 SafeBrowsingNavigationObserverManager::kDownloadAttribution) || 1883 SafeBrowsingNavigationObserverManager::kDownloadAttribution) ||
1829 !navigation_observer_manager_) { 1884 !navigation_observer_manager_) {
1830 return; 1885 return;
1831 } 1886 }
1832 1887
1833 int download_tab_id = SessionTabHelper::IdForTab(web_contents); 1888 int download_tab_id = SessionTabHelper::IdForTab(web_contents);
1834 UMA_HISTOGRAM_BOOLEAN( 1889 UMA_HISTOGRAM_BOOLEAN(
1835 "SafeBrowsing.ReferrerHasInvalidTabID.DownloadAttribution", 1890 "SafeBrowsing.ReferrerHasInvalidTabID.DownloadAttribution",
1836 download_tab_id == -1); 1891 download_tab_id == -1);
1837 SafeBrowsingNavigationObserverManager::ReferrerChain attribution_chain;
1838 SafeBrowsingNavigationObserverManager::AttributionResult result = 1892 SafeBrowsingNavigationObserverManager::AttributionResult result =
1839 navigation_observer_manager_->IdentifyReferrerChainForDownload( 1893 navigation_observer_manager_->IdentifyReferrerChainForDownload(
1840 download_url, 1894 download_url,
1841 download_tab_id, 1895 download_tab_id,
1842 kDownloadAttributionUserGestureLimit, 1896 kDownloadAttributionUserGestureLimit,
1843 &attribution_chain); 1897 out_referrer_chain);
1844 UMA_HISTOGRAM_COUNTS_100( 1898 UMA_HISTOGRAM_COUNTS_100(
1845 "SafeBrowsing.ReferrerURLChainSize.DownloadAttribution", 1899 "SafeBrowsing.ReferrerURLChainSize.DownloadAttribution",
1846 attribution_chain.size()); 1900 out_referrer_chain->size());
1847 UMA_HISTOGRAM_ENUMERATION( 1901 UMA_HISTOGRAM_ENUMERATION(
1848 "SafeBrowsing.ReferrerAttributionResult.DownloadAttribution", result, 1902 "SafeBrowsing.ReferrerAttributionResult.DownloadAttribution", result,
1849 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX); 1903 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX);
1850 for (auto& entry : attribution_chain)
1851 out_request->add_referrer_chain()->Swap(entry.get());
1852 } 1904 }
1853 1905
1854 void DownloadProtectionService::AddReferrerChainToPPAPIClientDownloadRequest( 1906 void DownloadProtectionService::AddReferrerChainToPPAPIClientDownloadRequest(
1855 const GURL& initiating_frame_url, 1907 const GURL& initiating_frame_url,
1856 int tab_id, 1908 int tab_id,
1857 bool has_user_gesture, 1909 bool has_user_gesture,
1858 ClientDownloadRequest* out_request) { 1910 ClientDownloadRequest* out_request) {
1859 if (!base::FeatureList::IsEnabled( 1911 if (!base::FeatureList::IsEnabled(
1860 SafeBrowsingNavigationObserverManager::kDownloadAttribution) || 1912 SafeBrowsingNavigationObserverManager::kDownloadAttribution) ||
1861 !navigation_observer_manager_) { 1913 !navigation_observer_manager_) {
1862 return; 1914 return;
1863 } 1915 }
1864 1916
1865 UMA_HISTOGRAM_BOOLEAN( 1917 UMA_HISTOGRAM_BOOLEAN(
1866 "SafeBrowsing.ReferrerHasInvalidTabID.DownloadAttribution", 1918 "SafeBrowsing.ReferrerHasInvalidTabID.DownloadAttribution",
1867 tab_id == -1); 1919 tab_id == -1);
1868 SafeBrowsingNavigationObserverManager::ReferrerChain attribution_chain;
1869 SafeBrowsingNavigationObserverManager::AttributionResult result = 1920 SafeBrowsingNavigationObserverManager::AttributionResult result =
1870 navigation_observer_manager_->IdentifyReferrerChainForPPAPIDownload( 1921 navigation_observer_manager_->IdentifyReferrerChainForPPAPIDownload(
1871 initiating_frame_url, 1922 initiating_frame_url,
1872 tab_id, 1923 tab_id,
1873 has_user_gesture, 1924 has_user_gesture,
1874 kDownloadAttributionUserGestureLimit, 1925 kDownloadAttributionUserGestureLimit,
1875 &attribution_chain); 1926 out_request->mutable_referrer_chain());
1876 UMA_HISTOGRAM_COUNTS_100( 1927 UMA_HISTOGRAM_COUNTS_100(
1877 "SafeBrowsing.ReferrerURLChainSize.PPAPIDownloadAttribution", 1928 "SafeBrowsing.ReferrerURLChainSize.PPAPIDownloadAttribution",
1878 attribution_chain.size()); 1929 out_request->referrer_chain_size());
1879 UMA_HISTOGRAM_ENUMERATION( 1930 UMA_HISTOGRAM_ENUMERATION(
1880 "SafeBrowsing.ReferrerAttributionResult.PPAPIDownloadAttribution", result, 1931 "SafeBrowsing.ReferrerAttributionResult.PPAPIDownloadAttribution", result,
1881 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX); 1932 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX);
1882 for (auto& entry : attribution_chain)
1883 out_request->add_referrer_chain()->Swap(entry.get());
1884 } 1933 }
1885 1934
1886 } // namespace safe_browsing 1935 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698