Index: mash/runner/main.cc |
diff --git a/mash/runner/main.cc b/mash/runner/main.cc |
index 0da41cd783d6cfc770cea9fa5e4a8c94505adf7c..83d4e761e8eee870155447d7ddc26bfbb9371410 100644 |
--- a/mash/runner/main.cc |
+++ b/mash/runner/main.cc |
@@ -21,7 +21,10 @@ |
#include "base/process/launch.h" |
#include "base/run_loop.h" |
#include "base/threading/platform_thread.h" |
+#include "base/threading/thread.h" |
#include "build/build_config.h" |
+#include "mojo/edk/embedder/embedder.h" |
+#include "mojo/edk/embedder/scoped_ipc_support.h" |
#include "services/service_manager/runner/init.h" |
#include "services/service_manager/standalone/context.h" |
#include "services/service_manager/switches.h" |
@@ -53,38 +56,39 @@ int main(int argc, char** argv) { |
base::FilePath exe_path; |
base::PathService::Get(base::DIR_EXE, &exe_path); |
base::FilePath catalog_path = exe_path.Append(kMashCatalogFilename); |
- DCHECK(base::ReadFileToString(catalog_path, &catalog_contents)); |
+ bool result = base::ReadFileToString(catalog_path, &catalog_contents); |
+ DCHECK(result); |
std::unique_ptr<base::Value> manifest_value = |
base::JSONReader::Read(catalog_contents); |
DCHECK(manifest_value); |
- auto params = base::MakeUnique<service_manager::Context::InitParams>(); |
- params->static_catalog = std::move(manifest_value); |
- |
#if defined(OS_WIN) && defined(COMPONENT_BUILD) |
// In Windows component builds, ensure that loaded service binaries always |
// search this exe's dir for DLLs. |
SetDllDirectory(exe_path.value().c_str()); |
#endif |
- // We want the Context to outlive the MessageLoop so that pipes are all |
- // gracefully closed / error-out before we try to shut the Context down. |
- service_manager::Context service_manager_context; |
- { |
- base::MessageLoop message_loop; |
- base::i18n::InitializeICU(); |
- service_manager_context.Init(std::move(params)); |
+ base::i18n::InitializeICU(); |
- message_loop.task_runner()->PostTask( |
- FROM_HERE, |
- base::Bind(&service_manager::Context::RunCommandLineApplication, |
- base::Unretained(&service_manager_context))); |
+ mojo::edk::Init(); |
- base::RunLoop().Run(); |
+ base::Thread ipc_thread("IPC thread"); |
+ ipc_thread.StartWithOptions( |
+ base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
- // Must be called before |message_loop| is destroyed. |
- service_manager_context.Shutdown(); |
- } |
+ // We can use fast IPC shutdown here since service manager termination must |
+ // effectively bring down all services as well. |
+ mojo::edk::ScopedIPCSupport ipc_support( |
+ ipc_thread.task_runner(), |
+ mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST); |
+ base::MessageLoop message_loop; |
+ service_manager::Context service_manager_context(nullptr, |
+ std::move(manifest_value)); |
+ message_loop.task_runner()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&service_manager::Context::RunCommandLineApplication, |
+ base::Unretained(&service_manager_context))); |
+ base::RunLoop().Run(); |
return 0; |
} |