Commit 5beedd01 authored by danakj's avatar danakj Committed by Commit Bot

Move StartupData to ChromeContentBrowserClient.

Currently it's created with the ChromeContentBrowserClient, and a raw
pointer is passed to it, which it stores. It is primarily used by
ChromeContentBrowserClient. The ChromeMainDelegate has to manage the
lifetime of the two objects instead of one.

We can simplify the relationship here by having the StartupData owned
by ChromeContentBrowserClient instead. Since ChromeMainDelegate
already has a pointer to the ChromeContentBrowserClient it creates,
it can use the StartupData from there. This makes it clear in the
ChromeMainDelegate code that it depends on the ContentBrowserClient
being created already when using the StartupData.

R=avi@chromium.org

Bug: 811470
Change-Id: Ia099042e11f2adc6abb5186f57925fae05343da4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2508231
Commit-Queue: danakj <danakj@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822665}
parent b4fc4420
......@@ -531,9 +531,9 @@ void ChromeMainDelegate::PostEarlyInitialization(bool is_running_tests) {
chromeos::InitializeDBus();
#endif
DCHECK(startup_data_);
auto* chrome_feature_list_creator =
startup_data_->chrome_feature_list_creator();
ChromeFeatureListCreator* chrome_feature_list_creator =
chrome_content_browser_client_->startup_data()
->chrome_feature_list_creator();
chrome_feature_list_creator->CreateFeatureList();
PostFieldTrialInitialization();
......@@ -556,7 +556,7 @@ void ChromeMainDelegate::PostEarlyInitialization(bool is_running_tests) {
#endif
#if defined(OS_ANDROID)
startup_data_->CreateProfilePrefService();
chrome_content_browser_client_->startup_data()->CreateProfilePrefService();
net::NetworkChangeNotifier::SetFactory(
new net::NetworkChangeNotifierFactoryAndroid());
#endif
......@@ -569,7 +569,7 @@ void ChromeMainDelegate::PostEarlyInitialization(bool is_running_tests) {
base::FeatureList::IsEnabled(chrome::android::kUmaBackgroundSessions);
#endif
if (record)
startup_data_->RecordCoreSystemProfile();
chrome_content_browser_client_->startup_data()->RecordCoreSystemProfile();
}
#if defined(OS_ANDROID)
......@@ -1214,13 +1214,8 @@ content::ContentClient* ChromeMainDelegate::CreateContentClient() {
content::ContentBrowserClient*
ChromeMainDelegate::CreateContentBrowserClient() {
if (chrome_content_browser_client_ == nullptr) {
DCHECK(!startup_data_);
startup_data_ = std::make_unique<StartupData>();
chrome_content_browser_client_ =
std::make_unique<ChromeContentBrowserClient>(startup_data_.get());
}
chrome_content_browser_client_ =
std::make_unique<ChromeContentBrowserClient>();
return chrome_content_browser_client_.get();
}
......
......@@ -79,8 +79,6 @@ class ChromeMainDelegate : public content::ContentMainDelegate {
std::unique_ptr<ChromeContentBrowserClient> chrome_content_browser_client_;
std::unique_ptr<StartupData> startup_data_;
std::unique_ptr<tracing::TracingSamplerProfiler> tracing_sampler_profiler_;
// The controller schedules UMA heap profiles collections and forwarding down
......
......@@ -1270,9 +1270,7 @@ blink::UserAgentMetadata GetUserAgentMetadata() {
return metadata;
}
ChromeContentBrowserClient::ChromeContentBrowserClient(
StartupData* startup_data)
: startup_data_(startup_data) {
ChromeContentBrowserClient::ChromeContentBrowserClient() {
#if BUILDFLAG(ENABLE_PLUGINS)
extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart);
#endif
......@@ -1355,31 +1353,31 @@ ChromeContentBrowserClient::CreateBrowserMainParts(
// Construct the Main browser parts based on the OS type.
#if defined(OS_WIN)
main_parts =
std::make_unique<ChromeBrowserMainPartsWin>(parameters, startup_data_);
std::make_unique<ChromeBrowserMainPartsWin>(parameters, &startup_data_);
#elif defined(OS_MAC)
main_parts =
std::make_unique<ChromeBrowserMainPartsMac>(parameters, startup_data_);
std::make_unique<ChromeBrowserMainPartsMac>(parameters, &startup_data_);
#elif defined(OS_CHROMEOS)
main_parts = std::make_unique<chromeos::ChromeBrowserMainPartsChromeos>(
parameters, startup_data_);
parameters, &startup_data_);
#elif defined(OS_LINUX)
main_parts =
std::make_unique<ChromeBrowserMainPartsLinux>(parameters, startup_data_);
std::make_unique<ChromeBrowserMainPartsLinux>(parameters, &startup_data_);
#elif defined(OS_ANDROID)
main_parts = std::make_unique<ChromeBrowserMainPartsAndroid>(parameters,
startup_data_);
&startup_data_);
#elif defined(OS_POSIX)
main_parts =
std::make_unique<ChromeBrowserMainPartsPosix>(parameters, startup_data_);
std::make_unique<ChromeBrowserMainPartsPosix>(parameters, &startup_data_);
#else
NOTREACHED();
main_parts =
std::make_unique<ChromeBrowserMainParts>(parameters, startup_data_);
std::make_unique<ChromeBrowserMainParts>(parameters, &startup_data_);
#endif
bool add_profiles_extra_parts = true;
#if defined(OS_ANDROID)
if (startup_data_->HasBuiltProfilePrefService())
if (startup_data_.HasBuiltProfilePrefService())
add_profiles_extra_parts = false;
#endif
if (add_profiles_extra_parts)
......@@ -3804,23 +3802,21 @@ bool ChromeContentBrowserClient::IsRendererCodeIntegrityEnabled() {
void ChromeContentBrowserClient::WillStartServiceManager() {
#if defined(OS_WIN) || defined(OS_MAC) || \
(defined(OS_LINUX) && !defined(OS_CHROMEOS))
if (startup_data_) {
auto* chrome_feature_list_creator =
startup_data_->chrome_feature_list_creator();
// This has to run very early before ServiceManagerContext is created.
const policy::PolicyMap& policies =
chrome_feature_list_creator->browser_policy_connector()
->GetPolicyService()
->GetPolicies(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME,
std::string()));
const base::Value* audio_sandbox_enabled_policy_value =
policies.GetValue(policy::key::kAudioSandboxEnabled);
if (audio_sandbox_enabled_policy_value) {
bool force_enable_audio_sandbox;
audio_sandbox_enabled_policy_value->GetAsBoolean(
&force_enable_audio_sandbox);
SetForceAudioServiceSandboxed(force_enable_audio_sandbox);
}
auto* chrome_feature_list_creator =
startup_data_.chrome_feature_list_creator();
// This has to run very early before ServiceManagerContext is created.
const policy::PolicyMap& policies =
chrome_feature_list_creator->browser_policy_connector()
->GetPolicyService()
->GetPolicies(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME,
std::string()));
const base::Value* audio_sandbox_enabled_policy_value =
policies.GetValue(policy::key::kAudioSandboxEnabled);
if (audio_sandbox_enabled_policy_value) {
bool force_enable_audio_sandbox;
audio_sandbox_enabled_policy_value->GetAsBoolean(
&force_enable_audio_sandbox);
SetForceAudioServiceSandboxed(force_enable_audio_sandbox);
}
#endif
}
......@@ -4842,8 +4838,8 @@ void ChromeContentBrowserClient::OnNetworkServiceCreated(
DCHECK(g_browser_process->local_state());
local_state = g_browser_process->local_state();
} else {
DCHECK(startup_data_->chrome_feature_list_creator()->local_state());
local_state = startup_data_->chrome_feature_list_creator()->local_state();
DCHECK(startup_data_.chrome_feature_list_creator()->local_state());
local_state = startup_data_.chrome_feature_list_creator()->local_state();
}
if (!data_use_measurement::ChromeDataUseMeasurement::GetInstance())
......
......@@ -111,7 +111,7 @@ blink::UserAgentBrandList GenerateBrandVersionList(
class ChromeContentBrowserClient : public content::ContentBrowserClient {
public:
explicit ChromeContentBrowserClient(StartupData* startup_data = nullptr);
ChromeContentBrowserClient();
~ChromeContentBrowserClient() override;
// TODO(https://crbug.com/787567): This file is about calls from content/ out
......@@ -706,6 +706,8 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient {
void GetHyphenationDictionary(
base::OnceCallback<void(const base::FilePath&)>) override;
StartupData* startup_data() { return &startup_data_; }
protected:
static bool HandleWebUI(GURL* url, content::BrowserContext* browser_context);
static bool HandleWebUIReverse(GURL* url,
......@@ -773,7 +775,7 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient {
scoped_refptr<safe_browsing::UrlCheckerDelegate>
safe_browsing_url_checker_delegate_;
StartupData* startup_data_;
StartupData startup_data_;
#if !defined(OS_ANDROID)
std::unique_ptr<ChromeSerialDelegate> serial_delegate_;
......
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