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_client.h" | 5 #include "chrome/browser/metrics/chrome_metrics_service_client.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
18 #include "base/metrics/persistent_histogram_allocator.h" | |
18 #include "base/path_service.h" | 19 #include "base/path_service.h" |
19 #include "base/rand_util.h" | 20 #include "base/rand_util.h" |
20 #include "base/strings/string16.h" | 21 #include "base/strings/string16.h" |
21 #include "base/threading/platform_thread.h" | 22 #include "base/threading/platform_thread.h" |
22 #include "build/build_config.h" | 23 #include "build/build_config.h" |
23 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
24 #include "chrome/browser/chrome_notification_types.h" | 25 #include "chrome/browser/chrome_notification_types.h" |
25 #include "chrome/browser/google/google_brand.h" | 26 #include "chrome/browser/google/google_brand.h" |
26 #include "chrome/browser/metrics/chrome_stability_metrics_provider.h" | 27 #include "chrome/browser/metrics/chrome_stability_metrics_provider.h" |
27 #include "chrome/browser/metrics/metrics_reporting_state.h" | 28 #include "chrome/browser/metrics/metrics_reporting_state.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 PrefService* local_state = g_browser_process->local_state(); | 132 PrefService* local_state = g_browser_process->local_state(); |
132 return !local_state->HasPrefPath(metrics::prefs::kMetricsReportingEnabled) && | 133 return !local_state->HasPrefPath(metrics::prefs::kMetricsReportingEnabled) && |
133 variations::GetVariationParamValue("UMA_EnableCellularLogUpload", | 134 variations::GetVariationParamValue("UMA_EnableCellularLogUpload", |
134 "Enabled") == "true"; | 135 "Enabled") == "true"; |
135 #else | 136 #else |
136 return false; | 137 return false; |
137 #endif | 138 #endif |
138 } | 139 } |
139 | 140 |
140 void RegisterInstallerFileMetricsPreferences(PrefRegistrySimple* registry) { | 141 void RegisterInstallerFileMetricsPreferences(PrefRegistrySimple* registry) { |
142 base::GlobalHistogramAllocator* allocator = | |
143 base::GlobalHistogramAllocator::GetEvenIfDisabled(); | |
144 if (allocator) | |
Ilya Sherman
2016/04/25 19:48:40
In what case(s) might the allocator be null? (And
bcwhite
2016/04/25 20:37:17
I don't imagine it will be. But this code is so f
Ilya Sherman
2016/04/25 21:12:11
You're trading predictable crashes or DCHECK failu
| |
145 metrics::FileMetricsProvider::RegisterPrefs(registry, allocator->Name()); | |
146 | |
141 #if defined(OS_WIN) | 147 #if defined(OS_WIN) |
142 metrics::FileMetricsProvider::RegisterPrefs( | 148 metrics::FileMetricsProvider::RegisterPrefs( |
143 registry, installer::kSetupHistogramAllocatorName); | 149 registry, installer::kSetupHistogramAllocatorName); |
144 #endif | 150 #endif |
145 } | 151 } |
146 | 152 |
147 void RegisterInstallerFileMetricsProvider( | 153 void RegisterInstallerFileMetricsProvider( |
148 metrics::MetricsService* metrics_service) { | 154 metrics::MetricsService* metrics_service) { |
149 #if defined(OS_WIN) | 155 // Create an object to monitor files of metrics and include them in reports. |
150 std::unique_ptr<metrics::FileMetricsProvider> file_metrics( | 156 std::unique_ptr<metrics::FileMetricsProvider> file_metrics_provider( |
151 new metrics::FileMetricsProvider( | 157 new metrics::FileMetricsProvider( |
152 content::BrowserThread::GetBlockingPool() | 158 content::BrowserThread::GetBlockingPool() |
153 ->GetTaskRunnerWithShutdownBehavior( | 159 ->GetTaskRunnerWithShutdownBehavior( |
154 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN), | 160 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN), |
155 g_browser_process->local_state())); | 161 g_browser_process->local_state())); |
162 | |
163 // Build the pathname for browser's persistent metrics file. Set it as the | |
164 // destination for the GlobalHistogramAllocator during process exit and add | |
165 // it to the file-metrics-provider so one written from a previous run will | |
166 // be loaded. | |
167 base::FilePath metrics_file; | |
168 if (base::PathService::Get(chrome::DIR_USER_DATA, &metrics_file)) { | |
169 base::GlobalHistogramAllocator* allocator = | |
170 base::GlobalHistogramAllocator::GetEvenIfDisabled(); | |
171 if (allocator) { | |
172 const char* allocator_name = allocator->Name(); | |
173 metrics_file = metrics_file.AppendASCII(allocator_name) | |
174 .AddExtension(FILE_PATH_LITERAL(".pma")); | |
175 allocator->SetPersistentLocation(metrics_file); | |
176 | |
177 file_metrics_provider->RegisterFile( | |
178 metrics_file, | |
179 metrics::FileMetricsProvider::FILE_HISTOGRAMS_ATOMIC, | |
180 allocator_name); | |
181 } | |
182 } | |
183 | |
184 #if defined(OS_WIN) | |
185 // Read metrics file from setup.exe. | |
156 base::FilePath program_dir; | 186 base::FilePath program_dir; |
157 base::PathService::Get(base::DIR_EXE, &program_dir); | 187 base::PathService::Get(base::DIR_EXE, &program_dir); |
158 file_metrics->RegisterFile( | 188 file_metrics_provider->RegisterFile( |
159 program_dir.AppendASCII(installer::kSetupHistogramAllocatorName) | 189 program_dir.AppendASCII(installer::kSetupHistogramAllocatorName) |
160 .AddExtension(L".pma"), | 190 .AddExtension(FILE_PATH_LITERAL(".pma")), |
161 metrics::FileMetricsProvider::FILE_HISTOGRAMS_ATOMIC, | 191 metrics::FileMetricsProvider::FILE_HISTOGRAMS_ATOMIC, |
162 installer::kSetupHistogramAllocatorName); | 192 installer::kSetupHistogramAllocatorName); |
163 metrics_service->RegisterMetricsProvider(std::move(file_metrics)); | |
164 #endif | 193 #endif |
194 | |
195 // Give the new provider to the metrics service. | |
196 metrics_service->RegisterMetricsProvider(std::move(file_metrics_provider)); | |
165 } | 197 } |
166 | 198 |
167 } // namespace | 199 } // namespace |
168 | 200 |
169 | 201 |
170 ChromeMetricsServiceClient::ChromeMetricsServiceClient( | 202 ChromeMetricsServiceClient::ChromeMetricsServiceClient( |
171 metrics::MetricsStateManager* state_manager) | 203 metrics::MetricsStateManager* state_manager) |
172 : metrics_state_manager_(state_manager), | 204 : metrics_state_manager_(state_manager), |
173 #if defined(OS_CHROMEOS) | 205 #if defined(OS_CHROMEOS) |
174 chromeos_metrics_provider_(nullptr), | 206 chromeos_metrics_provider_(nullptr), |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
694 } | 726 } |
695 } | 727 } |
696 | 728 |
697 void ChromeMetricsServiceClient::OnURLOpenedFromOmnibox(OmniboxLog* log) { | 729 void ChromeMetricsServiceClient::OnURLOpenedFromOmnibox(OmniboxLog* log) { |
698 metrics_service_->OnApplicationNotIdle(); | 730 metrics_service_->OnApplicationNotIdle(); |
699 } | 731 } |
700 | 732 |
701 bool ChromeMetricsServiceClient::IsUMACellularUploadLogicEnabled() { | 733 bool ChromeMetricsServiceClient::IsUMACellularUploadLogicEnabled() { |
702 return IsCellularLogicEnabled(); | 734 return IsCellularLogicEnabled(); |
703 } | 735 } |
OLD | NEW |