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 // This is only possible during unit tests. If the unit test didn't set the |
| 25 // local_state then it doesn't care about pref value and therefore we return |
| 26 // false. |
| 27 if (!g_browser_process->local_state()) { |
| 28 DLOG(WARNING) << "Local state has not been set and pref cannot be read"; |
| 29 return false; |
| 30 } |
| 31 |
| 32 #if !defined(OS_ANDROID) |
25 return IsMetricsReportingEnabled(g_browser_process->local_state()); | 33 return IsMetricsReportingEnabled(g_browser_process->local_state()); |
26 #else | 34 #else |
27 // ChromeOS and Android currently obtain the value for whether the user has | 35 // Android currently obtain the value for whether the user has |
28 // obtain metrics reporting in non-standard ways. | 36 // obtain metrics reporting in non-standard ways. |
29 // TODO(gayane): Consolidate metric prefs on all platforms and eliminate this | 37 // TODO(gayane): Consolidate metric prefs on all platforms and eliminate this |
30 // special-case code, instead having all platforms go through the above flow. | 38 // special-case code, instead having all platforms go through the above flow. |
31 // http://crbug.com/362192, http://crbug.com/532084 | 39 // http://crbug.com/362192, http://crbug.com/532084 |
32 bool pref_value = false; | 40 bool pref_value = false; |
33 | 41 |
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( | 42 pref_value = g_browser_process->local_state()->GetBoolean( |
44 prefs::kCrashReportingEnabled); | 43 prefs::kCrashReportingEnabled); |
45 #endif // defined(OS_CHROMEOS) | |
46 | |
47 return IsMetricsReportingEnabledWithPrefValue(pref_value); | 44 return IsMetricsReportingEnabledWithPrefValue(pref_value); |
48 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 45 #endif // !defined(OS_ANDROID) |
49 } | 46 } |
50 | 47 |
51 // static | 48 // static |
52 bool ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial( | 49 bool ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial( |
53 const std::string& trial_name, | 50 const std::string& trial_name, |
54 const std::string& group_name) { | 51 const std::string& group_name) { |
55 return metrics::MetricsServiceAccessor::RegisterSyntheticFieldTrial( | 52 return metrics::MetricsServiceAccessor::RegisterSyntheticFieldTrial( |
56 g_browser_process->metrics_service(), trial_name, group_name); | 53 g_browser_process->metrics_service(), trial_name, group_name); |
57 } | 54 } |
58 | 55 |
59 // static | 56 // static |
60 bool ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrialWithNameHash( | 57 bool ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrialWithNameHash( |
61 uint32_t trial_name_hash, | 58 uint32_t trial_name_hash, |
62 const std::string& group_name) { | 59 const std::string& group_name) { |
63 return metrics::MetricsServiceAccessor:: | 60 return metrics::MetricsServiceAccessor:: |
64 RegisterSyntheticFieldTrialWithNameHash( | 61 RegisterSyntheticFieldTrialWithNameHash( |
65 g_browser_process->metrics_service(), trial_name_hash, group_name); | 62 g_browser_process->metrics_service(), trial_name_hash, group_name); |
66 } | 63 } |
OLD | NEW |