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/files/file_util.h" | |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
17 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
19 #include "base/metrics/persistent_histogram_allocator.h" | |
18 #include "base/path_service.h" | 20 #include "base/path_service.h" |
19 #include "base/rand_util.h" | 21 #include "base/rand_util.h" |
20 #include "base/strings/string16.h" | 22 #include "base/strings/string16.h" |
21 #include "base/threading/platform_thread.h" | 23 #include "base/threading/platform_thread.h" |
22 #include "build/build_config.h" | 24 #include "build/build_config.h" |
23 #include "chrome/browser/browser_process.h" | 25 #include "chrome/browser/browser_process.h" |
24 #include "chrome/browser/chrome_notification_types.h" | 26 #include "chrome/browser/chrome_notification_types.h" |
25 #include "chrome/browser/google/google_brand.h" | 27 #include "chrome/browser/google/google_brand.h" |
28 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | |
26 #include "chrome/browser/metrics/chrome_stability_metrics_provider.h" | 29 #include "chrome/browser/metrics/chrome_stability_metrics_provider.h" |
27 #include "chrome/browser/metrics/metrics_reporting_state.h" | 30 #include "chrome/browser/metrics/metrics_reporting_state.h" |
28 #include "chrome/browser/metrics/subprocess_metrics_provider.h" | 31 #include "chrome/browser/metrics/subprocess_metrics_provider.h" |
29 #include "chrome/browser/metrics/time_ticks_experiment_win.h" | 32 #include "chrome/browser/metrics/time_ticks_experiment_win.h" |
30 #include "chrome/browser/sync/chrome_sync_client.h" | 33 #include "chrome/browser/sync/chrome_sync_client.h" |
31 #include "chrome/browser/ui/browser_otr_state.h" | 34 #include "chrome/browser/ui/browser_otr_state.h" |
32 #include "chrome/common/channel_info.h" | 35 #include "chrome/common/channel_info.h" |
33 #include "chrome/common/chrome_paths.h" | 36 #include "chrome/common/chrome_paths.h" |
34 #include "chrome/common/chrome_switches.h" | 37 #include "chrome/common/chrome_switches.h" |
35 #include "chrome/common/crash_keys.h" | 38 #include "chrome/common/crash_keys.h" |
36 #include "chrome/common/features.h" | 39 #include "chrome/common/features.h" |
37 #include "chrome/installer/util/util_constants.h" | 40 #include "chrome/installer/util/util_constants.h" |
38 #include "components/metrics/call_stack_profile_metrics_provider.h" | 41 #include "components/metrics/call_stack_profile_metrics_provider.h" |
39 #include "components/metrics/drive_metrics_provider.h" | 42 #include "components/metrics/drive_metrics_provider.h" |
40 #include "components/metrics/file_metrics_provider.h" | 43 #include "components/metrics/file_metrics_provider.h" |
41 #include "components/metrics/gpu/gpu_metrics_provider.h" | 44 #include "components/metrics/gpu/gpu_metrics_provider.h" |
42 #include "components/metrics/metrics_pref_names.h" | 45 #include "components/metrics/metrics_pref_names.h" |
43 #include "components/metrics/metrics_service.h" | 46 #include "components/metrics/metrics_service.h" |
44 #include "components/metrics/metrics_service_client.h" | 47 #include "components/metrics/metrics_service_client.h" |
48 #include "components/metrics/metrics_state_manager.h" | |
45 #include "components/metrics/net/net_metrics_log_uploader.h" | 49 #include "components/metrics/net/net_metrics_log_uploader.h" |
46 #include "components/metrics/net/network_metrics_provider.h" | 50 #include "components/metrics/net/network_metrics_provider.h" |
47 #include "components/metrics/net/version_utils.h" | 51 #include "components/metrics/net/version_utils.h" |
48 #include "components/metrics/profiler/profiler_metrics_provider.h" | 52 #include "components/metrics/profiler/profiler_metrics_provider.h" |
49 #include "components/metrics/profiler/tracking_synchronizer.h" | 53 #include "components/metrics/profiler/tracking_synchronizer.h" |
50 #include "components/metrics/stability_metrics_helper.h" | 54 #include "components/metrics/stability_metrics_helper.h" |
51 #include "components/metrics/ui/screen_info_metrics_provider.h" | 55 #include "components/metrics/ui/screen_info_metrics_provider.h" |
52 #include "components/metrics/url_constants.h" | 56 #include "components/metrics/url_constants.h" |
53 #include "components/omnibox/browser/omnibox_metrics_provider.h" | 57 #include "components/omnibox/browser/omnibox_metrics_provider.h" |
54 #include "components/prefs/pref_registry_simple.h" | 58 #include "components/prefs/pref_registry_simple.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 const int kMaxHistogramGatheringWaitDuration = 60000; // 60 seconds. | 105 const int kMaxHistogramGatheringWaitDuration = 60000; // 60 seconds. |
102 | 106 |
103 // Standard interval between log uploads, in seconds. | 107 // Standard interval between log uploads, in seconds. |
104 #if defined(OS_ANDROID) | 108 #if defined(OS_ANDROID) |
105 const int kStandardUploadIntervalSeconds = 5 * 60; // Five minutes. | 109 const int kStandardUploadIntervalSeconds = 5 * 60; // Five minutes. |
106 const int kStandardUploadIntervalCellularSeconds = 15 * 60; // Fifteen minutes. | 110 const int kStandardUploadIntervalCellularSeconds = 15 * 60; // Fifteen minutes. |
107 #else | 111 #else |
108 const int kStandardUploadIntervalSeconds = 30 * 60; // Thirty minutes. | 112 const int kStandardUploadIntervalSeconds = 30 * 60; // Thirty minutes. |
109 #endif | 113 #endif |
110 | 114 |
115 const char kBrowserMetricsFileName[] = "SavedMetrics"; | |
116 | |
111 // Returns true if current connection type is cellular and user is assigned to | 117 // Returns true if current connection type is cellular and user is assigned to |
112 // experimental group for enabled cellular uploads. | 118 // experimental group for enabled cellular uploads. |
113 bool IsCellularLogicEnabled() { | 119 bool IsCellularLogicEnabled() { |
114 if (variations::GetVariationParamValue("UMA_EnableCellularLogUpload", | 120 if (variations::GetVariationParamValue("UMA_EnableCellularLogUpload", |
115 "Enabled") != "true" || | 121 "Enabled") != "true" || |
116 variations::GetVariationParamValue("UMA_EnableCellularLogUpload", | 122 variations::GetVariationParamValue("UMA_EnableCellularLogUpload", |
117 "Optimize") == "false") { | 123 "Optimize") == "false") { |
118 return false; | 124 return false; |
119 } | 125 } |
120 | 126 |
(...skipping 10 matching lines...) Expand all Loading... | |
131 PrefService* local_state = g_browser_process->local_state(); | 137 PrefService* local_state = g_browser_process->local_state(); |
132 return !local_state->HasPrefPath(metrics::prefs::kMetricsReportingEnabled) && | 138 return !local_state->HasPrefPath(metrics::prefs::kMetricsReportingEnabled) && |
133 variations::GetVariationParamValue("UMA_EnableCellularLogUpload", | 139 variations::GetVariationParamValue("UMA_EnableCellularLogUpload", |
134 "Enabled") == "true"; | 140 "Enabled") == "true"; |
135 #else | 141 #else |
136 return false; | 142 return false; |
137 #endif | 143 #endif |
138 } | 144 } |
139 | 145 |
140 void RegisterInstallerFileMetricsPreferences(PrefRegistrySimple* registry) { | 146 void RegisterInstallerFileMetricsPreferences(PrefRegistrySimple* registry) { |
147 base::GlobalHistogramAllocator* allocator = | |
148 base::GlobalHistogramAllocator::GetEvenIfDisabled(); | |
149 if (allocator) | |
150 metrics::FileMetricsProvider::RegisterPrefs(registry, allocator->Name()); | |
151 | |
141 #if defined(OS_WIN) | 152 #if defined(OS_WIN) |
142 metrics::FileMetricsProvider::RegisterPrefs( | 153 metrics::FileMetricsProvider::RegisterPrefs( |
143 registry, installer::kSetupHistogramAllocatorName); | 154 registry, installer::kSetupHistogramAllocatorName); |
144 #endif | 155 #endif |
145 } | 156 } |
146 | 157 |
147 void RegisterInstallerFileMetricsProvider( | 158 void RegisterInstallerFileMetricsProvider( |
148 metrics::MetricsService* metrics_service) { | 159 metrics::MetricsService* metrics_service, |
149 #if defined(OS_WIN) | 160 metrics::MetricsStateManager* metrics_state_manager) { |
Alexei Svitkine (slow)
2016/05/10 19:55:42
Nit: How about just passing reporting_enabled bool
bcwhite
2016/05/11 15:47:12
I considered it. It seemed better to pass the obj
Alexei Svitkine (slow)
2016/05/11 15:51:28
I prefer the bool since it's easier to reason abou
bcwhite
2016/05/11 17:58:34
Done and Done.
| |
150 std::unique_ptr<metrics::FileMetricsProvider> file_metrics( | 161 // Create an object to monitor files of metrics and include them in reports. |
162 std::unique_ptr<metrics::FileMetricsProvider> file_metrics_provider( | |
151 new metrics::FileMetricsProvider( | 163 new metrics::FileMetricsProvider( |
152 content::BrowserThread::GetBlockingPool() | 164 content::BrowserThread::GetBlockingPool() |
153 ->GetTaskRunnerWithShutdownBehavior( | 165 ->GetTaskRunnerWithShutdownBehavior( |
154 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN), | 166 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN), |
155 g_browser_process->local_state())); | 167 g_browser_process->local_state())); |
168 | |
169 // Build the pathname for browser's persistent metrics file. Set it as the | |
170 // destination for the GlobalHistogramAllocator during process exit and add | |
171 // it to the file-metrics-provider so one written from a previous run will | |
172 // be loaded. | |
173 // TODO(bcwhite): Actually create those files. | |
174 base::FilePath metrics_file; | |
175 if (base::PathService::Get(chrome::DIR_USER_DATA, &metrics_file)) { | |
176 metrics_file = | |
177 metrics_file.AppendASCII(kBrowserMetricsFileName) | |
178 .AddExtension(base::PersistentMemoryAllocator::kFileExtension); | |
Alexei Svitkine (slow)
2016/05/10 19:55:42
Nit: Wonder if it would be shorter to have a stati
bcwhite
2016/05/11 15:47:12
Acknowledged.
| |
179 if (metrics_state_manager->IsMetricsReportingEnabled()) { | |
180 // Metrics get persisted to disk when the process exits. Store the path | |
181 // to that file in the global allocator for use at exit time and tell | |
182 // the FileMetricsProvider about that file so it can read one created | |
183 // by the previous run. | |
184 base::GlobalHistogramAllocator* allocator = | |
185 base::GlobalHistogramAllocator::GetEvenIfDisabled(); | |
186 if (allocator) { | |
187 const char* allocator_name = allocator->Name(); | |
188 allocator->SetPersistentLocation(metrics_file); | |
189 file_metrics_provider->RegisterFile( | |
190 metrics_file, | |
191 metrics::FileMetricsProvider::FILE_HISTOGRAMS_ATOMIC, | |
192 metrics::FileMetricsProvider::ASSOCIATE_PREVIOUS_RUN, | |
193 allocator_name); | |
194 } | |
195 } else { | |
196 // When metrics reporting is not enabled, any existing file should be | |
197 // deleted in order to preserve user privacy. | |
198 base::DeleteFile(metrics_file, false); | |
Alexei Svitkine (slow)
2016/05/10 19:55:42
Make this a post task to the blocking pool - no re
bcwhite
2016/05/11 15:47:12
Done.
| |
199 } | |
200 } | |
201 | |
202 #if defined(OS_WIN) | |
203 // Read metrics file from setup.exe. | |
156 base::FilePath program_dir; | 204 base::FilePath program_dir; |
157 base::PathService::Get(base::DIR_EXE, &program_dir); | 205 base::PathService::Get(base::DIR_EXE, &program_dir); |
158 file_metrics->RegisterFile( | 206 file_metrics_provider->RegisterFile( |
159 program_dir.AppendASCII(installer::kSetupHistogramAllocatorName) | 207 program_dir.AppendASCII(installer::kSetupHistogramAllocatorName) |
160 .AddExtension(L".pma"), | 208 .AddExtension(FILE_PATH_LITERAL(".pma")), |
161 metrics::FileMetricsProvider::FILE_HISTOGRAMS_ATOMIC, | 209 metrics::FileMetricsProvider::FILE_HISTOGRAMS_ATOMIC, |
210 metrics::FileMetricsProvider::ASSOCIATE_CURRENT_RUN, | |
162 installer::kSetupHistogramAllocatorName); | 211 installer::kSetupHistogramAllocatorName); |
163 metrics_service->RegisterMetricsProvider(std::move(file_metrics)); | |
164 #endif | 212 #endif |
213 | |
214 // Give the new provider to the metrics service. | |
215 metrics_service->RegisterMetricsProvider(std::move(file_metrics_provider)); | |
165 } | 216 } |
166 | 217 |
167 } // namespace | 218 } // namespace |
168 | 219 |
169 | 220 |
170 ChromeMetricsServiceClient::ChromeMetricsServiceClient( | 221 ChromeMetricsServiceClient::ChromeMetricsServiceClient( |
171 metrics::MetricsStateManager* state_manager) | 222 metrics::MetricsStateManager* state_manager) |
172 : metrics_state_manager_(state_manager), | 223 : metrics_state_manager_(state_manager), |
173 #if defined(OS_CHROMEOS) | 224 #if defined(OS_CHROMEOS) |
174 chromeos_metrics_provider_(nullptr), | 225 chromeos_metrics_provider_(nullptr), |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
387 std::unique_ptr<metrics::MetricsProvider>( | 438 std::unique_ptr<metrics::MetricsProvider>( |
388 new ChromeStabilityMetricsProvider( | 439 new ChromeStabilityMetricsProvider( |
389 g_browser_process->local_state()))); | 440 g_browser_process->local_state()))); |
390 metrics_service_->RegisterMetricsProvider( | 441 metrics_service_->RegisterMetricsProvider( |
391 std::unique_ptr<metrics::MetricsProvider>( | 442 std::unique_ptr<metrics::MetricsProvider>( |
392 new metrics::GPUMetricsProvider)); | 443 new metrics::GPUMetricsProvider)); |
393 metrics_service_->RegisterMetricsProvider( | 444 metrics_service_->RegisterMetricsProvider( |
394 std::unique_ptr<metrics::MetricsProvider>( | 445 std::unique_ptr<metrics::MetricsProvider>( |
395 new metrics::ScreenInfoMetricsProvider)); | 446 new metrics::ScreenInfoMetricsProvider)); |
396 | 447 |
397 RegisterInstallerFileMetricsProvider(metrics_service_.get()); | 448 RegisterInstallerFileMetricsProvider(metrics_service_.get(), |
449 metrics_state_manager_); | |
398 | 450 |
399 drive_metrics_provider_ = new metrics::DriveMetricsProvider( | 451 drive_metrics_provider_ = new metrics::DriveMetricsProvider( |
400 content::BrowserThread::GetMessageLoopProxyForThread( | 452 content::BrowserThread::GetMessageLoopProxyForThread( |
401 content::BrowserThread::FILE), | 453 content::BrowserThread::FILE), |
402 chrome::FILE_LOCAL_STATE); | 454 chrome::FILE_LOCAL_STATE); |
403 metrics_service_->RegisterMetricsProvider( | 455 metrics_service_->RegisterMetricsProvider( |
404 std::unique_ptr<metrics::MetricsProvider>(drive_metrics_provider_)); | 456 std::unique_ptr<metrics::MetricsProvider>(drive_metrics_provider_)); |
405 | 457 |
406 profiler_metrics_provider_ = | 458 profiler_metrics_provider_ = |
407 new metrics::ProfilerMetricsProvider(base::Bind(&IsCellularLogicEnabled)); | 459 new metrics::ProfilerMetricsProvider(base::Bind(&IsCellularLogicEnabled)); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
694 } | 746 } |
695 } | 747 } |
696 | 748 |
697 void ChromeMetricsServiceClient::OnURLOpenedFromOmnibox(OmniboxLog* log) { | 749 void ChromeMetricsServiceClient::OnURLOpenedFromOmnibox(OmniboxLog* log) { |
698 metrics_service_->OnApplicationNotIdle(); | 750 metrics_service_->OnApplicationNotIdle(); |
699 } | 751 } |
700 | 752 |
701 bool ChromeMetricsServiceClient::IsUMACellularUploadLogicEnabled() { | 753 bool ChromeMetricsServiceClient::IsUMACellularUploadLogicEnabled() { |
702 return IsCellularLogicEnabled(); | 754 return IsCellularLogicEnabled(); |
703 } | 755 } |
OLD | NEW |