Commit ce2e7d31 authored by robliao's avatar robliao Committed by Commit bot

Rearrange SetupMetricsAndFieldTrials to SetupFieldTrials and SetupMetrics

This allows for the Browser Task Scheduler to setup and redirect after
SetupFieldTrials to get variations data but before SetupMetrics, which
posts tasks to the blocking pool.

The corresponding iOS change will be in a later CL

BUG=636518

Review-Url: https://codereview.chromium.org/2342993002
Cr-Commit-Position: refs/heads/master@{#419511}
parent 7b1628cc
......@@ -791,8 +791,8 @@ ChromeBrowserMainParts::~ChromeBrowserMainParts() {
}
// This will be called after the command-line has been mutated by about:flags
void ChromeBrowserMainParts::SetupMetricsAndFieldTrials() {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::SetupMetricsAndFieldTrials");
void ChromeBrowserMainParts::SetupFieldTrials() {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::SetupFieldTrials");
// Initialize FieldTrialList to support FieldTrials that use one-time
// randomization.
......@@ -841,11 +841,6 @@ void ChromeBrowserMainParts::SetupMetricsAndFieldTrials() {
about_flags::RegisterAllFeatureVariationParameters(
&flags_storage, feature_list.get());
// Must initialize metrics after about:flags have been converted into
// switches, but before field trials are set up (so that client ID is
// available for one-time randomized field trials).
metrics::MetricsService* metrics = browser_process_->metrics_service();
variations::VariationsHttpHeaderProvider* http_header_provider =
variations::VariationsHttpHeaderProvider::GetInstance();
// Force the variation ids selected in chrome://flags and/or specified using
......@@ -855,7 +850,6 @@ void ChromeBrowserMainParts::SetupMetricsAndFieldTrials() {
&variation_ids);
CHECK(result) << "Invalid list of variation ids specified (either in --"
<< switches::kForceVariationIds << " or in chrome://flags)";
metrics->AddSyntheticTrialObserver(http_header_provider);
feature_list->InitializeFromCommandLine(
command_line->GetSwitchValueASCII(switches::kEnableFeatures),
......@@ -895,25 +889,6 @@ void ChromeBrowserMainParts::SetupMetricsAndFieldTrials() {
// deleted after the Task is executed.
field_trial_synchronizer_ = new FieldTrialSynchronizer();
// Now that field trials have been created, initializes metrics recording.
metrics->InitializeMetricsRecordingState();
const version_info::Channel channel = chrome::GetChannel();
// Enable profiler instrumentation depending on the channel.
switch (channel) {
case version_info::Channel::UNKNOWN:
case version_info::Channel::CANARY:
tracked_objects::ScopedTracker::Enable();
break;
case version_info::Channel::DEV:
case version_info::Channel::BETA:
case version_info::Channel::STABLE:
// Don't enable instrumentation.
break;
}
// Register a synthetic field trial for the sampling profiler configuration
// that was already chosen.
sampling_profiler_config_.RegisterSyntheticFieldTrial();
......@@ -935,7 +910,30 @@ void ChromeBrowserMainParts::SetupMetricsAndFieldTrials() {
#endif // defined(OS_WIN)
}
// ChromeBrowserMainParts: |SetupMetricsAndFieldTrials()| related --------------
void ChromeBrowserMainParts::SetupMetrics() {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::SetupMetrics");
metrics::MetricsService* metrics = browser_process_->metrics_service();
metrics->AddSyntheticTrialObserver(
variations::VariationsHttpHeaderProvider::GetInstance());
// Now that field trials have been created, initializes metrics recording.
metrics->InitializeMetricsRecordingState();
const version_info::Channel channel = chrome::GetChannel();
// Enable profiler instrumentation depending on the channel.
switch (channel) {
case version_info::Channel::UNKNOWN:
case version_info::Channel::CANARY:
tracked_objects::ScopedTracker::Enable();
break;
case version_info::Channel::DEV:
case version_info::Channel::BETA:
case version_info::Channel::STABLE:
// Don't enable instrumentation.
break;
}
}
void ChromeBrowserMainParts::StartMetricsRecording() {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::StartMetricsRecording");
......@@ -1319,16 +1317,17 @@ int ChromeBrowserMainParts::PreCreateThreadsImpl() {
#if defined(OS_CHROMEOS)
// Must be done after g_browser_process is constructed, before
// SetupMetricsAndFieldTrials().
// SetupFieldTrials() and SetupMetrics().
chromeos::CrosSettings::Initialize();
#endif // defined(OS_CHROMEOS)
SetupOriginTrialsCommandLine();
// Now the command line has been mutated based on about:flags, we can setup
// metrics and initialize field trials. The field trials are needed by
// Now the command line has been mutated based on about:flags, we can
// initialize field trials and setup metrics. The field trials are needed by
// IOThread's initialization which happens in BrowserProcess:PreCreateThreads.
SetupMetricsAndFieldTrials();
SetupFieldTrials();
SetupMetrics();
// ChromeOS needs ResourceBundle::InitSharedInstance to be called before this.
browser_process_->PreCreateThreads();
......@@ -1339,10 +1338,10 @@ int ChromeBrowserMainParts::PreCreateThreadsImpl() {
// This needs to be the last thing in PreCreateThreads() because the
// TaskScheduler needs to be created before any other threads are (by
// contract) but it creates threads itself so instantiating it earlier is also
// incorrect. It also has to be after SetupMetricsAndFieldTrials() to allow it
// to use field trials. Note: it could also be the first thing in
// CreateThreads() but being in chrome/ is convenient for now as the
// initialization uses variations parameters extensively.
// incorrect. It also has to be after SetupFieldTrials() to allow it to use
// field trials. Note: it could also be the first thing in CreateThreads() but
// being in chrome/ is convenient for now as the initialization uses
// variations parameters extensively.
//
// To maintain scoping symmetry, if this line is moved, the corresponding
// shutdown call may also need to be moved.
......
......@@ -102,12 +102,12 @@ class ChromeBrowserMainParts : public content::BrowserMainParts {
const PrefService* local_state() const { return local_state_; }
private:
// Methods for |SetupMetricsAndFieldTrials()| --------------------------------
// Sets up the field trials and related initialization. Call only after
// about:flags have been converted to switches.
void SetupFieldTrials();
// Constructs metrics service and does related initialization, including
// creation of field trials. Call only after labs have been converted to
// switches.
void SetupMetricsAndFieldTrials();
// Constructs the metrics service and initializes metrics recording.
void SetupMetrics();
// Starts recording of metrics. This can only be called after we have a file
// thread.
......@@ -139,8 +139,8 @@ class ChromeBrowserMainParts : public content::BrowserMainParts {
// it is destroyed last.
std::unique_ptr<ShutdownWatcherHelper> shutdown_watcher_;
// Statistical testing infrastructure for the entire browser. NULL until
// SetupMetricsAndFieldTrials is called.
// Statistical testing infrastructure for the entire browser. nullptr until
// |SetupFieldTrials()| is called.
std::unique_ptr<base::FieldTrialList> field_trial_list_;
ChromeBrowserFieldTrials browser_field_trials_;
......@@ -190,7 +190,7 @@ class ChromeBrowserMainParts : public content::BrowserMainParts {
bool run_message_loop_;
std::unique_ptr<ThreeDAPIObserver> three_d_observer_;
// Initialized in SetupMetricsAndFieldTrials.
// Initialized in |SetupFieldTrials()|.
scoped_refptr<FieldTrialSynchronizer> field_trial_synchronizer_;
// Members initialized in PreMainMessageLoopRun, needed in
......
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