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

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

Issue 2793393002: CrOS settings/metrics: Correctly store Subscriptions (Closed)
Patch Set: . Created 3 years, 8 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/metrics/chrome_metrics_services_manager_client.h" 5 #include "chrome/browser/metrics/chrome_metrics_services_manager_client.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/feature_list.h" 8 #include "base/feature_list.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 15 matching lines...) Expand all
26 #include "components/version_info/version_info.h" 26 #include "components/version_info/version_info.h"
27 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
28 28
29 #if defined(OS_WIN) 29 #if defined(OS_WIN)
30 #include "base/win/registry.h" 30 #include "base/win/registry.h"
31 #include "chrome/common/chrome_constants.h" 31 #include "chrome/common/chrome_constants.h"
32 #include "chrome/install_static/install_util.h" 32 #include "chrome/install_static/install_util.h"
33 #include "components/crash/content/app/crashpad.h" 33 #include "components/crash/content/app/crashpad.h"
34 #endif // OS_WIN 34 #endif // OS_WIN
35 35
36 #if defined(OS_CHROMEOS)
37 #include "chromeos/settings/cros_settings_names.h"
38 #endif // defined(OS_CHROMEOS)
39
36 namespace { 40 namespace {
37 41
38 #if defined(OS_WIN) 42 #if defined(OS_WIN)
39 // Type for the function pointer to enable and disable crash reporting on 43 // Type for the function pointer to enable and disable crash reporting on
40 // windows. Needed because the function is loaded from chrome_elf. 44 // windows. Needed because the function is loaded from chrome_elf.
41 typedef void (*SetUploadConsentPointer)(bool); 45 typedef void (*SetUploadConsentPointer)(bool);
42 46
43 // The name of the function used to set the uploads enabled state in 47 // The name of the function used to set the uploads enabled state in
44 // components/crash/content/app/crashpad.cc. This is used to call the function 48 // components/crash/content/app/crashpad.cc. This is used to call the function
45 // exported by the chrome_elf dll. 49 // exported by the chrome_elf dll.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 } 89 }
86 90
87 // Only clients that were given an opt-out metrics-reporting consent flow are 91 // Only clients that were given an opt-out metrics-reporting consent flow are
88 // eligible for sampling. 92 // eligible for sampling.
89 bool IsClientEligibleForSampling() { 93 bool IsClientEligibleForSampling() {
90 return metrics::GetMetricsReportingDefaultState( 94 return metrics::GetMetricsReportingDefaultState(
91 g_browser_process->local_state()) == 95 g_browser_process->local_state()) ==
92 metrics::EnableMetricsDefault::OPT_OUT; 96 metrics::EnableMetricsDefault::OPT_OUT;
93 } 97 }
94 98
99 #if defined(OS_CHROMEOS)
100 // Callback to update the metrics reporting state when the Chrome OS metrics
101 // reporting setting changes.
102 void OnCrosMetricsReportingSettingChange() {
103 bool enable_metrics = false;
104 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref,
105 &enable_metrics);
106 ChangeMetricsReportingState(enable_metrics);
107 }
108 #endif
109
95 } // namespace 110 } // namespace
96 111
97 112
98 class ChromeMetricsServicesManagerClient::ChromeEnabledStateProvider 113 class ChromeMetricsServicesManagerClient::ChromeEnabledStateProvider
99 : public metrics::EnabledStateProvider { 114 : public metrics::EnabledStateProvider {
100 public: 115 public:
101 ChromeEnabledStateProvider() {} 116 ChromeEnabledStateProvider() {}
102 ~ChromeEnabledStateProvider() override {} 117 ~ChromeEnabledStateProvider() override {}
103 118
104 bool IsConsentGiven() override { 119 bool IsConsentGiven() override {
105 return ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); 120 return ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled();
106 } 121 }
107 122
108 bool IsReportingEnabled() override { 123 bool IsReportingEnabled() override {
109 return IsConsentGiven() && 124 return IsConsentGiven() &&
110 ChromeMetricsServicesManagerClient::IsClientInSample(); 125 ChromeMetricsServicesManagerClient::IsClientInSample();
111 } 126 }
112 127
113 DISALLOW_COPY_AND_ASSIGN(ChromeEnabledStateProvider); 128 DISALLOW_COPY_AND_ASSIGN(ChromeEnabledStateProvider);
114 }; 129 };
115 130
116 ChromeMetricsServicesManagerClient::ChromeMetricsServicesManagerClient( 131 ChromeMetricsServicesManagerClient::ChromeMetricsServicesManagerClient(
117 PrefService* local_state) 132 PrefService* local_state)
118 : enabled_state_provider_(new ChromeEnabledStateProvider()), 133 : enabled_state_provider_(new ChromeEnabledStateProvider()),
119 local_state_(local_state) { 134 local_state_(local_state) {
120 DCHECK(local_state); 135 DCHECK(local_state);
121 136
122 SetupMetricsStateForChromeOS(); 137 #if defined(OS_CHROMEOS)
138 cros_settings_observer_ = chromeos::CrosSettings::Get()->AddSettingsObserver(
139 chromeos::kStatsReportingPref,
140 base::Bind(&OnCrosMetricsReportingSettingChange));
141 // Invoke the callback once initially to set the metrics reporting state.
142 OnCrosMetricsReportingSettingChange();
143 #endif
123 } 144 }
124 145
125 ChromeMetricsServicesManagerClient::~ChromeMetricsServicesManagerClient() {} 146 ChromeMetricsServicesManagerClient::~ChromeMetricsServicesManagerClient() {}
126 147
127 // static 148 // static
128 void ChromeMetricsServicesManagerClient::CreateFallbackSamplingTrial( 149 void ChromeMetricsServicesManagerClient::CreateFallbackSamplingTrial(
129 version_info::Channel channel, 150 version_info::Channel channel,
130 base::FeatureList* feature_list) { 151 base::FeatureList* feature_list) {
131 // The trial name must be kept in sync with the server config controlling 152 // The trial name must be kept in sync with the server config controlling
132 // sampling. If they don't match, then clients will be shuffled into different 153 // sampling. If they don't match, then clients will be shuffled into different
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 ChromeMetricsServicesManagerClient::GetMetricsStateManager() { 289 ChromeMetricsServicesManagerClient::GetMetricsStateManager() {
269 DCHECK(thread_checker_.CalledOnValidThread()); 290 DCHECK(thread_checker_.CalledOnValidThread());
270 if (!metrics_state_manager_) { 291 if (!metrics_state_manager_) {
271 metrics_state_manager_ = metrics::MetricsStateManager::Create( 292 metrics_state_manager_ = metrics::MetricsStateManager::Create(
272 local_state_, enabled_state_provider_.get(), 293 local_state_, enabled_state_provider_.get(),
273 base::Bind(&PostStoreMetricsClientInfo), 294 base::Bind(&PostStoreMetricsClientInfo),
274 base::Bind(&GoogleUpdateSettings::LoadMetricsClientInfo)); 295 base::Bind(&GoogleUpdateSettings::LoadMetricsClientInfo));
275 } 296 }
276 return metrics_state_manager_.get(); 297 return metrics_state_manager_.get();
277 } 298 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/chrome_metrics_services_manager_client.h ('k') | chrome/browser/metrics/metrics_reporting_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698