| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 #include "chrome/common/features.h" | 39 #include "chrome/common/features.h" |
| 40 #include "chrome/installer/util/util_constants.h" | 40 #include "chrome/installer/util/util_constants.h" |
| 41 #include "components/metrics/call_stack_profile_metrics_provider.h" | 41 #include "components/metrics/call_stack_profile_metrics_provider.h" |
| 42 #include "components/metrics/drive_metrics_provider.h" | 42 #include "components/metrics/drive_metrics_provider.h" |
| 43 #include "components/metrics/file_metrics_provider.h" | 43 #include "components/metrics/file_metrics_provider.h" |
| 44 #include "components/metrics/gpu/gpu_metrics_provider.h" | 44 #include "components/metrics/gpu/gpu_metrics_provider.h" |
| 45 #include "components/metrics/metrics_pref_names.h" | 45 #include "components/metrics/metrics_pref_names.h" |
| 46 #include "components/metrics/metrics_service.h" | 46 #include "components/metrics/metrics_service.h" |
| 47 #include "components/metrics/metrics_service_client.h" | 47 #include "components/metrics/metrics_service_client.h" |
| 48 #include "components/metrics/metrics_state_manager.h" | 48 #include "components/metrics/metrics_state_manager.h" |
| 49 #include "components/metrics/net/cellular_logic_helper.h" |
| 49 #include "components/metrics/net/net_metrics_log_uploader.h" | 50 #include "components/metrics/net/net_metrics_log_uploader.h" |
| 50 #include "components/metrics/net/network_metrics_provider.h" | 51 #include "components/metrics/net/network_metrics_provider.h" |
| 51 #include "components/metrics/net/version_utils.h" | 52 #include "components/metrics/net/version_utils.h" |
| 52 #include "components/metrics/profiler/profiler_metrics_provider.h" | 53 #include "components/metrics/profiler/profiler_metrics_provider.h" |
| 53 #include "components/metrics/profiler/tracking_synchronizer.h" | 54 #include "components/metrics/profiler/tracking_synchronizer.h" |
| 54 #include "components/metrics/stability_metrics_helper.h" | 55 #include "components/metrics/stability_metrics_helper.h" |
| 55 #include "components/metrics/ui/screen_info_metrics_provider.h" | 56 #include "components/metrics/ui/screen_info_metrics_provider.h" |
| 56 #include "components/metrics/url_constants.h" | 57 #include "components/metrics/url_constants.h" |
| 57 #include "components/omnibox/browser/omnibox_metrics_provider.h" | 58 #include "components/omnibox/browser/omnibox_metrics_provider.h" |
| 58 #include "components/prefs/pref_registry_simple.h" | 59 #include "components/prefs/pref_registry_simple.h" |
| 59 #include "components/prefs/pref_service.h" | 60 #include "components/prefs/pref_service.h" |
| 60 #include "components/sync_driver/device_count_metrics_provider.h" | 61 #include "components/sync_driver/device_count_metrics_provider.h" |
| 61 #include "components/variations/variations_associated_data.h" | |
| 62 #include "components/version_info/version_info.h" | 62 #include "components/version_info/version_info.h" |
| 63 #include "content/public/browser/browser_thread.h" | 63 #include "content/public/browser/browser_thread.h" |
| 64 #include "content/public/browser/histogram_fetcher.h" | 64 #include "content/public/browser/histogram_fetcher.h" |
| 65 #include "content/public/browser/notification_service.h" | 65 #include "content/public/browser/notification_service.h" |
| 66 | 66 |
| 67 #if BUILDFLAG(ANDROID_JAVA_UI) | 67 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 68 #include "chrome/browser/metrics/android_metrics_provider.h" | 68 #include "chrome/browser/metrics/android_metrics_provider.h" |
| 69 #endif | 69 #endif |
| 70 | 70 |
| 71 #if defined(ENABLE_PRINT_PREVIEW) | 71 #if defined(ENABLE_PRINT_PREVIEW) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 96 #if !defined(OS_CHROMEOS) | 96 #if !defined(OS_CHROMEOS) |
| 97 #include "chrome/browser/signin/chrome_signin_status_metrics_provider_delegate.h
" | 97 #include "chrome/browser/signin/chrome_signin_status_metrics_provider_delegate.h
" |
| 98 #include "components/signin/core/browser/signin_status_metrics_provider.h" | 98 #include "components/signin/core/browser/signin_status_metrics_provider.h" |
| 99 #endif // !defined(OS_CHROMEOS) | 99 #endif // !defined(OS_CHROMEOS) |
| 100 | 100 |
| 101 namespace { | 101 namespace { |
| 102 | 102 |
| 103 // This specifies the amount of time to wait for all renderers to send their | 103 // This specifies the amount of time to wait for all renderers to send their |
| 104 // data. | 104 // data. |
| 105 const int kMaxHistogramGatheringWaitDuration = 60000; // 60 seconds. | 105 const int kMaxHistogramGatheringWaitDuration = 60000; // 60 seconds. |
| 106 | |
| 107 // Standard interval between log uploads, in seconds. | |
| 108 #if defined(OS_ANDROID) | |
| 109 const int kStandardUploadIntervalSeconds = 5 * 60; // Five minutes. | |
| 110 const int kStandardUploadIntervalCellularSeconds = 15 * 60; // Fifteen minutes. | |
| 111 #else | |
| 112 const int kStandardUploadIntervalSeconds = 30 * 60; // Thirty minutes. | |
| 113 #endif | |
| 114 | |
| 115 const char kBrowserMetricsFileName[] = "SavedMetrics"; | 106 const char kBrowserMetricsFileName[] = "SavedMetrics"; |
| 116 | 107 |
| 117 // Returns true if current connection type is cellular and user is assigned to | |
| 118 // experimental group for enabled cellular uploads. | |
| 119 bool IsCellularLogicEnabled() { | |
| 120 if (variations::GetVariationParamValue("UMA_EnableCellularLogUpload", | |
| 121 "Enabled") != "true" || | |
| 122 variations::GetVariationParamValue("UMA_EnableCellularLogUpload", | |
| 123 "Optimize") == "false") { | |
| 124 return false; | |
| 125 } | |
| 126 | |
| 127 return net::NetworkChangeNotifier::IsConnectionCellular( | |
| 128 net::NetworkChangeNotifier::GetConnectionType()); | |
| 129 } | |
| 130 | |
| 131 // Checks whether it is the first time that cellular uploads logic should be | 108 // Checks whether it is the first time that cellular uploads logic should be |
| 132 // enabled based on whether the the preference for that logic is initialized. | 109 // enabled based on whether the the preference for that logic is initialized. |
| 133 // This should happen only once as the used preference will be initialized | 110 // This should happen only once as the used preference will be initialized |
| 134 // afterwards in |UmaSessionStats.java|. | 111 // afterwards in |UmaSessionStats.java|. |
| 135 bool ShouldClearSavedMetrics() { | 112 bool ShouldClearSavedMetrics() { |
| 136 #if BUILDFLAG(ANDROID_JAVA_UI) | 113 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 137 PrefService* local_state = g_browser_process->local_state(); | 114 PrefService* local_state = g_browser_process->local_state(); |
| 138 return !local_state->HasPrefPath(metrics::prefs::kMetricsReportingEnabled) && | 115 return !local_state->HasPrefPath(metrics::prefs::kMetricsReportingEnabled) && |
| 139 variations::GetVariationParamValue("UMA_EnableCellularLogUpload", | 116 metrics::IsCellularLogicEnabled(); |
| 140 "Enabled") == "true"; | |
| 141 #else | 117 #else |
| 142 return false; | 118 return false; |
| 143 #endif | 119 #endif |
| 144 } | 120 } |
| 145 | 121 |
| 146 void RegisterInstallerFileMetricsPreferences(PrefRegistrySimple* registry) { | 122 void RegisterInstallerFileMetricsPreferences(PrefRegistrySimple* registry) { |
| 147 base::GlobalHistogramAllocator* allocator = | 123 base::GlobalHistogramAllocator* allocator = |
| 148 base::GlobalHistogramAllocator::GetEvenIfDisabled(); | 124 base::GlobalHistogramAllocator::GetEvenIfDisabled(); |
| 149 if (allocator) | 125 if (allocator) |
| 150 metrics::FileMetricsProvider::RegisterPrefs(registry, allocator->Name()); | 126 metrics::FileMetricsProvider::RegisterPrefs(registry, allocator->Name()); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 ChromeMetricsServiceClient::CreateUploader( | 342 ChromeMetricsServiceClient::CreateUploader( |
| 367 const base::Callback<void(int)>& on_upload_complete) { | 343 const base::Callback<void(int)>& on_upload_complete) { |
| 368 return std::unique_ptr<metrics::MetricsLogUploader>( | 344 return std::unique_ptr<metrics::MetricsLogUploader>( |
| 369 new metrics::NetMetricsLogUploader( | 345 new metrics::NetMetricsLogUploader( |
| 370 g_browser_process->system_request_context(), | 346 g_browser_process->system_request_context(), |
| 371 metrics::kDefaultMetricsServerUrl, metrics::kDefaultMetricsMimeType, | 347 metrics::kDefaultMetricsServerUrl, metrics::kDefaultMetricsMimeType, |
| 372 on_upload_complete)); | 348 on_upload_complete)); |
| 373 } | 349 } |
| 374 | 350 |
| 375 base::TimeDelta ChromeMetricsServiceClient::GetStandardUploadInterval() { | 351 base::TimeDelta ChromeMetricsServiceClient::GetStandardUploadInterval() { |
| 376 #if defined(OS_ANDROID) | 352 return metrics::GetUploadInterval(); |
| 377 if (IsCellularLogicEnabled()) | |
| 378 return base::TimeDelta::FromSeconds(kStandardUploadIntervalCellularSeconds); | |
| 379 #endif | |
| 380 return base::TimeDelta::FromSeconds(kStandardUploadIntervalSeconds); | |
| 381 } | 353 } |
| 382 | 354 |
| 383 base::string16 ChromeMetricsServiceClient::GetRegistryBackupKey() { | 355 base::string16 ChromeMetricsServiceClient::GetRegistryBackupKey() { |
| 384 #if defined(OS_WIN) | 356 #if defined(OS_WIN) |
| 385 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); | 357 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); |
| 386 return distribution->GetRegistryPath().append(L"\\StabilityMetrics"); | 358 return distribution->GetRegistryPath().append(L"\\StabilityMetrics"); |
| 387 #else | 359 #else |
| 388 return base::string16(); | 360 return base::string16(); |
| 389 #endif | 361 #endif |
| 390 } | 362 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 CreateInstallerFileMetricsProvider( | 429 CreateInstallerFileMetricsProvider( |
| 458 metrics_state_manager_->IsMetricsReportingEnabled())); | 430 metrics_state_manager_->IsMetricsReportingEnabled())); |
| 459 | 431 |
| 460 drive_metrics_provider_ = new metrics::DriveMetricsProvider( | 432 drive_metrics_provider_ = new metrics::DriveMetricsProvider( |
| 461 content::BrowserThread::GetMessageLoopProxyForThread( | 433 content::BrowserThread::GetMessageLoopProxyForThread( |
| 462 content::BrowserThread::FILE), | 434 content::BrowserThread::FILE), |
| 463 chrome::FILE_LOCAL_STATE); | 435 chrome::FILE_LOCAL_STATE); |
| 464 metrics_service_->RegisterMetricsProvider( | 436 metrics_service_->RegisterMetricsProvider( |
| 465 std::unique_ptr<metrics::MetricsProvider>(drive_metrics_provider_)); | 437 std::unique_ptr<metrics::MetricsProvider>(drive_metrics_provider_)); |
| 466 | 438 |
| 467 profiler_metrics_provider_ = | 439 profiler_metrics_provider_ = new metrics::ProfilerMetricsProvider( |
| 468 new metrics::ProfilerMetricsProvider(base::Bind(&IsCellularLogicEnabled)); | 440 base::Bind(&metrics::IsCellularLogicEnabled)); |
| 469 metrics_service_->RegisterMetricsProvider( | 441 metrics_service_->RegisterMetricsProvider( |
| 470 std::unique_ptr<metrics::MetricsProvider>(profiler_metrics_provider_)); | 442 std::unique_ptr<metrics::MetricsProvider>(profiler_metrics_provider_)); |
| 471 | 443 |
| 472 metrics_service_->RegisterMetricsProvider( | 444 metrics_service_->RegisterMetricsProvider( |
| 473 std::unique_ptr<metrics::MetricsProvider>( | 445 std::unique_ptr<metrics::MetricsProvider>( |
| 474 new metrics::CallStackProfileMetricsProvider)); | 446 new metrics::CallStackProfileMetricsProvider)); |
| 475 | 447 |
| 476 #if BUILDFLAG(ANDROID_JAVA_UI) | 448 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 477 metrics_service_->RegisterMetricsProvider( | 449 metrics_service_->RegisterMetricsProvider( |
| 478 std::unique_ptr<metrics::MetricsProvider>( | 450 std::unique_ptr<metrics::MetricsProvider>( |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 default: | 725 default: |
| 754 NOTREACHED(); | 726 NOTREACHED(); |
| 755 } | 727 } |
| 756 } | 728 } |
| 757 | 729 |
| 758 void ChromeMetricsServiceClient::OnURLOpenedFromOmnibox(OmniboxLog* log) { | 730 void ChromeMetricsServiceClient::OnURLOpenedFromOmnibox(OmniboxLog* log) { |
| 759 metrics_service_->OnApplicationNotIdle(); | 731 metrics_service_->OnApplicationNotIdle(); |
| 760 } | 732 } |
| 761 | 733 |
| 762 bool ChromeMetricsServiceClient::IsUMACellularUploadLogicEnabled() { | 734 bool ChromeMetricsServiceClient::IsUMACellularUploadLogicEnabled() { |
| 763 return IsCellularLogicEnabled(); | 735 return metrics::IsCellularLogicEnabled(); |
| 764 } | 736 } |
| OLD | NEW |