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

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

Issue 2647323004: Move download attribution right after CheckDownloadUrl (Closed)
Patch Set: address potential race conditions 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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/callback_helpers.h" 12 #include "base/callback_helpers.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/format_macros.h" 15 #include "base/format_macros.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
18 #include "base/metrics/field_trial.h" 18 #include "base/metrics/field_trial.h"
19 #include "base/metrics/histogram_macros.h" 19 #include "base/metrics/histogram_macros.h"
20 #include "base/metrics/sparse_histogram.h" 20 #include "base/metrics/sparse_histogram.h"
21 #include "base/rand_util.h" 21 #include "base/rand_util.h"
22 #include "base/scoped_observer.h"
22 #include "base/sequenced_task_runner_helpers.h" 23 #include "base/sequenced_task_runner_helpers.h"
23 #include "base/sha1.h" 24 #include "base/sha1.h"
24 #include "base/stl_util.h" 25 #include "base/stl_util.h"
25 #include "base/strings/string_number_conversions.h" 26 #include "base/strings/string_number_conversions.h"
26 #include "base/strings/string_split.h" 27 #include "base/strings/string_split.h"
27 #include "base/strings/string_util.h" 28 #include "base/strings/string_util.h"
28 #include "base/strings/stringprintf.h" 29 #include "base/strings/stringprintf.h"
29 #include "base/task/cancelable_task_tracker.h" 30 #include "base/task/cancelable_task_tracker.h"
30 #include "base/threading/sequenced_worker_pool.h" 31 #include "base/threading/sequenced_worker_pool.h"
31 #include "base/time/time.h" 32 #include "base/time/time.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 const int64_t kDownloadRequestTimeoutMs = 7000; 82 const int64_t kDownloadRequestTimeoutMs = 7000;
82 // We sample 1% of whitelisted downloads to still send out download pings. 83 // We sample 1% of whitelisted downloads to still send out download pings.
83 const double kWhitelistDownloadSampleRate = 0.01; 84 const double kWhitelistDownloadSampleRate = 0.01;
84 85
85 // The number of user gestures we trace back for download attribution. 86 // The number of user gestures we trace back for download attribution.
86 const int kDownloadAttributionUserGestureLimit = 2; 87 const int kDownloadAttributionUserGestureLimit = 2;
87 88
88 const char kDownloadExtensionUmaName[] = "SBClientDownload.DownloadExtensions"; 89 const char kDownloadExtensionUmaName[] = "SBClientDownload.DownloadExtensions";
89 const char kUnsupportedSchemeUmaPrefix[] = "SBClientDownload.UnsupportedScheme"; 90 const char kUnsupportedSchemeUmaPrefix[] = "SBClientDownload.UnsupportedScheme";
90 91
92 const void* const kDownloadReferrerChainDataKey =
93 &kDownloadReferrerChainDataKey;
94
91 enum WhitelistType { 95 enum WhitelistType {
92 NO_WHITELIST_MATCH, 96 NO_WHITELIST_MATCH,
93 URL_WHITELIST, 97 URL_WHITELIST,
94 SIGNATURE_WHITELIST, 98 SIGNATURE_WHITELIST,
95 WHITELIST_TYPE_MAX 99 WHITELIST_TYPE_MAX
96 }; 100 };
97 101
98 void RecordCountOfWhitelistedDownload(WhitelistType type) { 102 void RecordCountOfWhitelistedDownload(WhitelistType type) {
99 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckWhitelistResult", type, 103 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckWhitelistResult", type,
100 WHITELIST_TYPE_MAX); 104 WHITELIST_TYPE_MAX);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 // ALWAYS ADD NEW VALUES BEFORE THIS ONE. 160 // ALWAYS ADD NEW VALUES BEFORE THIS ONE.
157 DOWNLOAD_CHECKS_MAX 161 DOWNLOAD_CHECKS_MAX
158 }; 162 };
159 163
160 } // namespace 164 } // namespace
161 165
162 // Parent SafeBrowsing::Client class used to lookup the bad binary 166 // Parent SafeBrowsing::Client class used to lookup the bad binary
163 // URL and digest list. There are two sub-classes (one for each list). 167 // URL and digest list. There are two sub-classes (one for each list).
164 class DownloadSBClient 168 class DownloadSBClient
165 : public SafeBrowsingDatabaseManager::Client, 169 : public SafeBrowsingDatabaseManager::Client,
170 public content::DownloadItem::Observer,
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 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 : observer_(this),
175 url_chain_(item.GetUrlChain()), 181 item_(item),
176 referrer_url_(item.GetReferrerUrl()), 182 sha256_hash_(item->GetHash()),
183 url_chain_(item->GetUrlChain()),
184 referrer_url_(item->GetReferrerUrl()),
185 service_(service),
177 callback_(callback), 186 callback_(callback),
178 ui_manager_(ui_manager), 187 ui_manager_(ui_manager),
179 start_time_(base::TimeTicks::Now()), 188 start_time_(base::TimeTicks::Now()),
180 total_type_(total_type), 189 total_type_(total_type),
181 dangerous_type_(dangerous_type) { 190 dangerous_type_(dangerous_type) {
182 Profile* profile = Profile::FromBrowserContext(item.GetBrowserContext()); 191 DCHECK_CURRENTLY_ON(BrowserThread::UI);
192 DCHECK(item_);
193 DCHECK(service_);
194 observer_.Add(item_);
195 Profile* profile = Profile::FromBrowserContext(item_->GetBrowserContext());
183 extended_reporting_level_ = 196 extended_reporting_level_ =
184 profile ? GetExtendedReportingLevel(*profile->GetPrefs()) 197 profile ? GetExtendedReportingLevel(*profile->GetPrefs())
185 : SBER_LEVEL_OFF; 198 : SBER_LEVEL_OFF;
199 download_attribution_enabled_ = service_->navigation_observer_manager() &&
200 base::FeatureList::IsEnabled(
201 SafeBrowsingNavigationObserverManager::kDownloadAttribution);
186 } 202 }
187 203
188 virtual void StartCheck() = 0; 204 virtual void StartCheck() = 0;
189 virtual bool IsDangerous(SBThreatType threat_type) const = 0; 205 virtual bool IsDangerous(SBThreatType threat_type) const = 0;
190 206
207 // Implements DownloadItem::Observer.
208 void OnDownloadDestroyed(content::DownloadItem* download) override {
209 observer_.Remove(download);
210 item_ = nullptr;
211 }
212
191 protected: 213 protected:
192 friend class base::RefCountedThreadSafe<DownloadSBClient>; 214 friend class base::RefCountedThreadSafe<DownloadSBClient>;
193 ~DownloadSBClient() override {} 215 ~DownloadSBClient() override {}
194 216
195 void CheckDone(SBThreatType threat_type) { 217 void CheckDone(SBThreatType threat_type) {
196 DownloadProtectionService::DownloadCheckResult result = 218 DownloadProtectionService::DownloadCheckResult result =
197 IsDangerous(threat_type) ? 219 IsDangerous(threat_type) ?
198 DownloadProtectionService::DANGEROUS : 220 DownloadProtectionService::DANGEROUS :
199 DownloadProtectionService::SAFE; 221 DownloadProtectionService::SAFE;
200 BrowserThread::PostTask(BrowserThread::UI, 222 BrowserThread::PostTask(BrowserThread::UI,
201 FROM_HERE, 223 FROM_HERE,
202 base::Bind(callback_, result)); 224 base::Bind(callback_, result));
asanka 2017/01/27 01:40:40 Forgot to move this? :-P
Jialiu Lin 2017/01/27 01:49:51 Oops! Thanks for catching this.
203 UpdateDownloadCheckStats(total_type_); 225 UpdateDownloadCheckStats(total_type_);
204 if (threat_type != SB_THREAT_TYPE_SAFE) { 226 if (threat_type != SB_THREAT_TYPE_SAFE) {
205 UpdateDownloadCheckStats(dangerous_type_); 227 UpdateDownloadCheckStats(dangerous_type_);
206 BrowserThread::PostTask( 228 BrowserThread::PostTask(
207 BrowserThread::UI, 229 BrowserThread::UI,
208 FROM_HERE, 230 FROM_HERE,
209 base::Bind(&DownloadSBClient::ReportMalware, 231 base::Bind(&DownloadSBClient::ReportMalware,
210 this, threat_type)); 232 this, threat_type));
233 } else if (download_attribution_enabled_) {
234 // Identify download referrer chain, which will be used in
235 // ClientDownloadRequest.
236 BrowserThread::PostTask(
237 BrowserThread::UI,
238 FROM_HERE,
239 base::Bind(&DownloadSBClient::IdentifyReferrerChain,
240 this));
211 } 241 }
212 } 242 }
213 243
214 void ReportMalware(SBThreatType threat_type) { 244 void ReportMalware(SBThreatType threat_type) {
215 std::string post_data; 245 std::string post_data;
216 if (!sha256_hash_.empty()) 246 if (!sha256_hash_.empty()) {
217 post_data += base::HexEncode(sha256_hash_.data(), 247 post_data += base::HexEncode(sha256_hash_.data(),
218 sha256_hash_.size()) + "\n"; 248 sha256_hash_.size()) + "\n";
249 }
219 for (size_t i = 0; i < url_chain_.size(); ++i) { 250 for (size_t i = 0; i < url_chain_.size(); ++i) {
220 post_data += url_chain_[i].spec() + "\n"; 251 post_data += url_chain_[i].spec() + "\n";
221 } 252 }
222 253
223 safe_browsing::HitReport hit_report; 254 safe_browsing::HitReport hit_report;
224 hit_report.malicious_url = url_chain_.back(); 255 hit_report.malicious_url = url_chain_.back();
225 hit_report.page_url = url_chain_.front(); 256 hit_report.page_url = url_chain_.front();
226 hit_report.referrer_url = referrer_url_; 257 hit_report.referrer_url = referrer_url_;
227 hit_report.is_subresource = true; 258 hit_report.is_subresource = true;
228 hit_report.threat_type = threat_type; 259 hit_report.threat_type = threat_type;
229 // TODO(nparker) Replace this with database_manager_->GetThreatSource(); 260 // TODO(nparker) Replace this with database_manager_->GetThreatSource();
230 hit_report.threat_source = safe_browsing::ThreatSource::LOCAL_PVER3; 261 hit_report.threat_source = safe_browsing::ThreatSource::LOCAL_PVER3;
231 // TODO(nparker) Populate hit_report.population_id once Pver4 is used here. 262 // TODO(nparker) Populate hit_report.population_id once Pver4 is used here.
232 hit_report.post_data = post_data; 263 hit_report.post_data = post_data;
233 hit_report.extended_reporting_level = extended_reporting_level_; 264 hit_report.extended_reporting_level = extended_reporting_level_;
234 hit_report.is_metrics_reporting_active = 265 hit_report.is_metrics_reporting_active =
235 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); 266 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled();
236 267
237 ui_manager_->MaybeReportSafeBrowsingHit(hit_report); 268 ui_manager_->MaybeReportSafeBrowsingHit(hit_report);
238 } 269 }
239 270
271 void IdentifyReferrerChain() {
272 DCHECK_CURRENTLY_ON(BrowserThread::UI);
273 if (!item_)
274 return;
275
276 item_->SetUserData(kDownloadReferrerChainDataKey,
277 new ReferrerChainData(
278 service_->IdentifyReferrerChain(
279 item_->GetURL(), item_->GetWebContents())));
280 }
281
240 void UpdateDownloadCheckStats(SBStatsType stat_type) { 282 void UpdateDownloadCheckStats(SBStatsType stat_type) {
241 UMA_HISTOGRAM_ENUMERATION("SB2.DownloadChecks", 283 UMA_HISTOGRAM_ENUMERATION("SB2.DownloadChecks",
242 stat_type, 284 stat_type,
243 DOWNLOAD_CHECKS_MAX); 285 DOWNLOAD_CHECKS_MAX);
244 } 286 }
245 287
288 ScopedObserver<content::DownloadItem,
289 content::DownloadItem::Observer> observer_;
290 // The DownloadItem we are checking. Must be accessed only on UI thread.
291 content::DownloadItem* item_;
292 // Copies of data from |item_| for access on other threads.
246 std::string sha256_hash_; 293 std::string sha256_hash_;
247 std::vector<GURL> url_chain_; 294 std::vector<GURL> url_chain_;
248 GURL referrer_url_; 295 GURL referrer_url_;
296 DownloadProtectionService* service_;
249 DownloadProtectionService::CheckDownloadCallback callback_; 297 DownloadProtectionService::CheckDownloadCallback callback_;
250 scoped_refptr<SafeBrowsingUIManager> ui_manager_; 298 scoped_refptr<SafeBrowsingUIManager> ui_manager_;
251 base::TimeTicks start_time_; 299 base::TimeTicks start_time_;
300 bool download_attribution_enabled_;
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 std::unique_ptr<ReferrerChain> 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 std::unique_ptr<ReferrerChain> referrer_chain =
1827 if (!base::FeatureList::IsEnabled( 1882 base::MakeUnique<ReferrerChain>();
1828 SafeBrowsingNavigationObserverManager::kDownloadAttribution) ||
1829 !navigation_observer_manager_) {
1830 return;
1831 }
1832
1833 int download_tab_id = SessionTabHelper::IdForTab(web_contents); 1883 int download_tab_id = SessionTabHelper::IdForTab(web_contents);
1834 UMA_HISTOGRAM_BOOLEAN( 1884 UMA_HISTOGRAM_BOOLEAN(
1835 "SafeBrowsing.ReferrerHasInvalidTabID.DownloadAttribution", 1885 "SafeBrowsing.ReferrerHasInvalidTabID.DownloadAttribution",
1836 download_tab_id == -1); 1886 download_tab_id == -1);
1837 SafeBrowsingNavigationObserverManager::ReferrerChain attribution_chain;
1838 SafeBrowsingNavigationObserverManager::AttributionResult result = 1887 SafeBrowsingNavigationObserverManager::AttributionResult result =
1839 navigation_observer_manager_->IdentifyReferrerChainForDownload( 1888 navigation_observer_manager_->IdentifyReferrerChainForDownload(
1840 download_url, 1889 download_url,
1841 download_tab_id, 1890 download_tab_id,
1842 kDownloadAttributionUserGestureLimit, 1891 kDownloadAttributionUserGestureLimit,
1843 &attribution_chain); 1892 referrer_chain.get());
1844 UMA_HISTOGRAM_COUNTS_100( 1893 UMA_HISTOGRAM_COUNTS_100(
1845 "SafeBrowsing.ReferrerURLChainSize.DownloadAttribution", 1894 "SafeBrowsing.ReferrerURLChainSize.DownloadAttribution",
1846 attribution_chain.size()); 1895 referrer_chain->size());
1847 UMA_HISTOGRAM_ENUMERATION( 1896 UMA_HISTOGRAM_ENUMERATION(
1848 "SafeBrowsing.ReferrerAttributionResult.DownloadAttribution", result, 1897 "SafeBrowsing.ReferrerAttributionResult.DownloadAttribution", result,
1849 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX); 1898 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX);
1850 for (auto& entry : attribution_chain) 1899 return referrer_chain;
1851 out_request->add_referrer_chain()->Swap(entry.get());
1852 } 1900 }
1853 1901
1854 void DownloadProtectionService::AddReferrerChainToPPAPIClientDownloadRequest( 1902 void DownloadProtectionService::AddReferrerChainToPPAPIClientDownloadRequest(
1855 const GURL& initiating_frame_url, 1903 const GURL& initiating_frame_url,
1856 int tab_id, 1904 int tab_id,
1857 bool has_user_gesture, 1905 bool has_user_gesture,
1858 ClientDownloadRequest* out_request) { 1906 ClientDownloadRequest* out_request) {
1859 if (!base::FeatureList::IsEnabled( 1907 if (!base::FeatureList::IsEnabled(
1860 SafeBrowsingNavigationObserverManager::kDownloadAttribution) || 1908 SafeBrowsingNavigationObserverManager::kDownloadAttribution) ||
1861 !navigation_observer_manager_) { 1909 !navigation_observer_manager_) {
1862 return; 1910 return;
1863 } 1911 }
1864 1912
1865 UMA_HISTOGRAM_BOOLEAN( 1913 UMA_HISTOGRAM_BOOLEAN(
1866 "SafeBrowsing.ReferrerHasInvalidTabID.DownloadAttribution", 1914 "SafeBrowsing.ReferrerHasInvalidTabID.DownloadAttribution",
1867 tab_id == -1); 1915 tab_id == -1);
1868 SafeBrowsingNavigationObserverManager::ReferrerChain attribution_chain;
1869 SafeBrowsingNavigationObserverManager::AttributionResult result = 1916 SafeBrowsingNavigationObserverManager::AttributionResult result =
1870 navigation_observer_manager_->IdentifyReferrerChainForPPAPIDownload( 1917 navigation_observer_manager_->IdentifyReferrerChainForPPAPIDownload(
1871 initiating_frame_url, 1918 initiating_frame_url,
1872 tab_id, 1919 tab_id,
1873 has_user_gesture, 1920 has_user_gesture,
1874 kDownloadAttributionUserGestureLimit, 1921 kDownloadAttributionUserGestureLimit,
1875 &attribution_chain); 1922 out_request->mutable_referrer_chain());
1876 UMA_HISTOGRAM_COUNTS_100( 1923 UMA_HISTOGRAM_COUNTS_100(
1877 "SafeBrowsing.ReferrerURLChainSize.PPAPIDownloadAttribution", 1924 "SafeBrowsing.ReferrerURLChainSize.PPAPIDownloadAttribution",
1878 attribution_chain.size()); 1925 out_request->referrer_chain_size());
1879 UMA_HISTOGRAM_ENUMERATION( 1926 UMA_HISTOGRAM_ENUMERATION(
1880 "SafeBrowsing.ReferrerAttributionResult.PPAPIDownloadAttribution", result, 1927 "SafeBrowsing.ReferrerAttributionResult.PPAPIDownloadAttribution", result,
1881 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX); 1928 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX);
1882 for (auto& entry : attribution_chain)
1883 out_request->add_referrer_chain()->Swap(entry.get());
1884 } 1929 }
1885 1930
1886 } // namespace safe_browsing 1931 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698