| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <memory> | 5 #include <memory> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/debug/debugger.h" | 12 #include "base/debug/debugger.h" |
| 13 #include "base/debug/stack_trace.h" | 13 #include "base/debug/stack_trace.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 16 #include "base/i18n/icu_util.h" | 16 #include "base/i18n/icu_util.h" |
| 17 #include "base/json/json_reader.h" | 17 #include "base/json/json_reader.h" |
| 18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 19 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
| 20 #include "base/path_service.h" | 20 #include "base/path_service.h" |
| 21 #include "base/process/launch.h" | 21 #include "base/process/launch.h" |
| 22 #include "base/run_loop.h" | 22 #include "base/run_loop.h" |
| 23 #include "base/threading/platform_thread.h" | 23 #include "base/threading/platform_thread.h" |
| 24 #include "base/threading/thread.h" |
| 24 #include "build/build_config.h" | 25 #include "build/build_config.h" |
| 26 #include "mojo/edk/embedder/embedder.h" |
| 27 #include "mojo/edk/embedder/scoped_ipc_support.h" |
| 25 #include "services/service_manager/runner/init.h" | 28 #include "services/service_manager/runner/init.h" |
| 26 #include "services/service_manager/standalone/context.h" | 29 #include "services/service_manager/standalone/context.h" |
| 27 #include "services/service_manager/switches.h" | 30 #include "services/service_manager/switches.h" |
| 28 | 31 |
| 29 namespace { | 32 namespace { |
| 30 | 33 |
| 31 const base::FilePath::CharType kMashCatalogFilename[] = | 34 const base::FilePath::CharType kMashCatalogFilename[] = |
| 32 FILE_PATH_LITERAL("mash_catalog.json"); | 35 FILE_PATH_LITERAL("mash_catalog.json"); |
| 33 | 36 |
| 34 } // namespace | 37 } // namespace |
| (...skipping 16 matching lines...) Expand all Loading... |
| 51 | 54 |
| 52 std::string catalog_contents; | 55 std::string catalog_contents; |
| 53 base::FilePath exe_path; | 56 base::FilePath exe_path; |
| 54 base::PathService::Get(base::DIR_EXE, &exe_path); | 57 base::PathService::Get(base::DIR_EXE, &exe_path); |
| 55 base::FilePath catalog_path = exe_path.Append(kMashCatalogFilename); | 58 base::FilePath catalog_path = exe_path.Append(kMashCatalogFilename); |
| 56 DCHECK(base::ReadFileToString(catalog_path, &catalog_contents)); | 59 DCHECK(base::ReadFileToString(catalog_path, &catalog_contents)); |
| 57 std::unique_ptr<base::Value> manifest_value = | 60 std::unique_ptr<base::Value> manifest_value = |
| 58 base::JSONReader::Read(catalog_contents); | 61 base::JSONReader::Read(catalog_contents); |
| 59 DCHECK(manifest_value); | 62 DCHECK(manifest_value); |
| 60 | 63 |
| 61 auto params = base::MakeUnique<service_manager::Context::InitParams>(); | |
| 62 params->static_catalog = std::move(manifest_value); | |
| 63 | |
| 64 #if defined(OS_WIN) && defined(COMPONENT_BUILD) | 64 #if defined(OS_WIN) && defined(COMPONENT_BUILD) |
| 65 // In Windows component builds, ensure that loaded service binaries always | 65 // In Windows component builds, ensure that loaded service binaries always |
| 66 // search this exe's dir for DLLs. | 66 // search this exe's dir for DLLs. |
| 67 SetDllDirectory(exe_path.value().c_str()); | 67 SetDllDirectory(exe_path.value().c_str()); |
| 68 #endif | 68 #endif |
| 69 | 69 |
| 70 // We want the Context to outlive the MessageLoop so that pipes are all | 70 base::i18n::InitializeICU(); |
| 71 // gracefully closed / error-out before we try to shut the Context down. | |
| 72 service_manager::Context service_manager_context; | |
| 73 { | |
| 74 base::MessageLoop message_loop; | |
| 75 base::i18n::InitializeICU(); | |
| 76 service_manager_context.Init(std::move(params)); | |
| 77 | 71 |
| 78 message_loop.task_runner()->PostTask( | 72 mojo::edk::Init(); |
| 79 FROM_HERE, | |
| 80 base::Bind(&service_manager::Context::RunCommandLineApplication, | |
| 81 base::Unretained(&service_manager_context))); | |
| 82 | 73 |
| 83 base::RunLoop().Run(); | 74 base::Thread ipc_thread("IPC thread"); |
| 75 ipc_thread.StartWithOptions( |
| 76 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
| 84 | 77 |
| 85 // Must be called before |message_loop| is destroyed. | 78 // We can use fast IPC shutdown here since service manager termination must |
| 86 service_manager_context.Shutdown(); | 79 // effectively bring down all services as well. |
| 87 } | 80 mojo::edk::ScopedIPCSupport ipc_support( |
| 81 ipc_thread.task_runner(), |
| 82 mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST); |
| 88 | 83 |
| 84 base::MessageLoop message_loop; |
| 85 service_manager::Context service_manager_context(nullptr, |
| 86 std::move(manifest_value)); |
| 87 message_loop.task_runner()->PostTask( |
| 88 FROM_HERE, |
| 89 base::Bind(&service_manager::Context::RunCommandLineApplication, |
| 90 base::Unretained(&service_manager_context))); |
| 91 base::RunLoop().Run(); |
| 89 return 0; | 92 return 0; |
| 90 } | 93 } |
| OLD | NEW |