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

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

Issue 2351873002: Clean up UMA 3g experiment and unify metrics enabled pref for Android (Closed)
Patch Set: remove optimization param Created 4 years, 3 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_reporting_state.h" 5 #include "chrome/browser/metrics/metrics_reporting_state.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 // to be done in the main thread. 54 // to be done in the main thread.
55 // As arguments this function gets: 55 // As arguments this function gets:
56 // |to_update_pref| which indicates what the desired update should be, 56 // |to_update_pref| which indicates what the desired update should be,
57 // |callback_fn| is the callback function to be called in the end 57 // |callback_fn| is the callback function to be called in the end
58 // |updated_pref| is the result of attempted update. 58 // |updated_pref| is the result of attempted update.
59 // Update considers to be successful if |to_update_pref| and |updated_pref| are 59 // Update considers to be successful if |to_update_pref| and |updated_pref| are
60 // the same. 60 // the same.
61 void SetMetricsReporting(bool to_update_pref, 61 void SetMetricsReporting(bool to_update_pref,
62 const OnMetricsReportingCallbackType& callback_fn, 62 const OnMetricsReportingCallbackType& callback_fn,
63 bool updated_pref) { 63 bool updated_pref) {
64 #if !defined(OS_ANDROID)
65 g_browser_process->local_state()->SetBoolean( 64 g_browser_process->local_state()->SetBoolean(
66 metrics::prefs::kMetricsReportingEnabled, updated_pref); 65 metrics::prefs::kMetricsReportingEnabled, updated_pref);
67 #endif // !defined(OS_ANDROID)
68 66
69 UpdateMetricsPrefsOnPermissionChange(updated_pref); 67 UpdateMetricsPrefsOnPermissionChange(updated_pref);
70 68
71 // Uses the current state of whether reporting is enabled to enable services. 69 // Uses the current state of whether reporting is enabled to enable services.
72 g_browser_process->GetMetricsServicesManager()->UpdateUploadPermissions(true); 70 g_browser_process->GetMetricsServicesManager()->UpdateUploadPermissions(true);
73 71
74 if (to_update_pref == updated_pref) { 72 if (to_update_pref == updated_pref) {
75 RecordMetricsReportingHistogramValue(updated_pref ? 73 RecordMetricsReportingHistogramValue(updated_pref ?
76 METRICS_REPORTING_ENABLED : METRICS_REPORTING_DISABLED); 74 METRICS_REPORTING_ENABLED : METRICS_REPORTING_DISABLED);
77 } else { 75 } else {
78 RecordMetricsReportingHistogramValue(METRICS_REPORTING_ERROR); 76 RecordMetricsReportingHistogramValue(METRICS_REPORTING_ERROR);
79 } 77 }
80 if (!callback_fn.is_null()) 78 if (!callback_fn.is_null())
81 callback_fn.Run(updated_pref); 79 callback_fn.Run(updated_pref);
82 } 80 }
83 81
84 #if defined(OS_CHROMEOS) 82 #if defined(OS_CHROMEOS)
85 // Callback function for Chrome OS device settings change, so that the update is 83 // Callback function for Chrome OS device settings change, so that the update is
86 // applied to metrics reporting state. 84 // applied to metrics reporting state.
87 void OnDeviceSettingChange() { 85 void OnDeviceSettingChange() {
88 bool enable_metrics = false; 86 bool enable_metrics = false;
89 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, 87 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref,
90 &enable_metrics); 88 &enable_metrics);
91 ChangeMetricsReportingState(enable_metrics); 89 ChangeMetricsReportingState(enable_metrics);
92 } 90 }
93 #endif 91 #endif
94 92
95 } // namespace 93 } // namespace
96 94
97 void ChangeMetricsReportingState(bool enabled) { 95 void ChangeMetricsReportingState(bool enabled) {
98 ChangeMetricsReportingStateWithReply(enabled, 96 ChangeMetricsReportingStateWithReply(enabled,
99 OnMetricsReportingCallbackType()); 97 OnMetricsReportingCallbackType());
100 } 98 }
101 99
102 // TODO(gayane): Instead of checking policy before setting the metrics pref set 100 // TODO(gayane): Instead of checking policy before setting the metrics pref set
103 // the pref and register for notifications for the rest of the changes. 101 // the pref and register for notifications for the rest of the changes.
104 void ChangeMetricsReportingStateWithReply( 102 void ChangeMetricsReportingStateWithReply(
105 bool enabled, 103 bool enabled,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 146
149 // TODO(gayane): Add unittest which will check that observer on device settings 147 // TODO(gayane): Add unittest which will check that observer on device settings
150 // will trigger this function and kMetricsReportinEnabled as well as metrics 148 // will trigger this function and kMetricsReportinEnabled as well as metrics
151 // service state will be updated accordingly. 149 // service state will be updated accordingly.
152 void SetupMetricsStateForChromeOS() { 150 void SetupMetricsStateForChromeOS() {
153 #if defined(OS_CHROMEOS) 151 #if defined(OS_CHROMEOS)
154 chromeos::CrosSettings::Get()->AddSettingsObserver( 152 chromeos::CrosSettings::Get()->AddSettingsObserver(
155 chromeos::kStatsReportingPref, base::Bind(&OnDeviceSettingChange)); 153 chromeos::kStatsReportingPref, base::Bind(&OnDeviceSettingChange));
156 154
157 OnDeviceSettingChange(); 155 OnDeviceSettingChange();
158 #endif // defined(OS_CHROMEOS) 156 #endif // defined(OS_CHROMEOS)
159 } 157 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/chrome_metrics_service_client.cc ('k') | chrome/browser/profiles/profile_io_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698