| 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/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/common/pref_names.h" | 9 #include "chrome/common/pref_names.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 11 | 11 |
| 12 #if defined(OS_CHROMEOS) | 12 #if defined(OS_CHROMEOS) |
| 13 #include "chrome/browser/chromeos/settings/cros_settings.h" | 13 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 14 #endif | 14 #endif |
| 15 | 15 |
| 16 // static | 16 // static |
| 17 bool ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled() { | 17 bool ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled() { |
| 18 // TODO(blundell): Fix the unittests that don't set up the UI thread and | 18 // TODO(blundell): Fix the unittests that don't set up the UI thread and |
| 19 // change this to just be DCHECK_CURRENTLY_ON(). | 19 // change this to just be DCHECK_CURRENTLY_ON(). |
| 20 DCHECK( | 20 DCHECK( |
| 21 !content::BrowserThread::IsMessageLoopValid(content::BrowserThread::UI) || | 21 !content::BrowserThread::IsMessageLoopValid(content::BrowserThread::UI) || |
| 22 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 22 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 23 | 23 |
| 24 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 24 #if !defined(OS_ANDROID) |
| 25 return IsMetricsReportingEnabled(g_browser_process->local_state()); | 25 return IsMetricsReportingEnabled(g_browser_process->local_state()); |
| 26 #else | 26 #else |
| 27 // ChromeOS and Android currently obtain the value for whether the user has | 27 // Android currently obtain the value for whether the user has |
| 28 // obtain metrics reporting in non-standard ways. | 28 // obtain metrics reporting in non-standard ways. |
| 29 // TODO(gayane): Consolidate metric prefs on all platforms and eliminate this | 29 // TODO(gayane): Consolidate metric prefs on all platforms and eliminate this |
| 30 // special-case code, instead having all platforms go through the above flow. | 30 // special-case code, instead having all platforms go through the above flow. |
| 31 // http://crbug.com/362192, http://crbug.com/532084 | 31 // http://crbug.com/362192, http://crbug.com/532084 |
| 32 bool pref_value = false; | 32 bool pref_value = false; |
| 33 | 33 |
| 34 #if defined(OS_CHROMEOS) | |
| 35 // TODO(gayane): The check is added as a temporary fix for unittests. It's | |
| 36 // not expected to happen from production code. This should be cleaned up | |
| 37 // soon when metrics pref from cros will be eliminated. | |
| 38 if (chromeos::CrosSettings::IsInitialized()) { | |
| 39 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, | |
| 40 &pref_value); | |
| 41 } | |
| 42 #else // Android | |
| 43 pref_value = g_browser_process->local_state()->GetBoolean( | 34 pref_value = g_browser_process->local_state()->GetBoolean( |
| 44 prefs::kCrashReportingEnabled); | 35 prefs::kCrashReportingEnabled); |
| 45 #endif // defined(OS_CHROMEOS) | |
| 46 | |
| 47 return IsMetricsReportingEnabledWithPrefValue(pref_value); | 36 return IsMetricsReportingEnabledWithPrefValue(pref_value); |
| 48 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 37 #endif // !defined(OS_ANDROID) |
| 49 } | 38 } |
| 50 | 39 |
| 51 // static | 40 // static |
| 52 bool ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial( | 41 bool ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial( |
| 53 const std::string& trial_name, | 42 const std::string& trial_name, |
| 54 const std::string& group_name) { | 43 const std::string& group_name) { |
| 55 return metrics::MetricsServiceAccessor::RegisterSyntheticFieldTrial( | 44 return metrics::MetricsServiceAccessor::RegisterSyntheticFieldTrial( |
| 56 g_browser_process->metrics_service(), trial_name, group_name); | 45 g_browser_process->metrics_service(), trial_name, group_name); |
| 57 } | 46 } |
| 58 | 47 |
| 59 // static | 48 // static |
| 60 bool ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrialWithNameHash( | 49 bool ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrialWithNameHash( |
| 61 uint32_t trial_name_hash, | 50 uint32_t trial_name_hash, |
| 62 const std::string& group_name) { | 51 const std::string& group_name) { |
| 63 return metrics::MetricsServiceAccessor:: | 52 return metrics::MetricsServiceAccessor:: |
| 64 RegisterSyntheticFieldTrialWithNameHash( | 53 RegisterSyntheticFieldTrialWithNameHash( |
| 65 g_browser_process->metrics_service(), trial_name_hash, group_name); | 54 g_browser_process->metrics_service(), trial_name_hash, group_name); |
| 66 } | 55 } |
| OLD | NEW |