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

Side by Side Diff: chrome/browser/ssl/cert_report_helper.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/ssl/cert_report_helper.h" 5 #include "chrome/browser/ssl/cert_report_helper.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
11 #include "base/rand_util.h" 11 #include "base/rand_util.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ssl/ssl_cert_reporter.h" 17 #include "chrome/browser/ssl/ssl_cert_reporter.h"
18 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
19 #include "chrome/grit/generated_resources.h" 19 #include "chrome/grit/generated_resources.h"
20 #include "components/prefs/pref_service.h" 20 #include "components/prefs/pref_service.h"
21 #include "components/safe_browsing_db/safe_browsing_prefs.h"
21 #include "components/security_interstitials/core/controller_client.h" 22 #include "components/security_interstitials/core/controller_client.h"
22 #include "components/security_interstitials/core/metrics_helper.h" 23 #include "components/security_interstitials/core/metrics_helper.h"
23 #include "components/variations/variations_associated_data.h" 24 #include "components/variations/variations_associated_data.h"
24 #include "content/public/browser/browser_context.h" 25 #include "content/public/browser/browser_context.h"
25 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
26 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
27 28
29 namespace {
30
31 // Returns a pointer to the Profile associated with |web_contents|.
32 Profile* GetProfile(content::WebContents* web_contents) {
33 return Profile::FromBrowserContext(web_contents->GetBrowserContext());
34 }
35
36 } // namespace
37
28 // Constants for the HTTPSErrorReporter Finch experiment 38 // Constants for the HTTPSErrorReporter Finch experiment
29 const char CertReportHelper::kFinchExperimentName[] = "ReportCertificateErrors"; 39 const char CertReportHelper::kFinchExperimentName[] = "ReportCertificateErrors";
30 const char CertReportHelper::kFinchGroupShowPossiblySend[] = 40 const char CertReportHelper::kFinchGroupShowPossiblySend[] =
31 "ShowAndPossiblySend"; 41 "ShowAndPossiblySend";
32 const char CertReportHelper::kFinchGroupDontShowDontSend[] = 42 const char CertReportHelper::kFinchGroupDontShowDontSend[] =
33 "DontShowAndDontSend"; 43 "DontShowAndDontSend";
34 const char CertReportHelper::kFinchParamName[] = "sendingThreshold"; 44 const char CertReportHelper::kFinchParamName[] = "sendingThreshold";
35 45
36 CertReportHelper::CertReportHelper( 46 CertReportHelper::CertReportHelper(
37 std::unique_ptr<SSLCertReporter> ssl_cert_reporter, 47 std::unique_ptr<SSLCertReporter> ssl_cert_reporter,
(...skipping 18 matching lines...) Expand all
56 base::DictionaryValue* load_time_data) { 66 base::DictionaryValue* load_time_data) {
57 // Only show the checkbox if not off-the-record and if this client is 67 // Only show the checkbox if not off-the-record and if this client is
58 // part of the respective Finch group, and the feature is not disabled 68 // part of the respective Finch group, and the feature is not disabled
59 // by policy. 69 // by policy.
60 const bool show = ShouldShowCertificateReporterCheckbox(); 70 const bool show = ShouldShowCertificateReporterCheckbox();
61 71
62 load_time_data->SetBoolean(security_interstitials::kDisplayCheckBox, show); 72 load_time_data->SetBoolean(security_interstitials::kDisplayCheckBox, show);
63 if (!show) 73 if (!show)
64 return; 74 return;
65 75
66 load_time_data->SetBoolean( 76 load_time_data->SetBoolean(security_interstitials::kBoxChecked,
67 security_interstitials::kBoxChecked, 77 safe_browsing::IsExtendedReportingEnabled(
68 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingEnabled)); 78 *GetProfile(web_contents_)->GetPrefs()));
69 79
70 const std::string privacy_link = base::StringPrintf( 80 const std::string privacy_link = base::StringPrintf(
71 security_interstitials::kPrivacyLinkHtml, 81 security_interstitials::kPrivacyLinkHtml,
72 security_interstitials::CMD_OPEN_REPORTING_PRIVACY, 82 security_interstitials::CMD_OPEN_REPORTING_PRIVACY,
73 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE).c_str()); 83 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE).c_str());
74 84
75 load_time_data->SetString( 85 load_time_data->SetString(
76 security_interstitials::kOptInLink, 86 security_interstitials::kOptInLink,
77 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE, 87 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE,
78 base::UTF8ToUTF16(privacy_link))); 88 base::UTF8ToUTF16(privacy_link)));
79 } 89 }
80 90
81 void CertReportHelper::FinishCertCollection( 91 void CertReportHelper::FinishCertCollection(
82 certificate_reporting::ErrorReport::ProceedDecision user_proceeded) { 92 certificate_reporting::ErrorReport::ProceedDecision user_proceeded) {
83 if (!ShouldShowCertificateReporterCheckbox()) 93 if (!ShouldShowCertificateReporterCheckbox())
84 return; 94 return;
85 95
86 if (!IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingEnabled)) 96 if (!safe_browsing::IsExtendedReportingEnabled(
97 *GetProfile(web_contents_)->GetPrefs()))
87 return; 98 return;
88 99
89 if (metrics_helper_) { 100 if (metrics_helper_) {
90 metrics_helper_->RecordUserInteraction( 101 metrics_helper_->RecordUserInteraction(
91 security_interstitials::MetricsHelper::EXTENDED_REPORTING_IS_ENABLED); 102 security_interstitials::MetricsHelper::EXTENDED_REPORTING_IS_ENABLED);
92 } 103 }
93 104
94 if (!ShouldReportCertificateError()) 105 if (!ShouldReportCertificateError())
95 return; 106 return;
96 107
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 double sendingThreshold; 149 double sendingThreshold;
139 if (base::StringToDouble(param, &sendingThreshold)) { 150 if (base::StringToDouble(param, &sendingThreshold)) {
140 if (sendingThreshold >= 0.0 && sendingThreshold <= 1.0) 151 if (sendingThreshold >= 0.0 && sendingThreshold <= 1.0)
141 return base::RandDouble() <= sendingThreshold; 152 return base::RandDouble() <= sendingThreshold;
142 } 153 }
143 } 154 }
144 return false; 155 return false;
145 } 156 }
146 157
147 bool CertReportHelper::IsPrefEnabled(const char* pref) { 158 bool CertReportHelper::IsPrefEnabled(const char* pref) {
148 Profile* profile = 159 return GetProfile(web_contents_)->GetPrefs()->GetBoolean(pref);
149 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
150 return profile->GetPrefs()->GetBoolean(pref);
151 } 160 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/ui_manager.cc ('k') | chrome/browser/ssl/certificate_reporting_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698