| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 bool IsCellularLogicEnabled() { | 94 bool IsCellularLogicEnabled() { |
| 95 if (variations::GetVariationParamValue("UMA_EnableCellularLogUpload", | 95 if (variations::GetVariationParamValue("UMA_EnableCellularLogUpload", |
| 96 "Enabled") != "true") { | 96 "Enabled") != "true") { |
| 97 return false; | 97 return false; |
| 98 } | 98 } |
| 99 | 99 |
| 100 return net::NetworkChangeNotifier::IsConnectionCellular( | 100 return net::NetworkChangeNotifier::IsConnectionCellular( |
| 101 net::NetworkChangeNotifier::GetConnectionType()); | 101 net::NetworkChangeNotifier::GetConnectionType()); |
| 102 } | 102 } |
| 103 | 103 |
| 104 // Checks whether it is the first time that cellular uploads logic should be |
| 105 // enabled based on whether the the preference for that logic is initialized. |
| 106 // This should happen only once as the used preference will be initialized |
| 107 // afterwards in |UmaSessionStats.java|. |
| 108 bool ShouldClearSavedMetrics() { |
| 109 #if defined(OS_ANDROID) |
| 110 PrefService* local_state = g_browser_process->local_state(); |
| 111 return !local_state->HasPrefPath(prefs::kMetricsReportingEnabled) && |
| 112 variations::GetVariationParamValue("UMA_EnableCellularLogUpload", |
| 113 "Enabled") == "true"; |
| 114 #else |
| 115 return false; |
| 116 #endif |
| 117 } |
| 118 |
| 104 } // namespace | 119 } // namespace |
| 105 | 120 |
| 121 |
| 106 ChromeMetricsServiceClient::ChromeMetricsServiceClient( | 122 ChromeMetricsServiceClient::ChromeMetricsServiceClient( |
| 107 metrics::MetricsStateManager* state_manager) | 123 metrics::MetricsStateManager* state_manager) |
| 108 : metrics_state_manager_(state_manager), | 124 : metrics_state_manager_(state_manager), |
| 109 chromeos_metrics_provider_(nullptr), | 125 chromeos_metrics_provider_(nullptr), |
| 110 waiting_for_collect_final_metrics_step_(false), | 126 waiting_for_collect_final_metrics_step_(false), |
| 111 num_async_histogram_fetches_in_progress_(0), | 127 num_async_histogram_fetches_in_progress_(0), |
| 112 profiler_metrics_provider_(nullptr), | 128 profiler_metrics_provider_(nullptr), |
| 113 #if defined(ENABLE_PLUGINS) | 129 #if defined(ENABLE_PLUGINS) |
| 114 plugin_metrics_provider_(nullptr), | 130 plugin_metrics_provider_(nullptr), |
| 115 #endif | 131 #endif |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 void ChromeMetricsServiceClient::LogPluginLoadingError( | 288 void ChromeMetricsServiceClient::LogPluginLoadingError( |
| 273 const base::FilePath& plugin_path) { | 289 const base::FilePath& plugin_path) { |
| 274 #if defined(ENABLE_PLUGINS) | 290 #if defined(ENABLE_PLUGINS) |
| 275 plugin_metrics_provider_->LogPluginLoadingError(plugin_path); | 291 plugin_metrics_provider_->LogPluginLoadingError(plugin_path); |
| 276 #else | 292 #else |
| 277 NOTREACHED(); | 293 NOTREACHED(); |
| 278 #endif // defined(ENABLE_PLUGINS) | 294 #endif // defined(ENABLE_PLUGINS) |
| 279 } | 295 } |
| 280 | 296 |
| 281 void ChromeMetricsServiceClient::Initialize() { | 297 void ChromeMetricsServiceClient::Initialize() { |
| 298 // Clear metrics reports if it is the first time cellular upload logic should |
| 299 // apply to avoid sudden bulk uploads. It needs to be done before initializing |
| 300 // metrics service so that metrics log manager is initialized correctly. |
| 301 if (ShouldClearSavedMetrics()) { |
| 302 PrefService* local_state = g_browser_process->local_state(); |
| 303 local_state->ClearPref(metrics::prefs::kMetricsInitialLogs); |
| 304 local_state->ClearPref(metrics::prefs::kMetricsOngoingLogs); |
| 305 } |
| 306 |
| 282 metrics_service_.reset(new metrics::MetricsService( | 307 metrics_service_.reset(new metrics::MetricsService( |
| 283 metrics_state_manager_, this, g_browser_process->local_state())); | 308 metrics_state_manager_, this, g_browser_process->local_state())); |
| 284 | 309 |
| 285 // Register metrics providers. | 310 // Register metrics providers. |
| 286 #if defined(ENABLE_EXTENSIONS) | 311 #if defined(ENABLE_EXTENSIONS) |
| 287 metrics_service_->RegisterMetricsProvider( | 312 metrics_service_->RegisterMetricsProvider( |
| 288 scoped_ptr<metrics::MetricsProvider>( | 313 scoped_ptr<metrics::MetricsProvider>( |
| 289 new ExtensionsMetricsProvider(metrics_state_manager_))); | 314 new ExtensionsMetricsProvider(metrics_state_manager_))); |
| 290 #endif | 315 #endif |
| 291 metrics_service_->RegisterMetricsProvider( | 316 metrics_service_->RegisterMetricsProvider( |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 new SigninStatusMetricsProviderChromeOS; | 381 new SigninStatusMetricsProviderChromeOS; |
| 357 metrics_service_->RegisterMetricsProvider( | 382 metrics_service_->RegisterMetricsProvider( |
| 358 scoped_ptr<metrics::MetricsProvider>(signin_metrics_provider_cros)); | 383 scoped_ptr<metrics::MetricsProvider>(signin_metrics_provider_cros)); |
| 359 #endif // defined(OS_CHROMEOS) | 384 #endif // defined(OS_CHROMEOS) |
| 360 | 385 |
| 361 #if !defined(OS_CHROMEOS) && !defined(OS_IOS) | 386 #if !defined(OS_CHROMEOS) && !defined(OS_IOS) |
| 362 metrics_service_->RegisterMetricsProvider( | 387 metrics_service_->RegisterMetricsProvider( |
| 363 scoped_ptr<metrics::MetricsProvider>( | 388 scoped_ptr<metrics::MetricsProvider>( |
| 364 SigninStatusMetricsProvider::CreateInstance())); | 389 SigninStatusMetricsProvider::CreateInstance())); |
| 365 #endif // !defined(OS_CHROMEOS) && !defined(OS_IOS) | 390 #endif // !defined(OS_CHROMEOS) && !defined(OS_IOS) |
| 391 |
| 392 // Clear stability metrics if it is the first time cellular upload logic |
| 393 // should apply to avoid sudden bulk uploads. It needs to be done after all |
| 394 // providers are registered. |
| 395 if (ShouldClearSavedMetrics()) |
| 396 metrics_service_->ClearSavedStabilityMetrics(); |
| 366 } | 397 } |
| 367 | 398 |
| 368 void ChromeMetricsServiceClient::OnInitTaskGotHardwareClass() { | 399 void ChromeMetricsServiceClient::OnInitTaskGotHardwareClass() { |
| 369 const base::Closure got_plugin_info_callback = | 400 const base::Closure got_plugin_info_callback = |
| 370 base::Bind(&ChromeMetricsServiceClient::OnInitTaskGotPluginInfo, | 401 base::Bind(&ChromeMetricsServiceClient::OnInitTaskGotPluginInfo, |
| 371 weak_ptr_factory_.GetWeakPtr()); | 402 weak_ptr_factory_.GetWeakPtr()); |
| 372 | 403 |
| 373 #if defined(ENABLE_PLUGINS) | 404 #if defined(ENABLE_PLUGINS) |
| 374 plugin_metrics_provider_->GetPluginInformation(got_plugin_info_callback); | 405 plugin_metrics_provider_->GetPluginInformation(got_plugin_info_callback); |
| 375 #else | 406 #else |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 case content::NOTIFICATION_LOAD_START: | 556 case content::NOTIFICATION_LOAD_START: |
| 526 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: | 557 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: |
| 527 case content::NOTIFICATION_RENDER_WIDGET_HOST_HANG: | 558 case content::NOTIFICATION_RENDER_WIDGET_HOST_HANG: |
| 528 metrics_service_->OnApplicationNotIdle(); | 559 metrics_service_->OnApplicationNotIdle(); |
| 529 break; | 560 break; |
| 530 | 561 |
| 531 default: | 562 default: |
| 532 NOTREACHED(); | 563 NOTREACHED(); |
| 533 } | 564 } |
| 534 } | 565 } |
| OLD | NEW |