Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Side by Side Diff: chrome/browser/metrics/chrome_metrics_service_client.cc

Issue 1891913002: Support saving browser metrics to disk and reading them during next run. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed review comments by Ilya Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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)
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.
Alexei Svitkine (slow) 2016/05/09 21:24:10 In this CL, these files are not yet being created
bcwhite 2016/05/10 15:42:40 Right. It used to be part but was removed because
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"));
Alexei Svitkine (slow) 2016/05/09 21:24:10 Didn't we have this extension as a constant somewh
bcwhite 2016/05/10 15:42:40 Yes. It's in another CL still in review. But I'm
175 allocator->SetPersistentLocation(metrics_file);
176
177 file_metrics_provider->RegisterFile(
178 metrics_file,
179 metrics::FileMetricsProvider::FILE_HISTOGRAMS_ATOMIC,
180 metrics::FileMetricsProvider::ASSOCIATE_PREVIOUS_RUN,
181 allocator_name);
182 }
183 }
184
185 #if defined(OS_WIN)
186 // Read metrics file from setup.exe.
156 base::FilePath program_dir; 187 base::FilePath program_dir;
157 base::PathService::Get(base::DIR_EXE, &program_dir); 188 base::PathService::Get(base::DIR_EXE, &program_dir);
158 file_metrics->RegisterFile( 189 file_metrics_provider->RegisterFile(
159 program_dir.AppendASCII(installer::kSetupHistogramAllocatorName) 190 program_dir.AppendASCII(installer::kSetupHistogramAllocatorName)
160 .AddExtension(L".pma"), 191 .AddExtension(FILE_PATH_LITERAL(".pma")),
161 metrics::FileMetricsProvider::FILE_HISTOGRAMS_ATOMIC, 192 metrics::FileMetricsProvider::FILE_HISTOGRAMS_ATOMIC,
193 metrics::FileMetricsProvider::ASSOCIATE_CURRENT_RUN,
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 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 } 728 }
695 } 729 }
696 730
697 void ChromeMetricsServiceClient::OnURLOpenedFromOmnibox(OmniboxLog* log) { 731 void ChromeMetricsServiceClient::OnURLOpenedFromOmnibox(OmniboxLog* log) {
698 metrics_service_->OnApplicationNotIdle(); 732 metrics_service_->OnApplicationNotIdle();
699 } 733 }
700 734
701 bool ChromeMetricsServiceClient::IsUMACellularUploadLogicEnabled() { 735 bool ChromeMetricsServiceClient::IsUMACellularUploadLogicEnabled() {
702 return IsCellularLogicEnabled(); 736 return IsCellularLogicEnabled();
703 } 737 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698