2020-10-08 21:54:42 +02:00
|
|
|
diff --git content/app/content_main.cc content/app/content_main.cc
|
2023-02-24 17:14:25 +01:00
|
|
|
index f646abaa56f8b..59d4a1f0817e6 100644
|
2020-10-08 21:54:42 +02:00
|
|
|
--- content/app/content_main.cc
|
|
|
|
+++ content/app/content_main.cc
|
2023-02-24 17:14:25 +01:00
|
|
|
@@ -172,11 +172,8 @@ ContentMainParams::~ContentMainParams() = default;
|
2021-12-16 23:35:54 +01:00
|
|
|
ContentMainParams::ContentMainParams(ContentMainParams&&) = default;
|
|
|
|
ContentMainParams& ContentMainParams::operator=(ContentMainParams&&) = default;
|
2020-10-08 21:54:42 +02:00
|
|
|
|
2021-08-20 01:40:49 +02:00
|
|
|
-// 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
|
2021-12-16 23:35:54 +01:00
|
|
|
-RunContentProcess(ContentMainParams params,
|
2021-08-20 01:40:49 +02:00
|
|
|
- ContentMainRunner* content_main_runner) {
|
2021-12-16 23:35:54 +01:00
|
|
|
+int ContentMainInitialize(ContentMainParams params,
|
2020-10-08 21:54:42 +02:00
|
|
|
+ ContentMainRunner* content_main_runner) {
|
2023-01-03 00:34:43 +01:00
|
|
|
base::FeatureList::FailOnFeatureAccessWithoutFeatureList();
|
2022-03-26 02:12:30 +01:00
|
|
|
#if BUILDFLAG(IS_CHROMEOS_LACROS)
|
|
|
|
// Lacros is launched with inherited priority. Revert to normal priority
|
2023-02-24 17:14:25 +01:00
|
|
|
@@ -185,9 +182,6 @@ RunContentProcess(ContentMainParams params,
|
2022-03-26 02:12:30 +01:00
|
|
|
#endif
|
2020-10-08 21:54:42 +02:00
|
|
|
int exit_code = -1;
|
|
|
|
base::debug::GlobalActivityTracker* tracker = nullptr;
|
2022-01-25 21:26:51 +01:00
|
|
|
-#if BUILDFLAG(IS_MAC)
|
2020-10-08 21:54:42 +02:00
|
|
|
- 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
|
2023-02-24 17:14:25 +01:00
|
|
|
@@ -273,12 +267,6 @@ RunContentProcess(ContentMainParams params,
|
2021-02-11 23:12:15 +01:00
|
|
|
#endif
|
|
|
|
|
2022-01-25 21:26:51 +01:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2021-02-11 23:12:15 +01:00
|
|
|
- // 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>();
|
2021-12-16 23:35:54 +01:00
|
|
|
- params.autorelease_pool = autorelease_pool.get();
|
2020-10-08 21:54:42 +02:00
|
|
|
InitializeMac();
|
|
|
|
#endif
|
|
|
|
|
2023-02-24 17:14:25 +01:00
|
|
|
@@ -318,8 +306,18 @@ RunContentProcess(ContentMainParams params,
|
2020-10-08 21:54:42 +02:00
|
|
|
|
|
|
|
if (IsSubprocess())
|
|
|
|
CommonSubprocessInit();
|
2021-12-16 23:35:54 +01:00
|
|
|
- exit_code = content_main_runner->Run();
|
2020-10-08 21:54:42 +02:00
|
|
|
|
|
|
|
+ return exit_code;
|
|
|
|
+}
|
|
|
|
+
|
2021-08-20 01:40:49 +02:00
|
|
|
+// 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
|
2021-12-16 23:35:54 +01:00
|
|
|
+ContentMainRun(ContentMainRunner* content_main_runner) {
|
|
|
|
+ int exit_code = content_main_runner->Run();
|
2020-10-08 21:54:42 +02:00
|
|
|
+
|
|
|
|
+ base::debug::GlobalActivityTracker* tracker =
|
|
|
|
+ base::debug::GlobalActivityTracker::Get();
|
|
|
|
if (tracker) {
|
|
|
|
if (exit_code == 0) {
|
|
|
|
tracker->SetProcessPhaseIfEnabled(
|
2023-02-24 17:14:25 +01:00
|
|
|
@@ -331,14 +329,41 @@ RunContentProcess(ContentMainParams params,
|
2020-10-08 21:54:42 +02:00
|
|
|
}
|
|
|
|
}
|
2021-08-20 01:40:49 +02:00
|
|
|
|
2022-01-25 21:26:51 +01:00
|
|
|
-#if BUILDFLAG(IS_MAC)
|
2021-08-20 01:40:49 +02:00
|
|
|
- autorelease_pool.reset();
|
|
|
|
-#endif
|
2020-10-08 21:54:42 +02:00
|
|
|
+ return exit_code;
|
|
|
|
+}
|
|
|
|
|
2021-12-16 23:35:54 +01:00
|
|
|
+void ContentMainShutdown(ContentMainRunner* content_main_runner) {
|
2022-01-25 21:26:51 +01:00
|
|
|
#if !BUILDFLAG(IS_ANDROID)
|
2021-08-20 01:40:49 +02:00
|
|
|
content_main_runner->Shutdown();
|
|
|
|
#endif
|
2020-10-08 21:54:42 +02:00
|
|
|
+}
|
|
|
|
+
|
2021-08-20 01:40:49 +02:00
|
|
|
+// 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
|
2021-12-16 23:35:54 +01:00
|
|
|
+RunContentProcess(ContentMainParams params,
|
2021-08-20 01:40:49 +02:00
|
|
|
+ ContentMainRunner* content_main_runner) {
|
2022-01-25 21:26:51 +01:00
|
|
|
+#if BUILDFLAG(IS_MAC)
|
2021-02-11 23:12:15 +01:00
|
|
|
+ // 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();
|
2021-08-20 01:40:49 +02:00
|
|
|
+#endif
|
|
|
|
+
|
2021-12-16 23:35:54 +01:00
|
|
|
+ int exit_code = ContentMainInitialize(std::move(params), content_main_runner);
|
2020-10-08 21:54:42 +02:00
|
|
|
+ if (exit_code >= 0)
|
|
|
|
+ return exit_code;
|
2021-12-16 23:35:54 +01:00
|
|
|
+ exit_code = ContentMainRun(content_main_runner);
|
2021-02-11 23:12:15 +01:00
|
|
|
+
|
2022-01-25 21:26:51 +01:00
|
|
|
+#if BUILDFLAG(IS_MAC)
|
2021-02-11 23:12:15 +01:00
|
|
|
+ params.autorelease_pool = nullptr;
|
|
|
|
+ autorelease_pool.reset();
|
2021-08-20 01:40:49 +02:00
|
|
|
+#endif
|
|
|
|
|
2021-12-16 23:35:54 +01:00
|
|
|
+ ContentMainShutdown(content_main_runner);
|
2020-10-08 21:54:42 +02:00
|
|
|
return exit_code;
|
|
|
|
}
|
|
|
|
|
|
|
|
diff --git content/app/content_main_runner_impl.cc content/app/content_main_runner_impl.cc
|
2023-01-30 18:43:54 +01:00
|
|
|
index 5029cbe44e4bd..fc6616da947eb 100644
|
2020-10-08 21:54:42 +02:00
|
|
|
--- content/app/content_main_runner_impl.cc
|
|
|
|
+++ content/app/content_main_runner_impl.cc
|
2023-01-30 18:43:54 +01:00
|
|
|
@@ -46,6 +46,7 @@
|
2020-10-08 21:54:42 +02:00
|
|
|
#include "base/task/thread_pool/thread_pool_instance.h"
|
|
|
|
#include "base/threading/hang_watcher.h"
|
2021-03-04 23:36:57 +01:00
|
|
|
#include "base/threading/platform_thread.h"
|
2020-10-08 21:54:42 +02:00
|
|
|
+#include "base/threading/thread_restrictions.h"
|
2021-03-04 23:36:57 +01:00
|
|
|
#include "base/time/time.h"
|
2020-10-08 21:54:42 +02:00
|
|
|
#include "base/trace_event/trace_event.h"
|
2021-03-04 23:36:57 +01:00
|
|
|
#include "build/build_config.h"
|
2023-01-30 18:43:54 +01:00
|
|
|
@@ -1290,6 +1291,12 @@ void ContentMainRunnerImpl::Shutdown() {
|
2020-10-08 21:54:42 +02:00
|
|
|
is_shutdown_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
+void ContentMainRunnerImpl::ShutdownOnUIThread() {
|
|
|
|
+ base::ScopedAllowBaseSyncPrimitivesForTesting allow_wait;
|
2022-03-09 20:45:39 +01:00
|
|
|
+ unregister_thread_closure_.RunAndReset();
|
2020-10-08 21:54:42 +02:00
|
|
|
+ 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
|
2023-01-30 18:43:54 +01:00
|
|
|
index ea9b5233820cd..aba62b3384134 100644
|
2020-10-08 21:54:42 +02:00
|
|
|
--- content/app/content_main_runner_impl.h
|
|
|
|
+++ content/app/content_main_runner_impl.h
|
2022-11-15 18:50:53 +01:00
|
|
|
@@ -27,7 +27,7 @@ class DiscardableSharedMemoryManager;
|
2022-04-21 20:58:48 +02:00
|
|
|
namespace content {
|
2021-01-28 00:13:12 +01:00
|
|
|
class MojoIpcSupport;
|
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();
|
|
|
|
|
2022-11-15 18:50:53 +01:00
|
|
|
@@ -46,6 +46,8 @@ class ContentMainRunnerImpl : public ContentMainRunner {
|
2021-12-16 23:35:54 +01:00
|
|
|
int Run() override;
|
2020-10-08 21:54:42 +02:00
|
|
|
void Shutdown() override;
|
|
|
|
|
|
|
|
+ void ShutdownOnUIThread();
|
|
|
|
+
|
|
|
|
private:
|
2021-12-16 23:35:54 +01:00
|
|
|
int RunBrowser(MainFunctionParams main_function_params,
|
2021-01-28 00:13:12 +01:00
|
|
|
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
|
2022-09-26 21:30:45 +02:00
|
|
|
index 04a08015aaff6..694f5c43a29e1 100644
|
2020-10-08 21:54:42 +02:00
|
|
|
--- 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;
|
|
|
|
|
2022-01-25 21:26:51 +01:00
|
|
|
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
|
2020-10-08 21:54:42 +02:00
|
|
|
- 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
|
2023-01-30 18:43:54 +01:00
|
|
|
index 16e8c657ad61f..62d58b8dcccf5 100644
|
2020-10-08 21:54:42 +02:00
|
|
|
--- content/public/app/content_main.h
|
|
|
|
+++ content/public/app/content_main.h
|
2021-12-16 23:35:54 +01:00
|
|
|
@@ -93,6 +93,13 @@ struct CONTENT_EXPORT ContentMainParams {
|
|
|
|
}
|
2020-10-08 21:54:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
+// Split RunContentProcess() into separate stages.
|
|
|
|
+CONTENT_EXPORT int ContentMainInitialize(
|
2021-12-16 23:35:54 +01:00
|
|
|
+ ContentMainParams params,
|
2020-10-08 21:54:42 +02:00
|
|
|
+ ContentMainRunner* content_main_runner);
|
2021-12-16 23:35:54 +01:00
|
|
|
+CONTENT_EXPORT int ContentMainRun(ContentMainRunner* content_main_runner);
|
|
|
|
+CONTENT_EXPORT void ContentMainShutdown(ContentMainRunner* content_main_runner);
|
2020-10-08 21:54:42 +02:00
|
|
|
+
|
2021-12-16 23:35:54 +01:00
|
|
|
CONTENT_EXPORT int RunContentProcess(ContentMainParams params,
|
2020-10-08 21:54:42 +02:00
|
|
|
ContentMainRunner* content_main_runner);
|
|
|
|
|