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

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

Issue 301633006: Move ChromeOS hardware class init out of MetricsService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/extensions_metrics_provider.h"
21 #include "chrome/browser/metrics/metrics_service.h" 22 #include "chrome/browser/metrics/metrics_service.h"
22 #include "chrome/browser/ui/browser_otr_state.h" 23 #include "chrome/browser/ui/browser_otr_state.h"
23 #include "chrome/common/chrome_constants.h" 24 #include "chrome/common/chrome_constants.h"
24 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
25 #include "chrome/common/chrome_version_info.h" 26 #include "chrome/common/chrome_version_info.h"
26 #include "chrome/common/crash_keys.h" 27 #include "chrome/common/crash_keys.h"
27 #include "chrome/common/render_messages.h" 28 #include "chrome/common/render_messages.h"
29 #include "content/public/browser/browser_thread.h"
28 #include "content/public/browser/histogram_fetcher.h" 30 #include "content/public/browser/histogram_fetcher.h"
29 #include "content/public/browser/notification_service.h" 31 #include "content/public/browser/notification_service.h"
30 #include "content/public/browser/render_process_host.h" 32 #include "content/public/browser/render_process_host.h"
31 33
32 #if !defined(OS_ANDROID) 34 #if !defined(OS_ANDROID)
33 #include "chrome/browser/service_process/service_process_control.h" 35 #include "chrome/browser/service_process/service_process_control.h"
34 #endif 36 #endif
35 37
38 #if defined(OS_CHROMEOS)
39 //#include "chrome/browser/chromeos/settings/cros_settings.h"
40 #include "chrome/browser/metrics/chromeos_metrics_provider.h"
41 #endif
42
36 #if defined(OS_WIN) 43 #if defined(OS_WIN)
37 #include <windows.h> 44 #include <windows.h>
38 #include "base/win/registry.h" 45 #include "base/win/registry.h"
39 #include "chrome/browser/metrics/google_update_metrics_provider_win.h" 46 #include "chrome/browser/metrics/google_update_metrics_provider_win.h"
40 #endif 47 #endif
41 48
42 namespace { 49 namespace {
43 50
51 // The delay, in seconds, after starting recording before doing expensive
52 // initialization work.
53 #if defined(OS_ANDROID) || defined(OS_IOS)
54 // On mobile devices, a significant portion of sessions last less than a minute.
55 // Use a shorter timer on these platforms to avoid losing data.
56 // TODO(dfalcantara): To avoid delaying startup, tighten up initialization so
57 // that it occurs after the user gets their initial page.
58 const int kInitializationDelaySeconds = 5;
59 #else
60 const int kInitializationDelaySeconds = 30;
61 #endif
62
44 // This specifies the amount of time to wait for all renderers to send their 63 // This specifies the amount of time to wait for all renderers to send their
45 // data. 64 // data.
46 const int kMaxHistogramGatheringWaitDuration = 60000; // 60 seconds. 65 const int kMaxHistogramGatheringWaitDuration = 60000; // 60 seconds.
47 66
48 metrics::SystemProfileProto::Channel AsProtobufChannel( 67 metrics::SystemProfileProto::Channel AsProtobufChannel(
49 chrome::VersionInfo::Channel channel) { 68 chrome::VersionInfo::Channel channel) {
50 switch (channel) { 69 switch (channel) {
51 case chrome::VersionInfo::CHANNEL_UNKNOWN: 70 case chrome::VersionInfo::CHANNEL_UNKNOWN:
52 return metrics::SystemProfileProto::CHANNEL_UNKNOWN; 71 return metrics::SystemProfileProto::CHANNEL_UNKNOWN;
53 case chrome::VersionInfo::CHANNEL_CANARY: 72 case chrome::VersionInfo::CHANNEL_CANARY:
(...skipping 25 matching lines...) Expand all
79 98
80 base::Closure callback_; 99 base::Closure callback_;
81 100
82 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails); 101 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails);
83 }; 102 };
84 103
85 } // namespace 104 } // namespace
86 105
87 ChromeMetricsServiceClient::ChromeMetricsServiceClient( 106 ChromeMetricsServiceClient::ChromeMetricsServiceClient(
88 metrics::MetricsStateManager* state_manager) 107 metrics::MetricsStateManager* state_manager)
89 : waiting_for_collect_final_metrics_step_(false), 108 : chromeos_metrics_provider_(NULL),
109 waiting_for_collect_final_metrics_step_(false),
90 num_async_histogram_fetches_in_progress_(0), 110 num_async_histogram_fetches_in_progress_(0),
91 weak_ptr_factory_(this) { 111 weak_ptr_factory_(this) {
92 DCHECK(thread_checker_.CalledOnValidThread()); 112 DCHECK(thread_checker_.CalledOnValidThread());
93 RecordCommandLineMetrics(); 113 RecordCommandLineMetrics();
94 RegisterForNotifications(); 114 RegisterForNotifications();
95 115
96 #if defined(OS_WIN) 116 #if defined(OS_WIN)
97 CountBrowserCrashDumpAttempts(); 117 CountBrowserCrashDumpAttempts();
98 #endif // defined(OS_WIN) 118 #endif // defined(OS_WIN)
99 } 119 }
100 120
101 ChromeMetricsServiceClient::~ChromeMetricsServiceClient() { 121 ChromeMetricsServiceClient::~ChromeMetricsServiceClient() {
102 DCHECK(thread_checker_.CalledOnValidThread()); 122 DCHECK(thread_checker_.CalledOnValidThread());
103 } 123 }
104 124
105 // static 125 // static
106 scoped_ptr<ChromeMetricsServiceClient> ChromeMetricsServiceClient::Create( 126 scoped_ptr<ChromeMetricsServiceClient> ChromeMetricsServiceClient::Create(
107 metrics::MetricsStateManager* state_manager) { 127 metrics::MetricsStateManager* state_manager) {
108 // Perform two-phase initialization so that |client->metrics_service_| only 128 // Perform two-phase initialization so that |client->metrics_service_| only
109 // receives pointers to fully constructed objects. 129 // receives pointers to fully constructed objects.
110 scoped_ptr<ChromeMetricsServiceClient> client( 130 scoped_ptr<ChromeMetricsServiceClient> client(
111 new ChromeMetricsServiceClient(state_manager)); 131 new ChromeMetricsServiceClient(state_manager));
112 client->metrics_service_.reset( 132 client->metrics_service_.reset(new MetricsService(
113 new MetricsService(state_manager, client.get())); 133 state_manager, client.get(), g_browser_process->local_state()));
134
135 // Register metrics providers.
136 client->metrics_service_->RegisterMetricsProvider(
137 scoped_ptr<metrics::MetricsProvider>(
138 new ExtensionsMetricsProvider(state_manager)));
139
140 #if defined(OS_CHROMEOS)
141 ChromeOSMetricsProvider* chromeos_metrics_provider =
142 new ChromeOSMetricsProvider;
143 client->chromeos_metrics_provider_ = chromeos_metrics_provider;
144 client->metrics_service_->RegisterMetricsProvider(
145 scoped_ptr<metrics::MetricsProvider>(chromeos_metrics_provider));
146 #endif
147
114 return client.Pass(); 148 return client.Pass();
115 } 149 }
116 150
117 void ChromeMetricsServiceClient::SetClientID(const std::string& client_id) { 151 void ChromeMetricsServiceClient::SetClientID(const std::string& client_id) {
118 crash_keys::SetClientID(client_id); 152 crash_keys::SetClientID(client_id);
119 } 153 }
120 154
121 bool ChromeMetricsServiceClient::IsOffTheRecordSessionActive() { 155 bool ChromeMetricsServiceClient::IsOffTheRecordSessionActive() {
122 return !chrome::IsOffTheRecordSessionActive(); 156 return !chrome::IsOffTheRecordSessionActive();
123 } 157 }
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 metrics_service_->OnApplicationNotIdle(); 337 metrics_service_->OnApplicationNotIdle();
304 break; 338 break;
305 339
306 default: 340 default:
307 NOTREACHED(); 341 NOTREACHED();
308 } 342 }
309 } 343 }
310 344
311 void ChromeMetricsServiceClient::StartGatheringMetrics( 345 void ChromeMetricsServiceClient::StartGatheringMetrics(
312 const base::Closure& done_callback) { 346 const base::Closure& done_callback) {
313 // TODO(blundell): Move metrics gathering tasks from MetricsService to here. 347 // TODO(blundell): Move all metrics gathering tasks from MetricsService to
314 done_callback.Run(); 348 // here.
349 // Schedules a task on the file thread for execution of slower
350 // initialization steps (such as plugin list generation) necessary
351 // for sending the initial log. This avoids blocking the main UI
352 // thread.
353 content::BrowserThread::PostDelayedTask(
354 content::BrowserThread::FILE,
355 FROM_HERE,
356 base::Bind(&ChromeMetricsServiceClient::InitTaskGetHardwareClass,
357 weak_ptr_factory_.GetWeakPtr(),
358 base::MessageLoop::current()->message_loop_proxy(),
359 done_callback),
360 base::TimeDelta::FromSeconds(kInitializationDelaySeconds));
361 }
362
363 void ChromeMetricsServiceClient::InitTaskGetHardwareClass(
364 base::MessageLoopProxy* target_loop,
365 const base::Closure& done_callback) {
366 #if defined(OS_CHROMEOS)
367 chromeos_metrics_provider_->InitTaskGetHardwareClass(target_loop,
368 done_callback);
369 #else
370 target_loop->PostTask(FROM_HERE, done_callback);
371 #endif
315 } 372 }
316 373
317 #if defined(OS_WIN) 374 #if defined(OS_WIN)
318 void ChromeMetricsServiceClient::CountBrowserCrashDumpAttempts() { 375 void ChromeMetricsServiceClient::CountBrowserCrashDumpAttempts() {
319 // Open the registry key for iteration. 376 // Open the registry key for iteration.
320 base::win::RegKey regkey; 377 base::win::RegKey regkey;
321 if (regkey.Open(HKEY_CURRENT_USER, 378 if (regkey.Open(HKEY_CURRENT_USER,
322 chrome::kBrowserCrashDumpAttemptsRegistryPath, 379 chrome::kBrowserCrashDumpAttemptsRegistryPath,
323 KEY_ALL_ACCESS) != ERROR_SUCCESS) { 380 KEY_ALL_ACCESS) != ERROR_SUCCESS) {
324 return; 381 return;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 // Capture the histogram samples. 415 // Capture the histogram samples.
359 if (dumps_with_crash != 0) 416 if (dumps_with_crash != 0)
360 UMA_HISTOGRAM_COUNTS("Chrome.BrowserDumpsWithCrash", dumps_with_crash); 417 UMA_HISTOGRAM_COUNTS("Chrome.BrowserDumpsWithCrash", dumps_with_crash);
361 if (dumps_with_no_crash != 0) 418 if (dumps_with_no_crash != 0)
362 UMA_HISTOGRAM_COUNTS("Chrome.BrowserDumpsWithNoCrash", dumps_with_no_crash); 419 UMA_HISTOGRAM_COUNTS("Chrome.BrowserDumpsWithNoCrash", dumps_with_no_crash);
363 int total_dumps = dumps_with_crash + dumps_with_no_crash; 420 int total_dumps = dumps_with_crash + dumps_with_no_crash;
364 if (total_dumps != 0) 421 if (total_dumps != 0)
365 UMA_HISTOGRAM_COUNTS("Chrome.BrowserCrashDumpAttempts", total_dumps); 422 UMA_HISTOGRAM_COUNTS("Chrome.BrowserCrashDumpAttempts", total_dumps);
366 } 423 }
367 #endif // defined(OS_WIN) 424 #endif // defined(OS_WIN)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698