| 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 : metrics_state_manager_(state_manager), |
| 96 chromeos_metrics_provider_(NULL), |
| 97 waiting_for_collect_final_metrics_step_(false), |
| 90 num_async_histogram_fetches_in_progress_(0), | 98 num_async_histogram_fetches_in_progress_(0), |
| 91 weak_ptr_factory_(this) { | 99 weak_ptr_factory_(this) { |
| 92 DCHECK(thread_checker_.CalledOnValidThread()); | 100 DCHECK(thread_checker_.CalledOnValidThread()); |
| 93 RecordCommandLineMetrics(); | 101 RecordCommandLineMetrics(); |
| 94 RegisterForNotifications(); | 102 RegisterForNotifications(); |
| 95 | 103 |
| 96 #if defined(OS_WIN) | 104 #if defined(OS_WIN) |
| 97 CountBrowserCrashDumpAttempts(); | 105 CountBrowserCrashDumpAttempts(); |
| 98 #endif // defined(OS_WIN) | 106 #endif // defined(OS_WIN) |
| 99 } | 107 } |
| 100 | 108 |
| 101 ChromeMetricsServiceClient::~ChromeMetricsServiceClient() { | 109 ChromeMetricsServiceClient::~ChromeMetricsServiceClient() { |
| 102 DCHECK(thread_checker_.CalledOnValidThread()); | 110 DCHECK(thread_checker_.CalledOnValidThread()); |
| 103 } | 111 } |
| 104 | 112 |
| 105 // static | 113 // static |
| 106 scoped_ptr<ChromeMetricsServiceClient> ChromeMetricsServiceClient::Create( | 114 scoped_ptr<ChromeMetricsServiceClient> ChromeMetricsServiceClient::Create( |
| 107 metrics::MetricsStateManager* state_manager, | 115 metrics::MetricsStateManager* state_manager, |
| 108 PrefService* local_state) { | 116 PrefService* local_state) { |
| 109 // Perform two-phase initialization so that |client->metrics_service_| only | 117 // Perform two-phase initialization so that |client->metrics_service_| only |
| 110 // receives pointers to fully constructed objects. | 118 // receives pointers to fully constructed objects. |
| 111 scoped_ptr<ChromeMetricsServiceClient> client( | 119 scoped_ptr<ChromeMetricsServiceClient> client( |
| 112 new ChromeMetricsServiceClient(state_manager)); | 120 new ChromeMetricsServiceClient(state_manager)); |
| 113 client->metrics_service_.reset( | 121 client->Initialize(); |
| 114 new MetricsService(state_manager, client.get(), local_state)); | 122 |
| 115 return client.Pass(); | 123 return client.Pass(); |
| 116 } | 124 } |
| 117 | 125 |
| 126 void ChromeMetricsServiceClient::Initialize() { |
| 127 metrics_service_.reset(new MetricsService( |
| 128 metrics_state_manager_, this, g_browser_process->local_state())); |
| 129 |
| 130 // Register metrics providers. |
| 131 metrics_service_->RegisterMetricsProvider( |
| 132 scoped_ptr<metrics::MetricsProvider>( |
| 133 new ExtensionsMetricsProvider(metrics_state_manager_))); |
| 134 |
| 135 #if defined(OS_CHROMEOS) |
| 136 ChromeOSMetricsProvider* chromeos_metrics_provider = |
| 137 new ChromeOSMetricsProvider; |
| 138 chromeos_metrics_provider_ = chromeos_metrics_provider; |
| 139 metrics_service_->RegisterMetricsProvider( |
| 140 scoped_ptr<metrics::MetricsProvider>(chromeos_metrics_provider)); |
| 141 #endif |
| 142 } |
| 143 |
| 118 void ChromeMetricsServiceClient::SetClientID(const std::string& client_id) { | 144 void ChromeMetricsServiceClient::SetClientID(const std::string& client_id) { |
| 119 crash_keys::SetClientID(client_id); | 145 crash_keys::SetClientID(client_id); |
| 120 } | 146 } |
| 121 | 147 |
| 122 bool ChromeMetricsServiceClient::IsOffTheRecordSessionActive() { | 148 bool ChromeMetricsServiceClient::IsOffTheRecordSessionActive() { |
| 123 return !chrome::IsOffTheRecordSessionActive(); | 149 return !chrome::IsOffTheRecordSessionActive(); |
| 124 } | 150 } |
| 125 | 151 |
| 126 std::string ChromeMetricsServiceClient::GetApplicationLocale() { | 152 std::string ChromeMetricsServiceClient::GetApplicationLocale() { |
| 127 return g_browser_process->GetApplicationLocale(); | 153 return g_browser_process->GetApplicationLocale(); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 metrics_service_->OnApplicationNotIdle(); | 330 metrics_service_->OnApplicationNotIdle(); |
| 305 break; | 331 break; |
| 306 | 332 |
| 307 default: | 333 default: |
| 308 NOTREACHED(); | 334 NOTREACHED(); |
| 309 } | 335 } |
| 310 } | 336 } |
| 311 | 337 |
| 312 void ChromeMetricsServiceClient::StartGatheringMetrics( | 338 void ChromeMetricsServiceClient::StartGatheringMetrics( |
| 313 const base::Closure& done_callback) { | 339 const base::Closure& done_callback) { |
| 314 // TODO(blundell): Move metrics gathering tasks from MetricsService to here. | 340 // TODO(blundell): Move all metrics gathering tasks from MetricsService to |
| 341 // here. |
| 342 #if defined(OS_CHROMEOS) |
| 343 chromeos_metrics_provider_->InitTaskGetHardwareClass(done_callback); |
| 344 #else |
| 315 done_callback.Run(); | 345 done_callback.Run(); |
| 346 #endif |
| 316 } | 347 } |
| 317 | 348 |
| 318 #if defined(OS_WIN) | 349 #if defined(OS_WIN) |
| 319 void ChromeMetricsServiceClient::CountBrowserCrashDumpAttempts() { | 350 void ChromeMetricsServiceClient::CountBrowserCrashDumpAttempts() { |
| 320 // Open the registry key for iteration. | 351 // Open the registry key for iteration. |
| 321 base::win::RegKey regkey; | 352 base::win::RegKey regkey; |
| 322 if (regkey.Open(HKEY_CURRENT_USER, | 353 if (regkey.Open(HKEY_CURRENT_USER, |
| 323 chrome::kBrowserCrashDumpAttemptsRegistryPath, | 354 chrome::kBrowserCrashDumpAttemptsRegistryPath, |
| 324 KEY_ALL_ACCESS) != ERROR_SUCCESS) { | 355 KEY_ALL_ACCESS) != ERROR_SUCCESS) { |
| 325 return; | 356 return; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 // Capture the histogram samples. | 390 // Capture the histogram samples. |
| 360 if (dumps_with_crash != 0) | 391 if (dumps_with_crash != 0) |
| 361 UMA_HISTOGRAM_COUNTS("Chrome.BrowserDumpsWithCrash", dumps_with_crash); | 392 UMA_HISTOGRAM_COUNTS("Chrome.BrowserDumpsWithCrash", dumps_with_crash); |
| 362 if (dumps_with_no_crash != 0) | 393 if (dumps_with_no_crash != 0) |
| 363 UMA_HISTOGRAM_COUNTS("Chrome.BrowserDumpsWithNoCrash", dumps_with_no_crash); | 394 UMA_HISTOGRAM_COUNTS("Chrome.BrowserDumpsWithNoCrash", dumps_with_no_crash); |
| 364 int total_dumps = dumps_with_crash + dumps_with_no_crash; | 395 int total_dumps = dumps_with_crash + dumps_with_no_crash; |
| 365 if (total_dumps != 0) | 396 if (total_dumps != 0) |
| 366 UMA_HISTOGRAM_COUNTS("Chrome.BrowserCrashDumpAttempts", total_dumps); | 397 UMA_HISTOGRAM_COUNTS("Chrome.BrowserCrashDumpAttempts", total_dumps); |
| 367 } | 398 } |
| 368 #endif // defined(OS_WIN) | 399 #endif // defined(OS_WIN) |
| OLD | NEW |