Commit aeb09c61 authored by Moe Ahmadi's avatar Moe Ahmadi Committed by Commit Bot

[UKM] Support --force-enable-metrics-reporting flag in iOS

Bug: 828878
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I76115730b550c8320e05c7c9fc1a20dd129f3626
Reviewed-on: https://chromium-review.googlesource.com/1012748
Commit-Queue: Moe Ahmadi <mahmadi@chromium.org>
Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarOlivier Robin <olivierrobin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551469}
parent a80616b7
......@@ -72,6 +72,7 @@
#include "components/metrics/metrics_service.h"
#include "components/metrics/metrics_service_client.h"
#include "components/metrics/metrics_state_manager.h"
#include "components/metrics/metrics_switches.h"
#include "components/metrics/net/cellular_logic_helper.h"
#include "components/metrics/net/net_metrics_log_uploader.h"
#include "components/metrics/net/network_metrics_provider.h"
......@@ -568,7 +569,7 @@ ChromeMetricsServiceClient::GetMetricsReportingDefaultState() {
// static
bool ChromeMetricsServiceClient::IsMetricsReportingForceEnabled() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kForceEnableMetricsReporting);
metrics::switches::kForceEnableMetricsReporting);
}
void ChromeMetricsServiceClient::Initialize() {
......
......@@ -387,9 +387,6 @@ const char kForceAppMode[] = "force-app-mode";
// is triggered.
const char kForceDesktopIOSPromotion[] = "force-desktop-ios-promotion";
// 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";
......
......@@ -122,7 +122,6 @@ extern const char kFastStart[];
extern const char kForceAndroidAppMode[];
extern const char kForceAppMode[];
extern const char kForceDesktopIOSPromotion[];
extern const char kForceEnableMetricsReporting[];
extern const char kForceFirstRun[];
extern const char kForceFirstRunDialog[];
extern const char kForceLocalNtp[];
......
......@@ -18,5 +18,8 @@ const char kMetricsRecordingOnly[] = "metrics-recording-only";
// known as the Chrome Variations state.
const char kResetVariationState[] = "reset-variation-state";
// Forces metrics reporting to be enabled.
const char kForceEnableMetricsReporting[] = "force-enable-metrics-reporting";
} // namespace switches
} // namespace metrics
......@@ -13,6 +13,7 @@ namespace switches {
extern const char kMetricsRecordingOnly[];
extern const char kResetVariationState[];
extern const char kForceEnableMetricsReporting[];
} // namespace switches
} // namespace metrics
......
......@@ -56,6 +56,9 @@ class IOSChromeMetricsServiceClient : public IncognitoWebStateObserver,
// 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;
......
......@@ -29,6 +29,7 @@
#include "components/metrics/metrics_pref_names.h"
#include "components/metrics/metrics_reporting_default_state.h"
#include "components/metrics/metrics_service.h"
#include "components/metrics/metrics_switches.h"
#include "components/metrics/net/cellular_logic_helper.h"
#include "components/metrics/net/net_metrics_log_uploader.h"
#include "components/metrics/net/network_metrics_provider.h"
......@@ -99,6 +100,12 @@ void IOSChromeMetricsServiceClient::RegisterPrefs(
ukm::UkmService::RegisterPrefs(registry);
}
// static
bool IOSChromeMetricsServiceClient::IsMetricsReportingForceEnabled() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
metrics::switches::kForceEnableMetricsReporting);
}
metrics::MetricsService* IOSChromeMetricsServiceClient::GetMetricsService() {
return metrics_service_.get();
}
......@@ -176,13 +183,14 @@ void IOSChromeMetricsServiceClient::Initialize() {
metrics_service_ = std::make_unique<metrics::MetricsService>(
metrics_state_manager_, this, local_state);
// Always restrict on iOS.
// TODO(crbug.com/828878): Use the flag to set this.
bool restrict_to_whitelist_entries = true;
if (base::FeatureList::IsEnabled(ukm::kUkmFeature))
if (IsMetricsReportingForceEnabled() ||
base::FeatureList::IsEnabled(ukm::kUkmFeature)) {
// We only need to restrict to whitelisted Entries if metrics reporting
// is not forced.
bool restrict_to_whitelist_entries = !IsMetricsReportingForceEnabled();
ukm_service_ = std::make_unique<ukm::UkmService>(
local_state, this, restrict_to_whitelist_entries);
}
// Register metrics providers.
metrics_service_->RegisterMetricsProvider(
......
......@@ -41,12 +41,11 @@ class IOSChromeMetricsServicesManagerClient
override;
std::unique_ptr<const base::FieldTrial::EntropyProvider>
CreateEntropyProvider() override;
net::URLRequestContextGetter* GetURLRequestContext() override;
bool IsMetricsReportingEnabled() override;
bool IsMetricsConsentGiven() override;
bool IsIncognitoSessionActive() override;
bool IsMetricsReportingForceEnabled() override;
// Gets the MetricsStateManager, creating it if it has not already been
// created.
......
......@@ -117,3 +117,7 @@ IOSChromeMetricsServicesManagerClient::GetMetricsStateManager() {
bool IOSChromeMetricsServicesManagerClient::IsIncognitoSessionActive() {
return TabModelList::IsOffTheRecordSessionActive();
}
bool IOSChromeMetricsServicesManagerClient::IsMetricsReportingForceEnabled() {
return IOSChromeMetricsServiceClient::IsMetricsReportingForceEnabled();
}
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