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 "build/build_config.h" | 7 #include "build/build_config.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/common/features.h" | 9 #include "chrome/common/features.h" |
10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
11 #include "components/prefs/pref_service.h" | 11 #include "components/prefs/pref_service.h" |
12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
13 | 13 |
14 #if defined(OS_CHROMEOS) | 14 #if defined(OS_CHROMEOS) |
15 #include "chrome/browser/chromeos/settings/cros_settings.h" | 15 #include "chrome/browser/chromeos/settings/cros_settings.h" |
16 #endif | 16 #endif |
17 | 17 |
| 18 namespace { |
| 19 |
| 20 const bool* g_metrics_consent_for_testing = nullptr; |
| 21 |
| 22 } // namespace |
| 23 |
| 24 // static |
| 25 void ChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting( |
| 26 const bool* value) { |
| 27 DCHECK_NE(g_metrics_consent_for_testing == nullptr, value == nullptr) |
| 28 << "Unpaired set/reset"; |
| 29 |
| 30 g_metrics_consent_for_testing = value; |
| 31 } |
| 32 |
18 // static | 33 // static |
19 bool ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled() { | 34 bool ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled() { |
| 35 if (g_metrics_consent_for_testing) |
| 36 return *g_metrics_consent_for_testing; |
| 37 |
20 // TODO(blundell): Fix the unittests that don't set up the UI thread and | 38 // TODO(blundell): Fix the unittests that don't set up the UI thread and |
21 // change this to just be DCHECK_CURRENTLY_ON(). | 39 // change this to just be DCHECK_CURRENTLY_ON(). |
22 DCHECK( | 40 DCHECK( |
23 !content::BrowserThread::IsMessageLoopValid(content::BrowserThread::UI) || | 41 !content::BrowserThread::IsMessageLoopValid(content::BrowserThread::UI) || |
24 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 42 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
25 | 43 |
26 // This is only possible during unit tests. If the unit test didn't set the | 44 // This is only possible during unit tests. If the unit test didn't set the |
27 // local_state then it doesn't care about pref value and therefore we return | 45 // local_state then it doesn't care about pref value and therefore we return |
28 // false. | 46 // false. |
29 if (!g_browser_process->local_state()) { | 47 if (!g_browser_process->local_state()) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 } | 82 } |
65 | 83 |
66 // static | 84 // static |
67 bool ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrialWithNameHash( | 85 bool ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrialWithNameHash( |
68 uint32_t trial_name_hash, | 86 uint32_t trial_name_hash, |
69 const std::string& group_name) { | 87 const std::string& group_name) { |
70 return metrics::MetricsServiceAccessor:: | 88 return metrics::MetricsServiceAccessor:: |
71 RegisterSyntheticFieldTrialWithNameHash( | 89 RegisterSyntheticFieldTrialWithNameHash( |
72 g_browser_process->metrics_service(), trial_name_hash, group_name); | 90 g_browser_process->metrics_service(), trial_name_hash, group_name); |
73 } | 91 } |
OLD | NEW |