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

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

Issue 293393010: Move initial metrics gathering tasks out of MetricsService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes Created 6 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/threading/platform_thread.h" 15 #include "base/threading/platform_thread.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/chrome_notification_types.h" 18 #include "chrome/browser/chrome_notification_types.h"
19 #include "chrome/browser/google/google_util.h" 19 #include "chrome/browser/google/google_util.h"
20 #include "chrome/browser/memory_details.h" 20 #include "chrome/browser/memory_details.h"
21 #include "chrome/browser/metrics/chrome_stability_metrics_provider.h"
21 #include "chrome/browser/metrics/extensions_metrics_provider.h" 22 #include "chrome/browser/metrics/extensions_metrics_provider.h"
23 #include "chrome/browser/metrics/gpu_metrics_provider.h"
22 #include "chrome/browser/metrics/metrics_service.h" 24 #include "chrome/browser/metrics/metrics_service.h"
25 #include "chrome/browser/metrics/network_metrics_provider.h"
26 #include "chrome/browser/metrics/omnibox_metrics_provider.h"
27 #include "chrome/browser/metrics/tracking_synchronizer.h"
23 #include "chrome/browser/ui/browser_otr_state.h" 28 #include "chrome/browser/ui/browser_otr_state.h"
24 #include "chrome/common/chrome_constants.h" 29 #include "chrome/common/chrome_constants.h"
25 #include "chrome/common/chrome_switches.h" 30 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/chrome_version_info.h" 31 #include "chrome/common/chrome_version_info.h"
27 #include "chrome/common/crash_keys.h" 32 #include "chrome/common/crash_keys.h"
28 #include "chrome/common/render_messages.h" 33 #include "chrome/common/render_messages.h"
29 #include "content/public/browser/browser_thread.h" 34 #include "content/public/browser/browser_thread.h"
30 #include "content/public/browser/histogram_fetcher.h" 35 #include "content/public/browser/histogram_fetcher.h"
31 #include "content/public/browser/notification_service.h" 36 #include "content/public/browser/notification_service.h"
32 #include "content/public/browser/render_process_host.h" 37 #include "content/public/browser/render_process_host.h"
33 38
34 #if !defined(OS_ANDROID) 39 #if defined(ENABLE_PLUGINS)
40 #include "chrome/browser/metrics/plugin_metrics_provider.h"
41 #endif
42
43 #if defined(OS_ANDROID)
44 #include "chrome/browser/metrics/android_metrics_provider.h"
45 #else
35 #include "chrome/browser/service_process/service_process_control.h" 46 #include "chrome/browser/service_process/service_process_control.h"
36 #endif 47 #endif
37 48
38 #if defined(OS_CHROMEOS) 49 #if defined(OS_CHROMEOS)
39 #include "chrome/browser/metrics/chromeos_metrics_provider.h" 50 #include "chrome/browser/metrics/chromeos_metrics_provider.h"
40 #endif 51 #endif
41 52
42 #if defined(OS_WIN) 53 #if defined(OS_WIN)
43 #include <windows.h> 54 #include <windows.h>
44 #include "base/win/registry.h" 55 #include "base/win/registry.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 scoped_ptr<ChromeMetricsServiceClient> ChromeMetricsServiceClient::Create( 136 scoped_ptr<ChromeMetricsServiceClient> ChromeMetricsServiceClient::Create(
126 metrics::MetricsStateManager* state_manager) { 137 metrics::MetricsStateManager* state_manager) {
127 // Perform two-phase initialization so that |client->metrics_service_| only 138 // Perform two-phase initialization so that |client->metrics_service_| only
128 // receives pointers to fully constructed objects. 139 // receives pointers to fully constructed objects.
129 scoped_ptr<ChromeMetricsServiceClient> client( 140 scoped_ptr<ChromeMetricsServiceClient> client(
130 new ChromeMetricsServiceClient(state_manager)); 141 new ChromeMetricsServiceClient(state_manager));
131 client->metrics_service_.reset(new MetricsService( 142 client->metrics_service_.reset(new MetricsService(
132 state_manager, client.get(), g_browser_process->local_state())); 143 state_manager, client.get(), g_browser_process->local_state()));
133 144
134 // Register metrics providers. 145 // Register metrics providers.
146
135 client->metrics_service_->RegisterMetricsProvider( 147 client->metrics_service_->RegisterMetricsProvider(
136 scoped_ptr<metrics::MetricsProvider>( 148 scoped_ptr<metrics::MetricsProvider>(
137 new ExtensionsMetricsProvider(state_manager))); 149 new ExtensionsMetricsProvider(state_manager)));
150 client->metrics_service_->RegisterMetricsProvider(
151 scoped_ptr<metrics::MetricsProvider>(new NetworkMetricsProvider));
152 client->metrics_service_->RegisterMetricsProvider(
153 scoped_ptr<metrics::MetricsProvider>(new OmniboxMetricsProvider));
154 client->metrics_service_->RegisterMetricsProvider(
155 scoped_ptr<metrics::MetricsProvider>(new ChromeStabilityMetricsProvider));
156 client->metrics_service_->RegisterMetricsProvider(
157 scoped_ptr<metrics::MetricsProvider>(new GPUMetricsProvider()));
158
159 #if defined(OS_ANDROID)
160 client->metrics_service_->RegisterMetricsProvider(
161 scoped_ptr<metrics::MetricsProvider>(
162 new AndroidMetricsProvider(local_state_)));
163 #endif // defined(OS_ANDROID)
164
165 #if defined(OS_WIN)
166 GoogleUpdateMetricsProviderWin* google_update_metrics_provider =
167 new GoogleUpdateMetricsProviderWin;
168 client->google_update_metrics_provider_ = google_update_metrics_provider;
169 client->metrics_service_->RegisterMetricsProvider(
170 scoped_ptr<metrics::MetricsProvider>(google_update_metrics_provider));
171 #endif
172
173 #if defined(ENABLE_PLUGINS)
174 PluginMetricsProvider* plugin_metrics_provider =
175 new PluginMetricsProvider(g_browser_process->local_state());
176 client->plugin_metrics_provider_ = plugin_metrics_provider;
177 client->metrics_service_->RegisterMetricsProvider(
178 scoped_ptr<metrics::MetricsProvider>(plugin_metrics_provider));
179 #endif
138 180
139 #if defined(OS_CHROMEOS) 181 #if defined(OS_CHROMEOS)
140 ChromeOSMetricsProvider* chromeos_metrics_provider = 182 ChromeOSMetricsProvider* chromeos_metrics_provider =
141 new ChromeOSMetricsProvider; 183 new ChromeOSMetricsProvider;
142 client->chromeos_metrics_provider_ = chromeos_metrics_provider; 184 client->chromeos_metrics_provider_ = chromeos_metrics_provider;
143 client->metrics_service_->RegisterMetricsProvider( 185 client->metrics_service_->RegisterMetricsProvider(
144 scoped_ptr<metrics::MetricsProvider>(chromeos_metrics_provider)); 186 scoped_ptr<metrics::MetricsProvider>(chromeos_metrics_provider));
145 #endif 187 #endif
146 188
147 return client.Pass(); 189 return client.Pass();
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 metrics_service_->OnApplicationNotIdle(); 378 metrics_service_->OnApplicationNotIdle();
337 break; 379 break;
338 380
339 default: 381 default:
340 NOTREACHED(); 382 NOTREACHED();
341 } 383 }
342 } 384 }
343 385
344 void ChromeMetricsServiceClient::StartGatheringMetrics( 386 void ChromeMetricsServiceClient::StartGatheringMetrics(
345 const base::Closure& done_callback) { 387 const base::Closure& done_callback) {
346 // TODO(blundell): Move all metrics gathering tasks from MetricsService to
347 // here.
348 // Schedules a task on the file thread for execution of slower 388 // Schedules a task on the file thread for execution of slower
349 // initialization steps (such as plugin list generation) necessary 389 // initialization steps (such as plugin list generation) necessary
350 // for sending the initial log. This avoids blocking the main UI 390 // for sending the initial log. This avoids blocking the main UI
351 // thread. 391 // thread.
392 finished_gathering_initial_metrics_callback_ = done_callback;
352 content::BrowserThread::PostDelayedTask( 393 content::BrowserThread::PostDelayedTask(
353 content::BrowserThread::FILE, 394 content::BrowserThread::FILE,
354 FROM_HERE, 395 FROM_HERE,
355 base::Bind(&ChromeMetricsServiceClient::InitTaskGetHardwareClass, 396 base::Bind(&ChromeMetricsServiceClient::InitTaskGetHardwareClass,
356 weak_ptr_factory_.GetWeakPtr(), 397 weak_ptr_factory_.GetWeakPtr(),
357 base::MessageLoop::current()->message_loop_proxy(), 398 base::MessageLoop::current()->message_loop_proxy()),
358 done_callback),
359 base::TimeDelta::FromSeconds(kInitializationDelaySeconds)); 399 base::TimeDelta::FromSeconds(kInitializationDelaySeconds));
360 } 400 }
361 401
362 void ChromeMetricsServiceClient::InitTaskGetHardwareClass( 402 void ChromeMetricsServiceClient::InitTaskGetHardwareClass(
363 base::MessageLoopProxy* target_loop, 403 base::MessageLoopProxy* target_loop) {
364 const base::Closure& done_callback) { 404 base::Closure callback =
405 base::Bind(&ChromeMetricsServiceClient::OnInitTaskGotHardwareClass,
406 weak_ptr_factory_.GetWeakPtr());
365 #if defined(OS_CHROMEOS) 407 #if defined(OS_CHROMEOS)
366 chromeos_metrics_provider_->InitTaskGetHardwareClass(target_loop, 408 chromeos_metrics_provider_->InitTaskGetHardwareClass(target_loop, callback);
367 done_callback);
368 #else 409 #else
369 target_loop->PostTask(FROM_HERE, done_callback); 410 target_loop->PostTask(FROM_HERE, callback);
370 #endif 411 #endif
371 } 412 }
372 413
414 void ChromeMetricsServiceClient::OnInitTaskGotHardwareClass() {
415 const base::Closure got_plugin_info_callback =
416 base::Bind(&ChromeMetricsServiceClient::OnInitTaskGotPluginInfo,
417 weak_ptr_factory_.GetWeakPtr());
418
419 #if defined(ENABLE_PLUGINS)
420 plugin_metrics_provider_->GetPluginInformation(got_plugin_info_callback);
421 #else
422 got_plugin_info_callback.Run();
423 #endif
424 }
425
426 void ChromeMetricsServiceClient::OnInitTaskGotPluginInfo() {
427 const base::Closure got_metrics_callback =
428 base::Bind(&ChromeMetricsServiceClient::OnInitTaskGotGoogleUpdateData,
429 weak_ptr_factory_.GetWeakPtr());
430
431 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)
432 google_update_metrics_provider_->GetGoogleUpdateData(got_metrics_callback);
433 #else
434 got_metrics_callback.Run();
435 #endif
436 }
437
438 void ChromeMetricsServiceClient::OnInitTaskGotGoogleUpdateData() {
439 // Start the next part of the init task: fetching performance data. This will
440 // call into |FinishedReceivingProfilerData()| when the task completes.
441 chrome_browser_metrics::TrackingSynchronizer::FetchProfilerDataAsynchronously(
442 weak_ptr_factory_.GetWeakPtr());
443 }
444
445 void ChromeMetricsServiceClient::ReceivedProfilerData(
446 const tracked_objects::ProcessDataSnapshot& process_data,
447 int process_type) {
448 metrics_service_->ReceivedProfilerData(process_data, process_type);
449 }
450
451 void ChromeMetricsServiceClient::FinishedReceivingProfilerData() {
452 finished_gathering_initial_metrics_callback_.Run();
453 }
454
373 #if defined(OS_WIN) 455 #if defined(OS_WIN)
374 void ChromeMetricsServiceClient::CountBrowserCrashDumpAttempts() { 456 void ChromeMetricsServiceClient::CountBrowserCrashDumpAttempts() {
375 // Open the registry key for iteration. 457 // Open the registry key for iteration.
376 base::win::RegKey regkey; 458 base::win::RegKey regkey;
377 if (regkey.Open(HKEY_CURRENT_USER, 459 if (regkey.Open(HKEY_CURRENT_USER,
378 chrome::kBrowserCrashDumpAttemptsRegistryPath, 460 chrome::kBrowserCrashDumpAttemptsRegistryPath,
379 KEY_ALL_ACCESS) != ERROR_SUCCESS) { 461 KEY_ALL_ACCESS) != ERROR_SUCCESS) {
380 return; 462 return;
381 } 463 }
382 464
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 // Capture the histogram samples. 496 // Capture the histogram samples.
415 if (dumps_with_crash != 0) 497 if (dumps_with_crash != 0)
416 UMA_HISTOGRAM_COUNTS("Chrome.BrowserDumpsWithCrash", dumps_with_crash); 498 UMA_HISTOGRAM_COUNTS("Chrome.BrowserDumpsWithCrash", dumps_with_crash);
417 if (dumps_with_no_crash != 0) 499 if (dumps_with_no_crash != 0)
418 UMA_HISTOGRAM_COUNTS("Chrome.BrowserDumpsWithNoCrash", dumps_with_no_crash); 500 UMA_HISTOGRAM_COUNTS("Chrome.BrowserDumpsWithNoCrash", dumps_with_no_crash);
419 int total_dumps = dumps_with_crash + dumps_with_no_crash; 501 int total_dumps = dumps_with_crash + dumps_with_no_crash;
420 if (total_dumps != 0) 502 if (total_dumps != 0)
421 UMA_HISTOGRAM_COUNTS("Chrome.BrowserCrashDumpAttempts", total_dumps); 503 UMA_HISTOGRAM_COUNTS("Chrome.BrowserCrashDumpAttempts", total_dumps);
422 } 504 }
423 #endif // defined(OS_WIN) 505 #endif // defined(OS_WIN)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698