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