2017-04-20 21:28:17 +02:00
|
|
|
diff --git services/service_manager/embedder/main.cc services/service_manager/embedder/main.cc
|
2017-05-31 17:33:30 +02:00
|
|
|
index e661492..8a282fd 100644
|
2017-04-20 21:28:17 +02:00
|
|
|
--- services/service_manager/embedder/main.cc
|
|
|
|
+++ services/service_manager/embedder/main.cc
|
2017-05-31 17:33:30 +02:00
|
|
|
@@ -325,13 +325,30 @@ int RunService(MainDelegate* delegate) {
|
|
|
|
return exit_code;
|
|
|
|
}
|
2017-04-20 21:28:17 +02:00
|
|
|
|
2017-05-31 17:33:30 +02:00
|
|
|
+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
|
2017-04-20 21:28:17 +02:00
|
|
|
|
2017-05-31 17:33:30 +02:00
|
|
|
MainParams::MainParams(MainDelegate* delegate) : delegate(delegate) {}
|
2017-04-20 21:28:17 +02:00
|
|
|
|
|
|
|
MainParams::~MainParams() {}
|
|
|
|
|
|
|
|
-int Main(const MainParams& params) {
|
|
|
|
+int MainInitialize(MainParams& params) {
|
|
|
|
MainDelegate* delegate = params.delegate;
|
|
|
|
DCHECK(delegate);
|
|
|
|
|
2017-05-31 17:33:30 +02:00
|
|
|
@@ -399,30 +416,14 @@ int Main(const MainParams& params) {
|
2017-04-28 23:49:23 +02:00
|
|
|
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.
|
2017-04-20 21:28:17 +02:00
|
|
|
- std::unique_ptr<base::mac::ScopedNSAutoreleasePool> autorelease_pool =
|
2017-04-28 23:49:23 +02:00
|
|
|
- base::MakeUnique<base::mac::ScopedNSAutoreleasePool>();
|
2017-04-20 21:28:17 +02:00
|
|
|
- init_params.autorelease_pool = autorelease_pool.get();
|
|
|
|
+ init_params.autorelease_pool = params.autorelease_pool.get();
|
|
|
|
InitializeMac();
|
|
|
|
#endif
|
|
|
|
|
2017-05-31 17:33:30 +02:00
|
|
|
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);
|
|
|
|
@@ -449,6 +450,16 @@ int Main(const MainParams& params) {
|
|
|
|
trace_config, base::trace_event::TraceLog::RECORDING_MODE);
|
2017-04-20 21:28:17 +02:00
|
|
|
}
|
2017-05-31 17:33:30 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
+ return exit_code;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int MainRun(MainParams& params) {
|
|
|
|
+ MainDelegate* delegate = params.delegate;
|
|
|
|
+ DCHECK(delegate);
|
2017-05-31 17:33:30 +02:00
|
|
|
+
|
|
|
|
+ int exit_code = 0;
|
|
|
|
+ const ProcessType process_type =
|
|
|
|
+ GetProcessType(delegate, *base::CommandLine::ForCurrentProcess());
|
|
|
|
switch (process_type) {
|
|
|
|
case ProcessType::kDefault:
|
|
|
|
NOTREACHED();
|
|
|
|
@@ -470,6 +481,8 @@ int Main(const MainParams& params) {
|
|
|
|
break;
|
|
|
|
}
|
2017-04-20 21:28:17 +02:00
|
|
|
|
|
|
|
+ base::debug::GlobalActivityTracker* tracker =
|
|
|
|
+ base::debug::GlobalActivityTracker::Get();
|
|
|
|
if (tracker) {
|
|
|
|
if (exit_code == 0) {
|
|
|
|
tracker->SetProcessPhaseIfEnabled(
|
2017-05-31 17:33:30 +02:00
|
|
|
@@ -481,14 +494,39 @@ int Main(const MainParams& params) {
|
2017-04-20 21:28:17 +02:00
|
|
|
}
|
|
|
|
}
|
2017-05-31 17:33:30 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
+ return exit_code;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void MainShutdown(MainParams& params) {
|
|
|
|
+ MainDelegate* delegate = params.delegate;
|
|
|
|
+ DCHECK(delegate);
|
2017-05-31 17:33:30 +02:00
|
|
|
+
|
2017-04-20 21:28:17 +02:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
- autorelease_pool.reset();
|
|
|
|
+ params.autorelease_pool.reset();
|
|
|
|
#endif
|
|
|
|
|
2017-05-31 17:33:30 +02:00
|
|
|
+ const ProcessType process_type =
|
|
|
|
+ GetProcessType(delegate, *base::CommandLine::ForCurrentProcess());
|
|
|
|
if (process_type == ProcessType::kEmbedder)
|
|
|
|
delegate->ShutDownEmbedderProcess();
|
2017-04-20 21:28:17 +02:00
|
|
|
+}
|
2017-05-31 17:33:30 +02:00
|
|
|
|
|
|
|
- return exit_code;
|
2017-04-20 21:28:17 +02:00
|
|
|
+int Main(MainParams& params) {
|
2017-04-28 23:49:23 +02:00
|
|
|
+#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
|
2017-05-31 17:33:30 +02:00
|
|
|
+
|
2017-04-20 21:28:17 +02:00
|
|
|
+ int exit_code = MainInitialize(params);
|
|
|
|
+ if (exit_code >= 0)
|
|
|
|
+ return exit_code;
|
|
|
|
+ exit_code = MainRun(params);
|
|
|
|
+ MainShutdown(params);
|
2017-05-31 17:33:30 +02:00
|
|
|
+ return exit_code;
|
2017-04-20 21:28:17 +02:00
|
|
|
}
|
|
|
|
|
2017-05-31 17:33:30 +02:00
|
|
|
} // namespace service_manager
|
2017-04-20 21:28:17 +02:00
|
|
|
diff --git services/service_manager/embedder/main.h services/service_manager/embedder/main.h
|
2017-05-31 17:33:30 +02:00
|
|
|
index e86697a..771acd8 100644
|
2017-04-20 21:28:17 +02:00
|
|
|
--- 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
|
2017-05-31 17:33:30 +02:00
|
|
|
index 80b9a0a..5162354 100644
|
2017-04-20 21:28:17 +02:00
|
|
|
--- 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);
|