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 |
44 // This specifies the amount of time to wait for all renderers to send their | 50 // This specifies the amount of time to wait for all renderers to send their |
45 // data. | 51 // data. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 | 85 |
80 base::Closure callback_; | 86 base::Closure callback_; |
81 | 87 |
82 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails); | 88 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails); |
83 }; | 89 }; |
84 | 90 |
85 } // namespace | 91 } // namespace |
86 | 92 |
87 ChromeMetricsServiceClient::ChromeMetricsServiceClient( | 93 ChromeMetricsServiceClient::ChromeMetricsServiceClient( |
88 metrics::MetricsStateManager* state_manager) | 94 metrics::MetricsStateManager* state_manager) |
89 : waiting_for_collect_final_metrics_step_(false), | 95 : chromeos_metrics_provider_(NULL), |
96 waiting_for_collect_final_metrics_step_(false), | |
90 num_async_histogram_fetches_in_progress_(0), | 97 num_async_histogram_fetches_in_progress_(0), |
91 weak_ptr_factory_(this) { | 98 weak_ptr_factory_(this) { |
92 DCHECK(thread_checker_.CalledOnValidThread()); | 99 DCHECK(thread_checker_.CalledOnValidThread()); |
93 RecordCommandLineMetrics(); | 100 RecordCommandLineMetrics(); |
94 RegisterForNotifications(); | 101 RegisterForNotifications(); |
95 | 102 |
96 #if defined(OS_WIN) | 103 #if defined(OS_WIN) |
97 CountBrowserCrashDumpAttempts(); | 104 CountBrowserCrashDumpAttempts(); |
98 #endif // defined(OS_WIN) | 105 #endif // defined(OS_WIN) |
99 } | 106 } |
100 | 107 |
101 ChromeMetricsServiceClient::~ChromeMetricsServiceClient() { | 108 ChromeMetricsServiceClient::~ChromeMetricsServiceClient() { |
102 DCHECK(thread_checker_.CalledOnValidThread()); | 109 DCHECK(thread_checker_.CalledOnValidThread()); |
103 } | 110 } |
104 | 111 |
105 // static | 112 // static |
106 scoped_ptr<ChromeMetricsServiceClient> ChromeMetricsServiceClient::Create( | 113 scoped_ptr<ChromeMetricsServiceClient> ChromeMetricsServiceClient::Create( |
107 metrics::MetricsStateManager* state_manager) { | 114 metrics::MetricsStateManager* state_manager) { |
108 // Perform two-phase initialization so that |client->metrics_service_| only | 115 // Perform two-phase initialization so that |client->metrics_service_| only |
109 // receives pointers to fully constructed objects. | 116 // receives pointers to fully constructed objects. |
110 scoped_ptr<ChromeMetricsServiceClient> client( | 117 scoped_ptr<ChromeMetricsServiceClient> client( |
111 new ChromeMetricsServiceClient(state_manager)); | 118 new ChromeMetricsServiceClient(state_manager)); |
112 client->metrics_service_.reset( | 119 client->metrics_service_.reset(new MetricsService( |
Alexei Svitkine (slow)
2014/05/28 18:45:57
Nit: Now that there's a lot of code here, I sugges
blundell
2014/05/28 18:59:49
Done.
| |
113 new MetricsService(state_manager, client.get())); | 120 state_manager, client.get(), g_browser_process->local_state())); |
121 | |
122 // Register metrics providers. | |
123 client->metrics_service_->RegisterMetricsProvider( | |
124 scoped_ptr<metrics::MetricsProvider>( | |
125 new ExtensionsMetricsProvider(state_manager))); | |
126 | |
127 #if defined(OS_CHROMEOS) | |
128 ChromeOSMetricsProvider* chromeos_metrics_provider = | |
129 new ChromeOSMetricsProvider; | |
130 client->chromeos_metrics_provider_ = chromeos_metrics_provider; | |
131 client->metrics_service_->RegisterMetricsProvider( | |
132 scoped_ptr<metrics::MetricsProvider>(chromeos_metrics_provider)); | |
133 #endif | |
134 | |
114 return client.Pass(); | 135 return client.Pass(); |
115 } | 136 } |
116 | 137 |
117 void ChromeMetricsServiceClient::SetClientID(const std::string& client_id) { | 138 void ChromeMetricsServiceClient::SetClientID(const std::string& client_id) { |
118 crash_keys::SetClientID(client_id); | 139 crash_keys::SetClientID(client_id); |
119 } | 140 } |
120 | 141 |
121 bool ChromeMetricsServiceClient::IsOffTheRecordSessionActive() { | 142 bool ChromeMetricsServiceClient::IsOffTheRecordSessionActive() { |
122 return !chrome::IsOffTheRecordSessionActive(); | 143 return !chrome::IsOffTheRecordSessionActive(); |
123 } | 144 } |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 metrics_service_->OnApplicationNotIdle(); | 324 metrics_service_->OnApplicationNotIdle(); |
304 break; | 325 break; |
305 | 326 |
306 default: | 327 default: |
307 NOTREACHED(); | 328 NOTREACHED(); |
308 } | 329 } |
309 } | 330 } |
310 | 331 |
311 void ChromeMetricsServiceClient::StartGatheringMetrics( | 332 void ChromeMetricsServiceClient::StartGatheringMetrics( |
312 const base::Closure& done_callback) { | 333 const base::Closure& done_callback) { |
313 // TODO(blundell): Move metrics gathering tasks from MetricsService to here. | 334 // TODO(blundell): Move all metrics gathering tasks from MetricsService to |
335 // here. | |
336 #if defined(OS_CHROMEOS) | |
337 chromeos_metrics_provider_->InitTaskGetHardwareClass(done_callback); | |
338 #else | |
314 done_callback.Run(); | 339 done_callback.Run(); |
340 #endif | |
315 } | 341 } |
316 | 342 |
317 #if defined(OS_WIN) | 343 #if defined(OS_WIN) |
318 void ChromeMetricsServiceClient::CountBrowserCrashDumpAttempts() { | 344 void ChromeMetricsServiceClient::CountBrowserCrashDumpAttempts() { |
319 // Open the registry key for iteration. | 345 // Open the registry key for iteration. |
320 base::win::RegKey regkey; | 346 base::win::RegKey regkey; |
321 if (regkey.Open(HKEY_CURRENT_USER, | 347 if (regkey.Open(HKEY_CURRENT_USER, |
322 chrome::kBrowserCrashDumpAttemptsRegistryPath, | 348 chrome::kBrowserCrashDumpAttemptsRegistryPath, |
323 KEY_ALL_ACCESS) != ERROR_SUCCESS) { | 349 KEY_ALL_ACCESS) != ERROR_SUCCESS) { |
324 return; | 350 return; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 // Capture the histogram samples. | 384 // Capture the histogram samples. |
359 if (dumps_with_crash != 0) | 385 if (dumps_with_crash != 0) |
360 UMA_HISTOGRAM_COUNTS("Chrome.BrowserDumpsWithCrash", dumps_with_crash); | 386 UMA_HISTOGRAM_COUNTS("Chrome.BrowserDumpsWithCrash", dumps_with_crash); |
361 if (dumps_with_no_crash != 0) | 387 if (dumps_with_no_crash != 0) |
362 UMA_HISTOGRAM_COUNTS("Chrome.BrowserDumpsWithNoCrash", dumps_with_no_crash); | 388 UMA_HISTOGRAM_COUNTS("Chrome.BrowserDumpsWithNoCrash", dumps_with_no_crash); |
363 int total_dumps = dumps_with_crash + dumps_with_no_crash; | 389 int total_dumps = dumps_with_crash + dumps_with_no_crash; |
364 if (total_dumps != 0) | 390 if (total_dumps != 0) |
365 UMA_HISTOGRAM_COUNTS("Chrome.BrowserCrashDumpAttempts", total_dumps); | 391 UMA_HISTOGRAM_COUNTS("Chrome.BrowserCrashDumpAttempts", total_dumps); |
366 } | 392 } |
367 #endif // defined(OS_WIN) | 393 #endif // defined(OS_WIN) |
OLD | NEW |