[content] Make ContentMainParams and MainFunctionParams move-only
This is taking care of a long-standing TODO to move these OnceClosure holders rather than copy them around with their OnceClosure* members. This is a precursor to https://chromium-review.googlesource.com/c/chromium/src/+/3187153/35#message-fcc92e9f85e73f0e5ba6c03610a95cda8736f1f9 which highlighted a problem where some tests see a non-null MainFunctionParams::ui_task but running the closure results in a UAF. Logs show that the test hitting the UAF is not the one setting this field. This CL makes that impossible and fixes the issue in the follow-up CL. This CL is intended to be a logical no-op. This CL touches a lot of files and must happen all at once. The core change is that ContentMainParams and MainFunctionParams's moveable fields (ui_task, created_main_parts_closure, and startup_data) are now held by moveable types rather than raw pointers. This trickles in the following chain: main() (in various *_main.cc) (or SetUp() in !OS_ANDROID browser_test_base.cc) -> ContentMain() -> ContentMainRunnerImpl::Initialize() (forwards arg into MainFunctionParams) -> RunBrowser() -> BrowserMain() -> BrowserMainRunnerImpl::Initialize() -> BrowserMainLoop (stores MainFunctionParams) -> BrowserMainLoop::Init -> ContentBrowserClient::CreateBrowserMainParts() -> (Embedder)ContentBrowserClient::CreateBrowserMainParts() -> (Embedder)BrowserMainParts(Platform) -> (Embedder)BrowserMainParts -> RunOtherNamedProcessTypeMain() -> (Embedder)ContentMainDelegate::RunProcess() (or) -> FooMain() (kMainFunctions) (or) -> RunZygote() (creates its own MainFunctionParams) -> (Embedder)ContentMainDelegate::RunProcess() (on OS_ANDROID, browser_test_base.cc calls directly into ContentMainDelegate::RunProcess()) Few of these needed the params after passing them down so a move-only model was simple to adapt (even if invasive). The few exceptions like BrowserMainRunnerImpl::Initialize consuming |created_main_parts_closure| are better off in the new model (where they take the OnceClosure before passing down the params) because that prevents others down the chain from having access to a OnceClosure they shouldn't invoke anyways. Noteworthy: - ContentMainDelegate::RunProcess(): Returned an exit_code >= 0 to indicate the embedder elected to handle the run request given these params. With move-only semantics it is necessary to return the params back when the embedder declines handling this run request. An absl::variant return value is used to satisfy this requirement. - content/public/test/test_launcher.h : GetContentMainParams(): Becomes CopyContentMainParams() and only exposes a copy of copyable params. Uses new ContentMainParams::ShallowCopyForTesting() which verifies that moveable fields are still null by that time as should be the case in the order browser tests are initialized. - MainFunctionParams::command_line being const& violated the style-guide rule to "avoid defining functions that require a const reference parameter to outlive the call". This also prevented moving. The type was hence switched to a const CommandLine*. - BUILD.gn changes for nacl_helper_win_64 which requires static linking of its minimal //content deps (was previously missing a dep but was getting away with it because MainFunctionParams was .h only; required now with .cc). This was already done for static_switches and this CL adds static_main_function_params, reusing a similar static_features target that already existed but was no longer required in /c/nacl/broker, cleaning that up by replacing rather than copying that target's definition in this CL. - ContentMainParams::minimal_browser_mode was weirdly passed as a parameter to ContentMainRunner::Run(bool start_minimal_browser) but that method also has access to the ContentMainParams originally passed via ContentMainRunner::Init(). Passing the param again from Run() would be a use-after-move in content_main.cc, instead content_main_runner_impl.cc was updated to use the param it already has in store. Bug: 1175074 Change-Id: I3af90505525e426383c59107a3903d645d455682 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3244976 Commit-Queue: Gabriel Charette <gab@chromium.org> Auto-Submit: Gabriel Charette <gab@chromium.org> Reviewed-by: Alexander Timin <altimin@chromium.org> Reviewed-by: Brad Nelson <bradnelson@chromium.org> Reviewed-by: Scott Violet <sky@chromium.org> Reviewed-by: Clark DuVall <cduvall@chromium.org> Owners-Override: Alexander Timin <altimin@chromium.org> Cr-Commit-Position: refs/heads/main@{#940478}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
05f4160a30
commit
fbeeb1c228
android_webview
browser
lib
base/memory
chrome
app
browser
ash
chrome_browser_main.ccchrome_browser_main.hchrome_browser_main_android.ccchrome_browser_main_android.hchrome_browser_main_linux.ccchrome_browser_main_linux.hchrome_browser_main_mac.hchrome_browser_main_mac.mmchrome_browser_main_parts_fuchsia.ccchrome_browser_main_parts_fuchsia.hchrome_browser_main_parts_lacros.ccchrome_browser_main_parts_lacros.hchrome_browser_main_posix.ccchrome_browser_main_posix.hchrome_browser_main_win.ccchrome_browser_main_win.hchrome_content_browser_client.ccchrome_content_browser_client.hfirst_run
mac
service
test
chromecast
app
browser
cast_browser_main_parts.cccast_browser_main_parts.hcast_browser_main_parts_simple.cccast_content_browser_client.cccast_content_browser_client.h
cast_core
components/nacl
content
app
browser
browser_main.ccbrowser_main.hbrowser_main_loop.ccbrowser_main_loop.hbrowser_main_loop_unittest.ccbrowser_main_runner_impl.ccbrowser_main_runner_impl.hstartup_data_impl.h
gpu
ppapi_plugin
public
app
browser
common
test
renderer
shell
app
browser
utility
web_test
docs/memory
extensions/shell
app
browser
fuchsia/engine
browser
web_engine_browser_main.ccweb_engine_browser_main.hweb_engine_browser_main_parts.ccweb_engine_browser_main_parts.hweb_engine_content_browser_client.ccweb_engine_content_browser_client.h
web_engine_main.ccweb_engine_main_delegate.ccweb_engine_main_delegate.hheadless
app
lib
ui/views_content_client
views_content_browser_client.ccviews_content_browser_client.hviews_content_client.ccviews_content_client_main_parts.ccviews_content_client_main_parts.hviews_content_client_main_parts_aura.ccviews_content_client_main_parts_aura.hviews_content_client_main_parts_chromeos.ccviews_content_client_main_parts_desktop_aura.ccviews_content_client_main_parts_mac.mm
weblayer
@ -301,7 +301,7 @@ AwBrowserContext* AwContentBrowserClient::InitBrowserContext() {
|
||||
|
||||
std::unique_ptr<content::BrowserMainParts>
|
||||
AwContentBrowserClient::CreateBrowserMainParts(
|
||||
const content::MainFunctionParams& parameters) {
|
||||
content::MainFunctionParams /*parameters*/) {
|
||||
return std::make_unique<AwBrowserMainParts>(this);
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ class AwContentBrowserClient : public content::ContentBrowserClient {
|
||||
cert_verifier::mojom::CertVerifierCreationParams*
|
||||
cert_verifier_creation_params) override;
|
||||
std::unique_ptr<content::BrowserMainParts> CreateBrowserMainParts(
|
||||
const content::MainFunctionParams& parameters) override;
|
||||
content::MainFunctionParams parameters) override;
|
||||
content::WebContentsViewDelegate* GetWebContentsViewDelegate(
|
||||
content::WebContents* web_contents) override;
|
||||
void RenderProcessWillLaunch(content::RenderProcessHost* host) override;
|
||||
|
@ -53,6 +53,7 @@
|
||||
#include "content/public/common/content_descriptor_keys.h"
|
||||
#include "content/public/common/content_features.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "content/public/common/main_function_params.h"
|
||||
#include "device/base/features.h"
|
||||
#include "gin/public/isolate_holder.h"
|
||||
#include "gin/v8_initializer.h"
|
||||
@ -330,20 +331,18 @@ void AwMainDelegate::PreSandboxStartup() {
|
||||
sdk_int_key.Set(base::NumberToString(android_build_info->sdk_int()));
|
||||
}
|
||||
|
||||
int AwMainDelegate::RunProcess(
|
||||
absl::variant<int, content::MainFunctionParams> AwMainDelegate::RunProcess(
|
||||
const std::string& process_type,
|
||||
const content::MainFunctionParams& main_function_params) {
|
||||
content::MainFunctionParams main_function_params) {
|
||||
// Defer to the default main method outside the browser process.
|
||||
if (!process_type.empty())
|
||||
return -1;
|
||||
return std::move(main_function_params);
|
||||
|
||||
browser_runner_ = content::BrowserMainRunner::Create();
|
||||
int exit_code = browser_runner_->Initialize(main_function_params);
|
||||
int exit_code = browser_runner_->Initialize(std::move(main_function_params));
|
||||
// We do not expect Initialize() to ever fail in AndroidWebView. On success
|
||||
// it returns a negative value but we do not want to use that on Android.
|
||||
DCHECK_LT(exit_code, 0);
|
||||
// Return 0 so that we do NOT trigger the default behavior. On Android, the
|
||||
// UI message loop is managed by the Java application.
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -44,9 +44,9 @@ class AwMainDelegate : public content::ContentMainDelegate {
|
||||
// content::ContentMainDelegate implementation:
|
||||
bool BasicStartupComplete(int* exit_code) override;
|
||||
void PreSandboxStartup() override;
|
||||
int RunProcess(
|
||||
absl::variant<int, content::MainFunctionParams> RunProcess(
|
||||
const std::string& process_type,
|
||||
const content::MainFunctionParams& main_function_params) override;
|
||||
content::MainFunctionParams main_function_params) override;
|
||||
void ProcessExiting(const std::string& process_type) override;
|
||||
bool ShouldCreateFeatureList() override;
|
||||
void PostEarlyInitialization(bool is_running_tests) override;
|
||||
|
@ -14,7 +14,7 @@
|
||||
namespace content {
|
||||
struct MainFunctionParams;
|
||||
} // namespace content
|
||||
int CloudPrintServiceProcessMain(const content::MainFunctionParams& parameters);
|
||||
int CloudPrintServiceProcessMain(content::MainFunctionParams parameters);
|
||||
|
||||
namespace mojo {
|
||||
|
||||
@ -31,7 +31,7 @@ class SharedMemoryHooks {
|
||||
private:
|
||||
friend class SharedMemoryHooksTest;
|
||||
friend int ::CloudPrintServiceProcessMain(
|
||||
const content::MainFunctionParams& parameters);
|
||||
content::MainFunctionParams parameters);
|
||||
friend mojo::SharedMemoryUtils;
|
||||
|
||||
// Allows shared memory region creation to be hooked. Useful for sandboxed
|
||||
|
@ -77,13 +77,14 @@ void ChromeMainDelegateAndroid::SecureDataDirectory() {
|
||||
}
|
||||
}
|
||||
|
||||
int ChromeMainDelegateAndroid::RunProcess(
|
||||
absl::variant<int, content::MainFunctionParams>
|
||||
ChromeMainDelegateAndroid::RunProcess(
|
||||
const std::string& process_type,
|
||||
const content::MainFunctionParams& main_function_params) {
|
||||
content::MainFunctionParams main_function_params) {
|
||||
TRACE_EVENT0("startup", "ChromeMainDelegateAndroid::RunProcess");
|
||||
// Defer to the default main method outside the browser process.
|
||||
if (!process_type.empty())
|
||||
return -1;
|
||||
return std::move(main_function_params);
|
||||
|
||||
SecureDataDirectory();
|
||||
|
||||
@ -110,10 +111,9 @@ int ChromeMainDelegateAndroid::RunProcess(
|
||||
browser_runner_ = content::BrowserMainRunner::Create();
|
||||
}
|
||||
|
||||
int exit_code = browser_runner_->Initialize(main_function_params);
|
||||
int exit_code = browser_runner_->Initialize(std::move(main_function_params));
|
||||
// On Android we do not run BrowserMain(), so the above initialization of a
|
||||
// BrowserMainRunner is all we want to occur. Return >= 0 to avoid running
|
||||
// BrowserMain, while preserving any error codes > 0.
|
||||
// BrowserMainRunner is all we want to occur. Preserve any error codes > 0.
|
||||
if (exit_code > 0)
|
||||
return exit_code;
|
||||
return 0;
|
||||
|
@ -33,9 +33,9 @@ class ChromeMainDelegateAndroid : public ChromeMainDelegate {
|
||||
|
||||
bool BasicStartupComplete(int* exit_code) override;
|
||||
void PreSandboxStartup() override;
|
||||
int RunProcess(
|
||||
absl::variant<int, content::MainFunctionParams> RunProcess(
|
||||
const std::string& process_type,
|
||||
const content::MainFunctionParams& main_function_params) override;
|
||||
content::MainFunctionParams main_function_params) override;
|
||||
void ProcessExiting(const std::string& process_type) override;
|
||||
|
||||
private:
|
||||
|
@ -148,7 +148,7 @@ int ChromeMain(int argc, const char** argv) {
|
||||
#if defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_MAC) || \
|
||||
defined(OS_WIN)
|
||||
if (command_line->HasSwitch(switches::kHeadless))
|
||||
return headless::HeadlessShellMain(params);
|
||||
return headless::HeadlessShellMain(std::move(params));
|
||||
#endif // defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_MAC) ||
|
||||
// defined(OS_WIN)
|
||||
}
|
||||
@ -169,7 +169,7 @@ int ChromeMain(int argc, const char** argv) {
|
||||
}
|
||||
#endif
|
||||
|
||||
int rv = content::ContentMain(params);
|
||||
int rv = content::ContentMain(std::move(params));
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
@ -64,6 +64,7 @@
|
||||
#include "content/public/common/content_constants.h"
|
||||
#include "content/public/common/content_paths.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "content/public/common/main_function_params.h"
|
||||
#include "content/public/common/profiling.h"
|
||||
#include "content/public/common/url_constants.h"
|
||||
#include "extensions/common/constants.h"
|
||||
@ -197,10 +198,10 @@ base::LazyInstance<ChromeContentRendererClient>::DestructorAtExit
|
||||
base::LazyInstance<ChromeContentUtilityClient>::DestructorAtExit
|
||||
g_chrome_content_utility_client = LAZY_INSTANCE_INITIALIZER;
|
||||
|
||||
extern int NaClMain(const content::MainFunctionParams&);
|
||||
extern int NaClMain(content::MainFunctionParams);
|
||||
|
||||
#if !defined(OS_CHROMEOS)
|
||||
extern int CloudPrintServiceProcessMain(const content::MainFunctionParams&);
|
||||
extern int CloudPrintServiceProcessMain(content::MainFunctionParams);
|
||||
#endif
|
||||
|
||||
const char* const ChromeMainDelegate::kNonWildcardDomainNonPortSchemes[] = {
|
||||
@ -383,7 +384,7 @@ void SetUpProfilingShutdownHandler() {
|
||||
|
||||
struct MainFunction {
|
||||
const char* name;
|
||||
int (*function)(const content::MainFunctionParams&);
|
||||
int (*function)(content::MainFunctionParams);
|
||||
};
|
||||
|
||||
// Initializes the user data dir. Must be called before InitializeLocalState().
|
||||
@ -1211,9 +1212,9 @@ void ChromeMainDelegate::SandboxInitialized(const std::string& process_type) {
|
||||
#endif
|
||||
}
|
||||
|
||||
int ChromeMainDelegate::RunProcess(
|
||||
absl::variant<int, content::MainFunctionParams> ChromeMainDelegate::RunProcess(
|
||||
const std::string& process_type,
|
||||
const content::MainFunctionParams& main_function_params) {
|
||||
content::MainFunctionParams main_function_params) {
|
||||
// ANDROID doesn't support "service", so no CloudPrintServiceProcessMain, and
|
||||
// arraysize doesn't support empty array. So we comment out the block for
|
||||
// Android.
|
||||
@ -1241,11 +1242,11 @@ int ChromeMainDelegate::RunProcess(
|
||||
|
||||
for (size_t i = 0; i < base::size(kMainFunctions); ++i) {
|
||||
if (process_type == kMainFunctions[i].name)
|
||||
return kMainFunctions[i].function(main_function_params);
|
||||
return kMainFunctions[i].function(std::move(main_function_params));
|
||||
}
|
||||
#endif // !defined(OS_ANDROID)
|
||||
|
||||
return -1;
|
||||
return std::move(main_function_params);
|
||||
}
|
||||
|
||||
void ChromeMainDelegate::ProcessExiting(const std::string& process_type) {
|
||||
|
@ -53,9 +53,9 @@ class ChromeMainDelegate : public content::ContentMainDelegate {
|
||||
bool BasicStartupComplete(int* exit_code) override;
|
||||
void PreSandboxStartup() override;
|
||||
void SandboxInitialized(const std::string& process_type) override;
|
||||
int RunProcess(
|
||||
absl::variant<int, content::MainFunctionParams> RunProcess(
|
||||
const std::string& process_type,
|
||||
const content::MainFunctionParams& main_function_params) override;
|
||||
content::MainFunctionParams main_function_params) override;
|
||||
void ProcessExiting(const std::string& process_type) override;
|
||||
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
|
||||
void ZygoteStarting(std::vector<std::unique_ptr<content::ZygoteForkDelegate>>*
|
||||
|
@ -532,9 +532,9 @@ class DBusServices {
|
||||
// ChromeBrowserMainPartsAsh ---------------------------------------------------
|
||||
|
||||
ChromeBrowserMainPartsAsh::ChromeBrowserMainPartsAsh(
|
||||
const content::MainFunctionParams& parameters,
|
||||
content::MainFunctionParams parameters,
|
||||
StartupData* startup_data)
|
||||
: ChromeBrowserMainPartsLinux(parameters, startup_data) {}
|
||||
: ChromeBrowserMainPartsLinux(std::move(parameters), startup_data) {}
|
||||
|
||||
ChromeBrowserMainPartsAsh::~ChromeBrowserMainPartsAsh() {
|
||||
// To be precise, logout (browser shutdown) is not yet done, but the
|
||||
@ -1077,7 +1077,7 @@ void ChromeBrowserMainPartsAsh::PostProfileInit() {
|
||||
|
||||
manager->SetState(session_manager->GetDefaultIMEState(profile()));
|
||||
|
||||
bool is_running_test = parameters().ui_task != nullptr;
|
||||
bool is_running_test = !!parameters().ui_task;
|
||||
g_browser_process->platform_part()->session_manager()->Initialize(
|
||||
parsed_command_line(), profile(), is_running_test);
|
||||
|
||||
|
@ -120,7 +120,7 @@ class DarkResumeController;
|
||||
// src/ash or chrome/browser/ui/ash.
|
||||
class ChromeBrowserMainPartsAsh : public ChromeBrowserMainPartsLinux {
|
||||
public:
|
||||
ChromeBrowserMainPartsAsh(const content::MainFunctionParams& parameters,
|
||||
ChromeBrowserMainPartsAsh(content::MainFunctionParams parameters,
|
||||
StartupData* startup_data);
|
||||
|
||||
ChromeBrowserMainPartsAsh(const ChromeBrowserMainPartsAsh&) = delete;
|
||||
|
@ -500,10 +500,10 @@ bool ProcessSingletonNotificationCallback(
|
||||
// BrowserMainParts ------------------------------------------------------------
|
||||
|
||||
ChromeBrowserMainParts::ChromeBrowserMainParts(
|
||||
const content::MainFunctionParams& parameters,
|
||||
content::MainFunctionParams parameters,
|
||||
StartupData* startup_data)
|
||||
: parameters_(parameters),
|
||||
parsed_command_line_(parameters.command_line),
|
||||
: parameters_(std::move(parameters)),
|
||||
parsed_command_line_(*parameters.command_line),
|
||||
should_call_pre_main_loop_start_startup_on_variations_service_(
|
||||
!parameters.ui_task),
|
||||
startup_data_(startup_data) {
|
||||
@ -1097,7 +1097,7 @@ int ChromeBrowserMainParts::PreMainMessageLoopRun() {
|
||||
// PostProfileInit()
|
||||
// ... additional setup
|
||||
// PreBrowserStart()
|
||||
// ... browser_creator_->Start (OR parameters().ui_task->Run())
|
||||
// ... browser_creator_->Start (OR parameters_.ui_task->Run())
|
||||
// PostBrowserStart()
|
||||
|
||||
void ChromeBrowserMainParts::PreProfileInit() {
|
||||
@ -1433,7 +1433,7 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
|
||||
// This step is costly and is already measured in Startup.CreateFirstProfile
|
||||
// and more directly Profile.CreateAndInitializeProfile.
|
||||
StartupProfileInfo profile_info = CreatePrimaryProfile(
|
||||
parameters(), /*cur_dir=*/base::FilePath(), parsed_command_line());
|
||||
parameters_, /*cur_dir=*/base::FilePath(), parsed_command_line());
|
||||
|
||||
profile_ = profile_info.profile;
|
||||
if (profile_info.mode == StartupProfileMode::kError)
|
||||
@ -1726,8 +1726,8 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
|
||||
#if defined(OS_MAC)
|
||||
// Call Recycle() here as late as possible, before going into the loop
|
||||
// because Start() will add things to it while creating the main window.
|
||||
if (parameters().autorelease_pool)
|
||||
parameters().autorelease_pool->Recycle();
|
||||
if (parameters_.autorelease_pool)
|
||||
parameters_.autorelease_pool->Recycle();
|
||||
#endif // defined(OS_MAC)
|
||||
|
||||
// Transfer ownership of the browser's lifetime to the BrowserProcess.
|
||||
@ -1744,9 +1744,8 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
|
||||
// The ui_task can be injected by tests to replace the main message loop.
|
||||
// In that case we Run() it here, and set a flag to avoid running the main
|
||||
// message loop later, as the test will do so as needed from the |ui_task|.
|
||||
if (parameters().ui_task) {
|
||||
std::move(*parameters().ui_task).Run();
|
||||
delete parameters().ui_task;
|
||||
if (parameters_.ui_task) {
|
||||
std::move(parameters_.ui_task).Run();
|
||||
run_message_loop_ = false;
|
||||
}
|
||||
|
||||
@ -1840,7 +1839,7 @@ void ChromeBrowserMainParts::PostMainMessageLoopRun() {
|
||||
// Some tests don't set parameters.ui_task, so they started translate
|
||||
// language fetch that was never completed so we need to cleanup here
|
||||
// otherwise it will be done by the destructor in a wrong thread.
|
||||
TranslateService::Shutdown(!parameters().ui_task);
|
||||
TranslateService::Shutdown(!parameters_.ui_task);
|
||||
|
||||
if (notify_result_ == ProcessSingleton::PROCESS_NONE)
|
||||
process_singleton_->Cleanup();
|
||||
|
@ -60,7 +60,7 @@ class ChromeBrowserMainParts : public content::BrowserMainParts {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
ChromeBrowserMainParts(const content::MainFunctionParams& parameters,
|
||||
ChromeBrowserMainParts(content::MainFunctionParams parameters,
|
||||
StartupData* startup_data);
|
||||
|
||||
// content::BrowserMainParts overrides.
|
||||
@ -139,7 +139,7 @@ class ChromeBrowserMainParts : public content::BrowserMainParts {
|
||||
|
||||
// Members initialized on construction ---------------------------------------
|
||||
|
||||
const content::MainFunctionParams parameters_;
|
||||
content::MainFunctionParams parameters_;
|
||||
// TODO(sky): remove this. This class (and related calls), may mutate the
|
||||
// CommandLine, so it is misleading keeping a const ref here.
|
||||
const base::CommandLine& parsed_command_line_;
|
||||
|
@ -31,9 +31,9 @@
|
||||
#include "ui/base/ui_base_paths.h"
|
||||
|
||||
ChromeBrowserMainPartsAndroid::ChromeBrowserMainPartsAndroid(
|
||||
const content::MainFunctionParams& parameters,
|
||||
content::MainFunctionParams parameters,
|
||||
StartupData* startup_data)
|
||||
: ChromeBrowserMainParts(parameters, startup_data) {}
|
||||
: ChromeBrowserMainParts(std::move(parameters), startup_data) {}
|
||||
|
||||
ChromeBrowserMainPartsAndroid::~ChromeBrowserMainPartsAndroid() {
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
class ChromeBrowserMainPartsAndroid : public ChromeBrowserMainParts {
|
||||
public:
|
||||
ChromeBrowserMainPartsAndroid(const content::MainFunctionParams& parameters,
|
||||
ChromeBrowserMainPartsAndroid(content::MainFunctionParams parameters,
|
||||
StartupData* startup_data);
|
||||
|
||||
ChromeBrowserMainPartsAndroid(const ChromeBrowserMainPartsAndroid&) = delete;
|
||||
|
@ -45,9 +45,9 @@
|
||||
#endif
|
||||
|
||||
ChromeBrowserMainPartsLinux::ChromeBrowserMainPartsLinux(
|
||||
const content::MainFunctionParams& parameters,
|
||||
content::MainFunctionParams parameters,
|
||||
StartupData* startup_data)
|
||||
: ChromeBrowserMainPartsPosix(parameters, startup_data) {}
|
||||
: ChromeBrowserMainPartsPosix(std::move(parameters), startup_data) {}
|
||||
|
||||
ChromeBrowserMainPartsLinux::~ChromeBrowserMainPartsLinux() {
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
class ChromeBrowserMainPartsLinux : public ChromeBrowserMainPartsPosix {
|
||||
public:
|
||||
ChromeBrowserMainPartsLinux(const content::MainFunctionParams& parameters,
|
||||
ChromeBrowserMainPartsLinux(content::MainFunctionParams parameters,
|
||||
StartupData* startup_data);
|
||||
|
||||
ChromeBrowserMainPartsLinux(const ChromeBrowserMainPartsLinux&) = delete;
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
class ChromeBrowserMainPartsMac : public ChromeBrowserMainPartsPosix {
|
||||
public:
|
||||
ChromeBrowserMainPartsMac(const content::MainFunctionParams& parameters,
|
||||
ChromeBrowserMainPartsMac(content::MainFunctionParams parameters,
|
||||
StartupData* startup_data);
|
||||
|
||||
ChromeBrowserMainPartsMac(const ChromeBrowserMainPartsMac&) = delete;
|
||||
|
@ -52,9 +52,9 @@
|
||||
// ChromeBrowserMainPartsMac ---------------------------------------------------
|
||||
|
||||
ChromeBrowserMainPartsMac::ChromeBrowserMainPartsMac(
|
||||
const content::MainFunctionParams& parameters,
|
||||
content::MainFunctionParams parameters,
|
||||
StartupData* startup_data)
|
||||
: ChromeBrowserMainPartsPosix(parameters, startup_data) {}
|
||||
: ChromeBrowserMainPartsPosix(std::move(parameters), startup_data) {}
|
||||
|
||||
ChromeBrowserMainPartsMac::~ChromeBrowserMainPartsMac() {
|
||||
}
|
||||
|
@ -198,9 +198,9 @@ class ViewProviderScenic : public fuchsia::ui::app::ViewProvider {
|
||||
} // namespace
|
||||
|
||||
ChromeBrowserMainPartsFuchsia::ChromeBrowserMainPartsFuchsia(
|
||||
const content::MainFunctionParams& parameters,
|
||||
content::MainFunctionParams parameters,
|
||||
StartupData* startup_data)
|
||||
: ChromeBrowserMainParts(parameters, startup_data) {}
|
||||
: ChromeBrowserMainParts(std::move(parameters), startup_data) {}
|
||||
|
||||
ChromeBrowserMainPartsFuchsia::~ChromeBrowserMainPartsFuchsia() = default;
|
||||
|
||||
|
@ -15,7 +15,7 @@ class ProcessLifecycle;
|
||||
|
||||
class ChromeBrowserMainPartsFuchsia : public ChromeBrowserMainParts {
|
||||
public:
|
||||
ChromeBrowserMainPartsFuchsia(const content::MainFunctionParams& parameters,
|
||||
ChromeBrowserMainPartsFuchsia(content::MainFunctionParams parameters,
|
||||
StartupData* startup_data);
|
||||
|
||||
ChromeBrowserMainPartsFuchsia(const ChromeBrowserMainPartsFuchsia&) = delete;
|
||||
|
@ -16,9 +16,9 @@
|
||||
#include "ui/wm/core/wm_core_switches.h"
|
||||
|
||||
ChromeBrowserMainPartsLacros::ChromeBrowserMainPartsLacros(
|
||||
const content::MainFunctionParams& parameters,
|
||||
content::MainFunctionParams parameters,
|
||||
StartupData* startup_data)
|
||||
: ChromeBrowserMainPartsLinux(parameters, startup_data) {}
|
||||
: ChromeBrowserMainPartsLinux(std::move(parameters), startup_data) {}
|
||||
|
||||
ChromeBrowserMainPartsLacros::~ChromeBrowserMainPartsLacros() = default;
|
||||
|
||||
|
@ -15,7 +15,7 @@ class PrefsAshObserver;
|
||||
// Startup and shutdown code for Lacros. See ChromeBrowserMainParts for details.
|
||||
class ChromeBrowserMainPartsLacros : public ChromeBrowserMainPartsLinux {
|
||||
public:
|
||||
ChromeBrowserMainPartsLacros(const content::MainFunctionParams& parameters,
|
||||
ChromeBrowserMainPartsLacros(content::MainFunctionParams parameters,
|
||||
StartupData* startup_data);
|
||||
ChromeBrowserMainPartsLacros(const ChromeBrowserMainPartsLacros&) = delete;
|
||||
ChromeBrowserMainPartsLacros& operator=(const ChromeBrowserMainPartsLacros&) =
|
||||
|
@ -137,9 +137,9 @@ void ExitHandler::Exit() {
|
||||
// ChromeBrowserMainPartsPosix -------------------------------------------------
|
||||
|
||||
ChromeBrowserMainPartsPosix::ChromeBrowserMainPartsPosix(
|
||||
const content::MainFunctionParams& parameters,
|
||||
content::MainFunctionParams parameters,
|
||||
StartupData* startup_data)
|
||||
: ChromeBrowserMainParts(parameters, startup_data) {}
|
||||
: ChromeBrowserMainParts(std::move(parameters), startup_data) {}
|
||||
|
||||
int ChromeBrowserMainPartsPosix::PreEarlyInitialization() {
|
||||
const int result = ChromeBrowserMainParts::PreEarlyInitialization();
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
class ChromeBrowserMainPartsPosix : public ChromeBrowserMainParts {
|
||||
public:
|
||||
ChromeBrowserMainPartsPosix(const content::MainFunctionParams& parameters,
|
||||
ChromeBrowserMainPartsPosix(content::MainFunctionParams parameters,
|
||||
StartupData* startup_data);
|
||||
|
||||
ChromeBrowserMainPartsPosix(const ChromeBrowserMainPartsPosix&) = delete;
|
||||
|
@ -560,9 +560,9 @@ int DoUninstallTasks(bool chrome_still_running) {
|
||||
// ChromeBrowserMainPartsWin ---------------------------------------------------
|
||||
|
||||
ChromeBrowserMainPartsWin::ChromeBrowserMainPartsWin(
|
||||
const content::MainFunctionParams& parameters,
|
||||
content::MainFunctionParams parameters,
|
||||
StartupData* startup_data)
|
||||
: ChromeBrowserMainParts(parameters, startup_data) {}
|
||||
: ChromeBrowserMainParts(std::move(parameters), startup_data) {}
|
||||
|
||||
ChromeBrowserMainPartsWin::~ChromeBrowserMainPartsWin() = default;
|
||||
|
||||
|
@ -24,7 +24,7 @@ int DoUninstallTasks(bool chrome_still_running);
|
||||
|
||||
class ChromeBrowserMainPartsWin : public ChromeBrowserMainParts {
|
||||
public:
|
||||
ChromeBrowserMainPartsWin(const content::MainFunctionParams& parameters,
|
||||
ChromeBrowserMainPartsWin(content::MainFunctionParams parameters,
|
||||
StartupData* startup_data);
|
||||
ChromeBrowserMainPartsWin(const ChromeBrowserMainPartsWin&) = delete;
|
||||
ChromeBrowserMainPartsWin& operator=(const ChromeBrowserMainPartsWin&) =
|
||||
|
@ -1334,37 +1334,37 @@ void ChromeContentBrowserClient::SetApplicationLocale(
|
||||
|
||||
std::unique_ptr<content::BrowserMainParts>
|
||||
ChromeContentBrowserClient::CreateBrowserMainParts(
|
||||
const content::MainFunctionParams& parameters) {
|
||||
content::MainFunctionParams parameters) {
|
||||
std::unique_ptr<ChromeBrowserMainParts> main_parts;
|
||||
// Construct the Main browser parts based on the OS type.
|
||||
#if defined(OS_WIN)
|
||||
main_parts =
|
||||
std::make_unique<ChromeBrowserMainPartsWin>(parameters, &startup_data_);
|
||||
main_parts = std::make_unique<ChromeBrowserMainPartsWin>(
|
||||
std::move(parameters), &startup_data_);
|
||||
#elif defined(OS_MAC)
|
||||
main_parts =
|
||||
std::make_unique<ChromeBrowserMainPartsMac>(parameters, &startup_data_);
|
||||
main_parts = std::make_unique<ChromeBrowserMainPartsMac>(
|
||||
std::move(parameters), &startup_data_);
|
||||
#elif BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
main_parts = std::make_unique<ash::ChromeBrowserMainPartsAsh>(parameters,
|
||||
&startup_data_);
|
||||
main_parts = std::make_unique<ash::ChromeBrowserMainPartsAsh>(
|
||||
std::move(parameters), &startup_data_);
|
||||
#elif BUILDFLAG(IS_CHROMEOS_LACROS)
|
||||
main_parts = std::make_unique<ChromeBrowserMainPartsLacros>(parameters,
|
||||
&startup_data_);
|
||||
main_parts = std::make_unique<ChromeBrowserMainPartsLacros>(
|
||||
std::move(parameters), &startup_data_);
|
||||
#elif defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
|
||||
main_parts =
|
||||
std::make_unique<ChromeBrowserMainPartsLinux>(parameters, &startup_data_);
|
||||
main_parts = std::make_unique<ChromeBrowserMainPartsLinux>(
|
||||
std::move(parameters), &startup_data_);
|
||||
#elif defined(OS_ANDROID)
|
||||
main_parts = std::make_unique<ChromeBrowserMainPartsAndroid>(parameters,
|
||||
&startup_data_);
|
||||
main_parts = std::make_unique<ChromeBrowserMainPartsAndroid>(
|
||||
std::move(parameters), &startup_data_);
|
||||
#elif defined(OS_POSIX)
|
||||
main_parts =
|
||||
std::make_unique<ChromeBrowserMainPartsPosix>(parameters, &startup_data_);
|
||||
main_parts = std::make_unique<ChromeBrowserMainPartsPosix>(
|
||||
std::move(parameters), &startup_data_);
|
||||
#elif defined(OS_FUCHSIA)
|
||||
main_parts = std::make_unique<ChromeBrowserMainPartsFuchsia>(parameters,
|
||||
&startup_data_);
|
||||
main_parts = std::make_unique<ChromeBrowserMainPartsFuchsia>(
|
||||
std::move(parameters), &startup_data_);
|
||||
#else
|
||||
NOTREACHED();
|
||||
main_parts =
|
||||
std::make_unique<ChromeBrowserMainParts>(parameters, &startup_data_);
|
||||
main_parts = std::make_unique<ChromeBrowserMainParts>(std::move(parameters),
|
||||
&startup_data_);
|
||||
#endif
|
||||
|
||||
bool add_profiles_extra_parts = true;
|
||||
|
@ -131,7 +131,7 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient {
|
||||
|
||||
// content::ContentBrowserClient:
|
||||
std::unique_ptr<content::BrowserMainParts> CreateBrowserMainParts(
|
||||
const content::MainFunctionParams& parameters) override;
|
||||
content::MainFunctionParams parameters) override;
|
||||
void PostAfterStartupTask(
|
||||
const base::Location& from_here,
|
||||
const scoped_refptr<base::SequencedTaskRunner>& task_runner,
|
||||
|
@ -58,7 +58,7 @@ class FirstRunInternalPosixTest : public InProcessBrowserTest {
|
||||
|
||||
// The modal dialog will spawn and spin a nested RunLoop when
|
||||
// content::BrowserTestBase::SetUp() invokes content::ContentMain().
|
||||
// BrowserTestBase sets GetContentMainParams()->ui_task before this, but the
|
||||
// BrowserTestBase sets ContentMainParams::ui_task before this, but the
|
||||
// ui_task isn't actually Run() until after the dialog is spawned in
|
||||
// ChromeBrowserMainParts::PreMainMessageLoopRunImpl(). Instead, try to
|
||||
// inspect state by posting a task to run in that nested RunLoop.
|
||||
|
@ -68,7 +68,7 @@ namespace internal {
|
||||
|
||||
// The entry point from ChromeMain into the relauncher process. This is not a
|
||||
// user API. Don't call it if your name isn't ChromeMain.
|
||||
int RelauncherMain(const content::MainFunctionParams& main_parameters);
|
||||
int RelauncherMain(content::MainFunctionParams main_parameters);
|
||||
|
||||
} // namespace internal
|
||||
|
||||
|
@ -242,7 +242,7 @@ void RelauncherSynchronizeWithParent() {
|
||||
|
||||
namespace internal {
|
||||
|
||||
int RelauncherMain(const content::MainFunctionParams& main_parameters) {
|
||||
int RelauncherMain(content::MainFunctionParams main_parameters) {
|
||||
@autoreleasepool {
|
||||
// CommandLine rearranges the order of the arguments returned by
|
||||
// main_parameters.argv(), rendering it impossible to determine which
|
||||
|
@ -15,8 +15,7 @@
|
||||
#include "net/url_request/url_request.h"
|
||||
|
||||
// Mainline routine for running as the Cloud Print service process.
|
||||
int CloudPrintServiceProcessMain(
|
||||
const content::MainFunctionParams& parameters) {
|
||||
int CloudPrintServiceProcessMain(content::MainFunctionParams parameters) {
|
||||
// This is a hack: the Cloud Print service doesn't actually set up a sandbox,
|
||||
// but sandbox::policy::SandboxTypeFromCommandLine(command_line)) doesn't know
|
||||
// about it, so it's considered sandboxed, causing shared memory hooks to be
|
||||
@ -43,12 +42,12 @@ int CloudPrintServiceProcessMain(
|
||||
base::SingleThreadTaskExecutor main_task_executor(base::MessagePumpType::UI);
|
||||
#endif
|
||||
|
||||
if (parameters.command_line.HasSwitch(switches::kWaitForDebugger)) {
|
||||
if (parameters.command_line->HasSwitch(switches::kWaitForDebugger)) {
|
||||
base::debug::WaitForDebugger(60, true);
|
||||
}
|
||||
|
||||
VLOG(1) << "Service process launched: "
|
||||
<< parameters.command_line.GetCommandLineString();
|
||||
<< parameters.command_line->GetCommandLineString();
|
||||
|
||||
auto initialize_service = [](ServiceProcessState* service) {
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
@ -70,7 +69,7 @@ int CloudPrintServiceProcessMain(
|
||||
base::RunLoop run_loop;
|
||||
ServiceProcess service_process;
|
||||
if (service_process.Initialize(run_loop.QuitClosure(),
|
||||
parameters.command_line, std::move(state))) {
|
||||
*parameters.command_line, std::move(state))) {
|
||||
run_loop.Run();
|
||||
} else {
|
||||
LOG(ERROR) << "Service process failed to initialize";
|
||||
|
@ -16,23 +16,25 @@
|
||||
|
||||
namespace test {
|
||||
|
||||
TestChromeBase::TestChromeBase(const content::ContentMainParams& params)
|
||||
: params_(params) {
|
||||
TestChromeBase::TestChromeBase(content::ContentMainParams params)
|
||||
: params_(std::move(params)) {
|
||||
auto created_main_parts_closure =
|
||||
std::make_unique<content::CreatedMainPartsClosure>(
|
||||
base::BindOnce(&TestChromeBase::CreatedBrowserMainPartsImpl,
|
||||
weak_ptr_factory_.GetWeakPtr()));
|
||||
params_.created_main_parts_closure = created_main_parts_closure.release();
|
||||
base::BindOnce(&TestChromeBase::CreatedBrowserMainPartsImpl,
|
||||
weak_ptr_factory_.GetWeakPtr());
|
||||
params_.created_main_parts_closure = std::move(created_main_parts_closure);
|
||||
}
|
||||
|
||||
TestChromeBase::~TestChromeBase() = default;
|
||||
|
||||
int TestChromeBase::Start() {
|
||||
// Can only Start()'ed once.
|
||||
DCHECK(params_.created_main_parts_closure);
|
||||
|
||||
int rv = 0;
|
||||
if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kHeadless)) {
|
||||
rv = headless::HeadlessShellMain(params_);
|
||||
rv = headless::HeadlessShellMain(std::move(params_));
|
||||
} else {
|
||||
rv = content::ContentMain(params_);
|
||||
rv = content::ContentMain(std::move(params_));
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "content/public/app/content_main.h"
|
||||
#include "content/public/common/main_function_params.h"
|
||||
|
||||
namespace content {
|
||||
class BrowserMainParts;
|
||||
@ -17,7 +18,7 @@ namespace test {
|
||||
|
||||
class TestChromeBase {
|
||||
public:
|
||||
explicit TestChromeBase(const content::ContentMainParams& params);
|
||||
explicit TestChromeBase(content::ContentMainParams params);
|
||||
TestChromeBase(const TestChromeBase&) = delete;
|
||||
TestChromeBase& operator=(const TestChromeBase&) = delete;
|
||||
~TestChromeBase();
|
||||
|
@ -35,6 +35,6 @@ int ChromeMain(int argc, const char** argv) {
|
||||
// run the sampling profiler for test ash chrome.
|
||||
MainThreadStackSamplingProfiler scoped_sampling_profiler;
|
||||
|
||||
test::TestChromeBase test_chrome_base(params);
|
||||
test::TestChromeBase test_chrome_base(std::move(params));
|
||||
return test_chrome_base.Start();
|
||||
}
|
||||
|
@ -10,5 +10,5 @@ int main(int argc, const char** argv) {
|
||||
content::ContentMainParams params(&delegate);
|
||||
params.argc = argc;
|
||||
params.argv = argv;
|
||||
return content::ContentMain(params);
|
||||
return content::ContentMain(std::move(params));
|
||||
}
|
||||
|
@ -197,25 +197,24 @@ void CastMainDelegate::PreSandboxStartup() {
|
||||
InitializeResourceBundle();
|
||||
}
|
||||
|
||||
int CastMainDelegate::RunProcess(
|
||||
absl::variant<int, content::MainFunctionParams> CastMainDelegate::RunProcess(
|
||||
const std::string& process_type,
|
||||
const content::MainFunctionParams& main_function_params) {
|
||||
content::MainFunctionParams main_function_params) {
|
||||
#if defined(OS_ANDROID)
|
||||
if (!process_type.empty())
|
||||
return -1;
|
||||
return std::move(main_function_params);
|
||||
|
||||
// Note: Android must handle running its own browser process.
|
||||
// See ChromeMainDelegateAndroid::RunProcess.
|
||||
browser_runner_ = content::BrowserMainRunner::Create();
|
||||
int exit_code = browser_runner_->Initialize(main_function_params);
|
||||
int exit_code = browser_runner_->Initialize(std::move(main_function_params));
|
||||
// On Android we do not run BrowserMain(), so the above initialization of a
|
||||
// BrowserMainRunner is all we want to occur. Return >= 0 to avoid running
|
||||
// BrowserMain, while preserving any error codes > 0.
|
||||
// BrowserMainRunner is all we want to occur. Preserve any error codes > 0.
|
||||
if (exit_code > 0)
|
||||
return exit_code;
|
||||
return 0;
|
||||
#else
|
||||
return -1;
|
||||
return std::move(main_function_params);
|
||||
#endif // defined(OS_ANDROID)
|
||||
}
|
||||
|
||||
|
@ -40,9 +40,9 @@ class CastMainDelegate : public content::ContentMainDelegate {
|
||||
// content::ContentMainDelegate implementation:
|
||||
bool BasicStartupComplete(int* exit_code) override;
|
||||
void PreSandboxStartup() override;
|
||||
int RunProcess(
|
||||
absl::variant<int, content::MainFunctionParams> RunProcess(
|
||||
const std::string& process_type,
|
||||
const content::MainFunctionParams& main_function_params) override;
|
||||
content::MainFunctionParams main_function_params) override;
|
||||
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
|
||||
void ZygoteForked() override;
|
||||
#endif // defined(OS_LINUX) || defined(OS_CHROMEOS)
|
||||
|
@ -398,11 +398,11 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
|
||||
} // namespace
|
||||
|
||||
CastBrowserMainParts::CastBrowserMainParts(
|
||||
const content::MainFunctionParams& parameters,
|
||||
content::MainFunctionParams parameters,
|
||||
CastContentBrowserClient* cast_content_browser_client)
|
||||
: BrowserMainParts(),
|
||||
cast_browser_process_(new CastBrowserProcess()),
|
||||
parameters_(parameters),
|
||||
parameters_(std::move(parameters)),
|
||||
cast_content_browser_client_(cast_content_browser_client),
|
||||
|
||||
media_caps_(std::make_unique<media::MediaCapsImpl>()),
|
||||
@ -699,8 +699,7 @@ int CastBrowserMainParts::PreMainMessageLoopRun() {
|
||||
cast_browser_process_->cast_service()->Start();
|
||||
|
||||
if (parameters_.ui_task) {
|
||||
std::move(*parameters_.ui_task).Run();
|
||||
delete parameters_.ui_task;
|
||||
std::move(parameters_.ui_task).Run();
|
||||
run_message_loop_ = false;
|
||||
}
|
||||
|
||||
|
@ -71,11 +71,11 @@ class CastBrowserMainParts : public content::BrowserMainParts {
|
||||
// Creates an implementation of CastBrowserMainParts. Platform should
|
||||
// link in an implementation as needed.
|
||||
static std::unique_ptr<CastBrowserMainParts> Create(
|
||||
const content::MainFunctionParams& parameters,
|
||||
content::MainFunctionParams parameters,
|
||||
CastContentBrowserClient* cast_content_browser_client);
|
||||
|
||||
// This class does not take ownership of |url_request_content_factory|.
|
||||
CastBrowserMainParts(const content::MainFunctionParams& parameters,
|
||||
CastBrowserMainParts(content::MainFunctionParams parameters,
|
||||
CastContentBrowserClient* cast_content_browser_client);
|
||||
|
||||
CastBrowserMainParts(const CastBrowserMainParts&) = delete;
|
||||
@ -102,7 +102,7 @@ class CastBrowserMainParts : public content::BrowserMainParts {
|
||||
|
||||
private:
|
||||
std::unique_ptr<CastBrowserProcess> cast_browser_process_;
|
||||
const content::MainFunctionParams parameters_; // For running browser tests.
|
||||
content::MainFunctionParams parameters_; // For running browser tests.
|
||||
// Caches a pointer of the CastContentBrowserClient.
|
||||
CastContentBrowserClient* const cast_content_browser_client_ = nullptr;
|
||||
std::unique_ptr<ServiceManagerContext> service_manager_context_;
|
||||
|
@ -9,9 +9,9 @@ namespace shell {
|
||||
|
||||
// static
|
||||
std::unique_ptr<CastBrowserMainParts> CastBrowserMainParts::Create(
|
||||
const content::MainFunctionParams& parameters,
|
||||
content::MainFunctionParams parameters,
|
||||
CastContentBrowserClient* cast_content_browser_client) {
|
||||
return std::make_unique<CastBrowserMainParts>(parameters,
|
||||
return std::make_unique<CastBrowserMainParts>(std::move(parameters),
|
||||
cast_content_browser_client);
|
||||
}
|
||||
|
||||
|
@ -357,10 +357,10 @@ std::vector<std::string> CastContentBrowserClient::GetStartupServices() {
|
||||
|
||||
std::unique_ptr<content::BrowserMainParts>
|
||||
CastContentBrowserClient::CreateBrowserMainParts(
|
||||
const content::MainFunctionParams& parameters) {
|
||||
content::MainFunctionParams parameters) {
|
||||
DCHECK(!cast_browser_main_parts_);
|
||||
|
||||
auto main_parts = CastBrowserMainParts::Create(parameters, this);
|
||||
auto main_parts = CastBrowserMainParts::Create(std::move(parameters), this);
|
||||
|
||||
cast_browser_main_parts_ = main_parts.get();
|
||||
CastBrowserProcess::GetInstance()->SetCastContentBrowserClient(this);
|
||||
|
@ -181,7 +181,7 @@ class CastContentBrowserClient
|
||||
|
||||
// content::ContentBrowserClient implementation:
|
||||
std::unique_ptr<content::BrowserMainParts> CreateBrowserMainParts(
|
||||
const content::MainFunctionParams& parameters) override;
|
||||
content::MainFunctionParams parameters) override;
|
||||
void RenderProcessWillLaunch(content::RenderProcessHost* host) override;
|
||||
bool IsHandledURL(const GURL& url) override;
|
||||
void SiteInstanceGotProcess(content::SiteInstance* site_instance) override;
|
||||
|
@ -10,5 +10,5 @@ int main(int argc, const char** argv) {
|
||||
content::ContentMainParams params(&delegate);
|
||||
params.argc = argc;
|
||||
params.argv = argv;
|
||||
return content::ContentMain(params);
|
||||
return content::ContentMain(std::move(params));
|
||||
}
|
||||
|
@ -105,7 +105,6 @@ if (current_cpu == "x86") {
|
||||
"//chrome/install_static:install_static_util",
|
||||
"//components/crash/content/app:deprecated_breakpad_win",
|
||||
"//components/nacl/loader:nacl_helper_win_64",
|
||||
"//content/public/common:static_features",
|
||||
"//content/public/common:static_switches",
|
||||
"//ppapi/proxy:ipc",
|
||||
"//sandbox",
|
||||
|
@ -205,6 +205,7 @@ if (is_win && target_cpu == "x86" && current_cpu == "x64") {
|
||||
"//base",
|
||||
"//components/nacl/broker",
|
||||
"//components/nacl/common:switches",
|
||||
"//content/public/common:static_main_function_params",
|
||||
"//content/public/common:static_switches",
|
||||
"//mojo/core/embedder",
|
||||
"//sandbox",
|
||||
|
@ -31,12 +31,12 @@
|
||||
#include "sandbox/policy/sandbox_type.h"
|
||||
#include "sandbox/win/src/sandbox_types.h"
|
||||
|
||||
extern int NaClMain(const content::MainFunctionParams&);
|
||||
extern int NaClMain(content::MainFunctionParams);
|
||||
|
||||
namespace {
|
||||
// main() routine for the NaCl broker process.
|
||||
// This is necessary for supporting NaCl in Chrome on Win64.
|
||||
int NaClBrokerMain(const content::MainFunctionParams& parameters) {
|
||||
int NaClBrokerMain(content::MainFunctionParams parameters) {
|
||||
base::SingleThreadTaskExecutor io_task_executor(base::MessagePumpType::IO);
|
||||
base::PlatformThread::SetName("CrNaClBrokerMain");
|
||||
|
||||
@ -60,23 +60,24 @@ int NaClWin64Main() {
|
||||
sandbox::SandboxInterfaceInfo sandbox_info = {nullptr};
|
||||
content::InitializeSandboxInfo(&sandbox_info);
|
||||
|
||||
const base::CommandLine& command_line =
|
||||
*base::CommandLine::ForCurrentProcess();
|
||||
const base::CommandLine* command_line =
|
||||
base::CommandLine::ForCurrentProcess();
|
||||
std::string process_type =
|
||||
command_line.GetSwitchValueASCII(switches::kProcessType);
|
||||
command_line->GetSwitchValueASCII(switches::kProcessType);
|
||||
|
||||
// Copy what ContentMain() does.
|
||||
base::EnableTerminationOnHeapCorruption();
|
||||
base::EnableTerminationOnOutOfMemory();
|
||||
base::win::RegisterInvalidParamHandler();
|
||||
base::win::SetupCRT(command_line);
|
||||
base::win::SetupCRT(*command_line);
|
||||
// Route stdio to parent console (if any) or create one.
|
||||
if (command_line.HasSwitch(switches::kEnableLogging))
|
||||
if (command_line->HasSwitch(switches::kEnableLogging))
|
||||
base::RouteStdioToConsole(true);
|
||||
|
||||
// Initialize the sandbox for this process.
|
||||
bool sandbox_initialized_ok = sandbox::policy::Sandbox::Initialize(
|
||||
sandbox::policy::SandboxTypeFromCommandLine(command_line), &sandbox_info);
|
||||
sandbox::policy::SandboxTypeFromCommandLine(*command_line),
|
||||
&sandbox_info);
|
||||
|
||||
// Die if the sandbox can't be enabled.
|
||||
CHECK(sandbox_initialized_ok) << "Error initializing sandbox for "
|
||||
@ -85,10 +86,10 @@ int NaClWin64Main() {
|
||||
main_params.sandbox_info = &sandbox_info;
|
||||
|
||||
if (process_type == switches::kNaClLoaderProcess)
|
||||
return NaClMain(main_params);
|
||||
return NaClMain(std::move(main_params));
|
||||
|
||||
if (process_type == switches::kNaClBrokerProcess)
|
||||
return NaClBrokerMain(main_params);
|
||||
return NaClBrokerMain(std::move(main_params));
|
||||
|
||||
CHECK(false) << "Unknown NaCl 64 process.";
|
||||
return -1;
|
||||
|
@ -10,9 +10,6 @@
|
||||
#include "base/power_monitor/power_monitor_device_source.h"
|
||||
#include "base/task/single_thread_task_executor.h"
|
||||
#include "base/timer/hi_res_timer_manager.h"
|
||||
#if defined(OS_WIN)
|
||||
#include "base/win/win_util.h"
|
||||
#endif
|
||||
#include "build/build_config.h"
|
||||
#include "components/nacl/loader/nacl_listener.h"
|
||||
#include "components/nacl/loader/nacl_main_platform_delegate.h"
|
||||
@ -20,9 +17,13 @@
|
||||
#include "mojo/core/embedder/embedder.h"
|
||||
#include "sandbox/policy/switches.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#include "base/win/win_util.h"
|
||||
#endif
|
||||
|
||||
// main() routine for the NaCl loader process.
|
||||
int NaClMain(const content::MainFunctionParams& parameters) {
|
||||
const base::CommandLine& parsed_command_line = parameters.command_line;
|
||||
int NaClMain(content::MainFunctionParams parameters) {
|
||||
const base::CommandLine& parsed_command_line = *parameters.command_line;
|
||||
|
||||
// The Mojo EDK must be initialized before using IPC.
|
||||
mojo::core::Init();
|
||||
|
@ -48,7 +48,7 @@ static jint JNI_ContentMain_Start(JNIEnv* env, jboolean start_minimal_browser) {
|
||||
TRACE_EVENT0("startup", "content::Start");
|
||||
ContentMainParams params(g_content_main_delegate.Get().get());
|
||||
params.minimal_browser_mode = start_minimal_browser;
|
||||
return RunContentProcess(params, GetContentMainRunner());
|
||||
return RunContentProcess(std::move(params), GetContentMainRunner());
|
||||
}
|
||||
|
||||
void SetContentMainDelegate(ContentMainDelegate* delegate) {
|
||||
|
@ -216,13 +216,19 @@ void InitializeMojo(mojo::core::Configuration* config) {
|
||||
|
||||
} // namespace
|
||||
|
||||
ContentMainParams::ContentMainParams(ContentMainDelegate* delegate)
|
||||
: delegate(delegate) {}
|
||||
|
||||
ContentMainParams::~ContentMainParams() = default;
|
||||
|
||||
ContentMainParams::ContentMainParams(ContentMainParams&&) = default;
|
||||
ContentMainParams& ContentMainParams::operator=(ContentMainParams&&) = default;
|
||||
|
||||
// This function must be marked with NO_STACK_PROTECTOR or it may crash on
|
||||
// return, see the --change-stack-guard-on-fork command line flag.
|
||||
int NO_STACK_PROTECTOR
|
||||
RunContentProcess(const ContentMainParams& params,
|
||||
RunContentProcess(ContentMainParams params,
|
||||
ContentMainRunner* content_main_runner) {
|
||||
ContentMainParams content_main_params(params);
|
||||
|
||||
int exit_code = -1;
|
||||
base::debug::GlobalActivityTracker* tracker = nullptr;
|
||||
#if defined(OS_MAC)
|
||||
@ -314,7 +320,7 @@ RunContentProcess(const ContentMainParams& params,
|
||||
// Each "main" needs to flush this pool right before it goes into its main
|
||||
// event loop to get rid of the cruft.
|
||||
autorelease_pool = std::make_unique<base::mac::ScopedNSAutoreleasePool>();
|
||||
content_main_params.autorelease_pool = autorelease_pool.get();
|
||||
params.autorelease_pool = autorelease_pool.get();
|
||||
InitializeMac();
|
||||
#endif
|
||||
|
||||
@ -328,7 +334,7 @@ RunContentProcess(const ContentMainParams& params,
|
||||
|
||||
ui::RegisterPathProvider();
|
||||
tracker = base::debug::GlobalActivityTracker::Get();
|
||||
exit_code = content_main_runner->Initialize(content_main_params);
|
||||
exit_code = content_main_runner->Initialize(std::move(params));
|
||||
|
||||
if (exit_code >= 0) {
|
||||
if (tracker) {
|
||||
@ -387,7 +393,7 @@ RunContentProcess(const ContentMainParams& params,
|
||||
|
||||
if (IsSubprocess())
|
||||
CommonSubprocessInit();
|
||||
exit_code = content_main_runner->Run(params.minimal_browser_mode);
|
||||
exit_code = content_main_runner->Run();
|
||||
|
||||
if (tracker) {
|
||||
if (exit_code == 0) {
|
||||
@ -413,9 +419,9 @@ RunContentProcess(const ContentMainParams& params,
|
||||
|
||||
// This function must be marked with NO_STACK_PROTECTOR or it may crash on
|
||||
// return, see the --change-stack-guard-on-fork command line flag.
|
||||
int NO_STACK_PROTECTOR ContentMain(const ContentMainParams& params) {
|
||||
int NO_STACK_PROTECTOR ContentMain(ContentMainParams params) {
|
||||
auto runner = ContentMainRunner::Create();
|
||||
return RunContentProcess(params, runner.get());
|
||||
return RunContentProcess(std::move(params), runner.get());
|
||||
}
|
||||
|
||||
} // namespace content
|
||||
|
@ -179,12 +179,12 @@
|
||||
#endif
|
||||
|
||||
namespace content {
|
||||
extern int GpuMain(const content::MainFunctionParams&);
|
||||
extern int GpuMain(MainFunctionParams);
|
||||
#if BUILDFLAG(ENABLE_PLUGINS)
|
||||
extern int PpapiPluginMain(const MainFunctionParams&);
|
||||
extern int PpapiPluginMain(MainFunctionParams);
|
||||
#endif
|
||||
extern int RendererMain(const content::MainFunctionParams&);
|
||||
extern int UtilityMain(const MainFunctionParams&);
|
||||
extern int RendererMain(MainFunctionParams);
|
||||
extern int UtilityMain(MainFunctionParams);
|
||||
} // namespace content
|
||||
|
||||
namespace content {
|
||||
@ -541,7 +541,7 @@ class ContentClientInitializer {
|
||||
// flag. This struct is used to build a table of (flag, main function) pairs.
|
||||
struct MainFunction {
|
||||
const char* name;
|
||||
int (*function)(const MainFunctionParams&);
|
||||
int (*function)(MainFunctionParams);
|
||||
};
|
||||
|
||||
#if BUILDFLAG(USE_ZYGOTE_HANDLE)
|
||||
@ -576,13 +576,13 @@ int NO_STACK_PROTECTOR RunZygote(ContentMainDelegate* delegate) {
|
||||
|
||||
// Zygote::HandleForkRequest may have reallocated the command
|
||||
// line so update it here with the new version.
|
||||
const base::CommandLine& command_line =
|
||||
*base::CommandLine::ForCurrentProcess();
|
||||
const base::CommandLine* command_line =
|
||||
base::CommandLine::ForCurrentProcess();
|
||||
|
||||
// Re-randomize our stack canary, so processes don't share a single
|
||||
// stack canary.
|
||||
base::ScopedClosureRunner stack_canary_debug_message;
|
||||
if (command_line.GetSwitchValueASCII(switches::kChangeStackGuardOnFork) ==
|
||||
if (command_line->GetSwitchValueASCII(switches::kChangeStackGuardOnFork) ==
|
||||
switches::kChangeStackGuardOnForkEnabled) {
|
||||
base::ResetStackCanaryIfPossible();
|
||||
stack_canary_debug_message.ReplaceClosure(
|
||||
@ -592,7 +592,7 @@ int NO_STACK_PROTECTOR RunZygote(ContentMainDelegate* delegate) {
|
||||
delegate->ZygoteForked();
|
||||
|
||||
std::string process_type =
|
||||
command_line.GetSwitchValueASCII(switches::kProcessType);
|
||||
command_line->GetSwitchValueASCII(switches::kProcessType);
|
||||
|
||||
internal::PartitionAllocSupport::Get()->ReconfigureAfterZygoteFork(
|
||||
process_type);
|
||||
@ -612,10 +612,13 @@ int NO_STACK_PROTECTOR RunZygote(ContentMainDelegate* delegate) {
|
||||
|
||||
for (size_t i = 0; i < base::size(kMainFunctions); ++i) {
|
||||
if (process_type == kMainFunctions[i].name)
|
||||
return kMainFunctions[i].function(main_params);
|
||||
return kMainFunctions[i].function(std::move(main_params));
|
||||
}
|
||||
|
||||
return delegate->RunProcess(process_type, main_params);
|
||||
auto exit_code = delegate->RunProcess(process_type, std::move(main_params));
|
||||
DCHECK(absl::holds_alternative<int>(exit_code));
|
||||
DCHECK_GE(absl::get<int>(exit_code), 0);
|
||||
return absl::get<int>(exit_code);
|
||||
}
|
||||
#endif // BUILDFLAG(USE_ZYGOTE_HANDLE)
|
||||
|
||||
@ -629,16 +632,18 @@ static void RegisterMainThreadFactories() {
|
||||
|
||||
// Run the main function for browser process.
|
||||
// Returns the exit code for this process.
|
||||
int RunBrowserProcessMain(const MainFunctionParams& main_function_params,
|
||||
int RunBrowserProcessMain(MainFunctionParams main_function_params,
|
||||
ContentMainDelegate* delegate) {
|
||||
#if defined(OS_WIN)
|
||||
if (delegate->ShouldHandleConsoleControlEvents())
|
||||
InstallConsoleControlHandler(/*is_browser_process=*/true);
|
||||
#endif
|
||||
int exit_code = delegate->RunProcess("", main_function_params);
|
||||
if (exit_code >= 0)
|
||||
return exit_code;
|
||||
return BrowserMain(main_function_params);
|
||||
auto exit_code = delegate->RunProcess("", std::move(main_function_params));
|
||||
if (absl::holds_alternative<int>(exit_code)) {
|
||||
DCHECK_GE(absl::get<int>(exit_code), 0);
|
||||
return absl::get<int>(exit_code);
|
||||
}
|
||||
return BrowserMain(std::move(absl::get<MainFunctionParams>(exit_code)));
|
||||
}
|
||||
|
||||
// Run the FooMain() for a given process type.
|
||||
@ -647,7 +652,7 @@ int RunBrowserProcessMain(const MainFunctionParams& main_function_params,
|
||||
// return, see the --change-stack-guard-on-fork command line flag.
|
||||
int NO_STACK_PROTECTOR
|
||||
RunOtherNamedProcessTypeMain(const std::string& process_type,
|
||||
const MainFunctionParams& main_function_params,
|
||||
MainFunctionParams main_function_params,
|
||||
ContentMainDelegate* delegate) {
|
||||
#if defined(OS_WIN)
|
||||
if (delegate->ShouldHandleConsoleControlEvents())
|
||||
@ -664,10 +669,14 @@ RunOtherNamedProcessTypeMain(const std::string& process_type,
|
||||
|
||||
for (size_t i = 0; i < base::size(kMainFunctions); ++i) {
|
||||
if (process_type == kMainFunctions[i].name) {
|
||||
int exit_code = delegate->RunProcess(process_type, main_function_params);
|
||||
if (exit_code >= 0)
|
||||
return exit_code;
|
||||
return kMainFunctions[i].function(main_function_params);
|
||||
auto exit_code =
|
||||
delegate->RunProcess(process_type, std::move(main_function_params));
|
||||
if (absl::holds_alternative<int>(exit_code)) {
|
||||
DCHECK_GE(absl::get<int>(exit_code), 0);
|
||||
return absl::get<int>(exit_code);
|
||||
}
|
||||
return kMainFunctions[i].function(
|
||||
std::move(absl::get<MainFunctionParams>(exit_code)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -679,7 +688,11 @@ RunOtherNamedProcessTypeMain(const std::string& process_type,
|
||||
#endif // BUILDFLAG(USE_ZYGOTE_HANDLE)
|
||||
|
||||
// If it's a process we don't know about, the embedder should know.
|
||||
return delegate->RunProcess(process_type, main_function_params);
|
||||
auto exit_code =
|
||||
delegate->RunProcess(process_type, std::move(main_function_params));
|
||||
DCHECK(absl::holds_alternative<int>(exit_code));
|
||||
DCHECK_GE(absl::get<int>(exit_code), 0);
|
||||
return absl::get<int>(exit_code);
|
||||
}
|
||||
|
||||
// static
|
||||
@ -687,11 +700,7 @@ std::unique_ptr<ContentMainRunnerImpl> ContentMainRunnerImpl::Create() {
|
||||
return std::make_unique<ContentMainRunnerImpl>();
|
||||
}
|
||||
|
||||
ContentMainRunnerImpl::ContentMainRunnerImpl() {
|
||||
#if defined(OS_WIN)
|
||||
memset(&sandbox_info_, 0, sizeof(sandbox_info_));
|
||||
#endif
|
||||
}
|
||||
ContentMainRunnerImpl::ContentMainRunnerImpl() = default;
|
||||
|
||||
ContentMainRunnerImpl::~ContentMainRunnerImpl() {
|
||||
if (is_initialized_ && !is_shutdown_)
|
||||
@ -702,17 +711,10 @@ int ContentMainRunnerImpl::TerminateForFatalInitializationError() {
|
||||
return delegate_->TerminateForFatalInitializationError();
|
||||
}
|
||||
|
||||
int ContentMainRunnerImpl::Initialize(const ContentMainParams& params) {
|
||||
ui_task_ = params.ui_task;
|
||||
created_main_parts_closure_ = params.created_main_parts_closure;
|
||||
|
||||
#if defined(OS_WIN)
|
||||
sandbox_info_ = *params.sandbox_info;
|
||||
#else // !OS_WIN
|
||||
|
||||
#if defined(OS_MAC)
|
||||
autorelease_pool_ = params.autorelease_pool;
|
||||
#endif // defined(OS_MAC)
|
||||
int ContentMainRunnerImpl::Initialize(ContentMainParams params) {
|
||||
// ContentMainDelegate is used by this class, not forwarded to embedders.
|
||||
delegate_ = std::exchange(params.delegate, nullptr);
|
||||
content_main_params_ = std::move(params);
|
||||
|
||||
#if defined(OS_ANDROID)
|
||||
// Now that mojo's core is initialized we can enable tracing. Note that only
|
||||
@ -725,6 +727,8 @@ int ContentMainRunnerImpl::Initialize(const ContentMainParams& params) {
|
||||
TRACE_EVENT0("startup,benchmark,rail", "ContentMainRunnerImpl::Initialize");
|
||||
#endif // OS_ANDROID
|
||||
|
||||
#if !defined(OS_WIN)
|
||||
|
||||
base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance();
|
||||
ALLOW_UNUSED_LOCAL(g_fds);
|
||||
|
||||
@ -745,14 +749,13 @@ int ContentMainRunnerImpl::Initialize(const ContentMainParams& params) {
|
||||
#endif // !OS_WIN
|
||||
|
||||
is_initialized_ = true;
|
||||
delegate_ = params.delegate;
|
||||
|
||||
// The exit manager is in charge of calling the dtors of singleton objects.
|
||||
// On Android, AtExitManager is set up when library is loaded.
|
||||
// A consequence of this is that you can't use the ctor/dtor-based
|
||||
// TRACE_EVENT methods on Linux or iOS builds till after we set this up.
|
||||
#if !defined(OS_ANDROID)
|
||||
if (!ui_task_) {
|
||||
if (!content_main_params_.ui_task) {
|
||||
// When running browser tests, don't create a second AtExitManager as that
|
||||
// interfers with shutdown when objects created before ContentMain is
|
||||
// called are destructed when it returns.
|
||||
@ -919,7 +922,7 @@ int ContentMainRunnerImpl::Initialize(const ContentMainParams& params) {
|
||||
#if defined(OS_WIN)
|
||||
if (!InitializeSandbox(
|
||||
sandbox::policy::SandboxTypeFromCommandLine(command_line),
|
||||
params.sandbox_info))
|
||||
content_main_params_.sandbox_info))
|
||||
return TerminateForFatalInitializationError();
|
||||
#elif defined(OS_MAC)
|
||||
if (!sandbox::policy::IsUnsandboxedSandboxType(
|
||||
@ -955,13 +958,13 @@ int ContentMainRunnerImpl::Initialize(const ContentMainParams& params) {
|
||||
|
||||
// This function must be marked with NO_STACK_PROTECTOR or it may crash on
|
||||
// return, see the --change-stack-guard-on-fork command line flag.
|
||||
int NO_STACK_PROTECTOR ContentMainRunnerImpl::Run(bool start_minimal_browser) {
|
||||
int NO_STACK_PROTECTOR ContentMainRunnerImpl::Run() {
|
||||
DCHECK(is_initialized_);
|
||||
DCHECK(!is_shutdown_);
|
||||
const base::CommandLine& command_line =
|
||||
*base::CommandLine::ForCurrentProcess();
|
||||
const base::CommandLine* command_line =
|
||||
base::CommandLine::ForCurrentProcess();
|
||||
std::string process_type =
|
||||
command_line.GetSwitchValueASCII(switches::kProcessType);
|
||||
command_line->GetSwitchValueASCII(switches::kProcessType);
|
||||
// Run this logic on all child processes.
|
||||
if (!process_type.empty()) {
|
||||
if (process_type != switches::kZygoteProcess) {
|
||||
@ -990,23 +993,36 @@ int NO_STACK_PROTECTOR ContentMainRunnerImpl::Run(bool start_minimal_browser) {
|
||||
}
|
||||
|
||||
MainFunctionParams main_params(command_line);
|
||||
main_params.ui_task = ui_task_;
|
||||
main_params.created_main_parts_closure = created_main_parts_closure_;
|
||||
main_params.ui_task = std::move(content_main_params_.ui_task);
|
||||
main_params.created_main_parts_closure =
|
||||
std::move(content_main_params_.created_main_parts_closure);
|
||||
#if defined(OS_WIN)
|
||||
main_params.sandbox_info = &sandbox_info_;
|
||||
main_params.sandbox_info = content_main_params_.sandbox_info;
|
||||
#elif defined(OS_MAC)
|
||||
main_params.autorelease_pool = autorelease_pool_;
|
||||
main_params.autorelease_pool = content_main_params_.autorelease_pool;
|
||||
#endif
|
||||
|
||||
const bool start_minimal_browser = content_main_params_.minimal_browser_mode;
|
||||
|
||||
#if DCHECK_IS_ON()
|
||||
// ContentMainParams cannot be wholesaled moved into MainFunctionParams
|
||||
// because MainFunctionParams is in common/ and can't depend on
|
||||
// ContentMainParams, but this is the effective intent.
|
||||
// |content_main_params_| shouldn't be used after being handed off to
|
||||
// RunBrowser/RunOtherNamedProcessTypeMain below.
|
||||
content_main_params_ = ContentMainParams{nullptr};
|
||||
#endif
|
||||
|
||||
RegisterMainThreadFactories();
|
||||
|
||||
if (process_type.empty())
|
||||
return RunBrowser(main_params, start_minimal_browser);
|
||||
return RunBrowser(std::move(main_params), start_minimal_browser);
|
||||
|
||||
return RunOtherNamedProcessTypeMain(process_type, main_params, delegate_);
|
||||
return RunOtherNamedProcessTypeMain(process_type, std::move(main_params),
|
||||
delegate_);
|
||||
}
|
||||
|
||||
int ContentMainRunnerImpl::RunBrowser(MainFunctionParams& main_params,
|
||||
int ContentMainRunnerImpl::RunBrowser(MainFunctionParams main_params,
|
||||
bool start_minimal_browser) {
|
||||
TRACE_EVENT_INSTANT0("startup", "ContentMainRunnerImpl::RunBrowser(begin)",
|
||||
TRACE_EVENT_SCOPE_THREAD);
|
||||
@ -1053,7 +1069,7 @@ int ContentMainRunnerImpl::RunBrowser(MainFunctionParams& main_params,
|
||||
variations::VariationsIdsProvider::Mode::kUseSignedInState);
|
||||
}
|
||||
|
||||
delegate_->PostEarlyInitialization(main_params.ui_task != nullptr);
|
||||
delegate_->PostEarlyInitialization(!!main_params.ui_task);
|
||||
|
||||
// The hang watcher needs to be started once the feature list is available
|
||||
// but before the IO thread is started.
|
||||
@ -1132,9 +1148,8 @@ int ContentMainRunnerImpl::RunBrowser(MainFunctionParams& main_params,
|
||||
|
||||
DVLOG(0) << "Chrome is running in full browser mode.";
|
||||
is_browser_main_loop_started_ = true;
|
||||
startup_data_ = mojo_ipc_support_->CreateBrowserStartupData();
|
||||
main_params.startup_data = startup_data_.get();
|
||||
return RunBrowserProcessMain(main_params, delegate_);
|
||||
main_params.startup_data = mojo_ipc_support_->CreateBrowserStartupData();
|
||||
return RunBrowserProcessMain(std::move(main_params), delegate_);
|
||||
}
|
||||
|
||||
void ContentMainRunnerImpl::Shutdown() {
|
||||
|
@ -7,9 +7,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "base/callback_forward.h"
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
#include "base/metrics/field_trial.h"
|
||||
#include "base/callback_helpers.h"
|
||||
#include "base/threading/hang_watcher.h"
|
||||
#include "build/build_config.h"
|
||||
#include "content/browser/startup_data_impl.h"
|
||||
@ -19,12 +17,6 @@
|
||||
#include "content/public/common/main_function_params.h"
|
||||
#include "mojo/core/embedder/scoped_ipc_support.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#include "sandbox/win/src/sandbox_types.h"
|
||||
#elif defined(OS_MAC)
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#endif // OS_WIN
|
||||
|
||||
namespace base {
|
||||
class AtExitManager;
|
||||
} // namespace base
|
||||
@ -35,9 +27,7 @@ class DiscardableSharedMemoryManager;
|
||||
|
||||
namespace content {
|
||||
class ContentClient;
|
||||
class ContentMainDelegate;
|
||||
class MojoIpcSupport;
|
||||
struct ContentMainParams;
|
||||
|
||||
class ContentMainRunnerImpl : public ContentMainRunner {
|
||||
public:
|
||||
@ -53,12 +43,12 @@ class ContentMainRunnerImpl : public ContentMainRunner {
|
||||
int TerminateForFatalInitializationError();
|
||||
|
||||
// ContentMainRunner:
|
||||
int Initialize(const ContentMainParams& params) override;
|
||||
int Run(bool start_minimal_browser) override;
|
||||
int Initialize(ContentMainParams params) override;
|
||||
int Run() override;
|
||||
void Shutdown() override;
|
||||
|
||||
private:
|
||||
int RunBrowser(MainFunctionParams& main_function_params,
|
||||
int RunBrowser(MainFunctionParams main_function_params,
|
||||
bool start_minimal_browser);
|
||||
|
||||
bool is_browser_main_loop_started_ = false;
|
||||
@ -73,7 +63,6 @@ class ContentMainRunnerImpl : public ContentMainRunner {
|
||||
|
||||
std::unique_ptr<discardable_memory::DiscardableSharedMemoryManager>
|
||||
discardable_shared_memory_manager_;
|
||||
std::unique_ptr<StartupDataImpl> startup_data_;
|
||||
std::unique_ptr<MojoIpcSupport> mojo_ipc_support_;
|
||||
|
||||
// True if the runner has been initialized.
|
||||
@ -90,15 +79,8 @@ class ContentMainRunnerImpl : public ContentMainRunner {
|
||||
|
||||
std::unique_ptr<base::AtExitManager> exit_manager_;
|
||||
|
||||
#if defined(OS_WIN)
|
||||
sandbox::SandboxInterfaceInfo sandbox_info_;
|
||||
#elif defined(OS_MAC)
|
||||
base::mac::ScopedNSAutoreleasePool* autorelease_pool_ = nullptr;
|
||||
#endif
|
||||
|
||||
base::OnceClosure* ui_task_ = nullptr;
|
||||
|
||||
CreatedMainPartsClosure* created_main_parts_closure_ = nullptr;
|
||||
// Received in Initialize(), handed-off in Run().
|
||||
ContentMainParams content_main_params_{nullptr};
|
||||
};
|
||||
|
||||
// The BrowserTestBase on Android does not call ContentMain(). It tries instead
|
||||
|
@ -32,7 +32,7 @@ class ScopedBrowserMainEvent {
|
||||
} // namespace
|
||||
|
||||
// Main routine for running as the Browser process.
|
||||
int BrowserMain(const MainFunctionParams& parameters) {
|
||||
int BrowserMain(MainFunctionParams parameters) {
|
||||
ScopedBrowserMainEvent scoped_browser_main_event;
|
||||
|
||||
base::trace_event::TraceLog::GetInstance()->set_process_name("Browser");
|
||||
@ -42,7 +42,7 @@ int BrowserMain(const MainFunctionParams& parameters) {
|
||||
std::unique_ptr<BrowserMainRunnerImpl> main_runner(
|
||||
BrowserMainRunnerImpl::Create());
|
||||
|
||||
int exit_code = main_runner->Initialize(parameters);
|
||||
int exit_code = main_runner->Initialize(std::move(parameters));
|
||||
if (exit_code >= 0)
|
||||
return exit_code;
|
||||
|
||||
|
@ -11,7 +11,7 @@ namespace content {
|
||||
|
||||
struct MainFunctionParams;
|
||||
|
||||
CONTENT_EXPORT int BrowserMain(const content::MainFunctionParams& parameters);
|
||||
CONTENT_EXPORT int BrowserMain(content::MainFunctionParams parameters);
|
||||
|
||||
} // namespace content
|
||||
|
||||
|
@ -456,11 +456,11 @@ media::AudioManager* BrowserMainLoop::GetAudioManager() {
|
||||
}
|
||||
|
||||
BrowserMainLoop::BrowserMainLoop(
|
||||
const MainFunctionParams& parameters,
|
||||
MainFunctionParams parameters,
|
||||
std::unique_ptr<base::ThreadPoolInstance::ScopedExecutionFence>
|
||||
scoped_execution_fence)
|
||||
: parameters_(parameters),
|
||||
parsed_command_line_(parameters.command_line),
|
||||
: parameters_(std::move(parameters)),
|
||||
parsed_command_line_(*parameters_.command_line),
|
||||
result_code_(RESULT_CODE_NORMAL_EXIT),
|
||||
created_threads_(false),
|
||||
scoped_execution_fence_(std::move(scoped_execution_fence))
|
||||
@ -486,19 +486,27 @@ BrowserMainLoop::~BrowserMainLoop() {
|
||||
void BrowserMainLoop::Init() {
|
||||
TRACE_EVENT0("startup", "BrowserMainLoop::Init");
|
||||
|
||||
// |startup_data| is optional. If set, the thread owned by the data
|
||||
// will be registered as BrowserThread::IO in CreateThreads() instead of
|
||||
// creating a brand new thread.
|
||||
if (parameters_.startup_data) {
|
||||
StartupDataImpl* startup_data =
|
||||
static_cast<StartupDataImpl*>(parameters_.startup_data);
|
||||
static_cast<StartupDataImpl*>(parameters_.startup_data.get());
|
||||
|
||||
// This is always invoked before |io_thread_| is initialized (i.e. never
|
||||
// resets it).
|
||||
// resets it). The thread owned by the data will be registered as
|
||||
// BrowserThread::IO in CreateThreads() instead of creating a brand new
|
||||
// thread.
|
||||
DCHECK(!io_thread_);
|
||||
io_thread_ = std::move(startup_data->io_thread);
|
||||
|
||||
DCHECK(!mojo_ipc_support_);
|
||||
mojo_ipc_support_ = std::move(startup_data->mojo_ipc_support);
|
||||
|
||||
// The StartupDataImpl was destined to BrowserMainLoop, do not pass it
|
||||
// forward.
|
||||
parameters_.startup_data.reset();
|
||||
}
|
||||
|
||||
parts_ = GetContentClient()->browser()->CreateBrowserMainParts(parameters_);
|
||||
parts_ = GetContentClient()->browser()->CreateBrowserMainParts(
|
||||
std::move(parameters_));
|
||||
}
|
||||
|
||||
// BrowserMainLoop stages ==================================================
|
||||
|
@ -122,7 +122,7 @@ class CONTENT_EXPORT BrowserMainLoop {
|
||||
// The ThreadPoolInstance must exist but not to be started when building
|
||||
// BrowserMainLoop.
|
||||
explicit BrowserMainLoop(
|
||||
const MainFunctionParams& parameters,
|
||||
MainFunctionParams parameters,
|
||||
std::unique_ptr<base::ThreadPoolInstance::ScopedExecutionFence> fence);
|
||||
|
||||
BrowserMainLoop(const BrowserMainLoop&) = delete;
|
||||
@ -284,7 +284,7 @@ class CONTENT_EXPORT BrowserMainLoop {
|
||||
// OnFirstIdle()
|
||||
|
||||
// Members initialized on construction ---------------------------------------
|
||||
const MainFunctionParams& parameters_;
|
||||
MainFunctionParams parameters_;
|
||||
const base::CommandLine& parsed_command_line_;
|
||||
int result_code_;
|
||||
bool created_threads_; // True if the non-UI threads were created.
|
||||
|
@ -45,8 +45,8 @@ class BrowserMainLoopTest : public testing::Test {
|
||||
base::ThreadPoolInstance::Set(nullptr);
|
||||
}
|
||||
|
||||
const base::CommandLine& GetProcessCommandLine() {
|
||||
return *scoped_command_line_.GetProcessCommandLine();
|
||||
const base::CommandLine* GetProcessCommandLine() {
|
||||
return scoped_command_line_.GetProcessCommandLine();
|
||||
}
|
||||
|
||||
private:
|
||||
@ -58,12 +58,12 @@ class BrowserMainLoopTest : public testing::Test {
|
||||
TEST_F(BrowserMainLoopTest, CreateThreadsInSingleProcess) {
|
||||
MainFunctionParams main_function_params(GetProcessCommandLine());
|
||||
|
||||
StartupDataImpl startup_data;
|
||||
startup_data.io_thread = BrowserTaskExecutor::CreateIOThread();
|
||||
main_function_params.startup_data = &startup_data;
|
||||
auto startup_data = std::make_unique<StartupDataImpl>();
|
||||
startup_data->io_thread = BrowserTaskExecutor::CreateIOThread();
|
||||
main_function_params.startup_data = std::move(startup_data);
|
||||
|
||||
BrowserMainLoop browser_main_loop(
|
||||
main_function_params,
|
||||
std::move(main_function_params),
|
||||
std::make_unique<base::ThreadPoolInstance::ScopedExecutionFence>());
|
||||
browser_main_loop.Init();
|
||||
browser_main_loop.CreateMainMessageLoop();
|
||||
@ -80,12 +80,12 @@ TEST_F(BrowserMainLoopTest,
|
||||
PostTaskToIOThreadBeforeThreadCreationDoesNotRunTask) {
|
||||
MainFunctionParams main_function_params(GetProcessCommandLine());
|
||||
|
||||
StartupDataImpl startup_data;
|
||||
startup_data.io_thread = BrowserTaskExecutor::CreateIOThread();
|
||||
main_function_params.startup_data = &startup_data;
|
||||
auto startup_data = std::make_unique<StartupDataImpl>();
|
||||
startup_data->io_thread = BrowserTaskExecutor::CreateIOThread();
|
||||
main_function_params.startup_data = std::move(startup_data);
|
||||
|
||||
BrowserMainLoop browser_main_loop(
|
||||
main_function_params,
|
||||
std::move(main_function_params),
|
||||
std::make_unique<base::ThreadPoolInstance::ScopedExecutionFence>());
|
||||
browser_main_loop.Init();
|
||||
browser_main_loop.CreateMainMessageLoop();
|
||||
|
@ -63,7 +63,7 @@ BrowserMainRunnerImpl::~BrowserMainRunnerImpl() {
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
int BrowserMainRunnerImpl::Initialize(const MainFunctionParams& parameters) {
|
||||
int BrowserMainRunnerImpl::Initialize(MainFunctionParams parameters) {
|
||||
SCOPED_UMA_HISTOGRAM_LONG_TIMER(
|
||||
"Startup.BrowserMainRunnerImplInitializeLongTime");
|
||||
TRACE_EVENT0("startup", "BrowserMainRunnerImpl::Initialize");
|
||||
@ -79,10 +79,10 @@ int BrowserMainRunnerImpl::Initialize(const MainFunctionParams& parameters) {
|
||||
|
||||
SkGraphics::Init();
|
||||
|
||||
if (parameters.command_line.HasSwitch(switches::kWaitForDebugger))
|
||||
if (parameters.command_line->HasSwitch(switches::kWaitForDebugger))
|
||||
base::debug::WaitForDebugger(60, true);
|
||||
|
||||
if (parameters.command_line.HasSwitch(switches::kBrowserStartupDialog))
|
||||
if (parameters.command_line->HasSwitch(switches::kBrowserStartupDialog))
|
||||
WaitForDebugger("Browser");
|
||||
|
||||
notification_service_ = std::make_unique<NotificationServiceImpl>();
|
||||
@ -96,15 +96,16 @@ int BrowserMainRunnerImpl::Initialize(const MainFunctionParams& parameters) {
|
||||
|
||||
gfx::InitializeFonts();
|
||||
|
||||
auto created_main_parts_closure =
|
||||
std::move(parameters.created_main_parts_closure);
|
||||
|
||||
main_loop_ = std::make_unique<BrowserMainLoop>(
|
||||
parameters, std::move(scoped_execution_fence_));
|
||||
std::move(parameters), std::move(scoped_execution_fence_));
|
||||
|
||||
main_loop_->Init();
|
||||
|
||||
if (parameters.created_main_parts_closure) {
|
||||
std::move(*parameters.created_main_parts_closure)
|
||||
.Run(main_loop_->parts());
|
||||
delete parameters.created_main_parts_closure;
|
||||
if (created_main_parts_closure) {
|
||||
std::move(created_main_parts_closure).Run(main_loop_->parts());
|
||||
}
|
||||
|
||||
const int early_init_error_code = main_loop_->EarlyInitialization();
|
||||
|
@ -35,7 +35,7 @@ class BrowserMainRunnerImpl : public BrowserMainRunner {
|
||||
~BrowserMainRunnerImpl() override;
|
||||
|
||||
// BrowserMainRunner:
|
||||
int Initialize(const MainFunctionParams& parameters) override;
|
||||
int Initialize(MainFunctionParams parameters) override;
|
||||
#if defined(OS_ANDROID)
|
||||
void SynchronouslyFlushStartupTasks() override;
|
||||
#endif
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
#include "content/browser/browser_process_io_thread.h"
|
||||
#include "content/common/content_export.h"
|
||||
#include "content/public/browser/startup_data.h"
|
||||
#include "content/public/common/startup_data.h"
|
||||
#include "mojo/core/embedder/scoped_ipc_support.h"
|
||||
|
||||
namespace content {
|
||||
|
@ -186,13 +186,13 @@ class ContentSandboxHelper : public gpu::GpuSandboxHelper {
|
||||
} // namespace
|
||||
|
||||
// Main function for starting the Gpu process.
|
||||
int GpuMain(const MainFunctionParams& parameters) {
|
||||
int GpuMain(MainFunctionParams parameters) {
|
||||
TRACE_EVENT0("gpu", "GpuMain");
|
||||
base::trace_event::TraceLog::GetInstance()->set_process_name("GPU Process");
|
||||
base::trace_event::TraceLog::GetInstance()->SetProcessSortIndex(
|
||||
kTraceEventGpuProcessSortIndex);
|
||||
|
||||
const base::CommandLine& command_line = parameters.command_line;
|
||||
const base::CommandLine& command_line = *parameters.command_line;
|
||||
|
||||
gpu::GpuPreferences gpu_preferences;
|
||||
if (command_line.HasSwitch(switches::kGpuPreferences)) {
|
||||
|
@ -68,8 +68,8 @@ void* g_target_services = nullptr;
|
||||
namespace content {
|
||||
|
||||
// Main function for starting the PPAPI plugin process.
|
||||
int PpapiPluginMain(const MainFunctionParams& parameters) {
|
||||
const base::CommandLine& command_line = parameters.command_line;
|
||||
int PpapiPluginMain(MainFunctionParams parameters) {
|
||||
const base::CommandLine& command_line = *parameters.command_line;
|
||||
|
||||
#if defined(OS_WIN)
|
||||
// https://crbug.com/1139752 Premature unload of shell32 caused process to
|
||||
@ -146,7 +146,7 @@ int PpapiPluginMain(const MainFunctionParams& parameters) {
|
||||
ChildProcess ppapi_process;
|
||||
base::RunLoop run_loop;
|
||||
ppapi_process.set_main_thread(
|
||||
new PpapiThread(run_loop.QuitClosure(), parameters.command_line));
|
||||
new PpapiThread(run_loop.QuitClosure(), command_line));
|
||||
|
||||
#if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MAC)
|
||||
// Startup tracing is usually enabled earlier, but if we forked from a zygote,
|
||||
|
@ -38,11 +38,19 @@ if (is_win) {
|
||||
public_app_shared_sources += [ "sandbox_helper_win.h" ]
|
||||
}
|
||||
|
||||
public_app_shared_public_deps = [
|
||||
"//content:export",
|
||||
"//third_party/abseil-cpp:absl",
|
||||
]
|
||||
|
||||
public_app_shared_deps = [
|
||||
"//base",
|
||||
"//base:i18n",
|
||||
"//content:export",
|
||||
"//content/app",
|
||||
"//content/public/common:common_sources",
|
||||
"//content/public/gpu:gpu_sources",
|
||||
"//content/public/renderer:renderer_sources",
|
||||
"//content/public/utility:utility_sources",
|
||||
]
|
||||
|
||||
if (is_component_build) {
|
||||
@ -54,13 +62,10 @@ if (is_component_build) {
|
||||
|
||||
configs += [ "//content:content_implementation" ]
|
||||
|
||||
deps = public_app_shared_deps + [
|
||||
"//content/app",
|
||||
"//content/public/browser:browser_sources",
|
||||
"//content/public/gpu:gpu_sources",
|
||||
"//content/public/renderer:renderer_sources",
|
||||
"//content/public/utility:utility_sources",
|
||||
]
|
||||
public_deps = public_app_shared_public_deps
|
||||
|
||||
deps =
|
||||
public_app_shared_deps + [ "//content/public/browser:browser_sources" ]
|
||||
|
||||
allow_circular_includes_from = [
|
||||
# This target is a pair with the non-public version. They always go
|
||||
@ -77,13 +82,10 @@ if (is_component_build) {
|
||||
source_set("app") {
|
||||
sources = public_app_shared_sources
|
||||
configs += [ "//content:content_implementation" ]
|
||||
public_deps = public_app_shared_public_deps
|
||||
deps = public_app_shared_deps + [
|
||||
"//content/app",
|
||||
"//content/public/browser",
|
||||
"//content/public/common",
|
||||
"//content/public/gpu:gpu_sources",
|
||||
"//content/public/renderer:renderer_sources",
|
||||
"//content/public/utility:utility_sources",
|
||||
]
|
||||
|
||||
allow_circular_includes_from = [
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "base/callback_forward.h"
|
||||
#include "base/callback.h"
|
||||
#include "build/build_config.h"
|
||||
#include "content/common/content_export.h"
|
||||
|
||||
@ -33,9 +33,13 @@ class ContentMainRunner;
|
||||
|
||||
using CreatedMainPartsClosure = base::OnceCallback<void(BrowserMainParts*)>;
|
||||
|
||||
struct ContentMainParams {
|
||||
explicit ContentMainParams(ContentMainDelegate* delegate)
|
||||
: delegate(delegate) {}
|
||||
struct CONTENT_EXPORT ContentMainParams {
|
||||
explicit ContentMainParams(ContentMainDelegate* delegate);
|
||||
~ContentMainParams();
|
||||
|
||||
// Do not reuse the moved-from ContentMainParams after this call.
|
||||
ContentMainParams(ContentMainParams&&);
|
||||
ContentMainParams& operator=(ContentMainParams&&);
|
||||
|
||||
ContentMainDelegate* delegate;
|
||||
|
||||
@ -50,13 +54,13 @@ struct ContentMainParams {
|
||||
const char** argv = nullptr;
|
||||
#endif
|
||||
|
||||
// Used by browser_tests. If non-null BrowserMain schedules this task to run
|
||||
// on the MessageLoop. It's owned by the test code.
|
||||
base::OnceClosure* ui_task = nullptr;
|
||||
// Used by BrowserTestBase. If set, BrowserMainLoop runs this task instead of
|
||||
// the main message loop.
|
||||
base::OnceClosure ui_task;
|
||||
|
||||
// Used by InProcessBrowserTest. If non-null this is Run() after
|
||||
// BrowserMainParts has been created and before PreEarlyInitialization().
|
||||
CreatedMainPartsClosure* created_main_parts_closure = nullptr;
|
||||
// Used by BrowserTestBase. If set, this is invoked after BrowserMainParts has
|
||||
// been created and before PreEarlyInitialization().
|
||||
CreatedMainPartsClosure created_main_parts_closure;
|
||||
|
||||
// Indicates whether to run in a minimal browser mode where most subsystems
|
||||
// are left uninitialized.
|
||||
@ -66,9 +70,30 @@ struct ContentMainParams {
|
||||
// The outermost autorelease pool to pass to main entry points.
|
||||
base::mac::ScopedNSAutoreleasePool* autorelease_pool = nullptr;
|
||||
#endif
|
||||
|
||||
// Returns a copy of this ContentMainParams without the move-only data
|
||||
// (which is expected to be null when calling this). Used by the TestLauncher
|
||||
// to launch main multiple times under the same conditions.
|
||||
ContentMainParams ShallowCopyForTesting() const {
|
||||
ContentMainParams copy(delegate);
|
||||
#if defined(OS_WIN)
|
||||
copy.instance = instance;
|
||||
copy.sandbox_info = sandbox_info;
|
||||
#elif !defined(OS_ANDROID)
|
||||
copy.argc = argc;
|
||||
copy.argv = argv;
|
||||
#endif
|
||||
DCHECK(!ui_task);
|
||||
DCHECK(!created_main_parts_closure);
|
||||
copy.minimal_browser_mode = minimal_browser_mode;
|
||||
#if defined(OS_MAC)
|
||||
copy.autorelease_pool = autorelease_pool;
|
||||
#endif
|
||||
return copy;
|
||||
}
|
||||
};
|
||||
|
||||
CONTENT_EXPORT int RunContentProcess(const ContentMainParams& params,
|
||||
CONTENT_EXPORT int RunContentProcess(ContentMainParams params,
|
||||
ContentMainRunner* content_main_runner);
|
||||
|
||||
#if defined(OS_ANDROID)
|
||||
@ -91,7 +116,7 @@ ContentMainDelegate* GetContentMainDelegate();
|
||||
// initial setup for every process. The embedder has a chance to customize
|
||||
// startup using the ContentMainDelegate interface. The embedder can also pass
|
||||
// in null for |delegate| if they don't want to override default startup.
|
||||
CONTENT_EXPORT int ContentMain(const ContentMainParams& params);
|
||||
CONTENT_EXPORT int ContentMain(ContentMainParams params);
|
||||
#endif
|
||||
|
||||
} // namespace content
|
||||
|
@ -18,10 +18,10 @@ bool ContentMainDelegate::BasicStartupComplete(int* exit_code) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int ContentMainDelegate::RunProcess(
|
||||
absl::variant<int, MainFunctionParams> ContentMainDelegate::RunProcess(
|
||||
const std::string& process_type,
|
||||
const content::MainFunctionParams& main_function_params) {
|
||||
return -1;
|
||||
MainFunctionParams main_function_params) {
|
||||
return std::move(main_function_params);
|
||||
}
|
||||
|
||||
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
|
||||
|
@ -11,6 +11,8 @@
|
||||
|
||||
#include "build/build_config.h"
|
||||
#include "content/common/content_export.h"
|
||||
#include "content/public/common/main_function_params.h"
|
||||
#include "third_party/abseil-cpp/absl/types/variant.h"
|
||||
|
||||
namespace variations {
|
||||
class VariationsIdsProvider;
|
||||
@ -24,7 +26,6 @@ class ContentGpuClient;
|
||||
class ContentRendererClient;
|
||||
class ContentUtilityClient;
|
||||
class ZygoteForkDelegate;
|
||||
struct MainFunctionParams;
|
||||
|
||||
class CONTENT_EXPORT ContentMainDelegate {
|
||||
public:
|
||||
@ -45,10 +46,13 @@ class CONTENT_EXPORT ContentMainDelegate {
|
||||
// has been initialized.
|
||||
virtual void SandboxInitialized(const std::string& process_type) {}
|
||||
|
||||
// Asks the embedder to start a process. Return -1 for the default behavior.
|
||||
virtual int RunProcess(
|
||||
// Asks the embedder to start a process. The embedder may return the
|
||||
// |main_function_params| back to decline the request and kick-off the
|
||||
// default behavior or return a non-negative exit code to indicate it handled
|
||||
// the request.
|
||||
virtual absl::variant<int, MainFunctionParams> RunProcess(
|
||||
const std::string& process_type,
|
||||
const MainFunctionParams& main_function_params);
|
||||
MainFunctionParams main_function_params);
|
||||
|
||||
// Called right before the process exits.
|
||||
virtual void ProcessExiting(const std::string& process_type) {}
|
||||
|
@ -22,10 +22,10 @@ class CONTENT_EXPORT ContentMainRunner {
|
||||
static std::unique_ptr<ContentMainRunner> Create();
|
||||
|
||||
// Initialize all necessary content state.
|
||||
virtual int Initialize(const ContentMainParams& params) = 0;
|
||||
virtual int Initialize(ContentMainParams params) = 0;
|
||||
|
||||
// Perform the default run logic.
|
||||
virtual int Run(bool start_minimal_browser) = 0;
|
||||
virtual int Run() = 0;
|
||||
|
||||
// Shut down the content state.
|
||||
virtual void Shutdown() = 0;
|
||||
|
@ -360,7 +360,6 @@ source_set("browser_sources") {
|
||||
"ssl_host_state_delegate.h",
|
||||
"ssl_status.cc",
|
||||
"ssl_status.h",
|
||||
"startup_data.h",
|
||||
"storage_notification_service.h",
|
||||
"storage_partition.h",
|
||||
"storage_partition_config.cc",
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "build/build_config.h"
|
||||
#include "content/common/content_export.h"
|
||||
#include "content/public/common/main_function_params.h"
|
||||
|
||||
namespace content {
|
||||
|
||||
@ -25,10 +26,10 @@ class CONTENT_EXPORT BrowserMainRunner {
|
||||
// Returns true if the BrowserMainRunner has exited the main loop.
|
||||
static bool ExitedMainMessageLoop();
|
||||
|
||||
// Initialize all necessary browser state. The |parameters| values will be
|
||||
// copied. Returning a non-negative value indicates that initialization
|
||||
// failed, and the returned value is used as the exit code for the process.
|
||||
virtual int Initialize(const content::MainFunctionParams& parameters) = 0;
|
||||
// Initialize all necessary browser state. Returning a non-negative value
|
||||
// indicates that initialization failed, and the returned value is used as
|
||||
// the exit code for the process.
|
||||
virtual int Initialize(content::MainFunctionParams parameters) = 0;
|
||||
|
||||
#if defined(OS_ANDROID)
|
||||
// Run all queued startup tasks. Only defined on Android because other
|
||||
|
@ -78,7 +78,7 @@
|
||||
namespace content {
|
||||
|
||||
std::unique_ptr<BrowserMainParts> ContentBrowserClient::CreateBrowserMainParts(
|
||||
const MainFunctionParams& parameters) {
|
||||
MainFunctionParams parameters) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "content/public/browser/mojo_binder_policy_map.h"
|
||||
#include "content/public/browser/storage_partition_config.h"
|
||||
#include "content/public/browser/web_ui_browser_interface_broker_registry.h"
|
||||
#include "content/public/common/main_function_params.h"
|
||||
#include "content/public/common/page_visibility_state.h"
|
||||
#include "content/public/common/window_container_type.mojom-forward.h"
|
||||
#include "device/vr/buildflags/buildflags.h"
|
||||
@ -240,7 +241,6 @@ class WebUIBrowserInterfaceBrokerRegistry;
|
||||
class XrIntegrationClient;
|
||||
struct GlobalRenderFrameHostId;
|
||||
struct GlobalRequestID;
|
||||
struct MainFunctionParams;
|
||||
struct OpenURLParams;
|
||||
struct PepperPluginInfo;
|
||||
struct Referrer;
|
||||
@ -277,7 +277,7 @@ class CONTENT_EXPORT ContentBrowserClient {
|
||||
// implementations for the browser startup code. See comments in
|
||||
// browser_main_parts.h.
|
||||
virtual std::unique_ptr<BrowserMainParts> CreateBrowserMainParts(
|
||||
const MainFunctionParams& parameters);
|
||||
MainFunctionParams parameters);
|
||||
|
||||
// Allows the embedder to change the default behavior of
|
||||
// BrowserThread::PostAfterStartupTask to better match whatever
|
||||
|
@ -72,30 +72,22 @@ source_set("static_switches") {
|
||||
]
|
||||
}
|
||||
|
||||
# This target allows you to use the content_features constants and statically
|
||||
# link to it, without depending on the rest of content. This is only for use
|
||||
# without content, or you will get multiply defined symbols.
|
||||
source_set("static_features") {
|
||||
public = [ "content_features.h" ]
|
||||
# This target allows you to use the content MainFunctionParams struct and
|
||||
# statically link to it, without depending on the rest of content. This is only
|
||||
# for use without content, or you will get multiply defined symbols.
|
||||
source_set("static_main_function_params") {
|
||||
public = [ "main_function_params.h" ]
|
||||
sources = [
|
||||
"//content/common/content_export.h",
|
||||
"content_features.cc",
|
||||
"main_function_params.cc",
|
||||
"startup_data.h",
|
||||
]
|
||||
public_deps = [ "//base" ]
|
||||
|
||||
deps = [
|
||||
"//build:chromeos_buildflags",
|
||||
"//content/common:buildflags",
|
||||
]
|
||||
|
||||
public_configs = [
|
||||
":static_switches_defines",
|
||||
"//tools/v8_context_snapshot:use_v8_context_snapshot",
|
||||
]
|
||||
|
||||
if (is_chromeos_ash) {
|
||||
public_deps += [ "//media/capture/video/chromeos/public" ]
|
||||
}
|
||||
}
|
||||
|
||||
source_set("common_sources") {
|
||||
@ -132,6 +124,7 @@ source_set("common_sources") {
|
||||
"input_event_ack_state.h",
|
||||
"isolated_world_ids.h",
|
||||
"javascript_dialog_type.h",
|
||||
"main_function_params.cc",
|
||||
"main_function_params.h",
|
||||
"mhtml_generation_params.cc",
|
||||
"mhtml_generation_params.h",
|
||||
@ -161,6 +154,7 @@ source_set("common_sources") {
|
||||
"sandboxed_process_launcher_delegate.cc",
|
||||
"sandboxed_process_launcher_delegate.h",
|
||||
"socket_permission_request.h",
|
||||
"startup_data.h",
|
||||
"stop_find_action.h",
|
||||
"storage_quota_params.h",
|
||||
"three_d_api_types.h",
|
||||
|
23
content/public/common/main_function_params.cc
Normal file
23
content/public/common/main_function_params.cc
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright 2021 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "content/public/common/main_function_params.h"
|
||||
|
||||
#include "base/check.h"
|
||||
#include "content/public/common/startup_data.h"
|
||||
|
||||
namespace content {
|
||||
|
||||
MainFunctionParams::MainFunctionParams(const base::CommandLine* cl)
|
||||
: command_line(cl) {
|
||||
DCHECK(command_line);
|
||||
}
|
||||
|
||||
MainFunctionParams::~MainFunctionParams() = default;
|
||||
|
||||
MainFunctionParams::MainFunctionParams(MainFunctionParams&&) = default;
|
||||
MainFunctionParams& MainFunctionParams::operator=(MainFunctionParams&&) =
|
||||
default;
|
||||
|
||||
} // namespace content
|
@ -2,16 +2,15 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Wrapper to the parameter list for the "main" entry points (browser, renderer,
|
||||
// plugin) to shield the call sites from the differences between platforms
|
||||
// (e.g., POSIX doesn't need to pass any sandbox information).
|
||||
|
||||
#ifndef CONTENT_PUBLIC_COMMON_MAIN_FUNCTION_PARAMS_H_
|
||||
#define CONTENT_PUBLIC_COMMON_MAIN_FUNCTION_PARAMS_H_
|
||||
|
||||
#include "base/callback_forward.h"
|
||||
#include <memory>
|
||||
|
||||
#include "base/callback.h"
|
||||
#include "base/command_line.h"
|
||||
#include "build/build_config.h"
|
||||
#include "content/common/content_export.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
namespace sandbox {
|
||||
@ -32,10 +31,18 @@ struct StartupData;
|
||||
|
||||
using CreatedMainPartsClosure = base::OnceCallback<void(BrowserMainParts*)>;
|
||||
|
||||
struct MainFunctionParams {
|
||||
explicit MainFunctionParams(const base::CommandLine& cl) : command_line(cl) {}
|
||||
// Wrapper to the parameter list for the "main" entry points (browser, renderer,
|
||||
// plugin) to shield the call sites from the differences between platforms
|
||||
// (e.g., POSIX doesn't need to pass any sandbox information).
|
||||
struct CONTENT_EXPORT MainFunctionParams {
|
||||
explicit MainFunctionParams(const base::CommandLine* cl);
|
||||
~MainFunctionParams();
|
||||
|
||||
const base::CommandLine& command_line;
|
||||
// Do not reuse the moved-from MainFunctionParams after this call.
|
||||
MainFunctionParams(MainFunctionParams&&);
|
||||
MainFunctionParams& operator=(MainFunctionParams&&);
|
||||
|
||||
const base::CommandLine* command_line;
|
||||
|
||||
#if defined(OS_WIN)
|
||||
sandbox::SandboxInterfaceInfo* sandbox_info = nullptr;
|
||||
@ -45,22 +52,17 @@ struct MainFunctionParams {
|
||||
bool zygote_child = false;
|
||||
#endif
|
||||
|
||||
// TODO(sky): fix ownership of these tasks. MainFunctionParams should really
|
||||
// be passed as an r-value, at which point these can be unique_ptrs. For the
|
||||
// time ownership is passed with MainFunctionParams (meaning these are deleted
|
||||
// in content or client code).
|
||||
// Used by BrowserTestBase. If set, BrowserMainLoop runs this task instead of
|
||||
// the main message loop.
|
||||
base::OnceClosure ui_task;
|
||||
|
||||
// Used by InProcessBrowserTest. If non-null BrowserMain schedules this
|
||||
// task to run on the MessageLoop and BrowserInit is not invoked.
|
||||
base::OnceClosure* ui_task = nullptr;
|
||||
|
||||
// Used by InProcessBrowserTest. If non-null this is Run() after
|
||||
// BrowserMainParts has been created and before PreEarlyInitialization().
|
||||
CreatedMainPartsClosure* created_main_parts_closure = nullptr;
|
||||
// Used by BrowserTestBase. If set, this is invoked after BrowserMainParts has
|
||||
// been created and before PreEarlyInitialization().
|
||||
CreatedMainPartsClosure created_main_parts_closure;
|
||||
|
||||
// Used by //content, when the embedder yields control back to it, to extract
|
||||
// startup data passed from ContentMainRunner.
|
||||
StartupData* startup_data = nullptr;
|
||||
std::unique_ptr<StartupData> startup_data;
|
||||
};
|
||||
|
||||
} // namespace content
|
||||
|
@ -2,8 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef CONTENT_PUBLIC_BROWSER_STARTUP_DATA_H_
|
||||
#define CONTENT_PUBLIC_BROWSER_STARTUP_DATA_H_
|
||||
#ifndef CONTENT_PUBLIC_COMMON_STARTUP_DATA_H_
|
||||
#define CONTENT_PUBLIC_COMMON_STARTUP_DATA_H_
|
||||
|
||||
namespace content {
|
||||
|
||||
@ -15,4 +15,4 @@ struct StartupData {
|
||||
|
||||
} // namespace content
|
||||
|
||||
#endif // CONTENT_PUBLIC_BROWSER_STARTUP_DATA_H_
|
||||
#endif // CONTENT_PUBLIC_COMMON_STARTUP_DATA_H_
|
@ -533,9 +533,8 @@ void BrowserTestBase::SetUp() {
|
||||
// FeatureList::SetInstance, which expects no instance to exist.
|
||||
base::FeatureList::ClearInstanceForTesting();
|
||||
|
||||
auto created_main_parts_closure = std::make_unique<CreatedMainPartsClosure>(
|
||||
base::BindOnce(&BrowserTestBase::CreatedBrowserMainPartsImpl,
|
||||
base::Unretained(this)));
|
||||
auto created_main_parts_closure = base::BindOnce(
|
||||
&BrowserTestBase::CreatedBrowserMainPartsImpl, base::Unretained(this));
|
||||
|
||||
// If tracing is enabled, customise the output filename based on the name of
|
||||
// the test.
|
||||
@ -649,20 +648,20 @@ void BrowserTestBase::SetUp() {
|
||||
// run.
|
||||
base::RunLoop loop{base::RunLoop::Type::kNestableTasksAllowed};
|
||||
|
||||
auto ui_task = std::make_unique<base::OnceClosure>(
|
||||
base::BindOnce(&BrowserTestBase::WaitUntilJavaIsReady,
|
||||
base::Unretained(this), loop.QuitClosure(),
|
||||
/*wait_retry_left=*/
|
||||
TestTimeouts::action_max_timeout()));
|
||||
auto ui_task = base::BindOnce(&BrowserTestBase::WaitUntilJavaIsReady,
|
||||
base::Unretained(this), loop.QuitClosure(),
|
||||
/*wait_retry_left=*/
|
||||
TestTimeouts::action_max_timeout());
|
||||
|
||||
// The MainFunctionParams must out-live all the startup tasks running.
|
||||
MainFunctionParams params(*command_line);
|
||||
params.ui_task = ui_task.release();
|
||||
params.created_main_parts_closure = created_main_parts_closure.release();
|
||||
params.startup_data = startup_data.get();
|
||||
MainFunctionParams params(command_line);
|
||||
params.ui_task = std::move(ui_task);
|
||||
params.created_main_parts_closure = std::move(created_main_parts_closure);
|
||||
params.startup_data = std::move(startup_data);
|
||||
// Passing "" as the process type to indicate the browser process.
|
||||
int exit_code = delegate->RunProcess("", params);
|
||||
DCHECK_EQ(exit_code, 0);
|
||||
auto exit_code = delegate->RunProcess("", std::move(params));
|
||||
DCHECK(absl::holds_alternative<int>(exit_code));
|
||||
DCHECK_EQ(absl::get<int>(exit_code), 0);
|
||||
|
||||
// Waits for Java to finish initialization, then we can run the test.
|
||||
loop.Run();
|
||||
@ -694,12 +693,12 @@ void BrowserTestBase::SetUp() {
|
||||
BrowserTaskExecutor::Shutdown();
|
||||
|
||||
#else // defined(OS_ANDROID)
|
||||
auto ui_task = std::make_unique<base::OnceClosure>(base::BindOnce(
|
||||
&BrowserTestBase::ProxyRunTestOnMainThreadLoop, base::Unretained(this)));
|
||||
GetContentMainParams()->ui_task = ui_task.release();
|
||||
GetContentMainParams()->created_main_parts_closure =
|
||||
created_main_parts_closure.release();
|
||||
EXPECT_EQ(expected_exit_code_, ContentMain(*GetContentMainParams()));
|
||||
auto ui_task = base::BindOnce(&BrowserTestBase::ProxyRunTestOnMainThreadLoop,
|
||||
base::Unretained(this));
|
||||
auto params = CopyContentMainParams();
|
||||
params.ui_task = std::move(ui_task);
|
||||
params.created_main_parts_closure = std::move(created_main_parts_closure);
|
||||
EXPECT_EQ(expected_exit_code_, ContentMain(std::move(params)));
|
||||
#endif // defined(OS_ANDROID)
|
||||
|
||||
TearDownInProcessBrowserTestFixture();
|
||||
|
@ -474,7 +474,7 @@ void RenderViewTest::SetUp() {
|
||||
#endif
|
||||
command_line_ =
|
||||
std::make_unique<base::CommandLine>(base::CommandLine::NO_PROGRAM);
|
||||
params_ = std::make_unique<MainFunctionParams>(*command_line_);
|
||||
params_ = std::make_unique<MainFunctionParams>(command_line_.get());
|
||||
platform_ = std::make_unique<RendererMainPlatformDelegate>(*params_);
|
||||
platform_->PlatformInitialize();
|
||||
|
||||
|
@ -79,10 +79,12 @@ const char kPreTestPrefix[] = "PRE_";
|
||||
const char kManualTestPrefix[] = "MANUAL_";
|
||||
|
||||
TestLauncherDelegate* g_launcher_delegate = nullptr;
|
||||
#if !defined(OS_ANDROID)
|
||||
|
||||
// ContentMain is not run on Android in the test process, and is run via
|
||||
// java for child processes. So ContentMainParams does not exist there.
|
||||
ContentMainParams* g_params = nullptr;
|
||||
#if !defined(OS_ANDROID)
|
||||
// The global ContentMainParams config to be copied in each test.
|
||||
const ContentMainParams* g_params = nullptr;
|
||||
#endif
|
||||
|
||||
void PrintUsage() {
|
||||
@ -381,7 +383,7 @@ int LaunchTests(TestLauncherDelegate* launcher_delegate,
|
||||
// child processes don't have a TestSuite, and must initialize this
|
||||
// explicitly before ContentMain.
|
||||
TestTimeouts::Initialize();
|
||||
return ContentMain(params);
|
||||
return ContentMain(std::move(params));
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -447,8 +449,8 @@ TestLauncherDelegate* GetCurrentTestLauncherDelegate() {
|
||||
}
|
||||
|
||||
#if !defined(OS_ANDROID)
|
||||
ContentMainParams* GetContentMainParams() {
|
||||
return g_params;
|
||||
ContentMainParams CopyContentMainParams() {
|
||||
return g_params->ShallowCopyForTesting();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -72,10 +72,11 @@ int LaunchTests(TestLauncherDelegate* launcher_delegate,
|
||||
|
||||
TestLauncherDelegate* GetCurrentTestLauncherDelegate();
|
||||
|
||||
#if !defined(OS_ANDROID)
|
||||
// ContentMain is not run on Android in the test process, and is run via
|
||||
// java for child processes. So ContentMainParams does not exist there.
|
||||
ContentMainParams* GetContentMainParams();
|
||||
#if !defined(OS_ANDROID)
|
||||
// Returns a copy of the ContentMainParams initialized before launching tests.
|
||||
ContentMainParams CopyContentMainParams();
|
||||
#endif
|
||||
|
||||
// Returns true if the currently running test has a prefix that indicates it
|
||||
|
@ -106,7 +106,7 @@ std::unique_ptr<base::MessagePump> CreateMainThreadMessagePump() {
|
||||
} // namespace
|
||||
|
||||
// mainline routine for running as the Renderer process
|
||||
int RendererMain(const MainFunctionParams& parameters) {
|
||||
int RendererMain(MainFunctionParams parameters) {
|
||||
// Don't use the TRACE_EVENT0 macro because the tracing infrastructure doesn't
|
||||
// expect synchronous events around the main loop of a thread.
|
||||
TRACE_EVENT_NESTABLE_ASYNC_BEGIN1("startup", "RendererMain",
|
||||
@ -117,7 +117,7 @@ int RendererMain(const MainFunctionParams& parameters) {
|
||||
base::trace_event::TraceLog::GetInstance()->SetProcessSortIndex(
|
||||
kTraceEventRendererProcessSortIndex);
|
||||
|
||||
const base::CommandLine& command_line = parameters.command_line;
|
||||
const base::CommandLine& command_line = *parameters.command_line;
|
||||
|
||||
#if defined(OS_MAC)
|
||||
base::mac::ScopedNSAutoreleasePool* pool = parameters.autorelease_pool;
|
||||
|
@ -35,7 +35,7 @@ RendererMainPlatformDelegate::~RendererMainPlatformDelegate() {
|
||||
}
|
||||
|
||||
void RendererMainPlatformDelegate::PlatformInitialize() {
|
||||
const base::CommandLine& command_line = parameters_.command_line;
|
||||
const base::CommandLine& command_line = *parameters_.command_line;
|
||||
|
||||
// Be mindful of what resources you acquire here. They can be used by
|
||||
// malicious code if the renderer gets compromised.
|
||||
|
@ -24,6 +24,6 @@ int ContentMain(int argc,
|
||||
content::ContentMainParams params(&delegate);
|
||||
params.argc = argc;
|
||||
params.argv = argv;
|
||||
return content::ContentMain(params);
|
||||
return content::ContentMain(std::move(params));
|
||||
}
|
||||
#endif // OS_MAC
|
||||
|
@ -30,7 +30,7 @@ int main() {
|
||||
content::ContentMainParams params(&delegate);
|
||||
params.instance = instance;
|
||||
params.sandbox_info = &sandbox_info;
|
||||
return content::ContentMain(params);
|
||||
return content::ContentMain(std::move(params));
|
||||
}
|
||||
|
||||
#else
|
||||
@ -40,7 +40,7 @@ int main(int argc, const char** argv) {
|
||||
content::ContentMainParams params(&delegate);
|
||||
params.argc = argc;
|
||||
params.argv = argv;
|
||||
return content::ContentMain(params);
|
||||
return content::ContentMain(std::move(params));
|
||||
}
|
||||
|
||||
#endif // OS_POSIX
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "content/common/content_constants_internal.h"
|
||||
#include "content/public/browser/browser_main_runner.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "content/public/common/main_function_params.h"
|
||||
#include "content/public/common/url_constants.h"
|
||||
#include "content/shell/app/shell_crash_reporter_client.h"
|
||||
#include "content/shell/browser/shell_content_browser_client.h"
|
||||
@ -223,12 +224,12 @@ void ShellMainDelegate::PreSandboxStartup() {
|
||||
InitializeResourceBundle();
|
||||
}
|
||||
|
||||
int ShellMainDelegate::RunProcess(
|
||||
absl::variant<int, MainFunctionParams> ShellMainDelegate::RunProcess(
|
||||
const std::string& process_type,
|
||||
const MainFunctionParams& main_function_params) {
|
||||
MainFunctionParams main_function_params) {
|
||||
// For non-browser process, return and have the caller run the main loop.
|
||||
if (!process_type.empty())
|
||||
return -1;
|
||||
return std::move(main_function_params);
|
||||
|
||||
base::trace_event::TraceLog::GetInstance()->set_process_name("Browser");
|
||||
base::trace_event::TraceLog::GetInstance()->SetProcessSortIndex(
|
||||
@ -237,7 +238,7 @@ int ShellMainDelegate::RunProcess(
|
||||
#if !defined(OS_ANDROID)
|
||||
if (switches::IsRunWebTestsSwitchPresent()) {
|
||||
// Web tests implement their own BrowserMain() replacement.
|
||||
web_test_runner_->RunBrowserMain(main_function_params);
|
||||
web_test_runner_->RunBrowserMain(std::move(main_function_params));
|
||||
web_test_runner_.reset();
|
||||
// Returning 0 to indicate that we have replaced BrowserMain() and the
|
||||
// caller should not call BrowserMain() itself. Web tests do not ever
|
||||
@ -245,9 +246,9 @@ int ShellMainDelegate::RunProcess(
|
||||
return 0;
|
||||
}
|
||||
|
||||
// On non-Android, we can return -1 and have the caller run BrowserMain()
|
||||
// normally.
|
||||
return -1;
|
||||
// On non-Android, we can return the |main_function_params| back and have the
|
||||
// caller run BrowserMain() normally.
|
||||
return std::move(main_function_params);
|
||||
#else
|
||||
// On Android, we defer to the system message loop when the stack unwinds.
|
||||
// So here we only create (and leak) a BrowserMainRunner. The shutdown
|
||||
@ -257,7 +258,8 @@ int ShellMainDelegate::RunProcess(
|
||||
// In browser tests, the |main_function_params| contains a |ui_task| which
|
||||
// will execute the testing. The task will be executed synchronously inside
|
||||
// Initialize() so we don't depend on the BrowserMainRunner being Run().
|
||||
int initialize_exit_code = main_runner->Initialize(main_function_params);
|
||||
int initialize_exit_code =
|
||||
main_runner->Initialize(std::move(main_function_params));
|
||||
DCHECK_LT(initialize_exit_code, 0)
|
||||
<< "BrowserMainRunner::Initialize failed in ShellMainDelegate";
|
||||
ignore_result(main_runner.release());
|
||||
|
@ -36,8 +36,9 @@ class ShellMainDelegate : public ContentMainDelegate {
|
||||
bool BasicStartupComplete(int* exit_code) override;
|
||||
bool ShouldCreateFeatureList() override;
|
||||
void PreSandboxStartup() override;
|
||||
int RunProcess(const std::string& process_type,
|
||||
const MainFunctionParams& main_function_params) override;
|
||||
absl::variant<int, MainFunctionParams> RunProcess(
|
||||
const std::string& process_type,
|
||||
MainFunctionParams main_function_params) override;
|
||||
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
|
||||
void ZygoteForked() override;
|
||||
#endif
|
||||
|
@ -109,9 +109,8 @@ scoped_refptr<base::RefCountedMemory> PlatformResourceProvider(int key) {
|
||||
|
||||
} // namespace
|
||||
|
||||
ShellBrowserMainParts::ShellBrowserMainParts(
|
||||
const MainFunctionParams& parameters)
|
||||
: parameters_(parameters), run_message_loop_(true) {}
|
||||
ShellBrowserMainParts::ShellBrowserMainParts(MainFunctionParams parameters)
|
||||
: parameters_(std::move(parameters)), run_message_loop_(true) {}
|
||||
|
||||
ShellBrowserMainParts::~ShellBrowserMainParts() = default;
|
||||
|
||||
@ -188,8 +187,7 @@ int ShellBrowserMainParts::PreMainMessageLoopRun() {
|
||||
InitializeMessageLoopContext();
|
||||
|
||||
if (parameters_.ui_task) {
|
||||
std::move(*parameters_.ui_task).Run();
|
||||
delete parameters_.ui_task;
|
||||
std::move(parameters_.ui_task).Run();
|
||||
run_message_loop_ = false;
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ class ShellPlatformDelegate;
|
||||
|
||||
class ShellBrowserMainParts : public BrowserMainParts {
|
||||
public:
|
||||
explicit ShellBrowserMainParts(const MainFunctionParams& parameters);
|
||||
explicit ShellBrowserMainParts(MainFunctionParams parameters);
|
||||
|
||||
ShellBrowserMainParts(const ShellBrowserMainParts&) = delete;
|
||||
ShellBrowserMainParts& operator=(const ShellBrowserMainParts&) = delete;
|
||||
@ -69,7 +69,7 @@ class ShellBrowserMainParts : public BrowserMainParts {
|
||||
std::unique_ptr<ShellBrowserContext> off_the_record_browser_context_;
|
||||
|
||||
// For running content_browsertests.
|
||||
const MainFunctionParams parameters_;
|
||||
MainFunctionParams parameters_;
|
||||
bool run_message_loop_;
|
||||
|
||||
std::unique_ptr<performance_manager::PerformanceManagerLifetime>
|
||||
|
@ -248,8 +248,9 @@ ShellContentBrowserClient::~ShellContentBrowserClient() {
|
||||
|
||||
std::unique_ptr<BrowserMainParts>
|
||||
ShellContentBrowserClient::CreateBrowserMainParts(
|
||||
const MainFunctionParams& parameters) {
|
||||
auto browser_main_parts = std::make_unique<ShellBrowserMainParts>(parameters);
|
||||
MainFunctionParams parameters) {
|
||||
auto browser_main_parts =
|
||||
std::make_unique<ShellBrowserMainParts>(std::move(parameters));
|
||||
|
||||
shell_browser_main_parts_ = browser_main_parts.get();
|
||||
|
||||
|
@ -47,7 +47,7 @@ class ShellContentBrowserClient : public ContentBrowserClient {
|
||||
|
||||
// ContentBrowserClient overrides.
|
||||
std::unique_ptr<BrowserMainParts> CreateBrowserMainParts(
|
||||
const MainFunctionParams& parameters) override;
|
||||
MainFunctionParams parameters) override;
|
||||
bool IsHandledURL(const GURL& url) override;
|
||||
void AppendExtraCommandLineSwitches(base::CommandLine* command_line,
|
||||
int child_process_id) override;
|
||||
|
@ -65,15 +65,15 @@ sandbox::TargetServices* g_utility_target_services = nullptr;
|
||||
namespace content {
|
||||
|
||||
// Mainline routine for running as the utility process.
|
||||
int UtilityMain(const MainFunctionParams& parameters) {
|
||||
int UtilityMain(MainFunctionParams parameters) {
|
||||
base::MessagePumpType message_pump_type =
|
||||
parameters.command_line.HasSwitch(switches::kMessageLoopTypeUi)
|
||||
parameters.command_line->HasSwitch(switches::kMessageLoopTypeUi)
|
||||
? base::MessagePumpType::UI
|
||||
: base::MessagePumpType::DEFAULT;
|
||||
|
||||
#if defined(OS_MAC)
|
||||
auto sandbox_type =
|
||||
sandbox::policy::SandboxTypeFromCommandLine(parameters.command_line);
|
||||
sandbox::policy::SandboxTypeFromCommandLine(*parameters.command_line);
|
||||
if (sandbox_type != sandbox::mojom::Sandbox::kNoSandbox) {
|
||||
// On Mac, the TYPE_UI pump for the main thread is an NSApplication loop.
|
||||
// In a sandboxed utility process, NSApp attempts to acquire more Mach
|
||||
@ -94,8 +94,8 @@ int UtilityMain(const MainFunctionParams& parameters) {
|
||||
message_pump_type = base::MessagePumpType::IO;
|
||||
#endif // defined(OS_FUCHSIA)
|
||||
|
||||
if (parameters.command_line.HasSwitch(switches::kTimeZoneForTesting)) {
|
||||
std::string time_zone = parameters.command_line.GetSwitchValueASCII(
|
||||
if (parameters.command_line->HasSwitch(switches::kTimeZoneForTesting)) {
|
||||
std::string time_zone = parameters.command_line->GetSwitchValueASCII(
|
||||
switches::kTimeZoneForTesting);
|
||||
icu::TimeZone::adoptDefault(
|
||||
icu::TimeZone::createTimeZone(icu::UnicodeString(time_zone.c_str())));
|
||||
@ -105,11 +105,11 @@ int UtilityMain(const MainFunctionParams& parameters) {
|
||||
base::SingleThreadTaskExecutor main_thread_task_executor(message_pump_type);
|
||||
base::PlatformThread::SetName("CrUtilityMain");
|
||||
|
||||
if (parameters.command_line.HasSwitch(switches::kUtilityStartupDialog)) {
|
||||
auto dialog_match = parameters.command_line.GetSwitchValueASCII(
|
||||
if (parameters.command_line->HasSwitch(switches::kUtilityStartupDialog)) {
|
||||
auto dialog_match = parameters.command_line->GetSwitchValueASCII(
|
||||
switches::kUtilityStartupDialog);
|
||||
auto sub_type =
|
||||
parameters.command_line.GetSwitchValueASCII(switches::kUtilitySubType);
|
||||
parameters.command_line->GetSwitchValueASCII(switches::kUtilitySubType);
|
||||
if (dialog_match.empty() || dialog_match == sub_type) {
|
||||
WaitForDebugger(sub_type.empty() ? "Utility" : sub_type);
|
||||
}
|
||||
@ -120,7 +120,7 @@ int UtilityMain(const MainFunctionParams& parameters) {
|
||||
// TODO(jorgelo): move this after GTK initialization when we enable a strict
|
||||
// Seccomp-BPF policy.
|
||||
auto sandbox_type =
|
||||
sandbox::policy::SandboxTypeFromCommandLine(parameters.command_line);
|
||||
sandbox::policy::SandboxTypeFromCommandLine(*parameters.command_line);
|
||||
sandbox::policy::SandboxLinux::PreSandboxHook pre_sandbox_hook;
|
||||
switch (sandbox_type) {
|
||||
case sandbox::mojom::Sandbox::kNetwork:
|
||||
@ -199,7 +199,7 @@ int UtilityMain(const MainFunctionParams& parameters) {
|
||||
|
||||
#if defined(OS_WIN)
|
||||
auto sandbox_type =
|
||||
sandbox::policy::SandboxTypeFromCommandLine(parameters.command_line);
|
||||
sandbox::policy::SandboxTypeFromCommandLine(*parameters.command_line);
|
||||
DVLOG(1) << "Sandbox type: " << static_cast<int>(sandbox_type);
|
||||
|
||||
// https://crbug.com/1076771 https://crbug.com/1075487 Premature unload of
|
||||
|
@ -43,9 +43,8 @@
|
||||
|
||||
namespace content {
|
||||
|
||||
WebTestBrowserMainParts::WebTestBrowserMainParts(
|
||||
const MainFunctionParams& parameters)
|
||||
: ShellBrowserMainParts(parameters) {}
|
||||
WebTestBrowserMainParts::WebTestBrowserMainParts(MainFunctionParams parameters)
|
||||
: ShellBrowserMainParts(std::move(parameters)) {}
|
||||
|
||||
WebTestBrowserMainParts::~WebTestBrowserMainParts() {}
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "build/build_config.h"
|
||||
#include "content/public/common/main_function_params.h"
|
||||
#include "content/shell/browser/shell_browser_main_parts.h"
|
||||
#include "ppapi/buildflags/buildflags.h"
|
||||
|
||||
@ -18,7 +19,7 @@ class ShellPluginServiceFilter;
|
||||
|
||||
class WebTestBrowserMainParts : public ShellBrowserMainParts {
|
||||
public:
|
||||
explicit WebTestBrowserMainParts(const MainFunctionParams& parameters);
|
||||
explicit WebTestBrowserMainParts(MainFunctionParams parameters);
|
||||
|
||||
WebTestBrowserMainParts(const WebTestBrowserMainParts&) = delete;
|
||||
WebTestBrowserMainParts& operator=(const WebTestBrowserMainParts&) = delete;
|
||||
|
@ -232,10 +232,10 @@ void WebTestBrowserMainRunner::Initialize() {
|
||||
}
|
||||
|
||||
void WebTestBrowserMainRunner::RunBrowserMain(
|
||||
const content::MainFunctionParams& parameters) {
|
||||
content::MainFunctionParams parameters) {
|
||||
std::unique_ptr<content::BrowserMainRunner> main_runner =
|
||||
content::BrowserMainRunner::Create();
|
||||
int initialize_exit_code = main_runner->Initialize(parameters);
|
||||
int initialize_exit_code = main_runner->Initialize(std::move(parameters));
|
||||
DCHECK_LT(initialize_exit_code, 0)
|
||||
<< "BrowserMainRunner::Initialize failed in WebTestBrowserMainRunner";
|
||||
|
||||
|
@ -6,9 +6,9 @@
|
||||
#define CONTENT_WEB_TEST_BROWSER_WEB_TEST_BROWSER_MAIN_RUNNER_H_
|
||||
|
||||
#include "base/files/scoped_temp_dir.h"
|
||||
#include "content/public/common/main_function_params.h"
|
||||
|
||||
namespace content {
|
||||
struct MainFunctionParams;
|
||||
|
||||
class WebTestBrowserMainRunner {
|
||||
public:
|
||||
@ -18,7 +18,7 @@ class WebTestBrowserMainRunner {
|
||||
void Initialize();
|
||||
|
||||
// Main routine for running as the Browser process.
|
||||
void RunBrowserMain(const content::MainFunctionParams& parameters);
|
||||
void RunBrowserMain(content::MainFunctionParams parameters);
|
||||
|
||||
private:
|
||||
base::ScopedTempDir browser_context_path_for_web_tests_;
|
||||
|
@ -356,9 +356,9 @@ void WebTestContentBrowserClient::AppendExtraCommandLineSwitches(
|
||||
|
||||
std::unique_ptr<BrowserMainParts>
|
||||
WebTestContentBrowserClient::CreateBrowserMainParts(
|
||||
const MainFunctionParams& parameters) {
|
||||
MainFunctionParams parameters) {
|
||||
auto browser_main_parts =
|
||||
std::make_unique<WebTestBrowserMainParts>(parameters);
|
||||
std::make_unique<WebTestBrowserMainParts>(std::move(parameters));
|
||||
|
||||
set_browser_main_parts(browser_main_parts.get());
|
||||
|
||||
|
@ -66,7 +66,7 @@ class WebTestContentBrowserClient : public ShellContentBrowserClient {
|
||||
void AppendExtraCommandLineSwitches(base::CommandLine* command_line,
|
||||
int child_process_id) override;
|
||||
std::unique_ptr<BrowserMainParts> CreateBrowserMainParts(
|
||||
const MainFunctionParams& parameters) override;
|
||||
MainFunctionParams parameters) override;
|
||||
std::vector<url::Origin> GetOriginsRequiringDedicatedProcess() override;
|
||||
std::unique_ptr<OverlayWindow> CreateWindowForPictureInPicture(
|
||||
PictureInPictureWindowController* controller) override;
|
||||
|
@ -70,7 +70,7 @@ base::MessagePumpCFRunLoopBase::Run(base::MessagePump::Delegate*)
|
||||
ChromeBrowserMainParts::MainMessageLoopRun(int*)
|
||||
content::BrowserMainLoop::RunMainMessageLoopParts()
|
||||
content::BrowserMainRunnerImpl::Run()
|
||||
content::BrowserMain(content::MainFunctionParams const&)
|
||||
content::BrowserMain(content::MainFunctionParams)
|
||||
content::ContentMainRunnerImpl::Run()
|
||||
service_manager::Main(service_manager::MainParams const&)
|
||||
content::ContentMain(content::ContentMainParams const&)
|
||||
|
@ -21,7 +21,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) {
|
||||
params.instance = instance;
|
||||
params.sandbox_info = &sandbox_info;
|
||||
|
||||
return content::ContentMain(params);
|
||||
return content::ContentMain(std::move(params));
|
||||
}
|
||||
#else
|
||||
int main(int argc, const char** argv) {
|
||||
@ -31,6 +31,6 @@ int main(int argc, const char** argv) {
|
||||
params.argc = argc;
|
||||
params.argv = argv;
|
||||
|
||||
return content::ContentMain(params);
|
||||
return content::ContentMain(std::move(params));
|
||||
}
|
||||
#endif
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user