Chromium Code Reviews| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 #include "chrome/browser/signin/chrome_signin_status_metrics_provider_delegate.h " | 94 #include "chrome/browser/signin/chrome_signin_status_metrics_provider_delegate.h " |
| 94 #include "components/signin/core/browser/signin_status_metrics_provider.h" | 95 #include "components/signin/core/browser/signin_status_metrics_provider.h" |
| 95 #endif // !defined(OS_CHROMEOS) | 96 #endif // !defined(OS_CHROMEOS) |
| 96 | 97 |
| 97 namespace { | 98 namespace { |
| 98 | 99 |
| 99 // This specifies the amount of time to wait for all renderers to send their | 100 // This specifies the amount of time to wait for all renderers to send their |
| 100 // data. | 101 // data. |
| 101 const int kMaxHistogramGatheringWaitDuration = 60000; // 60 seconds. | 102 const int kMaxHistogramGatheringWaitDuration = 60000; // 60 seconds. |
| 102 | 103 |
| 104 // This is the name of the metrics allocator used by the browser. | |
| 105 // TODO(bcwhite): De-dup this with chrome_browser_field_trials.cc and move | |
| 106 // somewhere that content/ can read it from. | |
| 107 const char kBrowserMetricsAllocatorName[] = "BrowserMetrics"; | |
| 108 | |
| 103 // Standard interval between log uploads, in seconds. | 109 // Standard interval between log uploads, in seconds. |
| 104 #if defined(OS_ANDROID) | 110 #if defined(OS_ANDROID) |
| 105 const int kStandardUploadIntervalSeconds = 5 * 60; // Five minutes. | 111 const int kStandardUploadIntervalSeconds = 5 * 60; // Five minutes. |
| 106 const int kStandardUploadIntervalCellularSeconds = 15 * 60; // Fifteen minutes. | 112 const int kStandardUploadIntervalCellularSeconds = 15 * 60; // Fifteen minutes. |
| 107 #else | 113 #else |
| 108 const int kStandardUploadIntervalSeconds = 30 * 60; // Thirty minutes. | 114 const int kStandardUploadIntervalSeconds = 30 * 60; // Thirty minutes. |
| 109 #endif | 115 #endif |
| 110 | 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. |
| (...skipping 18 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 metrics::FileMetricsProvider::RegisterPrefs( | |
| 148 registry, kBrowserMetricsAllocatorName); | |
| 149 | |
| 141 #if defined(OS_WIN) | 150 #if defined(OS_WIN) |
| 142 metrics::FileMetricsProvider::RegisterPrefs( | 151 metrics::FileMetricsProvider::RegisterPrefs( |
| 143 registry, installer::kSetupHistogramAllocatorName); | 152 registry, installer::kSetupHistogramAllocatorName); |
| 144 #endif | 153 #endif |
| 145 } | 154 } |
| 146 | 155 |
| 147 void RegisterInstallerFileMetricsProvider( | 156 void RegisterInstallerFileMetricsProvider( |
| 148 metrics::MetricsService* metrics_service) { | 157 metrics::MetricsService* metrics_service) { |
| 149 #if defined(OS_WIN) | 158 // Create an object to monitor files of metrics and include them in reports. |
| 150 std::unique_ptr<metrics::FileMetricsProvider> file_metrics( | 159 std::unique_ptr<metrics::FileMetricsProvider> file_metrics_provider( |
| 151 new metrics::FileMetricsProvider( | 160 new metrics::FileMetricsProvider( |
| 152 content::BrowserThread::GetBlockingPool() | 161 content::BrowserThread::GetBlockingPool() |
| 153 ->GetTaskRunnerWithShutdownBehavior( | 162 ->GetTaskRunnerWithShutdownBehavior( |
| 154 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN), | 163 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN), |
| 155 g_browser_process->local_state())); | 164 g_browser_process->local_state())); |
| 165 | |
| 166 // Build the pathname for browser's persistent metrics file. Set it as the | |
| 167 // destination for the GlobalHistogramAllocator during process exit and add | |
| 168 // it to the file-metrics-provider so one written from a previous run will | |
| 169 // be loaded. | |
| 170 base::FilePath metrics_file; | |
| 171 if (base::PathService::Get(chrome::DIR_USER_DATA, &metrics_file)) { | |
| 172 metrics_file = metrics_file.AppendASCII(kBrowserMetricsAllocatorName) | |
| 173 .AddExtension(FILE_PATH_LITERAL(".pma")); | |
|
Ilya Sherman
2016/04/19 00:57:46
What is ".pma"? Is this just an extension that yo
bcwhite
2016/04/19 16:33:38
PersistentMemoryAllocator. Just a dump of memory
| |
| 174 | |
| 175 base::GlobalHistogramAllocator* allocator = | |
| 176 base::GlobalHistogramAllocator::Get(); | |
| 177 if (allocator) | |
| 178 allocator->SetPersistentLocation(metrics_file); | |
| 179 | |
| 180 file_metrics_provider->RegisterFile( | |
| 181 metrics_file, | |
| 182 metrics::FileMetricsProvider::FILE_HISTOGRAMS_ATOMIC, | |
| 183 kBrowserMetricsAllocatorName); | |
| 184 } | |
| 185 | |
| 186 #if defined(OS_WIN) | |
| 187 // Read metrics file from setup.exe. | |
| 156 base::FilePath program_dir; | 188 base::FilePath program_dir; |
| 157 base::PathService::Get(base::DIR_EXE, &program_dir); | 189 base::PathService::Get(base::DIR_EXE, &program_dir); |
| 158 file_metrics->RegisterFile( | 190 file_metrics_provider->RegisterFile( |
| 159 program_dir.AppendASCII(installer::kSetupHistogramAllocatorName) | 191 program_dir.AppendASCII(installer::kSetupHistogramAllocatorName) |
| 160 .AddExtension(L".pma"), | 192 .AddExtension(FILE_PATH_LITERAL(".pma")), |
| 161 metrics::FileMetricsProvider::FILE_HISTOGRAMS_ATOMIC, | 193 metrics::FileMetricsProvider::FILE_HISTOGRAMS_ATOMIC, |
| 162 installer::kSetupHistogramAllocatorName); | 194 installer::kSetupHistogramAllocatorName); |
| 163 metrics_service->RegisterMetricsProvider(std::move(file_metrics)); | |
| 164 #endif | 195 #endif |
| 196 | |
| 197 // Give the new provider to the metrics service. | |
| 198 metrics_service->RegisterMetricsProvider(std::move(file_metrics_provider)); | |
| 165 } | 199 } |
| 166 | 200 |
| 167 } // namespace | 201 } // namespace |
| 168 | 202 |
| 169 | 203 |
| 170 ChromeMetricsServiceClient::ChromeMetricsServiceClient( | 204 ChromeMetricsServiceClient::ChromeMetricsServiceClient( |
| 171 metrics::MetricsStateManager* state_manager) | 205 metrics::MetricsStateManager* state_manager) |
| 172 : metrics_state_manager_(state_manager), | 206 : metrics_state_manager_(state_manager), |
| 173 #if defined(OS_CHROMEOS) | 207 #if defined(OS_CHROMEOS) |
| 174 chromeos_metrics_provider_(nullptr), | 208 chromeos_metrics_provider_(nullptr), |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 691 } | 725 } |
| 692 } | 726 } |
| 693 | 727 |
| 694 void ChromeMetricsServiceClient::OnURLOpenedFromOmnibox(OmniboxLog* log) { | 728 void ChromeMetricsServiceClient::OnURLOpenedFromOmnibox(OmniboxLog* log) { |
| 695 metrics_service_->OnApplicationNotIdle(); | 729 metrics_service_->OnApplicationNotIdle(); |
| 696 } | 730 } |
| 697 | 731 |
| 698 bool ChromeMetricsServiceClient::IsUMACellularUploadLogicEnabled() { | 732 bool ChromeMetricsServiceClient::IsUMACellularUploadLogicEnabled() { |
| 699 return IsCellularLogicEnabled(); | 733 return IsCellularLogicEnabled(); |
| 700 } | 734 } |
| OLD | NEW |