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

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: Add missing dep 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
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 callback_(callback), 321 callback_(callback),
321 service_(service), 322 service_(service),
322 binary_feature_extractor_(binary_feature_extractor), 323 binary_feature_extractor_(binary_feature_extractor),
323 database_manager_(database_manager), 324 database_manager_(database_manager),
324 pingback_enabled_(service_->enabled()), 325 pingback_enabled_(service_->enabled()),
325 finished_(false), 326 finished_(false),
326 type_(ClientDownloadRequest::WIN_EXECUTABLE), 327 type_(ClientDownloadRequest::WIN_EXECUTABLE),
327 start_time_(base::TimeTicks::Now()), 328 start_time_(base::TimeTicks::Now()),
328 skipped_url_whitelist_(false), 329 skipped_url_whitelist_(false),
329 skipped_certificate_whitelist_(false), 330 skipped_certificate_whitelist_(false),
330 is_extended_reporting_(false), 331 extended_reporting_level_(SBER_LEVEL_OFF),
331 is_incognito_(false), 332 is_incognito_(false),
332 weakptr_factory_(this) { 333 weakptr_factory_(this) {
333 DCHECK_CURRENTLY_ON(BrowserThread::UI); 334 DCHECK_CURRENTLY_ON(BrowserThread::UI);
334 item_->AddObserver(this); 335 item_->AddObserver(this);
335 } 336 }
336 337
337 bool ShouldSampleUnsupportedFile(const base::FilePath& filename) { 338 bool ShouldSampleUnsupportedFile(const base::FilePath& filename) {
338 // If this extension is specifically marked as SAMPLED_PING (as are 339 // If this extension is specifically marked as SAMPLED_PING (as are
339 // all "unknown" extensions), we may want to sample it. Sampling it means 340 // all "unknown" extensions), we may want to sample it. Sampling it means
340 // we'll send a "light ping" with private info removed, and we won't 341 // we'll send a "light ping" with private info removed, and we won't
341 // use the verdict. 342 // use the verdict.
342 const FileTypePolicies* policies = FileTypePolicies::GetInstance(); 343 const FileTypePolicies* policies = FileTypePolicies::GetInstance();
343 return service_ && is_extended_reporting_ && !is_incognito_ && 344 return service_ && extended_reporting_level_ != SBER_LEVEL_OFF &&
345 !is_incognito_ &&
344 base::RandDouble() < policies->SampledPingProbability() && 346 base::RandDouble() < policies->SampledPingProbability() &&
345 policies->PingSettingForFile(filename) == 347 policies->PingSettingForFile(filename) ==
346 DownloadFileType::SAMPLED_PING; 348 DownloadFileType::SAMPLED_PING;
347 } 349 }
348 350
349 void Start() { 351 void Start() {
350 DVLOG(2) << "Starting SafeBrowsing download check for: " 352 DVLOG(2) << "Starting SafeBrowsing download check for: "
351 << item_->DebugString(true); 353 << item_->DebugString(true);
352 DCHECK_CURRENTLY_ON(BrowserThread::UI); 354 DCHECK_CURRENTLY_ON(BrowserThread::UI);
353 if (item_->GetBrowserContext()) { 355 if (item_->GetBrowserContext()) {
354 Profile* profile = 356 Profile* profile =
355 Profile::FromBrowserContext(item_->GetBrowserContext()); 357 Profile::FromBrowserContext(item_->GetBrowserContext());
356 is_extended_reporting_ = 358 extended_reporting_level_ =
357 profile && IsExtendedReportingEnabled(*profile->GetPrefs()); 359 profile ? GetExtendedReportingLevel(*profile->GetPrefs())
360 : SBER_LEVEL_OFF;
358 is_incognito_ = item_->GetBrowserContext()->IsOffTheRecord(); 361 is_incognito_ = item_->GetBrowserContext()->IsOffTheRecord();
359 } 362 }
360 363
361 DownloadCheckResultReason reason = REASON_MAX; 364 DownloadCheckResultReason reason = REASON_MAX;
362 if (!IsSupportedDownload( 365 if (!IsSupportedDownload(
363 *item_, item_->GetTargetFilePath(), &reason, &type_)) { 366 *item_, item_->GetTargetFilePath(), &reason, &type_)) {
364 switch (reason) { 367 switch (reason) {
365 case REASON_EMPTY_URL_CHAIN: 368 case REASON_EMPTY_URL_CHAIN:
366 case REASON_INVALID_URL: 369 case REASON_INVALID_URL:
367 case REASON_LOCAL_FILE: 370 case REASON_LOCAL_FILE:
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 } 796 }
794 } 797 }
795 798
796 OnFileFeatureExtractionDone(); 799 OnFileFeatureExtractionDone();
797 } 800 }
798 #endif // defined(OS_MACOSX) 801 #endif // defined(OS_MACOSX)
799 802
800 bool ShouldSampleWhitelistedDownload() { 803 bool ShouldSampleWhitelistedDownload() {
801 // We currently sample 1% whitelisted downloads from users who opted 804 // We currently sample 1% whitelisted downloads from users who opted
802 // in extended reporting and are not in incognito mode. 805 // in extended reporting and are not in incognito mode.
803 return service_ && is_extended_reporting_ && !is_incognito_ && 806 return service_ && extended_reporting_level_ != SBER_LEVEL_OFF &&
804 base::RandDouble() < service_->whitelist_sample_rate(); 807 !is_incognito_ &&
808 base::RandDouble() < service_->whitelist_sample_rate();
805 } 809 }
806 810
807 void CheckWhitelists() { 811 void CheckWhitelists() {
808 DCHECK_CURRENTLY_ON(BrowserThread::IO); 812 DCHECK_CURRENTLY_ON(BrowserThread::IO);
809 813
810 if (!database_manager_.get()) { 814 if (!database_manager_.get()) {
811 PostFinishTask(UNKNOWN, REASON_SB_DISABLED); 815 PostFinishTask(UNKNOWN, REASON_SB_DISABLED);
812 return; 816 return;
813 } 817 }
814 818
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 941
938 void SendRequest() { 942 void SendRequest() {
939 DCHECK_CURRENTLY_ON(BrowserThread::UI); 943 DCHECK_CURRENTLY_ON(BrowserThread::UI);
940 944
941 // This is our last chance to check whether the request has been canceled 945 // This is our last chance to check whether the request has been canceled
942 // before sending it. 946 // before sending it.
943 if (!service_) 947 if (!service_)
944 return; 948 return;
945 949
946 ClientDownloadRequest request; 950 ClientDownloadRequest request;
947 auto population = is_extended_reporting_ 951 auto population = extended_reporting_level_ != SBER_LEVEL_OFF
Jialiu Lin 2016/11/17 18:47:23 You might want to add ChromeUserPopulation::SCOUT_
lpz 2016/11/17 19:46:05 Agreed, back to a bool. I think adding another pop
948 ? ChromeUserPopulation::EXTENDED_REPORTING 952 ? ChromeUserPopulation::EXTENDED_REPORTING
949 : ChromeUserPopulation::SAFE_BROWSING; 953 : ChromeUserPopulation::SAFE_BROWSING;
950 request.mutable_population()->set_user_population(population); 954 request.mutable_population()->set_user_population(population);
951 955
952 request.set_url(SanitizeUrl(item_->GetUrlChain().back())); 956 request.set_url(SanitizeUrl(item_->GetUrlChain().back()));
953 request.mutable_digests()->set_sha256(item_->GetHash()); 957 request.mutable_digests()->set_sha256(item_->GetHash());
954 request.set_length(item_->GetReceivedBytes()); 958 request.set_length(item_->GetReceivedBytes());
955 request.set_skipped_url_whitelist(skipped_url_whitelist_); 959 request.set_skipped_url_whitelist(skipped_url_whitelist_);
956 request.set_skipped_certificate_whitelist(skipped_certificate_whitelist_); 960 request.set_skipped_certificate_whitelist(skipped_certificate_whitelist_);
957 for (size_t i = 0; i < item_->GetUrlChain().size(); ++i) { 961 for (size_t i = 0; i < item_->GetUrlChain().size(); ++i) {
958 ClientDownloadRequest::Resource* resource = request.add_resources(); 962 ClientDownloadRequest::Resource* resource = request.add_resources();
959 resource->set_url(SanitizeUrl(item_->GetUrlChain()[i])); 963 resource->set_url(SanitizeUrl(item_->GetUrlChain()[i]));
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 #endif 1178 #endif
1175 bool finished_; 1179 bool finished_;
1176 ClientDownloadRequest::DownloadType type_; 1180 ClientDownloadRequest::DownloadType type_;
1177 std::string client_download_request_data_; 1181 std::string client_download_request_data_;
1178 base::CancelableTaskTracker request_tracker_; // For HistoryService lookup. 1182 base::CancelableTaskTracker request_tracker_; // For HistoryService lookup.
1179 base::TimeTicks start_time_; // Used for stats. 1183 base::TimeTicks start_time_; // Used for stats.
1180 base::TimeTicks timeout_start_time_; 1184 base::TimeTicks timeout_start_time_;
1181 base::TimeTicks request_start_time_; 1185 base::TimeTicks request_start_time_;
1182 bool skipped_url_whitelist_; 1186 bool skipped_url_whitelist_;
1183 bool skipped_certificate_whitelist_; 1187 bool skipped_certificate_whitelist_;
1184 bool is_extended_reporting_; 1188 ExtendedReportingLevel extended_reporting_level_;
1185 bool is_incognito_; 1189 bool is_incognito_;
1186 base::WeakPtrFactory<CheckClientDownloadRequest> weakptr_factory_; 1190 base::WeakPtrFactory<CheckClientDownloadRequest> weakptr_factory_;
1187 1191
1188 DISALLOW_COPY_AND_ASSIGN(CheckClientDownloadRequest); 1192 DISALLOW_COPY_AND_ASSIGN(CheckClientDownloadRequest);
1189 }; 1193 };
1190 1194
1191 // A request for checking whether a PPAPI initiated download is safe. 1195 // A request for checking whether a PPAPI initiated download is safe.
1192 // 1196 //
1193 // These are considered different from DownloadManager mediated downloads 1197 // These are considered different from DownloadManager mediated downloads
1194 // because: 1198 // because:
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 default_file_path_(default_file_path), 1234 default_file_path_(default_file_path),
1231 alternate_extensions_(alternate_extensions), 1235 alternate_extensions_(alternate_extensions),
1232 callback_(callback), 1236 callback_(callback),
1233 service_(service), 1237 service_(service),
1234 database_manager_(database_manager), 1238 database_manager_(database_manager),
1235 start_time_(base::TimeTicks::Now()), 1239 start_time_(base::TimeTicks::Now()),
1236 supported_path_( 1240 supported_path_(
1237 GetSupportedFilePath(default_file_path, alternate_extensions)), 1241 GetSupportedFilePath(default_file_path, alternate_extensions)),
1238 weakptr_factory_(this) { 1242 weakptr_factory_(this) {
1239 DCHECK(profile); 1243 DCHECK(profile);
1240 is_extended_reporting_ = IsExtendedReportingEnabled(*profile->GetPrefs()); 1244 extended_reporting_level_ = GetExtendedReportingLevel(*profile->GetPrefs());
1241 } 1245 }
1242 1246
1243 ~PPAPIDownloadRequest() override { 1247 ~PPAPIDownloadRequest() override {
1244 if (fetcher_ && !callback_.is_null()) 1248 if (fetcher_ && !callback_.is_null())
1245 Finish(RequestOutcome::REQUEST_DESTROYED, UNKNOWN); 1249 Finish(RequestOutcome::REQUEST_DESTROYED, UNKNOWN);
1246 } 1250 }
1247 1251
1248 // Start the process of checking the download request. The callback passed as 1252 // 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 1253 // the |callback| parameter to the constructor will be invoked with the result
1250 // of the check at some point in the future. 1254 // of the check at some point in the future.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1318 // Not on whitelist, so we are going to check with the SafeBrowsing 1322 // Not on whitelist, so we are going to check with the SafeBrowsing
1319 // backend. 1323 // backend.
1320 SendRequest(); 1324 SendRequest();
1321 } 1325 }
1322 1326
1323 void SendRequest() { 1327 void SendRequest() {
1324 DVLOG(2) << __func__; 1328 DVLOG(2) << __func__;
1325 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1329 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1326 1330
1327 ClientDownloadRequest request; 1331 ClientDownloadRequest request;
1328 auto population = is_extended_reporting_ 1332 auto population = extended_reporting_level_ != SBER_LEVEL_OFF
Jialiu Lin 2016/11/17 18:47:23 Similar to above.
lpz 2016/11/17 19:46:05 Done.
1329 ? ChromeUserPopulation::EXTENDED_REPORTING 1333 ? ChromeUserPopulation::EXTENDED_REPORTING
1330 : ChromeUserPopulation::SAFE_BROWSING; 1334 : ChromeUserPopulation::SAFE_BROWSING;
1331 request.mutable_population()->set_user_population(population); 1335 request.mutable_population()->set_user_population(population);
1332 request.set_download_type(ClientDownloadRequest::PPAPI_SAVE_REQUEST); 1336 request.set_download_type(ClientDownloadRequest::PPAPI_SAVE_REQUEST);
1333 ClientDownloadRequest::Resource* resource = request.add_resources(); 1337 ClientDownloadRequest::Resource* resource = request.add_resources();
1334 resource->set_type(ClientDownloadRequest::PPAPI_DOCUMENT); 1338 resource->set_type(ClientDownloadRequest::PPAPI_DOCUMENT);
1335 resource->set_url(requestor_url_.spec()); 1339 resource->set_url(requestor_url_.spec());
1336 request.set_url(requestor_url_.spec()); 1340 request.set_url(requestor_url_.spec());
1337 request.set_file_basename(supported_path_.BaseName().AsUTF8Unsafe()); 1341 request.set_file_basename(supported_path_.BaseName().AsUTF8Unsafe());
1338 request.set_length(0); 1342 request.set_length(0);
1339 request.mutable_digests()->set_md5(std::string()); 1343 request.mutable_digests()->set_md5(std::string());
1340 for (const auto& alternate_extension : alternate_extensions_) { 1344 for (const auto& alternate_extension : alternate_extensions_) {
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1487 // Time request was started. 1491 // Time request was started.
1488 const base::TimeTicks start_time_; 1492 const base::TimeTicks start_time_;
1489 1493
1490 // A download path that is supported by SafeBrowsing. This is determined by 1494 // A download path that is supported by SafeBrowsing. This is determined by
1491 // invoking GetSupportedFilePath(). If non-empty, 1495 // invoking GetSupportedFilePath(). If non-empty,
1492 // IsCheckedBinaryFile(supported_path_) is always true. This 1496 // IsCheckedBinaryFile(supported_path_) is always true. This
1493 // path is therefore used as the download target when sending the SafeBrowsing 1497 // path is therefore used as the download target when sending the SafeBrowsing
1494 // ping. 1498 // ping.
1495 const base::FilePath supported_path_; 1499 const base::FilePath supported_path_;
1496 1500
1497 bool is_extended_reporting_; 1501 ExtendedReportingLevel extended_reporting_level_;
1498 1502
1499 base::WeakPtrFactory<PPAPIDownloadRequest> weakptr_factory_; 1503 base::WeakPtrFactory<PPAPIDownloadRequest> weakptr_factory_;
1500 1504
1501 DISALLOW_COPY_AND_ASSIGN(PPAPIDownloadRequest); 1505 DISALLOW_COPY_AND_ASSIGN(PPAPIDownloadRequest);
1502 }; 1506 };
1503 1507
1504 DownloadProtectionService::DownloadProtectionService( 1508 DownloadProtectionService::DownloadProtectionService(
1505 SafeBrowsingService* sb_service) 1509 SafeBrowsingService* sb_service)
1506 : request_context_getter_(sb_service ? sb_service->url_request_context() 1510 : request_context_getter_(sb_service ? sb_service->url_request_context()
1507 : nullptr), 1511 : nullptr),
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1771 GURL DownloadProtectionService::GetDownloadRequestUrl() { 1775 GURL DownloadProtectionService::GetDownloadRequestUrl() {
1772 GURL url(kDownloadRequestUrl); 1776 GURL url(kDownloadRequestUrl);
1773 std::string api_key = google_apis::GetAPIKey(); 1777 std::string api_key = google_apis::GetAPIKey();
1774 if (!api_key.empty()) 1778 if (!api_key.empty())
1775 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); 1779 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true));
1776 1780
1777 return url; 1781 return url;
1778 } 1782 }
1779 1783
1780 } // namespace safe_browsing 1784 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/local_database_manager.h » ('j') | chrome/browser/safe_browsing/protocol_manager.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698