Skip to content

Commit

Permalink
Move pref and switch in preparation for metrics componentization
Browse files Browse the repository at this point in the history
Code will shortly be componentized into the metrics component that uses
prefs::kMetricsReportingEnabled and switches::kForceFieldTrials. To enable that
componentization, this CL does the following:

- Moves prefs::kMetricsReportingEnabled into the metrics component.
- Moves switches:kForceFieldTrials from //content to //base to enable it to be
  used both by //content and by the metrics component.

BUG=508014

Committed: https://crrev.com/71f7da5a323ce64e8bc5b3ff2a62fc60e3c71bd0
Cr-Commit-Position: refs/heads/master@{#351268}

Review URL: https://codereview.chromium.org/1373823002

Cr-Commit-Position: refs/heads/master@{#351294}
  • Loading branch information
colinblundell authored and Commit bot committed Sep 29, 2015
1 parent f81cb5b commit 6e85b7c
Show file tree
Hide file tree
Showing 22 changed files with 43 additions and 42 deletions.
10 changes: 10 additions & 0 deletions base/base_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ const char kEnableLowEndDeviceMode[] = "enable-low-end-device-mode";
// Force disabling of low-end device mode when set.
const char kDisableLowEndDeviceMode[] = "disable-low-end-device-mode";

// This option can be used to force field trials when testing changes locally.
// The argument is a list of name and value pairs, separated by slashes. If a
// trial name is prefixed with an asterisk, that trial will start activated.
// For example, the following argument defines two trials, with the second one
// activated: "GoogleNow/Enable/*MaterialDesignNTP/Default/" This option can
// also be used by the browser process to send the list of trials to a
// non-browser process, using the same format. See
// FieldTrialList::CreateTrialsFromString() in field_trial.h for details.
const char kForceFieldTrials[] = "force-fieldtrials";

// Suppresses all error dialogs when present.
const char kNoErrorDialogs[] = "noerrdialogs";

Expand Down
1 change: 1 addition & 0 deletions base/base_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace switches {

extern const char kDisableBreakpad[];
extern const char kEnableCrashReporter[];
extern const char kForceFieldTrials[];
extern const char kFullMemoryCrashReport[];
extern const char kEnableLowEndDeviceMode[];
extern const char kDisableLowEndDeviceMode[];
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/android/preferences/pref_service_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -462,20 +462,20 @@ static jboolean GetFullscreenAllowed(JNIEnv* env,
static jboolean GetMetricsReportingEnabled(JNIEnv* env,
const JavaParamRef<jobject>& obj) {
PrefService* local_state = g_browser_process->local_state();
return local_state->GetBoolean(prefs::kMetricsReportingEnabled);
return local_state->GetBoolean(metrics::prefs::kMetricsReportingEnabled);
}

static void SetMetricsReportingEnabled(JNIEnv* env,
const JavaParamRef<jobject>& obj,
jboolean enabled) {
PrefService* local_state = g_browser_process->local_state();
local_state->SetBoolean(prefs::kMetricsReportingEnabled, enabled);
local_state->SetBoolean(metrics::prefs::kMetricsReportingEnabled, enabled);
}

static jboolean HasSetMetricsReporting(JNIEnv* env,
const JavaParamRef<jobject>& obj) {
PrefService* local_state = g_browser_process->local_state();
return local_state->HasPrefPath(prefs::kMetricsReportingEnabled);
return local_state->HasPrefPath(metrics::prefs::kMetricsReportingEnabled);
}

namespace {
Expand Down
7 changes: 3 additions & 4 deletions chrome/browser/browser_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -822,9 +822,8 @@ void BrowserProcessImpl::RegisterPrefs(PrefRegistrySimple* registry) {
std::string());
#endif // defined(OS_CHROMEOS)
#if !defined(OS_CHROMEOS)
registry->RegisterBooleanPref(
prefs::kMetricsReportingEnabled,
GoogleUpdateSettings::GetCollectStatsConsent());
registry->RegisterBooleanPref(metrics::prefs::kMetricsReportingEnabled,
GoogleUpdateSettings::GetCollectStatsConsent());
#endif // !defined(OS_CHROMEOS)

#if defined(OS_ANDROID)
Expand Down Expand Up @@ -1006,7 +1005,7 @@ void BrowserProcessImpl::CreateLocalState() {
// whenever the preference or its controlling policy changes.
#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && !defined(OS_IOS)
pref_change_registrar_.Add(
prefs::kMetricsReportingEnabled,
metrics::prefs::kMetricsReportingEnabled,
base::Bind(&BrowserProcessImpl::ApplyMetricsReportingPolicy,
base::Unretained(this)));
#endif
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/first_run/first_run_internal_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void DoPostImportPlatformSpecificTasks(Profile* profile) {
// this is POSIX-specific).
if (GoogleUpdateSettings::GetCollectStatsConsent()) {
g_browser_process->local_state()->SetBoolean(
prefs::kMetricsReportingEnabled, true);
metrics::prefs::kMetricsReportingEnabled, true);
}
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/metrics/chrome_metrics_service_accessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ bool ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled() {
prefs::kCrashReportingEnabled);
#else
enabled = g_browser_process->local_state()->
GetBoolean(prefs::kMetricsReportingEnabled);
GetBoolean(metrics::prefs::kMetricsReportingEnabled);
#endif // #if defined(OS_CHROMEOS)
#endif // defined(GOOGLE_CHROME_BUILD)
return enabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TEST_F(ChromeMetricsServiceAccessorTest, MetricsReportingEnabled) {
#if defined(OS_ANDROID)
const char* pref = prefs::kCrashReportingEnabled;
#else
const char* pref = prefs::kMetricsReportingEnabled;
const char* pref = metrics::prefs::kMetricsReportingEnabled;
#endif // defined(OS_ANDROID)
GetLocalState()->SetDefaultPrefValue(pref, new base::FundamentalValue(false));

Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/metrics/chrome_metrics_service_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ bool IsCellularLogicEnabled() {
bool ShouldClearSavedMetrics() {
#if defined(OS_ANDROID)
PrefService* local_state = g_browser_process->local_state();
return !local_state->HasPrefPath(prefs::kMetricsReportingEnabled) &&
return !local_state->HasPrefPath(metrics::prefs::kMetricsReportingEnabled) &&
variations::GetVariationParamValue("UMA_EnableCellularLogUpload",
"Enabled") == "true";
#else
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/metrics/metrics_reporting_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void SetMetricsReporting(bool to_update_pref,
}
#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
g_browser_process->local_state()->SetBoolean(
prefs::kMetricsReportingEnabled, updated_pref);
metrics::prefs::kMetricsReportingEnabled, updated_pref);
#endif
// When a user opts in to the metrics reporting service, the previously
// collected data should be cleared to ensure that nothing is reported before
Expand Down Expand Up @@ -103,6 +103,6 @@ void InitiateMetricsReportingChange(
bool IsMetricsReportingUserChangable() {
const PrefService* pref_service = g_browser_process->local_state();
const PrefService::Preference* pref =
pref_service->FindPreference(prefs::kMetricsReportingEnabled);
pref_service->FindPreference(metrics::prefs::kMetricsReportingEnabled);
return pref && !pref->IsManaged();
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const PolicyToPreferenceMapEntry kSimplePolicyMap[] = {
prefs::kPrintPreviewDisabled,
base::Value::TYPE_BOOLEAN },
{ key::kMetricsReportingEnabled,
prefs::kMetricsReportingEnabled,
metrics::prefs::kMetricsReportingEnabled,
base::Value::TYPE_BOOLEAN },
{ key::kApplicationLocaleValue,
prefs::kApplicationLocale,
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/prefs/tracked/pref_hash_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <string>

#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
Expand Down Expand Up @@ -31,7 +32,6 @@
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
#include "components/search_engines/default_search_manager.h"
#include "content/public/common/content_switches.h"
#include "extensions/browser/pref_names.h"
#include "extensions/common/extension.h"

Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/profiles/profile_io_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ void ProfileIOData::InitializeMetricsEnabledStateOnUIThread() {
#else
// Prep the PrefMember and send it to the IO thread, since this value will be
// read from there.
enable_metrics_.Init(prefs::kMetricsReportingEnabled,
enable_metrics_.Init(metrics::prefs::kMetricsReportingEnabled,
g_browser_process->local_state());
enable_metrics_.MoveToThread(
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/cocoa/first_run_dialog.mm
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ bool ShowFirstRun(Profile* profile) {
// (which is likely to be forced in enterprise deployments anyway).
const PrefService::Preference* metrics_reporting_pref =
g_browser_process->local_state()->FindPreference(
prefs::kMetricsReportingEnabled);
metrics::prefs::kMetricsReportingEnabled);
if (!metrics_reporting_pref || !metrics_reporting_pref->IsManaged()) {
base::scoped_nsobject<FirstRunDialogController> dialog(
[[FirstRunDialogController alloc] init]);
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/views/first_run_dialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ bool FirstRunDialog::Show(Profile* profile) {
// If the metrics reporting is managed, we won't ask.
const PrefService::Preference* metrics_reporting_pref =
g_browser_process->local_state()->FindPreference(
prefs::kMetricsReportingEnabled);
metrics::prefs::kMetricsReportingEnabled);

if (!metrics_reporting_pref ||
!metrics_reporting_pref->IsManaged()) {
Expand Down
6 changes: 4 additions & 2 deletions chrome/browser/ui/views/session_crashed_bubble_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,10 @@ void SessionCrashedBubbleView::ShowForReal(

#if defined(GOOGLE_CHROME_BUILD)
if (!uma_opted_in_already) {
offer_uma_optin = g_browser_process->local_state()->FindPreference(
prefs::kMetricsReportingEnabled)->IsUserModifiable();
offer_uma_optin =
g_browser_process->local_state()
->FindPreference(metrics::prefs::kMetricsReportingEnabled)
->IsUserModifiable();
}
#endif // defined(GOOGLE_CHROME_BUILD)

Expand Down
5 changes: 0 additions & 5 deletions chrome/common/pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1254,11 +1254,6 @@ const char kSSLVersionFallbackMin[] = "ssl.version_fallback_min";
const char kCipherSuiteBlacklist[] = "ssl.cipher_suites.blacklist";
const char kDisableSSLRecordSplitting[] = "ssl.ssl_record_splitting.disabled";

// Boolean that specifies whether or not crash reporting and metrics reporting
// are sent over the network for analysis.
const char kMetricsReportingEnabled[] =
"user_experience_metrics.reporting_enabled";

// Boolean that specifies whether or not crash reports are sent
// over the network for analysis.
#if defined(OS_ANDROID)
Expand Down
5 changes: 0 additions & 5 deletions chrome/common/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,6 @@ extern const char kGLVendorString[];
extern const char kGLRendererString[];
extern const char kGLVersionString[];

// For finding out whether metrics and crash reporting is enabled or not use
// |ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()| instead
// of reading platform specific prefs.
extern const char kMetricsReportingEnabled[];

// Android has it's own metric / crash reporting implemented in Android
// Java code so kMetricsReportingEnabled doesn't make sense. We use this
// to inform crashes_ui that we have enabled crash reporting.
Expand Down
2 changes: 1 addition & 1 deletion chrome/installer/util/uninstall_metrics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ bool ExtractUninstallMetrics(const base::DictionaryValue& root,
// Make sure that the user wants us reporting metrics. If not, don't
// add our uninstall metrics.
bool metrics_reporting_enabled = false;
if (!root.GetBoolean(prefs::kMetricsReportingEnabled,
if (!root.GetBoolean(metrics::prefs::kMetricsReportingEnabled,
&metrics_reporting_enabled) ||
!metrics_reporting_enabled) {
return false;
Expand Down
5 changes: 5 additions & 0 deletions components/metrics/metrics_pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ const char kMetricsOngoingLogs[] =
// client id and low entropy source should be reset.
const char kMetricsResetIds[] = "user_experience_metrics.reset_metrics_ids";

// Boolean that specifies whether or not crash reporting and metrics reporting
// are sent over the network for analysis.
const char kMetricsReportingEnabled[] =
"user_experience_metrics.reporting_enabled";

// Date/time when the user opted in to UMA and generated the client id for the
// very first time (local machine time, stored as a 64-bit time_t value).
const char kMetricsReportingEnabledTimestamp[] =
Expand Down
5 changes: 5 additions & 0 deletions components/metrics/metrics_pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ extern const char kMetricsLowEntropySource[];
extern const char kMetricsMachineId[];
extern const char kMetricsOngoingLogs[];
extern const char kMetricsResetIds[];

// For finding out whether metrics and crash reporting is enabled use
// ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled() instead of
// reading this pref directly.
extern const char kMetricsReportingEnabled[];
extern const char kMetricsReportingEnabledTimestamp[];
extern const char kMetricsSessionID[];
extern const char kStabilityBreakpadRegistrationSuccess[];
Expand Down
10 changes: 0 additions & 10 deletions content/public/common/content_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -494,16 +494,6 @@ const char kExplicitlyAllowedPorts[] = "explicitly-allowed-ports";
// Load NPAPI plugins from the specified directory.
const char kExtraPluginDir[] = "extra-plugin-dir";

// This option can be used to force field trials when testing changes locally.
// The argument is a list of name and value pairs, separated by slashes. If a
// trial name is prefixed with an asterisk, that trial will start activated.
// For example, the following argument defines two trials, with the second one
// activated: "GoogleNow/Enable/*MaterialDesignNTP/Default/"
// This option is also used by the browser to send the list of trials to
// renderers, using the same format. See
// FieldTrialList::CreateTrialsFromString() in field_trial.h for details.
const char kForceFieldTrials[] = "force-fieldtrials";

// Always use the Skia GPU backend for drawing layer tiles. Only valid with GPU
// accelerated compositing + impl-side painting. Overrides the
// kEnableGpuRasterization flag.
Expand Down
1 change: 0 additions & 1 deletion content/public/common/content_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ CONTENT_EXPORT extern const char kEnableZeroCopy[];
CONTENT_EXPORT extern const char kExplicitlyAllowedPorts[];
CONTENT_EXPORT extern const char kExtraPluginDir[];
CONTENT_EXPORT extern const char kForceDisplayList2dCanvas[];
CONTENT_EXPORT extern const char kForceFieldTrials[];
CONTENT_EXPORT extern const char kForceGpuRasterization[];
CONTENT_EXPORT extern const char kForceOverlayFullscreenVideo[];
CONTENT_EXPORT extern const char kForceRendererAccessibility[];
Expand Down

0 comments on commit 6e85b7c

Please sign in to comment.