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

Side by Side Diff: chrome/browser/ssl/cert_report_helper.cc

Issue 2903383002: Limit certificate error reports to running in official builds (Closed)
Patch Set: fix more tests Created 3 years, 7 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
« no previous file with comments | « chrome/browser/ssl/cert_report_helper.h ('k') | chrome/browser/ssl/ssl_browser_tests.cc » ('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 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"
(...skipping 11 matching lines...) Expand all
22 #include "components/security_interstitials/core/controller_client.h" 22 #include "components/security_interstitials/core/controller_client.h"
23 #include "components/security_interstitials/core/metrics_helper.h" 23 #include "components/security_interstitials/core/metrics_helper.h"
24 #include "components/strings/grit/components_strings.h" 24 #include "components/strings/grit/components_strings.h"
25 #include "components/variations/variations_associated_data.h" 25 #include "components/variations/variations_associated_data.h"
26 #include "content/public/browser/browser_context.h" 26 #include "content/public/browser/browser_context.h"
27 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
28 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
29 29
30 namespace { 30 namespace {
31 31
32 // Certificate reports are only sent from official builds, but this flag can be
33 // set by tests.
34 static bool g_is_fake_official_build_for_testing = false;
35
32 // Returns a pointer to the Profile associated with |web_contents|. 36 // Returns a pointer to the Profile associated with |web_contents|.
33 Profile* GetProfile(content::WebContents* web_contents) { 37 Profile* GetProfile(content::WebContents* web_contents) {
34 return Profile::FromBrowserContext(web_contents->GetBrowserContext()); 38 return Profile::FromBrowserContext(web_contents->GetBrowserContext());
35 } 39 }
36 40
37 } // namespace 41 } // namespace
38 42
39 // Constants for the HTTPSErrorReporter Finch experiment 43 // Constants for the HTTPSErrorReporter Finch experiment
40 const char CertReportHelper::kFinchExperimentName[] = "ReportCertificateErrors"; 44 const char CertReportHelper::kFinchExperimentName[] = "ReportCertificateErrors";
41 const char CertReportHelper::kFinchGroupShowPossiblySend[] = 45 const char CertReportHelper::kFinchGroupShowPossiblySend[] =
(...skipping 16 matching lines...) Expand all
58 request_url_(request_url), 62 request_url_(request_url),
59 ssl_info_(ssl_info), 63 ssl_info_(ssl_info),
60 interstitial_reason_(interstitial_reason), 64 interstitial_reason_(interstitial_reason),
61 overridable_(overridable), 65 overridable_(overridable),
62 interstitial_time_(interstitial_time), 66 interstitial_time_(interstitial_time),
63 metrics_helper_(metrics_helper) {} 67 metrics_helper_(metrics_helper) {}
64 68
65 CertReportHelper::~CertReportHelper() { 69 CertReportHelper::~CertReportHelper() {
66 } 70 }
67 71
72 // static
73 void CertReportHelper::SetFakeOfficialBuildForTesting() {
74 g_is_fake_official_build_for_testing = true;
75 }
76
68 void CertReportHelper::PopulateExtendedReportingOption( 77 void CertReportHelper::PopulateExtendedReportingOption(
69 base::DictionaryValue* load_time_data) { 78 base::DictionaryValue* load_time_data) {
70 // Only show the checkbox if not off-the-record and if this client is 79 // Only show the checkbox if not off-the-record and if this client is
71 // part of the respective Finch group, and the feature is not disabled 80 // part of the respective Finch group, and the feature is not disabled
72 // by policy. 81 // by policy.
73 const bool show = ShouldShowCertificateReporterCheckbox(); 82 const bool show = ShouldShowCertificateReporterCheckbox();
74 83
75 load_time_data->SetBoolean(security_interstitials::kDisplayCheckBox, show); 84 load_time_data->SetBoolean(security_interstitials::kDisplayCheckBox, show);
76 if (!show) 85 if (!show)
77 return; 86 return;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 const bool in_incognito = 151 const bool in_incognito =
143 web_contents_->GetBrowserContext()->IsOffTheRecord(); 152 web_contents_->GetBrowserContext()->IsOffTheRecord();
144 return base::FieldTrialList::FindFullName(kFinchExperimentName) == 153 return base::FieldTrialList::FindFullName(kFinchExperimentName) ==
145 kFinchGroupShowPossiblySend && 154 kFinchGroupShowPossiblySend &&
146 !in_incognito && 155 !in_incognito &&
147 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingOptInAllowed); 156 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingOptInAllowed);
148 } 157 }
149 158
150 bool CertReportHelper::ShouldReportCertificateError() { 159 bool CertReportHelper::ShouldReportCertificateError() {
151 DCHECK(ShouldShowCertificateReporterCheckbox()); 160 DCHECK(ShouldShowCertificateReporterCheckbox());
161
162 bool is_official_build = g_is_fake_official_build_for_testing;
Nathan Parker 2017/05/26 21:34:07 I feel like there could be a better pattern than t
163 #if defined(OFFICIAL_BUILD) && defined(GOOGLE_CHROME_BUILD)
164 is_official_build = true;
165 #endif
166
167 if (!is_official_build)
168 return false;
169
152 // Even in case the checkbox was shown, we don't send error reports 170 // Even in case the checkbox was shown, we don't send error reports
153 // for all of these users. Check the Finch configuration for a sending 171 // for all of these users. Check the Finch configuration for a sending
154 // threshold and only send reports in case the threshold isn't exceeded. 172 // threshold and only send reports in case the threshold isn't exceeded.
155 const std::string param = 173 const std::string param =
156 variations::GetVariationParamValue(kFinchExperimentName, kFinchParamName); 174 variations::GetVariationParamValue(kFinchExperimentName, kFinchParamName);
157 if (!param.empty()) { 175 if (!param.empty()) {
158 double sendingThreshold; 176 double sendingThreshold;
159 if (base::StringToDouble(param, &sendingThreshold)) { 177 if (base::StringToDouble(param, &sendingThreshold)) {
160 if (sendingThreshold >= 0.0 && sendingThreshold <= 1.0) 178 if (sendingThreshold >= 0.0 && sendingThreshold <= 1.0)
161 return base::RandDouble() <= sendingThreshold; 179 return base::RandDouble() <= sendingThreshold;
162 } 180 }
163 } 181 }
164 return false; 182 return false;
165 } 183 }
166 184
167 bool CertReportHelper::IsPrefEnabled(const char* pref) { 185 bool CertReportHelper::IsPrefEnabled(const char* pref) {
168 return GetProfile(web_contents_)->GetPrefs()->GetBoolean(pref); 186 return GetProfile(web_contents_)->GetPrefs()->GetBoolean(pref);
169 } 187 }
OLDNEW
« no previous file with comments | « chrome/browser/ssl/cert_report_helper.h ('k') | chrome/browser/ssl/ssl_browser_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698