Chromium Code Reviews| Index: chrome/browser/metrics/chrome_metrics_service_client.cc |
| diff --git a/chrome/browser/metrics/chrome_metrics_service_client.cc b/chrome/browser/metrics/chrome_metrics_service_client.cc |
| index b5af63a4c733a176d0e3388aac054856c5c5216a..bbec2c40ee8153d1c119507782fa968bd025dd77 100644 |
| --- a/chrome/browser/metrics/chrome_metrics_service_client.cc |
| +++ b/chrome/browser/metrics/chrome_metrics_service_client.cc |
| @@ -15,6 +15,7 @@ |
| #include "base/logging.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/metrics/histogram.h" |
| +#include "base/metrics/persistent_histogram_allocator.h" |
| #include "base/path_service.h" |
| #include "base/rand_util.h" |
| #include "base/strings/string16.h" |
| @@ -100,6 +101,11 @@ namespace { |
| // data. |
| const int kMaxHistogramGatheringWaitDuration = 60000; // 60 seconds. |
| +// This is the name of the metrics allocator used by the browser. |
| +// TODO(bcwhite): De-dup this with chrome_browser_field_trials.cc and move |
| +// somewhere that content/ can read it from. |
| +const char kBrowserMetricsAllocatorName[] = "BrowserMetrics"; |
| + |
| // Standard interval between log uploads, in seconds. |
| #if defined(OS_ANDROID) |
| const int kStandardUploadIntervalSeconds = 5 * 60; // Five minutes. |
| @@ -138,6 +144,9 @@ bool ShouldClearSavedMetrics() { |
| } |
| void RegisterInstallerFileMetricsPreferences(PrefRegistrySimple* registry) { |
| + metrics::FileMetricsProvider::RegisterPrefs( |
| + registry, kBrowserMetricsAllocatorName); |
| + |
| #if defined(OS_WIN) |
| metrics::FileMetricsProvider::RegisterPrefs( |
| registry, installer::kSetupHistogramAllocatorName); |
| @@ -146,22 +155,47 @@ void RegisterInstallerFileMetricsPreferences(PrefRegistrySimple* registry) { |
| void RegisterInstallerFileMetricsProvider( |
| metrics::MetricsService* metrics_service) { |
| -#if defined(OS_WIN) |
| - std::unique_ptr<metrics::FileMetricsProvider> file_metrics( |
| + // Create an object to monitor files of metrics and include them in reports. |
| + std::unique_ptr<metrics::FileMetricsProvider> file_metrics_provider( |
| new metrics::FileMetricsProvider( |
| content::BrowserThread::GetBlockingPool() |
| ->GetTaskRunnerWithShutdownBehavior( |
| base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN), |
| g_browser_process->local_state())); |
| + |
| + // Build the pathname for browser's persistent metrics file. Set it as the |
| + // destination for the GlobalHistogramAllocator during process exit and add |
| + // it to the file-metrics-provider so one written from a previous run will |
| + // be loaded. |
| + base::FilePath metrics_file; |
| + if (base::PathService::Get(chrome::DIR_USER_DATA, &metrics_file)) { |
| + metrics_file = metrics_file.AppendASCII(kBrowserMetricsAllocatorName) |
| + .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
|
| + |
| + base::GlobalHistogramAllocator* allocator = |
| + base::GlobalHistogramAllocator::Get(); |
| + if (allocator) |
| + allocator->SetPersistentLocation(metrics_file); |
| + |
| + file_metrics_provider->RegisterFile( |
| + metrics_file, |
| + metrics::FileMetricsProvider::FILE_HISTOGRAMS_ATOMIC, |
| + kBrowserMetricsAllocatorName); |
| + } |
| + |
| +#if defined(OS_WIN) |
| + // Read metrics file from setup.exe. |
| base::FilePath program_dir; |
| base::PathService::Get(base::DIR_EXE, &program_dir); |
| - file_metrics->RegisterFile( |
| + file_metrics_provider->RegisterFile( |
| program_dir.AppendASCII(installer::kSetupHistogramAllocatorName) |
| - .AddExtension(L".pma"), |
| + .AddExtension(FILE_PATH_LITERAL(".pma")), |
| metrics::FileMetricsProvider::FILE_HISTOGRAMS_ATOMIC, |
| installer::kSetupHistogramAllocatorName); |
| - metrics_service->RegisterMetricsProvider(std::move(file_metrics)); |
| #endif |
| + |
| + // Give the new provider to the metrics service. |
| + metrics_service->RegisterMetricsProvider(std::move(file_metrics_provider)); |
| } |
| } // namespace |