Commit d52ca402 authored by gayane's avatar gayane Committed by Commit bot

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}
parent 6e3b48b3
...@@ -273,9 +273,13 @@ void ChromeMetricsServiceClient::Initialize() { ...@@ -273,9 +273,13 @@ void ChromeMetricsServiceClient::Initialize() {
scoped_ptr<metrics::MetricsProvider>( scoped_ptr<metrics::MetricsProvider>(
new ExtensionsMetricsProvider(metrics_state_manager_))); new ExtensionsMetricsProvider(metrics_state_manager_)));
#endif #endif
metrics_service_->RegisterMetricsProvider( scoped_ptr<metrics::NetworkMetricsProvider> network_metrics_provider(
scoped_ptr<metrics::MetricsProvider>(new metrics::NetworkMetricsProvider( new metrics::NetworkMetricsProvider(
content::BrowserThread::GetBlockingPool()))); content::BrowserThread::GetBlockingPool()));
metrics_service_->SetConnectionTypeCallback(
network_metrics_provider->GetConnectionCallback());
metrics_service_->RegisterMetricsProvider(network_metrics_provider.Pass());
metrics_service_->RegisterMetricsProvider( metrics_service_->RegisterMetricsProvider(
scoped_ptr<metrics::MetricsProvider>(new OmniboxMetricsProvider)); scoped_ptr<metrics::MetricsProvider>(new OmniboxMetricsProvider));
metrics_service_->RegisterMetricsProvider( metrics_service_->RegisterMetricsProvider(
......
...@@ -38,6 +38,7 @@ const int kUnsentLogsIntervalSeconds = 15; ...@@ -38,6 +38,7 @@ const int kUnsentLogsIntervalSeconds = 15;
// Standard interval between log uploads, in seconds. // Standard interval between log uploads, in seconds.
#if defined(OS_ANDROID) || defined(OS_IOS) #if defined(OS_ANDROID) || defined(OS_IOS)
const int kStandardUploadIntervalSeconds = 5 * 60; // Five minutes. const int kStandardUploadIntervalSeconds = 5 * 60; // Five minutes.
const int kStandardUploadIntervalCellularSeconds = 15 * 60; // Fifteen minutes.
#else #else
const int kStandardUploadIntervalSeconds = 30 * 60; // Thirty minutes. const int kStandardUploadIntervalSeconds = 30 * 60; // Thirty minutes.
#endif #endif
...@@ -83,16 +84,28 @@ base::TimeDelta GetUploadIntervalFromExperiment() { ...@@ -83,16 +84,28 @@ base::TimeDelta GetUploadIntervalFromExperiment() {
return TimeDelta::FromMinutes(interval); 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 } // anonymous namespace
MetricsReportingScheduler::MetricsReportingScheduler( MetricsReportingScheduler::MetricsReportingScheduler(
const base::Closure& upload_callback) const base::Closure& upload_callback,
const base::Callback<void(bool*)>& cellular_callback)
: upload_callback_(upload_callback), : upload_callback_(upload_callback),
upload_interval_(TimeDelta::FromSeconds(kInitialUploadIntervalSeconds)), upload_interval_(TimeDelta::FromSeconds(kInitialUploadIntervalSeconds)),
running_(false), running_(false),
callback_pending_(false), callback_pending_(false),
init_task_complete_(false), init_task_complete_(false),
waiting_for_init_task_complete_(false) { waiting_for_init_task_complete_(false),
cellular_callback_(cellular_callback) {
} }
MetricsReportingScheduler::~MetricsReportingScheduler() {} MetricsReportingScheduler::~MetricsReportingScheduler() {}
...@@ -193,11 +206,15 @@ void MetricsReportingScheduler::BackOffUploadInterval() { ...@@ -193,11 +206,15 @@ void MetricsReportingScheduler::BackOffUploadInterval() {
} }
base::TimeDelta MetricsReportingScheduler::GetStandardUploadInterval() { base::TimeDelta MetricsReportingScheduler::GetStandardUploadInterval() {
#if defined(OS_ANDROID) #if defined(OS_ANDROID) || defined(OS_IOS)
return GetUploadIntervalFromExperiment(); bool is_cellular = false;
#else if (!cellular_callback_.is_null())
return TimeDelta::FromSeconds(kStandardUploadIntervalSeconds); cellular_callback_.Run(&is_cellular);
if (is_cellular && IsCellularEnabledByExperiment())
return TimeDelta::FromSeconds(kStandardUploadIntervalCellularSeconds);
#endif #endif
return TimeDelta::FromSeconds(kStandardUploadIntervalSeconds);
} }
} // namespace metrics } // namespace metrics
...@@ -10,13 +10,19 @@ ...@@ -10,13 +10,19 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "components/metrics/net/network_metrics_provider.h"
namespace metrics { namespace metrics {
// Scheduler task to drive a MetricsService object's uploading. // Scheduler task to drive a MetricsService object's uploading.
class MetricsReportingScheduler { class MetricsReportingScheduler {
public: 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(); ~MetricsReportingScheduler();
// Starts scheduling uploads. This in a no-op if the scheduler is already // Starts scheduling uploads. This in a no-op if the scheduler is already
...@@ -84,6 +90,9 @@ class MetricsReportingScheduler { ...@@ -84,6 +90,9 @@ class MetricsReportingScheduler {
// has been completed. // has been completed.
bool waiting_for_init_task_complete_; 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); DISALLOW_COPY_AND_ASSIGN(MetricsReportingScheduler);
}; };
......
...@@ -22,6 +22,11 @@ class MetricsReportingSchedulerTest : public testing::Test { ...@@ -22,6 +22,11 @@ class MetricsReportingSchedulerTest : public testing::Test {
base::Unretained(this)); 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_; } int callback_call_count() const { return callback_call_count_; }
private: private:
...@@ -29,6 +34,10 @@ class MetricsReportingSchedulerTest : public testing::Test { ...@@ -29,6 +34,10 @@ class MetricsReportingSchedulerTest : public testing::Test {
++callback_call_count_; ++callback_call_count_;
} }
void SetConnectionTypeCallback(bool* is_cellular_out) {
*is_cellular_out = false;
}
int callback_call_count_; int callback_call_count_;
base::MessageLoopForUI message_loop_; base::MessageLoopForUI message_loop_;
...@@ -38,7 +47,7 @@ class MetricsReportingSchedulerTest : public testing::Test { ...@@ -38,7 +47,7 @@ class MetricsReportingSchedulerTest : public testing::Test {
TEST_F(MetricsReportingSchedulerTest, InitTaskCompleteBeforeTimer) { TEST_F(MetricsReportingSchedulerTest, InitTaskCompleteBeforeTimer) {
MetricsReportingScheduler scheduler(GetCallback()); MetricsReportingScheduler scheduler(GetCallback(), GetConnectionCallback());
scheduler.SetUploadIntervalForTesting(base::TimeDelta()); scheduler.SetUploadIntervalForTesting(base::TimeDelta());
scheduler.InitTaskComplete(); scheduler.InitTaskComplete();
scheduler.Start(); scheduler.Start();
...@@ -49,7 +58,7 @@ TEST_F(MetricsReportingSchedulerTest, InitTaskCompleteBeforeTimer) { ...@@ -49,7 +58,7 @@ TEST_F(MetricsReportingSchedulerTest, InitTaskCompleteBeforeTimer) {
} }
TEST_F(MetricsReportingSchedulerTest, InitTaskCompleteAfterTimer) { TEST_F(MetricsReportingSchedulerTest, InitTaskCompleteAfterTimer) {
MetricsReportingScheduler scheduler(GetCallback()); MetricsReportingScheduler scheduler(GetCallback(), GetConnectionCallback());
scheduler.SetUploadIntervalForTesting(base::TimeDelta()); scheduler.SetUploadIntervalForTesting(base::TimeDelta());
scheduler.Start(); scheduler.Start();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
......
...@@ -342,9 +342,11 @@ MetricsService::~MetricsService() { ...@@ -342,9 +342,11 @@ MetricsService::~MetricsService() {
void MetricsService::InitializeMetricsRecordingState() { void MetricsService::InitializeMetricsRecordingState() {
InitializeMetricsState(); InitializeMetricsState();
base::Closure callback = base::Bind(&MetricsService::StartScheduledUpload, base::Closure upload_callback =
self_ptr_factory_.GetWeakPtr()); base::Bind(&MetricsService::StartScheduledUpload,
scheduler_.reset(new MetricsReportingScheduler(callback)); self_ptr_factory_.GetWeakPtr());
scheduler_.reset(
new MetricsReportingScheduler(upload_callback, is_cellular_callback_));
} }
void MetricsService::Start() { void MetricsService::Start() {
...@@ -1256,4 +1258,10 @@ void MetricsService::RecordCurrentState(PrefService* pref) { ...@@ -1256,4 +1258,10 @@ void MetricsService::RecordCurrentState(PrefService* pref) {
base::Time::Now().ToTimeT()); base::Time::Now().ToTimeT());
} }
void MetricsService::SetConnectionTypeCallback(
base::Callback<void(bool*)> is_cellular_callback) {
DCHECK(!scheduler_);
is_cellular_callback_ = is_cellular_callback;
}
} // namespace metrics } // namespace metrics
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "components/metrics/metrics_log.h" #include "components/metrics/metrics_log.h"
#include "components/metrics/metrics_log_manager.h" #include "components/metrics/metrics_log_manager.h"
#include "components/metrics/metrics_provider.h" #include "components/metrics/metrics_provider.h"
#include "components/metrics/net/network_metrics_provider.h"
#include "components/variations/active_field_trials.h" #include "components/variations/active_field_trials.h"
class MetricsServiceAccessor; class MetricsServiceAccessor;
...@@ -242,6 +243,10 @@ class MetricsService : public base::HistogramFlattener { ...@@ -242,6 +243,10 @@ class MetricsService : public base::HistogramFlattener {
// Clears the stability metrics that are saved in local state. // Clears the stability metrics that are saved in local state.
void ClearSavedStabilityMetrics(); void ClearSavedStabilityMetrics();
// Sets the connection type callback used to pass to the scheduler.
void SetConnectionTypeCallback(
base::Callback<void(bool*)> is_cellular_callback);
protected: protected:
// Exposed for testing. // Exposed for testing.
MetricsLogManager* log_manager() { return &log_manager_; } MetricsLogManager* log_manager() { return &log_manager_; }
...@@ -481,6 +486,9 @@ class MetricsService : public base::HistogramFlattener { ...@@ -481,6 +486,9 @@ class MetricsService : public base::HistogramFlattener {
// exited-cleanly bit in the prefs. // exited-cleanly bit in the prefs.
static ShutdownCleanliness clean_shutdown_status_; 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, IsPluginProcess);
FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest,
PermutedEntropyCacheClearedWhenLowEntropyReset); PermutedEntropyCacheClearedWhenLowEntropyReset);
......
...@@ -227,4 +227,24 @@ void NetworkMetricsProvider::WriteWifiAccessPointProto( ...@@ -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 } // namespace metrics
...@@ -27,6 +27,10 @@ class NetworkMetricsProvider ...@@ -27,6 +27,10 @@ class NetworkMetricsProvider
explicit NetworkMetricsProvider(base::TaskRunner* io_task_runner); explicit NetworkMetricsProvider(base::TaskRunner* io_task_runner);
~NetworkMetricsProvider() override; ~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: private:
// MetricsProvider: // MetricsProvider:
void OnDidCreateMetricsLog() override; void OnDidCreateMetricsLog() override;
...@@ -52,6 +56,13 @@ class NetworkMetricsProvider ...@@ -52,6 +56,13 @@ class NetworkMetricsProvider
const WifiAccessPointInfoProvider::WifiAccessPointInfo& info, const WifiAccessPointInfoProvider::WifiAccessPointInfo& info,
SystemProfileProto::Network* network_proto); 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. // Task runner used for blocking file I/O.
base::TaskRunner* io_task_runner_; base::TaskRunner* io_task_runner_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment