cef/patch/patches/service_manager_654986.patch

193 lines
6.6 KiB
Diff

diff --git services/service_manager/embedder/main.cc services/service_manager/embedder/main.cc
index 08ea94a11772..873726c6ea19 100644
--- services/service_manager/embedder/main.cc
+++ services/service_manager/embedder/main.cc
@@ -304,13 +304,30 @@ int RunService(MainDelegate* delegate) {
return exit_code;
}
+ProcessType GetProcessType(MainDelegate* delegate,
+ const base::CommandLine& command_line) {
+ ProcessType process_type = delegate->OverrideProcessType();
+ if (process_type == ProcessType::kDefault) {
+ const std::string& type_switch =
+ command_line.GetSwitchValueASCII(switches::kProcessType);
+ if (type_switch == switches::kProcessTypeServiceManager) {
+ process_type = ProcessType::kServiceManager;
+ } else if (type_switch == switches::kProcessTypeService) {
+ process_type = ProcessType::kService;
+ } else {
+ process_type = ProcessType::kEmbedder;
+ }
+ }
+ return process_type;
+}
+
} // namespace
MainParams::MainParams(MainDelegate* delegate) : delegate(delegate) {}
MainParams::~MainParams() {}
-int Main(const MainParams& params) {
+int MainInitialize(MainParams& params) {
MainDelegate* delegate = params.delegate;
DCHECK(delegate);
@@ -378,30 +395,14 @@ int Main(const MainParams& params) {
MainDelegate::InitializeParams init_params;
#if defined(OS_MACOSX)
- // 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>();
- init_params.autorelease_pool = autorelease_pool.get();
+ init_params.autorelease_pool = params.autorelease_pool.get();
InitializeMac();
#endif
mojo::edk::Configuration mojo_config;
- ProcessType process_type = delegate->OverrideProcessType();
- if (process_type == ProcessType::kDefault) {
- std::string type_switch =
- command_line.GetSwitchValueASCII(switches::kProcessType);
- if (type_switch == switches::kProcessTypeServiceManager) {
- mojo_config.is_broker_process = true;
- process_type = ProcessType::kServiceManager;
- } else if (type_switch == switches::kProcessTypeService) {
- process_type = ProcessType::kService;
- } else {
- process_type = ProcessType::kEmbedder;
- }
- }
+ const ProcessType process_type = GetProcessType(delegate, command_line);
+ if (process_type == ProcessType::kServiceManager)
+ mojo_config.is_broker_process = true;
mojo_config.max_message_num_bytes = kMaximumMojoMessageSize;
delegate->OverrideMojoConfiguration(&mojo_config);
mojo::edk::Init(mojo_config);
@@ -436,6 +437,16 @@ int Main(const MainParams& params) {
trace_config, base::trace_event::TraceLog::RECORDING_MODE);
}
+ return exit_code;
+}
+
+int MainRun(MainParams& params) {
+ MainDelegate* delegate = params.delegate;
+ DCHECK(delegate);
+
+ int exit_code = 0;
+ const ProcessType process_type =
+ GetProcessType(delegate, *base::CommandLine::ForCurrentProcess());
switch (process_type) {
case ProcessType::kDefault:
NOTREACHED();
@@ -457,6 +468,8 @@ int Main(const MainParams& params) {
break;
}
+ base::debug::GlobalActivityTracker* tracker =
+ base::debug::GlobalActivityTracker::Get();
if (tracker) {
if (exit_code == 0) {
tracker->SetProcessPhaseIfEnabled(
@@ -468,13 +481,38 @@ int Main(const MainParams& params) {
}
}
+ return exit_code;
+}
+
+void MainShutdown(MainParams& params) {
+ MainDelegate* delegate = params.delegate;
+ DCHECK(delegate);
+
#if defined(OS_MACOSX)
- autorelease_pool.reset();
+ params.autorelease_pool.reset();
#endif
+ const ProcessType process_type =
+ GetProcessType(delegate, *base::CommandLine::ForCurrentProcess());
if (process_type == ProcessType::kEmbedder)
delegate->ShutDownEmbedderProcess();
+}
+int Main(MainParams& params) {
+#if defined(OS_MACOSX)
+ // 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.
+ params.autorelease_pool =
+ base::MakeUnique<base::mac::ScopedNSAutoreleasePool>();
+#endif
+
+ int exit_code = MainInitialize(params);
+ if (exit_code >= 0)
+ return exit_code;
+ exit_code = MainRun(params);
+ MainShutdown(params);
return exit_code;
}
diff --git services/service_manager/embedder/main.h services/service_manager/embedder/main.h
index e86697a26d0f..771acd80a3e1 100644
--- services/service_manager/embedder/main.h
+++ services/service_manager/embedder/main.h
@@ -5,9 +5,15 @@
#ifndef SERVICES_SERVICE_MANAGER_EMBEDDER_MAIN_H_
#define SERVICES_SERVICE_MANAGER_EMBEDDER_MAIN_H_
+#include <memory>
+
#include "build/build_config.h"
#include "services/service_manager/embedder/service_manager_embedder_export.h"
+#if defined(OS_MACOSX)
+#include "base/mac/scoped_nsautorelease_pool.h"
+#endif // defined(OS_MACOSX)
+
namespace service_manager {
class MainDelegate;
@@ -22,11 +28,20 @@ struct SERVICE_MANAGER_EMBEDDER_EXPORT MainParams {
int argc = 0;
const char** argv = nullptr;
#endif
+
+#if defined(OS_MACOSX)
+ std::unique_ptr<base::mac::ScopedNSAutoreleasePool> autorelease_pool;
+#endif
};
+// Split Main() into separate stages.
+int SERVICE_MANAGER_EMBEDDER_EXPORT MainInitialize(MainParams& params);
+int SERVICE_MANAGER_EMBEDDER_EXPORT MainRun(MainParams& params);
+void SERVICE_MANAGER_EMBEDDER_EXPORT MainShutdown(MainParams& params);
+
// Main function which should be called as early as possible by any executable
// embedding the service manager.
-int SERVICE_MANAGER_EMBEDDER_EXPORT Main(const MainParams& params);
+int SERVICE_MANAGER_EMBEDDER_EXPORT Main(MainParams& params);
} // namespace service_manager
diff --git services/service_manager/embedder/set_process_title.cc services/service_manager/embedder/set_process_title.cc
index 1dc53b847ef9..5432ab02a088 100644
--- services/service_manager/embedder/set_process_title.cc
+++ services/service_manager/embedder/set_process_title.cc
@@ -44,7 +44,7 @@ void SetProcessTitleFromCommandLine(const char** main_argv) {
bool have_argv0 = false;
#if defined(OS_LINUX)
- DCHECK_EQ(base::PlatformThread::CurrentId(), getpid());
+ //DCHECK_EQ(base::PlatformThread::CurrentId(), getpid());
if (main_argv)
setproctitle_init(main_argv);