Commit 8d28e669 authored by holte's avatar holte Committed by Commit bot

Add an override flag to enable metrics reporting.

This simplifies local testing of metrics collection, particularly in dev builds.

BUG=717792

Review-Url: https://codereview.chromium.org/2861563002
Cr-Commit-Position: refs/heads/master@{#469526}
parent f05a24a4
......@@ -570,6 +570,12 @@ ChromeMetricsServiceClient::GetMetricsReportingDefaultState() {
g_browser_process->local_state());
}
// static
bool ChromeMetricsServiceClient::IsMetricsReportingForceEnabled() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kForceEnableMetricsReporting);
}
void ChromeMetricsServiceClient::Initialize() {
PrefService* local_state = g_browser_process->local_state();
......@@ -585,7 +591,8 @@ void ChromeMetricsServiceClient::Initialize() {
RegisterMetricsServiceProviders();
if (base::FeatureList::IsEnabled(ukm::kUkmFeature)) {
if (IsMetricsReportingForceEnabled() ||
base::FeatureList::IsEnabled(ukm::kUkmFeature)) {
ukm_service_.reset(new ukm::UkmService(local_state, this));
RegisterUKMProviders();
}
......
......@@ -64,6 +64,9 @@ class ChromeMetricsServiceClient : public metrics::MetricsServiceClient,
// Registers local state prefs used by this class.
static void RegisterPrefs(PrefRegistrySimple* registry);
// Checks if the user has forced metrics collection on via the override flag.
static bool IsMetricsReportingForceEnabled();
// metrics::MetricsServiceClient:
metrics::MetricsService* GetMetricsService() override;
ukm::UkmService* GetUkmService() override;
......
......@@ -288,3 +288,7 @@ ChromeMetricsServicesManagerClient::GetMetricsStateManager() {
}
return metrics_state_manager_.get();
}
bool ChromeMetricsServicesManagerClient::IsMetricsReportingForceEnabled() {
return ChromeMetricsServiceClient::IsMetricsReportingForceEnabled();
}
......@@ -79,6 +79,8 @@ class ChromeMetricsServicesManagerClient
void UpdateRunningServices(bool may_record, bool may_upload) override;
#endif // defined(OS_WIN)
bool IsMetricsReportingForceEnabled() override;
// Gets the MetricsStateManager, creating it if it has not already been
// created.
metrics::MetricsStateManager* GetMetricsStateManager();
......
......@@ -484,6 +484,9 @@ const char kForceDesktopIOSPromotion[] = "force-desktop-ios-promotion";
// connection type.
const char kForceEffectiveConnectionType[] = "force-effective-connection-type";
// Forces metrics reporting to be enabled.
const char kForceEnableMetricsReporting[] = "force-enable-metrics-reporting";
// Displays the First Run experience when the browser is started, regardless of
// whether or not it's actually the First Run (this overrides kNoFirstRun).
const char kForceFirstRun[] = "force-first-run";
......
......@@ -150,6 +150,7 @@ extern const char kForceAndroidAppMode[];
extern const char kForceAppMode[];
extern const char kForceDesktopIOSPromotion[];
extern const char kForceEffectiveConnectionType[];
extern const char kForceEnableMetricsReporting[];
extern const char kForceFirstRun[];
extern const char kForceLocalNtp[];
extern const char kForceVariationIds[];
......
......@@ -6,6 +6,7 @@ static_library("metrics_services_manager") {
sources = [
"metrics_services_manager.cc",
"metrics_services_manager.h",
"metrics_services_manager_client.cc",
"metrics_services_manager_client.h",
]
......
......@@ -132,6 +132,7 @@ void MetricsServicesManager::UpdateUkmService() {
if (!ukm)
return;
bool sync_enabled =
client_->IsMetricsReportingForceEnabled() ||
metrics_service_client_->IsHistorySyncEnabledOnAllProfiles();
if (may_record_ && sync_enabled) {
ukm->EnableRecording();
......@@ -146,7 +147,9 @@ void MetricsServicesManager::UpdateUkmService() {
}
void MetricsServicesManager::UpdateUploadPermissions(bool may_upload) {
UpdatePermissions(client_->IsMetricsReportingEnabled(), may_upload);
UpdatePermissions((client_->IsMetricsReportingForceEnabled() ||
client_->IsMetricsReportingEnabled()),
client_->IsMetricsReportingForceEnabled() || may_upload);
}
} // namespace metrics_services_manager
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/metrics_services_manager/metrics_services_manager_client.h"
namespace metrics_services_manager {
bool MetricsServicesManagerClient::IsMetricsReportingForceEnabled() {
return false;
}
} // namespace metrics_services_manager
......@@ -57,6 +57,9 @@ class MetricsServicesManagerClient {
// Update the running state of metrics services managed by the embedder, for
// example, crash reporting.
virtual void UpdateRunningServices(bool may_record, bool may_upload) {}
// If the user has forced metrics collection on via the override flag.
virtual bool IsMetricsReportingForceEnabled();
};
} // namespace metrics_services_manager
......
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