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

Side by Side Diff: chrome/browser/metrics/metrics_services_manager.cc

Issue 886523003: Add a Rappor option in the settings page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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/metrics/metrics_services_manager.h" 5 #include "chrome/browser/metrics/metrics_services_manager.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/metrics/chrome_metrics_service_client.h" 13 #include "chrome/browser/metrics/chrome_metrics_service_client.h"
14 #include "chrome/browser/metrics/variations/variations_service.h" 14 #include "chrome/browser/metrics/variations/variations_service.h"
15 #include "chrome/browser/ui/browser_otr_state.h" 15 #include "chrome/browser/ui/browser_otr_state.h"
16 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "chrome/installer/util/google_update_settings.h" 18 #include "chrome/installer/util/google_update_settings.h"
19 #include "components/metrics/metrics_service.h" 19 #include "components/metrics/metrics_service.h"
20 #include "components/metrics/metrics_state_manager.h" 20 #include "components/metrics/metrics_state_manager.h"
21 #include "components/rappor/rappor_pref_names.h"
21 #include "components/rappor/rappor_service.h" 22 #include "components/rappor/rappor_service.h"
22 23
23 #if defined(OS_CHROMEOS) 24 #if defined(OS_CHROMEOS)
24 #include "chrome/browser/chromeos/settings/cros_settings.h" 25 #include "chrome/browser/chromeos/settings/cros_settings.h"
25 #endif 26 #endif
26 27
27 MetricsServicesManager::MetricsServicesManager(PrefService* local_state) 28 MetricsServicesManager::MetricsServicesManager(PrefService* local_state)
28 : local_state_(local_state) { 29 : local_state_(local_state) {
29 DCHECK(local_state); 30 DCHECK(local_state);
30 } 31 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 metrics_state_manager_ = metrics::MetricsStateManager::Create( 80 metrics_state_manager_ = metrics::MetricsStateManager::Create(
80 local_state_, 81 local_state_,
81 base::Bind(&MetricsServicesManager::IsMetricsReportingEnabled, 82 base::Bind(&MetricsServicesManager::IsMetricsReportingEnabled,
82 base::Unretained(this)), 83 base::Unretained(this)),
83 base::Bind(&GoogleUpdateSettings::StoreMetricsClientInfo), 84 base::Bind(&GoogleUpdateSettings::StoreMetricsClientInfo),
84 base::Bind(&GoogleUpdateSettings::LoadMetricsClientInfo)); 85 base::Bind(&GoogleUpdateSettings::LoadMetricsClientInfo));
85 } 86 }
86 return metrics_state_manager_.get(); 87 return metrics_state_manager_.get();
87 } 88 }
88 89
90 bool MetricsServicesManager::IsRapporEnabled() const {
91 if (!local_state_->HasPrefPath(rappor::prefs::kRapporEnabled)) {
92 // For upgrading users, derive a default setting from safe browsing.
93 //bool sb_enabled = local_state_->GetBoolean(prefs::kSafeBrowsingEnabled);
Steven Holte 2015/02/06 00:15:46 I'm not actually sure what the correct way to get
Alexei Svitkine (slow) 2015/02/06 16:43:33 Yes, prefs work everywhere. You need to call Regis
94 local_state_->SetBoolean(rappor::prefs::kRapporEnabled, true);
95 }
96 return local_state_->GetBoolean(rappor::prefs::kRapporEnabled);
97 }
98
89 void MetricsServicesManager::UpdatePermissions(bool may_record, 99 void MetricsServicesManager::UpdatePermissions(bool may_record,
90 bool may_upload) { 100 bool may_upload) {
91 metrics::MetricsService* metrics = GetMetricsService(); 101 metrics::MetricsService* metrics = GetMetricsService();
92 102
93 const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); 103 const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
94 104
95 const bool only_do_metrics_recording = 105 const bool only_do_metrics_recording =
96 cmdline->HasSwitch(switches::kMetricsRecordingOnly) || 106 cmdline->HasSwitch(switches::kMetricsRecordingOnly) ||
97 cmdline->HasSwitch(switches::kEnableBenchmarking); 107 cmdline->HasSwitch(switches::kEnableBenchmarking);
98 108
99 if (only_do_metrics_recording) { 109 if (only_do_metrics_recording) {
100 metrics->StartRecordingForTests(); 110 metrics->StartRecordingForTests();
101 GetRapporService()->Update(rappor::FINE_LEVEL, false); 111 GetRapporService()->Update(rappor::FINE_LEVEL, false);
102 return; 112 return;
103 } 113 }
104 114
105 if (may_record) { 115 if (may_record) {
106 if (!metrics->recording_active()) 116 if (!metrics->recording_active())
107 metrics->Start(); 117 metrics->Start();
108 118
109 if (may_upload) 119 if (may_upload)
110 metrics->EnableReporting(); 120 metrics->EnableReporting();
111 else 121 else
112 metrics->DisableReporting(); 122 metrics->DisableReporting();
113 } else if (metrics->recording_active() || metrics->reporting_active()) { 123 } else if (metrics->recording_active() || metrics->reporting_active()) {
114 metrics->Stop(); 124 metrics->Stop();
115 } 125 }
116 126
117 rappor::RecordingLevel recording_level = may_record ? 127 rappor::RecordingLevel recording_level = rappor::RECORDING_DISABLED;
118 rappor::FINE_LEVEL : rappor::RECORDING_DISABLED; 128 #if defined(GOOGLE_CHROME_BUILD)
129 #if defined(OS_IOS) || defined(OS_ANDROID)
130 if (may_record) {
131 recording_level = rappor::FINE_LEVEL;
132 }
133 #else // defined(OS_IOS) || defined(OS_ANDROID)
134 if (IsRapporEnabled()) {
135 recording_level = may_record ? rappor::FINE_LEVEL : rappor::COARSE_LEVEL;
136 }
137 #endif // defined(OS_IOS) || defined(OS_ANDROID)
138 #endif // defined(GOOGLE_CHROME_BUILD)
119 GetRapporService()->Update(recording_level, may_upload); 139 GetRapporService()->Update(recording_level, may_upload);
120 } 140 }
121 141
122 // TODO(asvitkine): This function does not report the correct value on Android, 142 // TODO(asvitkine): This function does not report the correct value on Android,
123 // see http://crbug.com/362192. 143 // see http://crbug.com/362192.
124 bool MetricsServicesManager::IsMetricsReportingEnabled() const { 144 bool MetricsServicesManager::IsMetricsReportingEnabled() const {
125 // If the user permits metrics reporting with the checkbox in the 145 // If the user permits metrics reporting with the checkbox in the
126 // prefs, we turn on recording. We disable metrics completely for 146 // prefs, we turn on recording. We disable metrics completely for
127 // non-official builds, or when field trials are forced. 147 // non-official builds, or when field trials are forced.
128 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 148 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
129 switches::kForceFieldTrials)) 149 switches::kForceFieldTrials))
130 return false; 150 return false;
131 151
132 bool enabled = false; 152 bool enabled = false;
133 #if defined(GOOGLE_CHROME_BUILD) 153 #if defined(GOOGLE_CHROME_BUILD)
134 #if defined(OS_CHROMEOS) 154 #if defined(OS_CHROMEOS)
135 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, 155 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref,
136 &enabled); 156 &enabled);
137 #else 157 #else
138 enabled = local_state_->GetBoolean(prefs::kMetricsReportingEnabled); 158 enabled = local_state_->GetBoolean(prefs::kMetricsReportingEnabled);
139 #endif // #if defined(OS_CHROMEOS) 159 #endif // #if defined(OS_CHROMEOS)
140 #endif // defined(GOOGLE_CHROME_BUILD) 160 #endif // defined(GOOGLE_CHROME_BUILD)
141 return enabled; 161 return enabled;
142 } 162 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/metrics_services_manager.h ('k') | chrome/browser/resources/options/browser_options.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698