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() {
scoped_ptr<metrics::MetricsProvider>(
new ExtensionsMetricsProvider(metrics_state_manager_)));
#endif
metrics_service_->RegisterMetricsProvider(
scoped_ptr<metrics::MetricsProvider>(new metrics::NetworkMetricsProvider(
content::BrowserThread::GetBlockingPool())));
scoped_ptr<metrics::NetworkMetricsProvider> network_metrics_provider(
new metrics::NetworkMetricsProvider(
content::BrowserThread::GetBlockingPool()));
metrics_service_->SetConnectionTypeCallback(
network_metrics_provider->GetConnectionCallback());
metrics_service_->RegisterMetricsProvider(network_metrics_provider.Pass());
metrics_service_->RegisterMetricsProvider(
scoped_ptr<metrics::MetricsProvider>(new OmniboxMetricsProvider));
metrics_service_->RegisterMetricsProvider(
......
......@@ -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
......@@ -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);
};
......
......@@ -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();
......
......@@ -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
......@@ -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);
......
......@@ -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
......@@ -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_;
......
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