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

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

Issue 2505153002: Add support for scout to 'ext' param when creating SafeBrowsing ping URLs. (Closed)
Patch Set: Address comments Created 4 years, 1 month 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
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/local_database_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 SBStatsType dangerous_type) 170 SBStatsType dangerous_type)
171 : sha256_hash_(item.GetHash()), 171 : sha256_hash_(item.GetHash()),
172 url_chain_(item.GetUrlChain()), 172 url_chain_(item.GetUrlChain()),
173 referrer_url_(item.GetReferrerUrl()), 173 referrer_url_(item.GetReferrerUrl()),
174 callback_(callback), 174 callback_(callback),
175 ui_manager_(ui_manager), 175 ui_manager_(ui_manager),
176 start_time_(base::TimeTicks::Now()), 176 start_time_(base::TimeTicks::Now()),
177 total_type_(total_type), 177 total_type_(total_type),
178 dangerous_type_(dangerous_type) { 178 dangerous_type_(dangerous_type) {
179 Profile* profile = Profile::FromBrowserContext(item.GetBrowserContext()); 179 Profile* profile = Profile::FromBrowserContext(item.GetBrowserContext());
180 is_extended_reporting_ = 180 extended_reporting_level_ =
181 profile && IsExtendedReportingEnabled(*profile->GetPrefs()); 181 profile ? GetExtendedReportingLevel(*profile->GetPrefs())
182 : SBER_LEVEL_OFF;
182 } 183 }
183 184
184 virtual void StartCheck() = 0; 185 virtual void StartCheck() = 0;
185 virtual bool IsDangerous(SBThreatType threat_type) const = 0; 186 virtual bool IsDangerous(SBThreatType threat_type) const = 0;
186 187
187 protected: 188 protected:
188 friend class base::RefCountedThreadSafe<DownloadSBClient>; 189 friend class base::RefCountedThreadSafe<DownloadSBClient>;
189 ~DownloadSBClient() override {} 190 ~DownloadSBClient() override {}
190 191
191 void CheckDone(SBThreatType threat_type) { 192 void CheckDone(SBThreatType threat_type) {
(...skipping 27 matching lines...) Expand all
219 safe_browsing::HitReport hit_report; 220 safe_browsing::HitReport hit_report;
220 hit_report.malicious_url = url_chain_.back(); 221 hit_report.malicious_url = url_chain_.back();
221 hit_report.page_url = url_chain_.front(); 222 hit_report.page_url = url_chain_.front();
222 hit_report.referrer_url = referrer_url_; 223 hit_report.referrer_url = referrer_url_;
223 hit_report.is_subresource = true; 224 hit_report.is_subresource = true;
224 hit_report.threat_type = threat_type; 225 hit_report.threat_type = threat_type;
225 // TODO(nparker) Replace this with database_manager_->GetThreatSource(); 226 // TODO(nparker) Replace this with database_manager_->GetThreatSource();
226 hit_report.threat_source = safe_browsing::ThreatSource::LOCAL_PVER3; 227 hit_report.threat_source = safe_browsing::ThreatSource::LOCAL_PVER3;
227 // TODO(nparker) Populate hit_report.population_id once Pver4 is used here. 228 // TODO(nparker) Populate hit_report.population_id once Pver4 is used here.
228 hit_report.post_data = post_data; 229 hit_report.post_data = post_data;
229 hit_report.is_extended_reporting = is_extended_reporting_; 230 hit_report.extended_reporting_level = extended_reporting_level_;
230 hit_report.is_metrics_reporting_active = 231 hit_report.is_metrics_reporting_active =
231 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); 232 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled();
232 233
233 ui_manager_->MaybeReportSafeBrowsingHit(hit_report); 234 ui_manager_->MaybeReportSafeBrowsingHit(hit_report);
234 } 235 }
235 236
236 void UpdateDownloadCheckStats(SBStatsType stat_type) { 237 void UpdateDownloadCheckStats(SBStatsType stat_type) {
237 UMA_HISTOGRAM_ENUMERATION("SB2.DownloadChecks", 238 UMA_HISTOGRAM_ENUMERATION("SB2.DownloadChecks",
238 stat_type, 239 stat_type,
239 DOWNLOAD_CHECKS_MAX); 240 DOWNLOAD_CHECKS_MAX);
240 } 241 }
241 242
242 std::string sha256_hash_; 243 std::string sha256_hash_;
243 std::vector<GURL> url_chain_; 244 std::vector<GURL> url_chain_;
244 GURL referrer_url_; 245 GURL referrer_url_;
245 DownloadProtectionService::CheckDownloadCallback callback_; 246 DownloadProtectionService::CheckDownloadCallback callback_;
246 scoped_refptr<SafeBrowsingUIManager> ui_manager_; 247 scoped_refptr<SafeBrowsingUIManager> ui_manager_;
247 base::TimeTicks start_time_; 248 base::TimeTicks start_time_;
248 249
249 private: 250 private:
250 const SBStatsType total_type_; 251 const SBStatsType total_type_;
251 const SBStatsType dangerous_type_; 252 const SBStatsType dangerous_type_;
252 bool is_extended_reporting_; 253 ExtendedReportingLevel extended_reporting_level_;
253 254
254 DISALLOW_COPY_AND_ASSIGN(DownloadSBClient); 255 DISALLOW_COPY_AND_ASSIGN(DownloadSBClient);
255 }; 256 };
256 257
257 class DownloadUrlSBClient : public DownloadSBClient { 258 class DownloadUrlSBClient : public DownloadSBClient {
258 public: 259 public:
259 DownloadUrlSBClient( 260 DownloadUrlSBClient(
260 const content::DownloadItem& item, 261 const content::DownloadItem& item,
261 const DownloadProtectionService::CheckDownloadCallback& callback, 262 const DownloadProtectionService::CheckDownloadCallback& callback,
262 const scoped_refptr<SafeBrowsingUIManager>& ui_manager, 263 const scoped_refptr<SafeBrowsingUIManager>& ui_manager,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 } 348 }
348 349
349 void Start() { 350 void Start() {
350 DVLOG(2) << "Starting SafeBrowsing download check for: " 351 DVLOG(2) << "Starting SafeBrowsing download check for: "
351 << item_->DebugString(true); 352 << item_->DebugString(true);
352 DCHECK_CURRENTLY_ON(BrowserThread::UI); 353 DCHECK_CURRENTLY_ON(BrowserThread::UI);
353 if (item_->GetBrowserContext()) { 354 if (item_->GetBrowserContext()) {
354 Profile* profile = 355 Profile* profile =
355 Profile::FromBrowserContext(item_->GetBrowserContext()); 356 Profile::FromBrowserContext(item_->GetBrowserContext());
356 is_extended_reporting_ = 357 is_extended_reporting_ =
357 profile && IsExtendedReportingEnabled(*profile->GetPrefs()); 358 profile &&
359 GetExtendedReportingLevel(*profile->GetPrefs()) != SBER_LEVEL_OFF;
358 is_incognito_ = item_->GetBrowserContext()->IsOffTheRecord(); 360 is_incognito_ = item_->GetBrowserContext()->IsOffTheRecord();
359 } 361 }
360 362
361 DownloadCheckResultReason reason = REASON_MAX; 363 DownloadCheckResultReason reason = REASON_MAX;
362 if (!IsSupportedDownload( 364 if (!IsSupportedDownload(
363 *item_, item_->GetTargetFilePath(), &reason, &type_)) { 365 *item_, item_->GetTargetFilePath(), &reason, &type_)) {
364 switch (reason) { 366 switch (reason) {
365 case REASON_EMPTY_URL_CHAIN: 367 case REASON_EMPTY_URL_CHAIN:
366 case REASON_INVALID_URL: 368 case REASON_INVALID_URL:
367 case REASON_LOCAL_FILE: 369 case REASON_LOCAL_FILE:
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 } 796 }
795 797
796 OnFileFeatureExtractionDone(); 798 OnFileFeatureExtractionDone();
797 } 799 }
798 #endif // defined(OS_MACOSX) 800 #endif // defined(OS_MACOSX)
799 801
800 bool ShouldSampleWhitelistedDownload() { 802 bool ShouldSampleWhitelistedDownload() {
801 // We currently sample 1% whitelisted downloads from users who opted 803 // We currently sample 1% whitelisted downloads from users who opted
802 // in extended reporting and are not in incognito mode. 804 // in extended reporting and are not in incognito mode.
803 return service_ && is_extended_reporting_ && !is_incognito_ && 805 return service_ && is_extended_reporting_ && !is_incognito_ &&
804 base::RandDouble() < service_->whitelist_sample_rate(); 806 base::RandDouble() < service_->whitelist_sample_rate();
805 } 807 }
806 808
807 void CheckWhitelists() { 809 void CheckWhitelists() {
808 DCHECK_CURRENTLY_ON(BrowserThread::IO); 810 DCHECK_CURRENTLY_ON(BrowserThread::IO);
809 811
810 if (!database_manager_.get()) { 812 if (!database_manager_.get()) {
811 PostFinishTask(UNKNOWN, REASON_SB_DISABLED); 813 PostFinishTask(UNKNOWN, REASON_SB_DISABLED);
812 return; 814 return;
813 } 815 }
814 816
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 void SendRequest() { 940 void SendRequest() {
939 DCHECK_CURRENTLY_ON(BrowserThread::UI); 941 DCHECK_CURRENTLY_ON(BrowserThread::UI);
940 942
941 // This is our last chance to check whether the request has been canceled 943 // This is our last chance to check whether the request has been canceled
942 // before sending it. 944 // before sending it.
943 if (!service_) 945 if (!service_)
944 return; 946 return;
945 947
946 ClientDownloadRequest request; 948 ClientDownloadRequest request;
947 auto population = is_extended_reporting_ 949 auto population = is_extended_reporting_
948 ? ChromeUserPopulation::EXTENDED_REPORTING 950 ? ChromeUserPopulation::EXTENDED_REPORTING
949 : ChromeUserPopulation::SAFE_BROWSING; 951 : ChromeUserPopulation::SAFE_BROWSING;
950 request.mutable_population()->set_user_population(population); 952 request.mutable_population()->set_user_population(population);
951 953
952 request.set_url(SanitizeUrl(item_->GetUrlChain().back())); 954 request.set_url(SanitizeUrl(item_->GetUrlChain().back()));
953 request.mutable_digests()->set_sha256(item_->GetHash()); 955 request.mutable_digests()->set_sha256(item_->GetHash());
954 request.set_length(item_->GetReceivedBytes()); 956 request.set_length(item_->GetReceivedBytes());
955 request.set_skipped_url_whitelist(skipped_url_whitelist_); 957 request.set_skipped_url_whitelist(skipped_url_whitelist_);
956 request.set_skipped_certificate_whitelist(skipped_certificate_whitelist_); 958 request.set_skipped_certificate_whitelist(skipped_certificate_whitelist_);
957 for (size_t i = 0; i < item_->GetUrlChain().size(); ++i) { 959 for (size_t i = 0; i < item_->GetUrlChain().size(); ++i) {
958 ClientDownloadRequest::Resource* resource = request.add_resources(); 960 ClientDownloadRequest::Resource* resource = request.add_resources();
959 resource->set_url(SanitizeUrl(item_->GetUrlChain()[i])); 961 resource->set_url(SanitizeUrl(item_->GetUrlChain()[i]));
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 default_file_path_(default_file_path), 1232 default_file_path_(default_file_path),
1231 alternate_extensions_(alternate_extensions), 1233 alternate_extensions_(alternate_extensions),
1232 callback_(callback), 1234 callback_(callback),
1233 service_(service), 1235 service_(service),
1234 database_manager_(database_manager), 1236 database_manager_(database_manager),
1235 start_time_(base::TimeTicks::Now()), 1237 start_time_(base::TimeTicks::Now()),
1236 supported_path_( 1238 supported_path_(
1237 GetSupportedFilePath(default_file_path, alternate_extensions)), 1239 GetSupportedFilePath(default_file_path, alternate_extensions)),
1238 weakptr_factory_(this) { 1240 weakptr_factory_(this) {
1239 DCHECK(profile); 1241 DCHECK(profile);
1240 is_extended_reporting_ = IsExtendedReportingEnabled(*profile->GetPrefs()); 1242 is_extended_reporting_ =
1243 GetExtendedReportingLevel(*profile->GetPrefs()) != SBER_LEVEL_OFF;
Jialiu Lin 2016/11/17 19:50:30 nit, feel free to ignore.: why not IsExtendedRepor
lpz 2016/11/17 19:57:08 Doh, I went too fast. Of course, it should be as y
1241 } 1244 }
1242 1245
1243 ~PPAPIDownloadRequest() override { 1246 ~PPAPIDownloadRequest() override {
1244 if (fetcher_ && !callback_.is_null()) 1247 if (fetcher_ && !callback_.is_null())
1245 Finish(RequestOutcome::REQUEST_DESTROYED, UNKNOWN); 1248 Finish(RequestOutcome::REQUEST_DESTROYED, UNKNOWN);
1246 } 1249 }
1247 1250
1248 // Start the process of checking the download request. The callback passed as 1251 // Start the process of checking the download request. The callback passed as
1249 // the |callback| parameter to the constructor will be invoked with the result 1252 // the |callback| parameter to the constructor will be invoked with the result
1250 // of the check at some point in the future. 1253 // of the check at some point in the future.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1319 // backend. 1322 // backend.
1320 SendRequest(); 1323 SendRequest();
1321 } 1324 }
1322 1325
1323 void SendRequest() { 1326 void SendRequest() {
1324 DVLOG(2) << __func__; 1327 DVLOG(2) << __func__;
1325 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1328 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1326 1329
1327 ClientDownloadRequest request; 1330 ClientDownloadRequest request;
1328 auto population = is_extended_reporting_ 1331 auto population = is_extended_reporting_
1329 ? ChromeUserPopulation::EXTENDED_REPORTING 1332 ? ChromeUserPopulation::EXTENDED_REPORTING
1330 : ChromeUserPopulation::SAFE_BROWSING; 1333 : ChromeUserPopulation::SAFE_BROWSING;
1331 request.mutable_population()->set_user_population(population); 1334 request.mutable_population()->set_user_population(population);
1332 request.set_download_type(ClientDownloadRequest::PPAPI_SAVE_REQUEST); 1335 request.set_download_type(ClientDownloadRequest::PPAPI_SAVE_REQUEST);
1333 ClientDownloadRequest::Resource* resource = request.add_resources(); 1336 ClientDownloadRequest::Resource* resource = request.add_resources();
1334 resource->set_type(ClientDownloadRequest::PPAPI_DOCUMENT); 1337 resource->set_type(ClientDownloadRequest::PPAPI_DOCUMENT);
1335 resource->set_url(requestor_url_.spec()); 1338 resource->set_url(requestor_url_.spec());
1336 request.set_url(requestor_url_.spec()); 1339 request.set_url(requestor_url_.spec());
1337 request.set_file_basename(supported_path_.BaseName().AsUTF8Unsafe()); 1340 request.set_file_basename(supported_path_.BaseName().AsUTF8Unsafe());
1338 request.set_length(0); 1341 request.set_length(0);
1339 request.mutable_digests()->set_md5(std::string()); 1342 request.mutable_digests()->set_md5(std::string());
1340 for (const auto& alternate_extension : alternate_extensions_) { 1343 for (const auto& alternate_extension : alternate_extensions_) {
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
1771 GURL DownloadProtectionService::GetDownloadRequestUrl() { 1774 GURL DownloadProtectionService::GetDownloadRequestUrl() {
1772 GURL url(kDownloadRequestUrl); 1775 GURL url(kDownloadRequestUrl);
1773 std::string api_key = google_apis::GetAPIKey(); 1776 std::string api_key = google_apis::GetAPIKey();
1774 if (!api_key.empty()) 1777 if (!api_key.empty())
1775 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); 1778 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true));
1776 1779
1777 return url; 1780 return url;
1778 } 1781 }
1779 1782
1780 } // namespace safe_browsing 1783 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/local_database_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698