diff options
author | gayane <gayane@chromium.org> | 2015-02-23 13:23:06 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-23 21:23:59 +0000 |
commit | d52ca402963fc3fc25c9f93b577f79a5eebbb10f (patch) | |
tree | 181f987526dacfb08ab33d7a21692e3f778f7720 /components/metrics | |
parent | 6e3b48b35f7a96246bcc0bb9e2ec846053349d99 (diff) | |
download | chromium_src-d52ca402963fc3fc25c9f93b577f79a5eebbb10f.zip chromium_src-d52ca402963fc3fc25c9f93b577f79a5eebbb10f.tar.gz chromium_src-d52ca402963fc3fc25c9f93b577f79a5eebbb10f.tar.bz2 |
Enable UMA log uploads for cellular networks.
For enabling UMA uploads on cellular networks upload interval should be increased to 15min instead of 5min which according to initial experiments showed to decrease average overall size of the upload.
This behavior is enabled for users which are assigned to Finch experiment.
BUG=455847
Review URL: https://codereview.chromium.org/922383003
Cr-Commit-Position: refs/heads/master@{#317654}
Diffstat (limited to 'components/metrics')
-rw-r--r-- | components/metrics/metrics_reporting_scheduler.cc | 29 | ||||
-rw-r--r-- | components/metrics/metrics_reporting_scheduler.h | 11 | ||||
-rw-r--r-- | components/metrics/metrics_reporting_scheduler_unittest.cc | 13 | ||||
-rw-r--r-- | components/metrics/metrics_service.cc | 14 | ||||
-rw-r--r-- | components/metrics/metrics_service.h | 8 | ||||
-rw-r--r-- | components/metrics/net/network_metrics_provider.cc | 20 | ||||
-rw-r--r-- | components/metrics/net/network_metrics_provider.h | 11 |
7 files changed, 94 insertions, 12 deletions
diff --git a/components/metrics/metrics_reporting_scheduler.cc b/components/metrics/metrics_reporting_scheduler.cc index 53c0cc5..fb5461b 100644 --- a/components/metrics/metrics_reporting_scheduler.cc +++ b/components/metrics/metrics_reporting_scheduler.cc @@ -38,6 +38,7 @@ const int kUnsentLogsIntervalSeconds = 15; // Standard interval between log uploads, in seconds. #if defined(OS_ANDROID) || defined(OS_IOS) const int kStandardUploadIntervalSeconds = 5 * 60; // Five minutes. +const int kStandardUploadIntervalCellularSeconds = 15 * 60; // Fifteen minutes. #else const int kStandardUploadIntervalSeconds = 30 * 60; // Thirty minutes. #endif @@ -83,16 +84,28 @@ base::TimeDelta GetUploadIntervalFromExperiment() { return TimeDelta::FromMinutes(interval); } +#if defined(OS_ANDROID) || defined(OS_IOS) +// Returns true if the user is assigned to the experiment group for enabled +// cellular uploads. +bool IsCellularEnabledByExperiment() { + const std::string group_name = + base::FieldTrialList::FindFullName("UMA_EnableCellularLogUpload"); + return group_name == "Enabled"; +} +#endif + } // anonymous namespace MetricsReportingScheduler::MetricsReportingScheduler( - const base::Closure& upload_callback) + const base::Closure& upload_callback, + const base::Callback<void(bool*)>& cellular_callback) : upload_callback_(upload_callback), upload_interval_(TimeDelta::FromSeconds(kInitialUploadIntervalSeconds)), running_(false), callback_pending_(false), init_task_complete_(false), - waiting_for_init_task_complete_(false) { + waiting_for_init_task_complete_(false), + cellular_callback_(cellular_callback) { } MetricsReportingScheduler::~MetricsReportingScheduler() {} @@ -193,11 +206,15 @@ void MetricsReportingScheduler::BackOffUploadInterval() { } base::TimeDelta MetricsReportingScheduler::GetStandardUploadInterval() { -#if defined(OS_ANDROID) - return GetUploadIntervalFromExperiment(); -#else - return TimeDelta::FromSeconds(kStandardUploadIntervalSeconds); +#if defined(OS_ANDROID) || defined(OS_IOS) + bool is_cellular = false; + if (!cellular_callback_.is_null()) + cellular_callback_.Run(&is_cellular); + + if (is_cellular && IsCellularEnabledByExperiment()) + return TimeDelta::FromSeconds(kStandardUploadIntervalCellularSeconds); #endif + return TimeDelta::FromSeconds(kStandardUploadIntervalSeconds); } } // namespace metrics diff --git a/components/metrics/metrics_reporting_scheduler.h b/components/metrics/metrics_reporting_scheduler.h index 19f0757..ddfe651 100644 --- a/components/metrics/metrics_reporting_scheduler.h +++ b/components/metrics/metrics_reporting_scheduler.h @@ -10,13 +10,19 @@ #include "base/memory/weak_ptr.h" #include "base/time/time.h" #include "base/timer/timer.h" +#include "components/metrics/net/network_metrics_provider.h" namespace metrics { // Scheduler task to drive a MetricsService object's uploading. class MetricsReportingScheduler { public: - explicit MetricsReportingScheduler(const base::Closure& upload_callback); + // Creates MetricsServiceScheduler object with the given |upload_callback| + // callback to call when uploading should happen and |cellular_callback| + // callback to get current network connection type. + MetricsReportingScheduler( + const base::Closure& upload_callback, + const base::Callback<void(bool*)>& cellular_callback); ~MetricsReportingScheduler(); // Starts scheduling uploads. This in a no-op if the scheduler is already @@ -84,6 +90,9 @@ class MetricsReportingScheduler { // has been completed. bool waiting_for_init_task_complete_; + // Callback function used to get current network connection type. + base::Callback<void(bool*)> cellular_callback_; + DISALLOW_COPY_AND_ASSIGN(MetricsReportingScheduler); }; diff --git a/components/metrics/metrics_reporting_scheduler_unittest.cc b/components/metrics/metrics_reporting_scheduler_unittest.cc index ee80cc7..2a8e7fa 100644 --- a/components/metrics/metrics_reporting_scheduler_unittest.cc +++ b/components/metrics/metrics_reporting_scheduler_unittest.cc @@ -22,6 +22,11 @@ class MetricsReportingSchedulerTest : public testing::Test { base::Unretained(this)); } + base::Callback<void(bool*)> GetConnectionCallback() { + return base::Bind(&MetricsReportingSchedulerTest::SetConnectionTypeCallback, + base::Unretained(this)); + } + int callback_call_count() const { return callback_call_count_; } private: @@ -29,6 +34,10 @@ class MetricsReportingSchedulerTest : public testing::Test { ++callback_call_count_; } + void SetConnectionTypeCallback(bool* is_cellular_out) { + *is_cellular_out = false; + } + int callback_call_count_; base::MessageLoopForUI message_loop_; @@ -38,7 +47,7 @@ class MetricsReportingSchedulerTest : public testing::Test { TEST_F(MetricsReportingSchedulerTest, InitTaskCompleteBeforeTimer) { - MetricsReportingScheduler scheduler(GetCallback()); + MetricsReportingScheduler scheduler(GetCallback(), GetConnectionCallback()); scheduler.SetUploadIntervalForTesting(base::TimeDelta()); scheduler.InitTaskComplete(); scheduler.Start(); @@ -49,7 +58,7 @@ TEST_F(MetricsReportingSchedulerTest, InitTaskCompleteBeforeTimer) { } TEST_F(MetricsReportingSchedulerTest, InitTaskCompleteAfterTimer) { - MetricsReportingScheduler scheduler(GetCallback()); + MetricsReportingScheduler scheduler(GetCallback(), GetConnectionCallback()); scheduler.SetUploadIntervalForTesting(base::TimeDelta()); scheduler.Start(); base::RunLoop().RunUntilIdle(); diff --git a/components/metrics/metrics_service.cc b/components/metrics/metrics_service.cc index 962d836..b7aa20e 100644 --- a/components/metrics/metrics_service.cc +++ b/components/metrics/metrics_service.cc @@ -342,9 +342,11 @@ MetricsService::~MetricsService() { void MetricsService::InitializeMetricsRecordingState() { InitializeMetricsState(); - base::Closure callback = base::Bind(&MetricsService::StartScheduledUpload, - self_ptr_factory_.GetWeakPtr()); - scheduler_.reset(new MetricsReportingScheduler(callback)); + base::Closure upload_callback = + base::Bind(&MetricsService::StartScheduledUpload, + self_ptr_factory_.GetWeakPtr()); + scheduler_.reset( + new MetricsReportingScheduler(upload_callback, is_cellular_callback_)); } void MetricsService::Start() { @@ -1256,4 +1258,10 @@ void MetricsService::RecordCurrentState(PrefService* pref) { base::Time::Now().ToTimeT()); } +void MetricsService::SetConnectionTypeCallback( + base::Callback<void(bool*)> is_cellular_callback) { + DCHECK(!scheduler_); + is_cellular_callback_ = is_cellular_callback; +} + } // namespace metrics diff --git a/components/metrics/metrics_service.h b/components/metrics/metrics_service.h index 9041474..c7bf8e5 100644 --- a/components/metrics/metrics_service.h +++ b/components/metrics/metrics_service.h @@ -27,6 +27,7 @@ #include "components/metrics/metrics_log.h" #include "components/metrics/metrics_log_manager.h" #include "components/metrics/metrics_provider.h" +#include "components/metrics/net/network_metrics_provider.h" #include "components/variations/active_field_trials.h" class MetricsServiceAccessor; @@ -242,6 +243,10 @@ class MetricsService : public base::HistogramFlattener { // Clears the stability metrics that are saved in local state. void ClearSavedStabilityMetrics(); + // Sets the connection type callback used to pass to the scheduler. + void SetConnectionTypeCallback( + base::Callback<void(bool*)> is_cellular_callback); + protected: // Exposed for testing. MetricsLogManager* log_manager() { return &log_manager_; } @@ -481,6 +486,9 @@ class MetricsService : public base::HistogramFlattener { // exited-cleanly bit in the prefs. static ShutdownCleanliness clean_shutdown_status_; + // Callback function used to get current network connection type. + base::Callback<void(bool*)> is_cellular_callback_; + FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, PermutedEntropyCacheClearedWhenLowEntropyReset); diff --git a/components/metrics/net/network_metrics_provider.cc b/components/metrics/net/network_metrics_provider.cc index e845cde..4ec6574 100644 --- a/components/metrics/net/network_metrics_provider.cc +++ b/components/metrics/net/network_metrics_provider.cc @@ -227,4 +227,24 @@ void NetworkMetricsProvider::WriteWifiAccessPointProto( } } +bool NetworkMetricsProvider::IsCellularConnection() { + switch (GetConnectionType()) { + case SystemProfileProto_Network_ConnectionType_CONNECTION_2G: + case SystemProfileProto_Network_ConnectionType_CONNECTION_3G: + case SystemProfileProto_Network_ConnectionType_CONNECTION_4G: + return true; + default: + return false; + } +} + +void NetworkMetricsProvider::GetIsCellularConnection(bool* is_cellular_out) { + *is_cellular_out = IsCellularConnection(); +} + +base::Callback<void(bool*)> NetworkMetricsProvider::GetConnectionCallback() { + return base::Bind(&NetworkMetricsProvider::GetIsCellularConnection, + weak_ptr_factory_.GetWeakPtr()); +} + } // namespace metrics diff --git a/components/metrics/net/network_metrics_provider.h b/components/metrics/net/network_metrics_provider.h index 412ef67..ffdc017 100644 --- a/components/metrics/net/network_metrics_provider.h +++ b/components/metrics/net/network_metrics_provider.h @@ -27,6 +27,10 @@ class NetworkMetricsProvider explicit NetworkMetricsProvider(base::TaskRunner* io_task_runner); ~NetworkMetricsProvider() override; + // Returns callback function bound to the weak pointer of the provider, which + // can be used to get whether current connection type is cellular. + base::Callback<void(bool*)> GetConnectionCallback(); + private: // MetricsProvider: void OnDidCreateMetricsLog() override; @@ -52,6 +56,13 @@ class NetworkMetricsProvider const WifiAccessPointInfoProvider::WifiAccessPointInfo& info, SystemProfileProto::Network* network_proto); + // Returns true if the connection type is 2G, 3G, or 4G. + bool IsCellularConnection(); + + // Assigns the passed |is_cellular_out| parameter based on whether current + // network connection is cellular. + void GetIsCellularConnection(bool* is_cellular_out); + // Task runner used for blocking file I/O. base::TaskRunner* io_task_runner_; |