| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 const int kMaxHistogramGatheringWaitDuration = 60000; // 60 seconds. | 99 const int kMaxHistogramGatheringWaitDuration = 60000; // 60 seconds. |
| 100 | 100 |
| 101 // Standard interval between log uploads, in seconds. | 101 // Standard interval between log uploads, in seconds. |
| 102 #if defined(OS_ANDROID) | 102 #if defined(OS_ANDROID) |
| 103 const int kStandardUploadIntervalSeconds = 5 * 60; // Five minutes. | 103 const int kStandardUploadIntervalSeconds = 5 * 60; // Five minutes. |
| 104 const int kStandardUploadIntervalCellularSeconds = 15 * 60; // Fifteen minutes. | 104 const int kStandardUploadIntervalCellularSeconds = 15 * 60; // Fifteen minutes. |
| 105 #else | 105 #else |
| 106 const int kStandardUploadIntervalSeconds = 30 * 60; // Thirty minutes. | 106 const int kStandardUploadIntervalSeconds = 30 * 60; // Thirty minutes. |
| 107 #endif | 107 #endif |
| 108 | 108 |
| 109 // Returns true if current connection type is cellular and user is assigned to | |
| 110 // experimental group for enabled cellular uploads. | |
| 111 bool IsCellularLogicEnabled() { | |
| 112 if (variations::GetVariationParamValue("UMA_EnableCellularLogUpload", | |
| 113 "Enabled") != "true" || | |
| 114 variations::GetVariationParamValue("UMA_EnableCellularLogUpload", | |
| 115 "Optimize") == "false") { | |
| 116 return false; | |
| 117 } | |
| 118 | |
| 119 return net::NetworkChangeNotifier::IsConnectionCellular( | |
| 120 net::NetworkChangeNotifier::GetConnectionType()); | |
| 121 } | |
| 122 | 109 |
| 123 // Checks whether it is the first time that cellular uploads logic should be | 110 // Checks whether it is the first time that cellular uploads logic should be |
| 124 // enabled based on whether the the preference for that logic is initialized. | 111 // enabled based on whether the the preference for that logic is initialized. |
| 125 // This should happen only once as the used preference will be initialized | 112 // This should happen only once as the used preference will be initialized |
| 126 // afterwards in |UmaSessionStats.java|. | 113 // afterwards in |UmaSessionStats.java|. |
| 127 bool ShouldClearSavedMetrics() { | 114 bool ShouldClearSavedMetrics() { |
| 128 #if BUILDFLAG(ANDROID_JAVA_UI) | 115 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 129 PrefService* local_state = g_browser_process->local_state(); | 116 PrefService* local_state = g_browser_process->local_state(); |
| 130 return !local_state->HasPrefPath(metrics::prefs::kMetricsReportingEnabled) && | 117 return !local_state->HasPrefPath(metrics::prefs::kMetricsReportingEnabled) && |
| 131 variations::GetVariationParamValue("UMA_EnableCellularLogUpload", | 118 variations::GetVariationParamValue("UMA_EnableCellularLogUpload", |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 return scoped_ptr<metrics::MetricsLogUploader>( | 291 return scoped_ptr<metrics::MetricsLogUploader>( |
| 305 new metrics::NetMetricsLogUploader( | 292 new metrics::NetMetricsLogUploader( |
| 306 g_browser_process->system_request_context(), | 293 g_browser_process->system_request_context(), |
| 307 metrics::kDefaultMetricsServerUrl, | 294 metrics::kDefaultMetricsServerUrl, |
| 308 metrics::kDefaultMetricsMimeType, | 295 metrics::kDefaultMetricsMimeType, |
| 309 on_upload_complete)); | 296 on_upload_complete)); |
| 310 } | 297 } |
| 311 | 298 |
| 312 base::TimeDelta ChromeMetricsServiceClient::GetStandardUploadInterval() { | 299 base::TimeDelta ChromeMetricsServiceClient::GetStandardUploadInterval() { |
| 313 #if defined(OS_ANDROID) | 300 #if defined(OS_ANDROID) |
| 314 if (IsCellularLogicEnabled()) | 301 bool is_cellular = false; |
| 302 IsCellularLogicEnabled(&is_cellular); |
| 303 if (is_cellular) |
| 315 return base::TimeDelta::FromSeconds(kStandardUploadIntervalCellularSeconds); | 304 return base::TimeDelta::FromSeconds(kStandardUploadIntervalCellularSeconds); |
| 316 #endif | 305 #endif |
| 317 return base::TimeDelta::FromSeconds(kStandardUploadIntervalSeconds); | 306 return base::TimeDelta::FromSeconds(kStandardUploadIntervalSeconds); |
| 318 } | 307 } |
| 319 | 308 |
| 320 base::string16 ChromeMetricsServiceClient::GetRegistryBackupKey() { | 309 base::string16 ChromeMetricsServiceClient::GetRegistryBackupKey() { |
| 321 #if defined(OS_WIN) | 310 #if defined(OS_WIN) |
| 322 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); | 311 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); |
| 323 return distribution->GetRegistryPath().append(L"\\StabilityMetrics"); | 312 return distribution->GetRegistryPath().append(L"\\StabilityMetrics"); |
| 324 #else | 313 #else |
| (...skipping 23 matching lines...) Expand all Loading... |
| 348 // Clear metrics reports if it is the first time cellular upload logic should | 337 // Clear metrics reports if it is the first time cellular upload logic should |
| 349 // apply to avoid sudden bulk uploads. It needs to be done before initializing | 338 // apply to avoid sudden bulk uploads. It needs to be done before initializing |
| 350 // metrics service so that metrics log manager is initialized correctly. | 339 // metrics service so that metrics log manager is initialized correctly. |
| 351 if (ShouldClearSavedMetrics()) { | 340 if (ShouldClearSavedMetrics()) { |
| 352 PrefService* local_state = g_browser_process->local_state(); | 341 PrefService* local_state = g_browser_process->local_state(); |
| 353 local_state->ClearPref(metrics::prefs::kMetricsInitialLogs); | 342 local_state->ClearPref(metrics::prefs::kMetricsInitialLogs); |
| 354 local_state->ClearPref(metrics::prefs::kMetricsOngoingLogs); | 343 local_state->ClearPref(metrics::prefs::kMetricsOngoingLogs); |
| 355 } | 344 } |
| 356 | 345 |
| 357 metrics_service_.reset(new metrics::MetricsService( | 346 metrics_service_.reset(new metrics::MetricsService( |
| 358 metrics_state_manager_, this, g_browser_process->local_state())); | 347 metrics_state_manager_, this, g_browser_process->local_state(), |
| 348 base::Bind(&ChromeMetricsServiceClient::IsCellularLogicEnabled, |
| 349 weak_ptr_factory_.GetWeakPtr()))); |
| 359 | 350 |
| 360 // Register metrics providers. | 351 // Register metrics providers. |
| 361 #if defined(ENABLE_EXTENSIONS) | 352 #if defined(ENABLE_EXTENSIONS) |
| 362 metrics_service_->RegisterMetricsProvider( | 353 metrics_service_->RegisterMetricsProvider( |
| 363 scoped_ptr<metrics::MetricsProvider>( | 354 scoped_ptr<metrics::MetricsProvider>( |
| 364 new ExtensionsMetricsProvider(metrics_state_manager_))); | 355 new ExtensionsMetricsProvider(metrics_state_manager_))); |
| 365 #endif | 356 #endif |
| 366 metrics_service_->RegisterMetricsProvider( | 357 metrics_service_->RegisterMetricsProvider( |
| 367 scoped_ptr<metrics::MetricsProvider>(new metrics::NetworkMetricsProvider( | 358 scoped_ptr<metrics::MetricsProvider>(new metrics::NetworkMetricsProvider( |
| 368 content::BrowserThread::GetBlockingPool()))); | 359 content::BrowserThread::GetBlockingPool()))); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 384 | 375 |
| 385 RegisterInstallerFileMetricsProvider(metrics_service_.get()); | 376 RegisterInstallerFileMetricsProvider(metrics_service_.get()); |
| 386 | 377 |
| 387 drive_metrics_provider_ = new metrics::DriveMetricsProvider( | 378 drive_metrics_provider_ = new metrics::DriveMetricsProvider( |
| 388 content::BrowserThread::GetMessageLoopProxyForThread( | 379 content::BrowserThread::GetMessageLoopProxyForThread( |
| 389 content::BrowserThread::FILE), | 380 content::BrowserThread::FILE), |
| 390 chrome::FILE_LOCAL_STATE); | 381 chrome::FILE_LOCAL_STATE); |
| 391 metrics_service_->RegisterMetricsProvider( | 382 metrics_service_->RegisterMetricsProvider( |
| 392 scoped_ptr<metrics::MetricsProvider>(drive_metrics_provider_)); | 383 scoped_ptr<metrics::MetricsProvider>(drive_metrics_provider_)); |
| 393 | 384 |
| 394 profiler_metrics_provider_ = | 385 profiler_metrics_provider_ = new metrics::ProfilerMetricsProvider( |
| 395 new metrics::ProfilerMetricsProvider(base::Bind(&IsCellularLogicEnabled)); | 386 base::Bind(&ChromeMetricsServiceClient::IsCellularLogicEnabled, |
| 387 weak_ptr_factory_.GetWeakPtr())); |
| 396 metrics_service_->RegisterMetricsProvider( | 388 metrics_service_->RegisterMetricsProvider( |
| 397 scoped_ptr<metrics::MetricsProvider>(profiler_metrics_provider_)); | 389 scoped_ptr<metrics::MetricsProvider>(profiler_metrics_provider_)); |
| 398 | 390 |
| 399 metrics_service_->RegisterMetricsProvider( | 391 metrics_service_->RegisterMetricsProvider( |
| 400 scoped_ptr<metrics::MetricsProvider>( | 392 scoped_ptr<metrics::MetricsProvider>( |
| 401 new metrics::CallStackProfileMetricsProvider)); | 393 new metrics::CallStackProfileMetricsProvider)); |
| 402 | 394 |
| 403 #if BUILDFLAG(ANDROID_JAVA_UI) | 395 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 404 metrics_service_->RegisterMetricsProvider( | 396 metrics_service_->RegisterMetricsProvider( |
| 405 scoped_ptr<metrics::MetricsProvider>( | 397 scoped_ptr<metrics::MetricsProvider>( |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 break; | 669 break; |
| 678 | 670 |
| 679 default: | 671 default: |
| 680 NOTREACHED(); | 672 NOTREACHED(); |
| 681 } | 673 } |
| 682 } | 674 } |
| 683 | 675 |
| 684 void ChromeMetricsServiceClient::OnURLOpenedFromOmnibox(OmniboxLog* log) { | 676 void ChromeMetricsServiceClient::OnURLOpenedFromOmnibox(OmniboxLog* log) { |
| 685 metrics_service_->OnApplicationNotIdle(); | 677 metrics_service_->OnApplicationNotIdle(); |
| 686 } | 678 } |
| 679 |
| 680 // Assigns true to output param if current connection type is cellular and user |
| 681 // is assigned to experimental group for enabled cellular uploads. |
| 682 void ChromeMetricsServiceClient::IsCellularLogicEnabled(bool* out_is_enabled) { |
| 683 if (variations::GetVariationParamValue("UMA_EnableCellularLogUpload", |
| 684 "Enabled") != "true" || |
| 685 variations::GetVariationParamValue("UMA_EnableCellularLogUpload", |
| 686 "Optimize") == "false") { |
| 687 *out_is_enabled = false; |
| 688 } else { |
| 689 *out_is_enabled = net::NetworkChangeNotifier::IsConnectionCellular( |
| 690 net::NetworkChangeNotifier::GetConnectionType()); |
| 691 } |
| 692 } |
| OLD | NEW |