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

Side by Side Diff: chrome/browser/safe_browsing/incident_reporting/incident_reporting_service.cc

Issue 2418813002: [Reland] Refactoring of SBER preference usage (Closed)
Patch Set: Sync Created 4 years, 2 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/incident_reporting/incident_reporting_ser vice.h" 5 #include "chrome/browser/safe_browsing/incident_reporting/incident_reporting_ser vice.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 21 matching lines...) Expand all
32 #include "chrome/browser/safe_browsing/incident_reporting/incident_receiver.h" 32 #include "chrome/browser/safe_browsing/incident_reporting/incident_receiver.h"
33 #include "chrome/browser/safe_browsing/incident_reporting/incident_report_upload er_impl.h" 33 #include "chrome/browser/safe_browsing/incident_reporting/incident_report_upload er_impl.h"
34 #include "chrome/browser/safe_browsing/incident_reporting/preference_validation_ delegate.h" 34 #include "chrome/browser/safe_browsing/incident_reporting/preference_validation_ delegate.h"
35 #include "chrome/browser/safe_browsing/incident_reporting/state_store.h" 35 #include "chrome/browser/safe_browsing/incident_reporting/state_store.h"
36 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 36 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
37 #include "chrome/common/chrome_features.h" 37 #include "chrome/common/chrome_features.h"
38 #include "chrome/common/pref_names.h" 38 #include "chrome/common/pref_names.h"
39 #include "chrome/common/safe_browsing/csd.pb.h" 39 #include "chrome/common/safe_browsing/csd.pb.h"
40 #include "components/prefs/pref_service.h" 40 #include "components/prefs/pref_service.h"
41 #include "components/safe_browsing_db/database_manager.h" 41 #include "components/safe_browsing_db/database_manager.h"
42 #include "components/safe_browsing_db/safe_browsing_prefs.h"
42 #include "components/user_prefs/tracked/tracked_preference_validation_delegate.h " 43 #include "components/user_prefs/tracked/tracked_preference_validation_delegate.h "
43 #include "content/public/browser/browser_thread.h" 44 #include "content/public/browser/browser_thread.h"
44 #include "content/public/browser/notification_service.h" 45 #include "content/public/browser/notification_service.h"
45 #include "net/url_request/url_request_context_getter.h" 46 #include "net/url_request/url_request_context_getter.h"
46 47
47 namespace safe_browsing { 48 namespace safe_browsing {
48 49
49 #if !defined(GOOGLE_CHROME_BUILD) 50 #if !defined(GOOGLE_CHROME_BUILD)
50 // Chromium-only flag to disable incident uploads. 51 // Chromium-only flag to disable incident uploads.
51 extern const base::Feature kIncidentReportingDisableUpload{ 52 extern const base::Feature kIncidentReportingDisableUpload{
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 129
129 bool ProfileCanAcceptIncident(Profile* profile, const Incident& incident) { 130 bool ProfileCanAcceptIncident(Profile* profile, const Incident& incident) {
130 if (profile->IsOffTheRecord()) 131 if (profile->IsOffTheRecord())
131 return false; 132 return false;
132 if (!profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)) 133 if (!profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled))
133 return false; 134 return false;
134 switch (incident.GetMinimumProfileConsent()) { 135 switch (incident.GetMinimumProfileConsent()) {
135 case MinimumProfileConsent::SAFE_BROWSING_ENABLED: 136 case MinimumProfileConsent::SAFE_BROWSING_ENABLED:
136 return true; 137 return true;
137 case MinimumProfileConsent::SAFE_BROWSING_EXTENDED_REPORTING_ENABLED: 138 case MinimumProfileConsent::SAFE_BROWSING_EXTENDED_REPORTING_ENABLED:
138 return profile->GetPrefs()->GetBoolean( 139 return IsExtendedReportingEnabled(*profile->GetPrefs());
139 prefs::kSafeBrowsingExtendedReportingEnabled);
140 } 140 }
141 NOTREACHED(); 141 NOTREACHED();
142 return false; 142 return false;
143 } 143 }
144 144
145 // Returns the shutdown behavior for the task runners of the incident reporting 145 // Returns the shutdown behavior for the task runners of the incident reporting
146 // service. Current metrics suggest that CONTINUE_ON_SHUTDOWN will reduce the 146 // service. Current metrics suggest that CONTINUE_ON_SHUTDOWN will reduce the
147 // number of browser hangs on shutdown. 147 // number of browser hangs on shutdown.
148 base::SequencedWorkerPool::WorkerShutdown GetShutdownBehavior() { 148 base::SequencedWorkerPool::WorkerShutdown GetShutdownBehavior() {
149 return base::FeatureList::IsEnabled(features::kBrowserHangFixesExperiment) 149 return base::FeatureList::IsEnabled(features::kBrowserHangFixesExperiment)
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 } 321 }
322 322
323 // static 323 // static
324 bool IncidentReportingService::IsEnabledForProfile(Profile* profile) { 324 bool IncidentReportingService::IsEnabledForProfile(Profile* profile) {
325 if (profile->IsOffTheRecord()) 325 if (profile->IsOffTheRecord())
326 return false; 326 return false;
327 if (!profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)) 327 if (!profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled))
328 return false; 328 return false;
329 if (IsFieldTrialEnabled()) 329 if (IsFieldTrialEnabled())
330 return true; 330 return true;
331 return profile->GetPrefs()->GetBoolean( 331 return IsExtendedReportingEnabled(*profile->GetPrefs());
332 prefs::kSafeBrowsingExtendedReportingEnabled);
333 } 332 }
334 333
335 IncidentReportingService::IncidentReportingService( 334 IncidentReportingService::IncidentReportingService(
336 SafeBrowsingService* safe_browsing_service) 335 SafeBrowsingService* safe_browsing_service)
337 : database_manager_(safe_browsing_service 336 : database_manager_(safe_browsing_service
338 ? safe_browsing_service->database_manager() 337 ? safe_browsing_service->database_manager()
339 : nullptr), 338 : nullptr),
340 url_request_context_getter_( 339 url_request_context_getter_(
341 safe_browsing_service ? safe_browsing_service->url_request_context() 340 safe_browsing_service ? safe_browsing_service->url_request_context()
342 : nullptr), 341 : nullptr),
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 433
435 // |callback| will be run on the blocking pool. The receiver will bounce back 434 // |callback| will be run on the blocking pool. The receiver will bounce back
436 // to the origin thread if needed. 435 // to the origin thread if needed.
437 extended_reporting_only_delayed_analysis_callbacks_.RegisterCallback( 436 extended_reporting_only_delayed_analysis_callbacks_.RegisterCallback(
438 base::Bind(callback, base::Passed(GetIncidentReceiver()))); 437 base::Bind(callback, base::Passed(GetIncidentReceiver())));
439 438
440 // Start running the callbacks if any profiles have opted into Safebrowsing 439 // Start running the callbacks if any profiles have opted into Safebrowsing
441 // extended reporting. If none are now, running will commence if/when such a 440 // extended reporting. If none are now, running will commence if/when such a
442 // profile is added. 441 // profile is added.
443 Profile* profile = FindEligibleProfile(); 442 Profile* profile = FindEligibleProfile();
444 if (profile && 443 if (profile && IsExtendedReportingEnabled(*profile->GetPrefs())) {
445 profile->GetPrefs()->GetBoolean(
446 prefs::kSafeBrowsingExtendedReportingEnabled)) {
447 extended_reporting_only_delayed_analysis_callbacks_.Start(); 444 extended_reporting_only_delayed_analysis_callbacks_.Start();
448 } 445 }
449 } 446 }
450 447
451 void IncidentReportingService::AddDownloadManager( 448 void IncidentReportingService::AddDownloadManager(
452 content::DownloadManager* download_manager) { 449 content::DownloadManager* download_manager) {
453 download_metadata_manager_.AddDownloadManager(download_manager); 450 download_metadata_manager_.AddDownloadManager(download_manager);
454 } 451 }
455 452
456 IncidentReportingService::IncidentReportingService( 453 IncidentReportingService::IncidentReportingService(
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 LogIncidentDataType(DROPPED, *incident); 523 LogIncidentDataType(DROPPED, *incident);
527 context->incidents.clear(); 524 context->incidents.clear();
528 } 525 }
529 526
530 if (enabled_for_profile) { 527 if (enabled_for_profile) {
531 // Start processing delayed analysis callbacks if incident reporting is 528 // Start processing delayed analysis callbacks if incident reporting is
532 // enabled for this new profile. Start is idempotent, so this is safe even 529 // enabled for this new profile. Start is idempotent, so this is safe even
533 // if they're already running. 530 // if they're already running.
534 delayed_analysis_callbacks_.Start(); 531 delayed_analysis_callbacks_.Start();
535 532
536 if (profile->GetPrefs()->GetBoolean( 533 if (IsExtendedReportingEnabled(*profile->GetPrefs())) {
537 prefs::kSafeBrowsingExtendedReportingEnabled)) {
538 extended_reporting_only_delayed_analysis_callbacks_.Start(); 534 extended_reporting_only_delayed_analysis_callbacks_.Start();
539 } 535 }
540 536
541 // Start a new report if there are process-wide incidents, or incidents for 537 // Start a new report if there are process-wide incidents, or incidents for
542 // this profile. 538 // this profile.
543 if ((GetProfileContext(nullptr) && 539 if ((GetProfileContext(nullptr) &&
544 GetProfileContext(nullptr)->HasIncidents()) || 540 GetProfileContext(nullptr)->HasIncidents()) ||
545 context->HasIncidents()) { 541 context->HasIncidents()) {
546 BeginReportProcessing(); 542 BeginReportProcessing();
547 } 543 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 // Skip over profiles that have yet to be added to the profile manager. 629 // Skip over profiles that have yet to be added to the profile manager.
634 // This will also skip over the NULL-profile context used to hold 630 // This will also skip over the NULL-profile context used to hold
635 // process-wide incidents. 631 // process-wide incidents.
636 if (!scan->second->added) 632 if (!scan->second->added)
637 continue; 633 continue;
638 // Also skip over profiles for which IncidentReporting is not enabled. 634 // Also skip over profiles for which IncidentReporting is not enabled.
639 if (!IsEnabledForProfile(scan->first)) 635 if (!IsEnabledForProfile(scan->first))
640 continue; 636 continue;
641 // If the current profile has Extended Reporting enabled, stop looking and 637 // If the current profile has Extended Reporting enabled, stop looking and
642 // use that one. 638 // use that one.
643 if (scan->first->GetPrefs()->GetBoolean( 639 if (IsExtendedReportingEnabled(*scan->first->GetPrefs())) {
644 prefs::kSafeBrowsingExtendedReportingEnabled)) {
645 return scan->first; 640 return scan->first;
646 } 641 }
647 // Otherwise, store this one as a candidate and keep looking (in case we 642 // Otherwise, store this one as a candidate and keep looking (in case we
648 // find one with Extended Reporting enabled). 643 // find one with Extended Reporting enabled).
649 candidate = scan->first; 644 candidate = scan->first;
650 } 645 }
651 646
652 return candidate; 647 return candidate;
653 } 648 }
654 649
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 902
908 ClientIncidentReport_EnvironmentData_Process* process = 903 ClientIncidentReport_EnvironmentData_Process* process =
909 report->mutable_environment()->mutable_process(); 904 report->mutable_environment()->mutable_process();
910 905
911 process->set_metrics_consent( 906 process->set_metrics_consent(
912 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()); 907 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled());
913 908
914 // Find the profile that benefits from the strongest protections. 909 // Find the profile that benefits from the strongest protections.
915 Profile* eligible_profile = FindEligibleProfile(); 910 Profile* eligible_profile = FindEligibleProfile();
916 process->set_extended_consent( 911 process->set_extended_consent(
917 eligible_profile ? eligible_profile->GetPrefs()->GetBoolean( 912 eligible_profile &&
918 prefs::kSafeBrowsingExtendedReportingEnabled) : 913 IsExtendedReportingEnabled(*eligible_profile->GetPrefs()));
919 false);
920 914
921 process->set_field_trial_participant(enabled_by_field_trial_); 915 process->set_field_trial_participant(enabled_by_field_trial_);
922 916
923 // Associate process-wide incidents with the profile that benefits from the 917 // Associate process-wide incidents with the profile that benefits from the
924 // strongest safe browsing protections. If there is no such profile, drop the 918 // strongest safe browsing protections. If there is no such profile, drop the
925 // incidents. 919 // incidents.
926 ProfileContext* null_context = GetProfileContext(nullptr); 920 ProfileContext* null_context = GetProfileContext(nullptr);
927 if (null_context && null_context->HasIncidents()) { 921 if (null_context && null_context->HasIncidents()) {
928 if (eligible_profile) { 922 if (eligible_profile) {
929 ProfileContext* eligible_context = GetProfileContext(eligible_profile); 923 ProfileContext* eligible_context = GetProfileContext(eligible_profile);
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 if (!profile->IsOffTheRecord()) 1135 if (!profile->IsOffTheRecord())
1142 OnProfileDestroyed(profile); 1136 OnProfileDestroyed(profile);
1143 break; 1137 break;
1144 } 1138 }
1145 default: 1139 default:
1146 break; 1140 break;
1147 } 1141 }
1148 } 1142 }
1149 1143
1150 } // namespace safe_browsing 1144 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698