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/metrics_services_manager.h" | 5 #include "chrome/browser/metrics/metrics_services_manager.h" |
6 | 6 |
| 7 #include <string> |
| 8 |
7 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" |
8 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
9 #include "chrome/browser/metrics/chrome_metrics_service_client.h" | 12 #include "chrome/browser/metrics/chrome_metrics_service_client.h" |
10 #include "chrome/browser/metrics/variations/variations_service.h" | 13 #include "chrome/browser/metrics/variations/variations_service.h" |
11 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
12 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 16 #include "chrome/installer/util/google_update_settings.h" |
13 #include "components/metrics/metrics_service.h" | 17 #include "components/metrics/metrics_service.h" |
14 #include "components/metrics/metrics_state_manager.h" | 18 #include "components/metrics/metrics_state_manager.h" |
15 #include "components/rappor/rappor_service.h" | 19 #include "components/rappor/rappor_service.h" |
16 | 20 |
17 #if defined(OS_CHROMEOS) | 21 #if defined(OS_CHROMEOS) |
18 #include "chrome/browser/chromeos/settings/cros_settings.h" | 22 #include "chrome/browser/chromeos/settings/cros_settings.h" |
19 #endif | 23 #endif |
20 | 24 |
21 MetricsServicesManager::MetricsServicesManager(PrefService* local_state) | 25 MetricsServicesManager::MetricsServicesManager(PrefService* local_state) |
22 : local_state_(local_state) { | 26 : local_state_(local_state) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } | 67 } |
64 return metrics_service_client_.get(); | 68 return metrics_service_client_.get(); |
65 } | 69 } |
66 | 70 |
67 metrics::MetricsStateManager* MetricsServicesManager::GetMetricsStateManager() { | 71 metrics::MetricsStateManager* MetricsServicesManager::GetMetricsStateManager() { |
68 DCHECK(thread_checker_.CalledOnValidThread()); | 72 DCHECK(thread_checker_.CalledOnValidThread()); |
69 if (!metrics_state_manager_) { | 73 if (!metrics_state_manager_) { |
70 metrics_state_manager_ = metrics::MetricsStateManager::Create( | 74 metrics_state_manager_ = metrics::MetricsStateManager::Create( |
71 local_state_, | 75 local_state_, |
72 base::Bind(&MetricsServicesManager::IsMetricsReportingEnabled, | 76 base::Bind(&MetricsServicesManager::IsMetricsReportingEnabled, |
73 base::Unretained(this))); | 77 base::Unretained(this)), |
| 78 base::Bind(&GoogleUpdateSettings::StoreMetricsClientInfo), |
| 79 base::Bind(&GoogleUpdateSettings::LoadMetricsClientInfo)); |
74 } | 80 } |
75 return metrics_state_manager_.get(); | 81 return metrics_state_manager_.get(); |
76 } | 82 } |
77 | 83 |
78 // TODO(asvitkine): This function does not report the correct value on Android, | 84 // TODO(asvitkine): This function does not report the correct value on Android, |
79 // see http://crbug.com/362192. | 85 // see http://crbug.com/362192. |
80 bool MetricsServicesManager::IsMetricsReportingEnabled() const { | 86 bool MetricsServicesManager::IsMetricsReportingEnabled() const { |
81 // If the user permits metrics reporting with the checkbox in the | 87 // If the user permits metrics reporting with the checkbox in the |
82 // prefs, we turn on recording. We disable metrics completely for | 88 // prefs, we turn on recording. We disable metrics completely for |
83 // non-official builds, or when field trials are forced. | 89 // non-official builds, or when field trials are forced. |
84 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kForceFieldTrials)) | 90 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kForceFieldTrials)) |
85 return false; | 91 return false; |
86 | 92 |
87 bool enabled = false; | 93 bool enabled = false; |
88 #if defined(GOOGLE_CHROME_BUILD) | 94 #if defined(GOOGLE_CHROME_BUILD) |
89 #if defined(OS_CHROMEOS) | 95 #if defined(OS_CHROMEOS) |
90 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, | 96 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, |
91 &enabled); | 97 &enabled); |
92 #else | 98 #else |
93 enabled = local_state_->GetBoolean(prefs::kMetricsReportingEnabled); | 99 enabled = local_state_->GetBoolean(prefs::kMetricsReportingEnabled); |
94 #endif // #if defined(OS_CHROMEOS) | 100 #endif // #if defined(OS_CHROMEOS) |
95 #endif // defined(GOOGLE_CHROME_BUILD) | 101 #endif // defined(GOOGLE_CHROME_BUILD) |
96 return enabled; | 102 return enabled; |
97 } | 103 } |
OLD | NEW |