Commit 9a375622 authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

Move around FieldTrial initialization in content:

. Content moves loading from PreCreateThreads() to
  PreEarlyInitialization() (or right after calling
  BrowserMainParts::PreEarlyInitialization()
  . This necessitated a change for cast to have content not init
    FieldTrials.
. Moves creation of FieldTrial in tests from
  TestBlinkWebUnitTestSupport to UnittestTestSuite. This is so code
  run after that (but before TestBlinkWebUnitTestSupport) has the
  FeatureList setup.

BUG=800357
TEST=none

Change-Id: I50e121f4c5654288571715b0e72bf04db340daf1
Reviewed-on: https://chromium-review.googlesource.com/925685Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537817}
parent 5909b562
......@@ -1072,6 +1072,11 @@ DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded() {
// content::BrowserMainParts implementation ------------------------------------
bool ChromeBrowserMainParts::ShouldContentCreateFeatureList() {
// Chrome creates the FeatureList, so no need for content to do the same.
return false;
}
int ChromeBrowserMainParts::PreEarlyInitialization() {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreEarlyInitialization");
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
......
......@@ -63,6 +63,7 @@ class ChromeBrowserMainParts : public content::BrowserMainParts {
const content::MainFunctionParams& parameters);
// content::BrowserMainParts overrides.
bool ShouldContentCreateFeatureList() override;
// These are called in-order by content::BrowserMainLoop.
// Each stage calls the same stages in any ChromeBrowserMainExtraParts added
// with AddParts() from ChromeContentBrowserClient::CreateBrowserMainParts.
......
......@@ -356,6 +356,10 @@ content::BrowserContext* CastBrowserMainParts::browser_context() {
return cast_browser_process_->browser_context();
}
bool CastBrowserMainParts::ShouldContentCreateFeatureList() {
return false;
}
void CastBrowserMainParts::PreMainMessageLoopStart() {
// GroupedHistograms needs to be initialized before any threads are created
// to prevent race conditions between calls to Preregister and those threads
......
......@@ -72,6 +72,7 @@ class CastBrowserMainParts : public content::BrowserMainParts {
content::BrowserContext* browser_context();
// content::BrowserMainParts implementation:
bool ShouldContentCreateFeatureList() override;
void PreMainMessageLoopStart() override;
void PostMainMessageLoopStart() override;
void ToolkitInitialized() override;
......
......@@ -668,6 +668,16 @@ int BrowserMainLoop::EarlyInitialization() {
return pre_early_init_error_code;
}
if (!parts_ || parts_->ShouldContentCreateFeatureList()) {
// Note that we do not initialize a new FeatureList when calling this for
// the second time.
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
base::FeatureList::InitializeInstance(
command_line->GetSwitchValueASCII(switches::kEnableFeatures),
command_line->GetSwitchValueASCII(switches::kDisableFeatures));
}
#if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_CHROMEOS)
// We use quite a few file descriptors for our IPC as well as disk the disk
// cache,and the default limit on the Mac is low (256), so bump it up.
......@@ -862,14 +872,6 @@ int BrowserMainLoop::PreCreateThreads() {
if (!base::SequencedWorkerPool::IsEnabled())
base::SequencedWorkerPool::EnableForProcess();
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
// Note that we do not initialize a new FeatureList when calling this for
// the second time.
base::FeatureList::InitializeInstance(
command_line->GetSwitchValueASCII(switches::kEnableFeatures),
command_line->GetSwitchValueASCII(switches::kDisableFeatures));
InitializeMemoryManagementComponent();
#if defined(OS_MACOSX)
......
......@@ -8,6 +8,10 @@
namespace content {
bool BrowserMainParts::ShouldContentCreateFeatureList() {
return true;
}
int BrowserMainParts::PreEarlyInitialization() {
return RESULT_CODE_NORMAL_EXIT;
}
......
......@@ -53,6 +53,11 @@ class CONTENT_EXPORT BrowserMainParts {
BrowserMainParts() {}
virtual ~BrowserMainParts() {}
// Returns true if content should create a FeatureList. Default
// implementation returns true. Embedders that need to control when and/or
// how FeatureList should be created should override and return false.
virtual bool ShouldContentCreateFeatureList();
// A return value other than RESULT_CODE_NORMAL_EXIT indicates error and is
// used as the exit status.
virtual int PreEarlyInitialization();
......
......@@ -4,6 +4,7 @@
#include "content/public/test/unittest_test_suite.h"
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/rand_util.h"
......@@ -24,6 +25,14 @@ namespace content {
UnitTestTestSuite::UnitTestTestSuite(base::TestSuite* test_suite)
: test_suite_(test_suite) {
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
std::string enabled =
command_line->GetSwitchValueASCII(switches::kEnableFeatures);
std::string disabled =
command_line->GetSwitchValueASCII(switches::kDisableFeatures);
feature_list_.InitFromCommandLine(enabled, disabled);
#if defined(USE_X11)
XInitThreads();
#endif
......
......@@ -8,6 +8,7 @@
#include <memory>
#include "base/macros.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#if defined(USE_AURA)
......@@ -39,6 +40,8 @@ class UnitTestTestSuite {
private:
std::unique_ptr<base::TestSuite> test_suite_;
base::test::ScopedFeatureList feature_list_;
std::unique_ptr<TestBlinkWebUnitTestSupport> blink_test_support_;
#if defined(USE_AURA)
std::unique_ptr<aura::AuraTestSuiteSetup> aura_test_suite_setup_;
......
......@@ -139,6 +139,7 @@ int ShellBrowserMainParts::PreEarlyInitialization() {
net::NetworkChangeNotifier::SetFactory(
new net::NetworkChangeNotifierFactoryAndroid());
#endif
SetupFieldTrials();
return RESULT_CODE_NORMAL_EXIT;
}
......@@ -180,7 +181,6 @@ void ShellBrowserMainParts::SetupFieldTrials() {
}
int ShellBrowserMainParts::PreCreateThreads() {
SetupFieldTrials();
#if defined(OS_ANDROID)
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
......
......@@ -5,7 +5,6 @@
#include "content/test/test_blink_web_unit_test_support.h"
#include "base/callback.h"
#include "base/feature_list.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
......@@ -164,10 +163,6 @@ TestBlinkWebUnitTestSupport::TestBlinkWebUnitTestSupport()
web_thread_ = renderer_scheduler_->CreateMainThread();
shared_bitmap_manager_.reset(new cc::TestSharedBitmapManager);
// Set up a FeatureList instance, so that code using that API will not hit a
// an error that it's not set. Cleared by ClearInstanceForTesting() below.
base::FeatureList::SetInstance(base::WrapUnique(new base::FeatureList));
// Initialize mojo firstly to enable Blink initialization to use it.
InitializeMojo();
......@@ -204,9 +199,6 @@ TestBlinkWebUnitTestSupport::~TestBlinkWebUnitTestSupport() {
mock_clipboard_.reset();
if (renderer_scheduler_)
renderer_scheduler_->Shutdown();
// Clear the FeatureList that was registered in the constructor.
base::FeatureList::ClearInstanceForTesting();
}
blink::WebBlobRegistry* TestBlinkWebUnitTestSupport::GetBlobRegistry() {
......
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