| OLD | NEW |
| 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/chrome_metrics_service_accessor.h" | 5 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" |
| 7 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 8 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/metrics/metrics_services_manager.h" |
| 11 #include "chrome/common/chrome_switches.h" |
| 9 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 10 #include "components/metrics/metrics_service.h" | 13 #include "components/metrics/metrics_service.h" |
| 11 #include "components/variations/metrics_util.h" | 14 #include "components/variations/metrics_util.h" |
| 12 | 15 |
| 13 #if defined(OS_CHROMEOS) | 16 #if defined(OS_CHROMEOS) |
| 14 #include "chrome/browser/chromeos/settings/cros_settings.h" | 17 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 15 #endif | 18 #endif |
| 16 | 19 |
| 17 // static | 20 // static |
| 21 // TODO(asvitkine): This function does not report the correct value on Android, |
| 22 // see http://crbug.com/362192. |
| 18 bool ChromeMetricsServiceAccessor::IsMetricsReportingEnabled() { | 23 bool ChromeMetricsServiceAccessor::IsMetricsReportingEnabled() { |
| 19 bool result = false; | 24 // If the user permits metrics reporting with the checkbox in the |
| 20 const PrefService* local_state = g_browser_process->local_state(); | 25 // prefs, we turn on recording. We disable metrics completely for |
| 21 if (local_state) { | 26 // non-official builds, or when field trials are forced. |
| 22 const PrefService::Preference* uma_pref = | 27 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 23 local_state->FindPreference(prefs::kMetricsReportingEnabled); | 28 switches::kForceFieldTrials)) { |
| 24 if (uma_pref) { | 29 return false; |
| 25 bool success = uma_pref->GetValue()->GetAsBoolean(&result); | |
| 26 DCHECK(success); | |
| 27 } | |
| 28 } | 30 } |
| 29 return result; | 31 |
| 32 bool enabled = false; |
| 33 #if defined(GOOGLE_CHROME_BUILD) |
| 34 #if defined(OS_CHROMEOS) |
| 35 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, |
| 36 &enabled); |
| 37 #else |
| 38 enabled = g_browser_process->local_state()-> |
| 39 GetBoolean(prefs::kMetricsReportingEnabled); |
| 40 #endif // #if defined(OS_CHROMEOS) |
| 41 #endif // defined(GOOGLE_CHROME_BUILD) |
| 42 return enabled; |
| 30 } | 43 } |
| 31 | 44 |
| 32 bool ChromeMetricsServiceAccessor::IsCrashReportingEnabled() { | 45 bool ChromeMetricsServiceAccessor::IsCrashReportingEnabled() { |
| 33 #if defined(GOOGLE_CHROME_BUILD) | 46 #if defined(GOOGLE_CHROME_BUILD) |
| 34 #if defined(OS_CHROMEOS) | 47 #if defined(OS_ANDROID) |
| 35 bool reporting_enabled = false; | |
| 36 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, | |
| 37 &reporting_enabled); | |
| 38 return reporting_enabled; | |
| 39 #elif defined(OS_ANDROID) | |
| 40 // Android has its own settings for metrics / crash uploading. | 48 // Android has its own settings for metrics / crash uploading. |
| 41 const PrefService* prefs = g_browser_process->local_state(); | 49 const PrefService* prefs = g_browser_process->local_state(); |
| 42 return prefs->GetBoolean(prefs::kCrashReportingEnabled); | 50 return prefs->GetBoolean(prefs::kCrashReportingEnabled); |
| 43 #else | 51 #else |
| 44 return ChromeMetricsServiceAccessor::IsMetricsReportingEnabled(); | 52 return ChromeMetricsServiceAccessor::IsMetricsReportingEnabled(); |
| 45 #endif | 53 #endif |
| 46 #else | 54 #else |
| 47 return false; | 55 return false; |
| 48 #endif | 56 #endif |
| 49 } | 57 } |
| 50 | 58 |
| 51 // static | 59 // static |
| 52 bool ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial( | 60 bool ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial( |
| 53 const std::string& trial_name, | 61 const std::string& trial_name, |
| 54 const std::string& group_name) { | 62 const std::string& group_name) { |
| 55 return RegisterSyntheticFieldTrialWithNameHash(metrics::HashName(trial_name), | 63 return RegisterSyntheticFieldTrialWithNameHash(metrics::HashName(trial_name), |
| 56 group_name); | 64 group_name); |
| 57 } | 65 } |
| 58 | 66 |
| 59 // static | 67 // static |
| 60 bool ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrialWithNameHash( | 68 bool ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrialWithNameHash( |
| 61 uint32_t trial_name_hash, | 69 uint32_t trial_name_hash, |
| 62 const std::string& group_name) { | 70 const std::string& group_name) { |
| 63 return metrics::MetricsServiceAccessor::RegisterSyntheticFieldTrial( | 71 return metrics::MetricsServiceAccessor::RegisterSyntheticFieldTrial( |
| 64 g_browser_process->metrics_service(), | 72 g_browser_process->metrics_service(), |
| 65 trial_name_hash, | 73 trial_name_hash, |
| 66 metrics::HashName(group_name)); | 74 metrics::HashName(group_name)); |
| 67 } | 75 } |
| OLD | NEW |