Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: chrome/browser/metrics/chrome_metrics_service_client.cc

Issue 1818613002: Implement UMA log throttling for cellular connections (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: singleton pattern removed Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 const int kMaxHistogramGatheringWaitDuration = 60000; // 60 seconds. 97 const int kMaxHistogramGatheringWaitDuration = 60000; // 60 seconds.
98 98
99 // Standard interval between log uploads, in seconds. 99 // Standard interval between log uploads, in seconds.
100 #if defined(OS_ANDROID) 100 #if defined(OS_ANDROID)
101 const int kStandardUploadIntervalSeconds = 5 * 60; // Five minutes. 101 const int kStandardUploadIntervalSeconds = 5 * 60; // Five minutes.
102 const int kStandardUploadIntervalCellularSeconds = 15 * 60; // Fifteen minutes. 102 const int kStandardUploadIntervalCellularSeconds = 15 * 60; // Fifteen minutes.
103 #else 103 #else
104 const int kStandardUploadIntervalSeconds = 30 * 60; // Thirty minutes. 104 const int kStandardUploadIntervalSeconds = 30 * 60; // Thirty minutes.
105 #endif 105 #endif
106 106
107 // Returns true if current connection type is cellular and user is assigned to
108 // experimental group for enabled cellular uploads.
109 bool IsCellularLogicEnabled() {
110 if (variations::GetVariationParamValue("UMA_EnableCellularLogUpload",
111 "Enabled") != "true" ||
112 variations::GetVariationParamValue("UMA_EnableCellularLogUpload",
113 "Optimize") == "false") {
114 return false;
115 }
116
117 return net::NetworkChangeNotifier::IsConnectionCellular(
118 net::NetworkChangeNotifier::GetConnectionType());
119 }
120 107
121 // 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
122 // 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.
123 // 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
124 // afterwards in |UmaSessionStats.java|. 111 // afterwards in |UmaSessionStats.java|.
125 bool ShouldClearSavedMetrics() { 112 bool ShouldClearSavedMetrics() {
126 #if BUILDFLAG(ANDROID_JAVA_UI) 113 #if BUILDFLAG(ANDROID_JAVA_UI)
127 PrefService* local_state = g_browser_process->local_state(); 114 PrefService* local_state = g_browser_process->local_state();
128 return !local_state->HasPrefPath(metrics::prefs::kMetricsReportingEnabled) && 115 return !local_state->HasPrefPath(metrics::prefs::kMetricsReportingEnabled) &&
129 variations::GetVariationParamValue("UMA_EnableCellularLogUpload", 116 variations::GetVariationParamValue("UMA_EnableCellularLogUpload",
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 // Clear metrics reports if it is the first time cellular upload logic should 322 // Clear metrics reports if it is the first time cellular upload logic should
336 // apply to avoid sudden bulk uploads. It needs to be done before initializing 323 // apply to avoid sudden bulk uploads. It needs to be done before initializing
337 // metrics service so that metrics log manager is initialized correctly. 324 // metrics service so that metrics log manager is initialized correctly.
338 if (ShouldClearSavedMetrics()) { 325 if (ShouldClearSavedMetrics()) {
339 PrefService* local_state = g_browser_process->local_state(); 326 PrefService* local_state = g_browser_process->local_state();
340 local_state->ClearPref(metrics::prefs::kMetricsInitialLogs); 327 local_state->ClearPref(metrics::prefs::kMetricsInitialLogs);
341 local_state->ClearPref(metrics::prefs::kMetricsOngoingLogs); 328 local_state->ClearPref(metrics::prefs::kMetricsOngoingLogs);
342 } 329 }
343 330
344 metrics_service_.reset(new metrics::MetricsService( 331 metrics_service_.reset(new metrics::MetricsService(
345 metrics_state_manager_, this, g_browser_process->local_state())); 332 metrics_state_manager_, this, g_browser_process->local_state(),
333 base::Bind(&ChromeMetricsServiceClient::IsCellularLogicEnabled,
334 weak_ptr_factory_.GetWeakPtr())));
346 335
347 // Register metrics providers. 336 // Register metrics providers.
348 #if defined(ENABLE_EXTENSIONS) 337 #if defined(ENABLE_EXTENSIONS)
349 metrics_service_->RegisterMetricsProvider( 338 metrics_service_->RegisterMetricsProvider(
350 scoped_ptr<metrics::MetricsProvider>( 339 scoped_ptr<metrics::MetricsProvider>(
351 new ExtensionsMetricsProvider(metrics_state_manager_))); 340 new ExtensionsMetricsProvider(metrics_state_manager_)));
352 #endif 341 #endif
353 metrics_service_->RegisterMetricsProvider( 342 metrics_service_->RegisterMetricsProvider(
354 scoped_ptr<metrics::MetricsProvider>(new metrics::NetworkMetricsProvider( 343 scoped_ptr<metrics::MetricsProvider>(new metrics::NetworkMetricsProvider(
355 content::BrowserThread::GetBlockingPool()))); 344 content::BrowserThread::GetBlockingPool())));
(...skipping 15 matching lines...) Expand all
371 360
372 RegisterInstallerFileMetricsProvider(metrics_service_.get()); 361 RegisterInstallerFileMetricsProvider(metrics_service_.get());
373 362
374 drive_metrics_provider_ = new metrics::DriveMetricsProvider( 363 drive_metrics_provider_ = new metrics::DriveMetricsProvider(
375 content::BrowserThread::GetMessageLoopProxyForThread( 364 content::BrowserThread::GetMessageLoopProxyForThread(
376 content::BrowserThread::FILE), 365 content::BrowserThread::FILE),
377 chrome::FILE_LOCAL_STATE); 366 chrome::FILE_LOCAL_STATE);
378 metrics_service_->RegisterMetricsProvider( 367 metrics_service_->RegisterMetricsProvider(
379 scoped_ptr<metrics::MetricsProvider>(drive_metrics_provider_)); 368 scoped_ptr<metrics::MetricsProvider>(drive_metrics_provider_));
380 369
381 profiler_metrics_provider_ = 370 profiler_metrics_provider_ = new metrics::ProfilerMetricsProvider(
382 new metrics::ProfilerMetricsProvider(base::Bind(&IsCellularLogicEnabled)); 371 base::Bind(&ChromeMetricsServiceClient::IsCellularLogicEnabled,
372 weak_ptr_factory_.GetWeakPtr()));
383 metrics_service_->RegisterMetricsProvider( 373 metrics_service_->RegisterMetricsProvider(
384 scoped_ptr<metrics::MetricsProvider>(profiler_metrics_provider_)); 374 scoped_ptr<metrics::MetricsProvider>(profiler_metrics_provider_));
385 375
386 metrics_service_->RegisterMetricsProvider( 376 metrics_service_->RegisterMetricsProvider(
387 scoped_ptr<metrics::MetricsProvider>( 377 scoped_ptr<metrics::MetricsProvider>(
388 new metrics::CallStackProfileMetricsProvider)); 378 new metrics::CallStackProfileMetricsProvider));
389 379
390 #if BUILDFLAG(ANDROID_JAVA_UI) 380 #if BUILDFLAG(ANDROID_JAVA_UI)
391 metrics_service_->RegisterMetricsProvider( 381 metrics_service_->RegisterMetricsProvider(
392 scoped_ptr<metrics::MetricsProvider>( 382 scoped_ptr<metrics::MetricsProvider>(
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 break; 654 break;
665 655
666 default: 656 default:
667 NOTREACHED(); 657 NOTREACHED();
668 } 658 }
669 } 659 }
670 660
671 void ChromeMetricsServiceClient::OnURLOpenedFromOmnibox(OmniboxLog* log) { 661 void ChromeMetricsServiceClient::OnURLOpenedFromOmnibox(OmniboxLog* log) {
672 metrics_service_->OnApplicationNotIdle(); 662 metrics_service_->OnApplicationNotIdle();
673 } 663 }
664
665 // Assigns true if current connection type is cellular and user is assigned to
666 // experimental group for enabled cellular uploads.
667 void ChromeMetricsServiceClient::IsCellularLogicEnabled(bool* out_is_enabled) {
668 if (variations::GetVariationParamValue("UMA_EnableCellularLogUpload",
669 "Enabled") != "true" ||
670 variations::GetVariationParamValue("UMA_EnableCellularLogUpload",
671 "Optimize") == "false") {
672 *out_is_enabled = false;
673 } else {
674 *out_is_enabled = net::NetworkChangeNotifier::IsConnectionCellular(
675 net::NetworkChangeNotifier::GetConnectionType());
676 }
677 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698