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 11 matching lines...) Expand all Loading... |
46 | 49 |
47 #if !defined(OFFICIAL_BUILD) | 50 #if !defined(OFFICIAL_BUILD) |
48 base::debug::EnableInProcessStackDumping(); | 51 base::debug::EnableInProcessStackDumping(); |
49 #endif | 52 #endif |
50 base::PlatformThread::SetName("service_manager"); | 53 base::PlatformThread::SetName("service_manager"); |
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 bool result = base::ReadFileToString(catalog_path, &catalog_contents); |
| 60 DCHECK(result); |
57 std::unique_ptr<base::Value> manifest_value = | 61 std::unique_ptr<base::Value> manifest_value = |
58 base::JSONReader::Read(catalog_contents); | 62 base::JSONReader::Read(catalog_contents); |
59 DCHECK(manifest_value); | 63 DCHECK(manifest_value); |
60 | 64 |
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) | 65 #if defined(OS_WIN) && defined(COMPONENT_BUILD) |
65 // In Windows component builds, ensure that loaded service binaries always | 66 // In Windows component builds, ensure that loaded service binaries always |
66 // search this exe's dir for DLLs. | 67 // search this exe's dir for DLLs. |
67 SetDllDirectory(exe_path.value().c_str()); | 68 SetDllDirectory(exe_path.value().c_str()); |
68 #endif | 69 #endif |
69 | 70 |
70 // We want the Context to outlive the MessageLoop so that pipes are all | 71 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 | 72 |
78 message_loop.task_runner()->PostTask( | 73 mojo::edk::Init(); |
79 FROM_HERE, | |
80 base::Bind(&service_manager::Context::RunCommandLineApplication, | |
81 base::Unretained(&service_manager_context))); | |
82 | 74 |
83 base::RunLoop().Run(); | 75 base::Thread ipc_thread("IPC thread"); |
| 76 ipc_thread.StartWithOptions( |
| 77 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
84 | 78 |
85 // Must be called before |message_loop| is destroyed. | 79 // We can use fast IPC shutdown here since service manager termination must |
86 service_manager_context.Shutdown(); | 80 // effectively bring down all services as well. |
87 } | 81 mojo::edk::ScopedIPCSupport ipc_support( |
| 82 ipc_thread.task_runner(), |
| 83 mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST); |
88 | 84 |
| 85 base::MessageLoop message_loop; |
| 86 service_manager::Context service_manager_context(nullptr, |
| 87 std::move(manifest_value)); |
| 88 message_loop.task_runner()->PostTask( |
| 89 FROM_HERE, |
| 90 base::Bind(&service_manager::Context::RunCommandLineApplication, |
| 91 base::Unretained(&service_manager_context))); |
| 92 base::RunLoop().Run(); |
89 return 0; | 93 return 0; |
90 } | 94 } |
OLD | NEW |