2020-10-08 21:54:42 +02:00
|
|
|
diff --git content/app/content_main.cc content/app/content_main.cc
|
2021-02-11 23:12:15 +01:00
|
|
|
index 2aba28d210db..00edc202e2c4 100644
|
2020-10-08 21:54:42 +02:00
|
|
|
--- content/app/content_main.cc
|
|
|
|
+++ content/app/content_main.cc
|
2020-12-02 23:31:49 +01:00
|
|
|
@@ -205,15 +205,10 @@ void InitializeMojo(mojo::core::Configuration* config) {
|
2020-10-08 21:54:42 +02:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
-int RunContentProcess(const ContentMainParams& params,
|
|
|
|
- ContentMainRunner* content_main_runner) {
|
|
|
|
- ContentMainParams content_main_params(params);
|
|
|
|
-
|
|
|
|
+int ContentMainInitialize(ContentMainParams& params,
|
|
|
|
+ ContentMainRunner* content_main_runner) {
|
|
|
|
int exit_code = -1;
|
|
|
|
base::debug::GlobalActivityTracker* tracker = nullptr;
|
|
|
|
-#if defined(OS_MAC)
|
|
|
|
- std::unique_ptr<base::mac::ScopedNSAutoreleasePool> autorelease_pool;
|
|
|
|
-#endif
|
|
|
|
|
|
|
|
// A flag to indicate whether Main() has been called before. On Android, we
|
|
|
|
// may re-run Main() without restarting the browser process. This flag
|
2021-02-11 23:12:15 +01:00
|
|
|
@@ -295,12 +290,6 @@ int RunContentProcess(const ContentMainParams& params,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(OS_MAC)
|
|
|
|
- // We need this pool for all the objects created before we get to the event
|
|
|
|
- // loop, but we don't want to leave them hanging around until the app quits.
|
|
|
|
- // Each "main" needs to flush this pool right before it goes into its main
|
|
|
|
- // event loop to get rid of the cruft.
|
2020-10-08 21:54:42 +02:00
|
|
|
- autorelease_pool = std::make_unique<base::mac::ScopedNSAutoreleasePool>();
|
|
|
|
- content_main_params.autorelease_pool = autorelease_pool.get();
|
|
|
|
InitializeMac();
|
|
|
|
#endif
|
|
|
|
|
2021-02-11 23:12:15 +01:00
|
|
|
@@ -310,7 +299,7 @@ int RunContentProcess(const ContentMainParams& params,
|
2020-10-08 21:54:42 +02:00
|
|
|
|
|
|
|
ui::RegisterPathProvider();
|
|
|
|
tracker = base::debug::GlobalActivityTracker::Get();
|
|
|
|
- exit_code = content_main_runner->Initialize(content_main_params);
|
|
|
|
+ exit_code = content_main_runner->Initialize(params);
|
|
|
|
|
|
|
|
if (exit_code >= 0) {
|
|
|
|
if (tracker) {
|
2021-02-11 23:12:15 +01:00
|
|
|
@@ -369,8 +358,16 @@ int RunContentProcess(const ContentMainParams& params,
|
2020-10-08 21:54:42 +02:00
|
|
|
|
|
|
|
if (IsSubprocess())
|
|
|
|
CommonSubprocessInit();
|
|
|
|
- exit_code = content_main_runner->Run(params.minimal_browser_mode);
|
|
|
|
|
|
|
|
+ return exit_code;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int ContentMainRun(ContentMainParams& params,
|
|
|
|
+ ContentMainRunner* content_main_runner) {
|
|
|
|
+ int exit_code = content_main_runner->Run(params.minimal_browser_mode);
|
|
|
|
+
|
|
|
|
+ base::debug::GlobalActivityTracker* tracker =
|
|
|
|
+ base::debug::GlobalActivityTracker::Get();
|
|
|
|
if (tracker) {
|
|
|
|
if (exit_code == 0) {
|
|
|
|
tracker->SetProcessPhaseIfEnabled(
|
2021-02-11 23:12:15 +01:00
|
|
|
@@ -381,19 +378,45 @@ int RunContentProcess(const ContentMainParams& params,
|
2020-10-08 21:54:42 +02:00
|
|
|
tracker->process_data().SetInt("exit-code", exit_code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ return exit_code;
|
|
|
|
+}
|
|
|
|
|
|
|
|
+void ContentMainShutdown(ContentMainParams& params,
|
|
|
|
+ ContentMainRunner* content_main_runner) {
|
2021-02-11 23:12:15 +01:00
|
|
|
+#if !defined(OS_ANDROID)
|
|
|
|
+ content_main_runner->Shutdown();
|
|
|
|
+#endif
|
2020-10-08 21:54:42 +02:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int RunContentProcess(ContentMainParams& params,
|
|
|
|
+ ContentMainRunner* content_main_runner) {
|
2021-02-11 23:12:15 +01:00
|
|
|
#if defined(OS_MAC)
|
|
|
|
- autorelease_pool.reset();
|
|
|
|
+ // We need this pool for all the objects created before we get to the event
|
|
|
|
+ // loop, but we don't want to leave them hanging around until the app quits.
|
|
|
|
+ // Each "main" needs to flush this pool right before it goes into its main
|
|
|
|
+ // event loop to get rid of the cruft.
|
|
|
|
+ std::unique_ptr<base::mac::ScopedNSAutoreleasePool> autorelease_pool =
|
|
|
|
+ std::make_unique<base::mac::ScopedNSAutoreleasePool>();
|
|
|
|
+ params.autorelease_pool = autorelease_pool.get();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
-#if !defined(OS_ANDROID)
|
|
|
|
- content_main_runner->Shutdown();
|
2020-10-08 21:54:42 +02:00
|
|
|
+ int exit_code = ContentMainInitialize(params, content_main_runner);
|
|
|
|
+ if (exit_code >= 0)
|
|
|
|
+ return exit_code;
|
|
|
|
+ exit_code = ContentMainRun(params, content_main_runner);
|
2021-02-11 23:12:15 +01:00
|
|
|
+
|
|
|
|
+#if defined(OS_MAC)
|
|
|
|
+ params.autorelease_pool = nullptr;
|
|
|
|
+ autorelease_pool.reset();
|
|
|
|
#endif
|
2020-10-08 21:54:42 +02:00
|
|
|
|
2021-02-11 23:12:15 +01:00
|
|
|
+ ContentMainShutdown(params, content_main_runner);
|
|
|
|
+
|
2020-10-08 21:54:42 +02:00
|
|
|
return exit_code;
|
|
|
|
}
|
|
|
|
|
|
|
|
-int ContentMain(const ContentMainParams& params) {
|
|
|
|
+int ContentMain(ContentMainParams& params) {
|
|
|
|
auto runner = ContentMainRunner::Create();
|
|
|
|
return RunContentProcess(params, runner.get());
|
|
|
|
}
|
|
|
|
diff --git content/app/content_main_runner_impl.cc content/app/content_main_runner_impl.cc
|
2021-02-11 23:12:15 +01:00
|
|
|
index 811017f5d455..57055727e83d 100644
|
2020-10-08 21:54:42 +02:00
|
|
|
--- content/app/content_main_runner_impl.cc
|
|
|
|
+++ content/app/content_main_runner_impl.cc
|
2021-01-28 00:13:12 +01:00
|
|
|
@@ -48,6 +48,7 @@
|
2020-10-08 21:54:42 +02:00
|
|
|
#include "base/task/post_task.h"
|
|
|
|
#include "base/task/thread_pool/thread_pool_instance.h"
|
|
|
|
#include "base/threading/hang_watcher.h"
|
|
|
|
+#include "base/threading/thread_restrictions.h"
|
|
|
|
#include "base/trace_event/trace_event.h"
|
|
|
|
#include "components/discardable_memory/service/discardable_shared_memory_manager.h"
|
|
|
|
#include "components/download/public/common/download_task_runner.h"
|
2021-01-28 00:13:12 +01:00
|
|
|
@@ -1089,6 +1090,11 @@ void ContentMainRunnerImpl::Shutdown() {
|
2020-10-08 21:54:42 +02:00
|
|
|
is_shutdown_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
+void ContentMainRunnerImpl::ShutdownOnUIThread() {
|
|
|
|
+ base::ScopedAllowBaseSyncPrimitivesForTesting allow_wait;
|
|
|
|
+ discardable_shared_memory_manager_.reset();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
// static
|
|
|
|
std::unique_ptr<ContentMainRunner> ContentMainRunner::Create() {
|
|
|
|
return ContentMainRunnerImpl::Create();
|
|
|
|
diff --git content/app/content_main_runner_impl.h content/app/content_main_runner_impl.h
|
2021-01-28 00:13:12 +01:00
|
|
|
index 86c624e53cf9..090171f7db22 100644
|
2020-10-08 21:54:42 +02:00
|
|
|
--- content/app/content_main_runner_impl.h
|
|
|
|
+++ content/app/content_main_runner_impl.h
|
2020-12-02 23:31:49 +01:00
|
|
|
@@ -39,7 +39,7 @@ class ContentMainDelegate;
|
2021-01-28 00:13:12 +01:00
|
|
|
class MojoIpcSupport;
|
2020-12-02 23:31:49 +01:00
|
|
|
struct ContentMainParams;
|
2020-10-08 21:54:42 +02:00
|
|
|
|
|
|
|
-class ContentMainRunnerImpl : public ContentMainRunner {
|
|
|
|
+class CONTENT_EXPORT ContentMainRunnerImpl : public ContentMainRunner {
|
|
|
|
public:
|
|
|
|
static std::unique_ptr<ContentMainRunnerImpl> Create();
|
|
|
|
|
2020-12-02 23:31:49 +01:00
|
|
|
@@ -53,6 +53,8 @@ class ContentMainRunnerImpl : public ContentMainRunner {
|
2021-01-28 00:13:12 +01:00
|
|
|
int Run(bool start_minimal_browser) override;
|
2020-10-08 21:54:42 +02:00
|
|
|
void Shutdown() override;
|
|
|
|
|
|
|
|
+ void ShutdownOnUIThread();
|
|
|
|
+
|
|
|
|
private:
|
2021-01-28 00:13:12 +01:00
|
|
|
int RunBrowser(MainFunctionParams& main_function_params,
|
|
|
|
bool start_minimal_browser);
|
2020-10-08 21:54:42 +02:00
|
|
|
diff --git content/common/set_process_title.cc content/common/set_process_title.cc
|
|
|
|
index 8b829a488773..a69a08869728 100644
|
|
|
|
--- content/common/set_process_title.cc
|
|
|
|
+++ content/common/set_process_title.cc
|
|
|
|
@@ -54,7 +54,7 @@ void SetProcessTitleFromCommandLine(const char** main_argv) {
|
|
|
|
bool have_argv0 = false;
|
|
|
|
|
|
|
|
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
|
|
|
|
- DCHECK_EQ(base::PlatformThread::CurrentId(), getpid());
|
|
|
|
+ // DCHECK_EQ(base::PlatformThread::CurrentId(), getpid());
|
|
|
|
|
|
|
|
if (main_argv)
|
|
|
|
setproctitle_init(main_argv);
|
|
|
|
diff --git content/public/app/content_main.h content/public/app/content_main.h
|
2021-02-11 23:12:15 +01:00
|
|
|
index 97aac3d0c758..fc795ae0287f 100644
|
2020-10-08 21:54:42 +02:00
|
|
|
--- content/public/app/content_main.h
|
|
|
|
+++ content/public/app/content_main.h
|
2021-02-11 23:12:15 +01:00
|
|
|
@@ -68,7 +68,16 @@ struct ContentMainParams {
|
2020-10-08 21:54:42 +02:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
-CONTENT_EXPORT int RunContentProcess(const ContentMainParams& params,
|
|
|
|
+// Split RunContentProcess() into separate stages.
|
|
|
|
+CONTENT_EXPORT int ContentMainInitialize(
|
|
|
|
+ ContentMainParams& params,
|
|
|
|
+ ContentMainRunner* content_main_runner);
|
|
|
|
+CONTENT_EXPORT int ContentMainRun(ContentMainParams& params,
|
|
|
|
+ ContentMainRunner* content_main_runner);
|
|
|
|
+CONTENT_EXPORT void ContentMainShutdown(ContentMainParams& params,
|
|
|
|
+ ContentMainRunner* content_main_runner);
|
|
|
|
+
|
|
|
|
+CONTENT_EXPORT int RunContentProcess(ContentMainParams& params,
|
|
|
|
ContentMainRunner* content_main_runner);
|
|
|
|
|
|
|
|
#if defined(OS_ANDROID)
|
2021-02-11 23:12:15 +01:00
|
|
|
@@ -91,7 +100,7 @@ ContentMainDelegate* GetContentMainDelegate();
|
2020-10-08 21:54:42 +02:00
|
|
|
// 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
|