Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(503)

Side by Side Diff: mash/runner/main.cc

Issue 2651953002: Revert of [Service Manager] Get rid of dynamic service discovery (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mash/runner/DEPS ('k') | mash/test/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
25 #include "build/build_config.h" 24 #include "build/build_config.h"
26 #include "mojo/edk/embedder/embedder.h"
27 #include "mojo/edk/embedder/scoped_ipc_support.h"
28 #include "services/service_manager/runner/init.h" 25 #include "services/service_manager/runner/init.h"
29 #include "services/service_manager/standalone/context.h" 26 #include "services/service_manager/standalone/context.h"
30 #include "services/service_manager/switches.h" 27 #include "services/service_manager/switches.h"
31 28
32 namespace { 29 namespace {
33 30
34 const base::FilePath::CharType kMashCatalogFilename[] = 31 const base::FilePath::CharType kMashCatalogFilename[] =
35 FILE_PATH_LITERAL("mash_catalog.json"); 32 FILE_PATH_LITERAL("mash_catalog.json");
36 33
37 } // namespace 34 } // namespace
(...skipping 11 matching lines...) Expand all
49 46
50 #if !defined(OFFICIAL_BUILD) 47 #if !defined(OFFICIAL_BUILD)
51 base::debug::EnableInProcessStackDumping(); 48 base::debug::EnableInProcessStackDumping();
52 #endif 49 #endif
53 base::PlatformThread::SetName("service_manager"); 50 base::PlatformThread::SetName("service_manager");
54 51
55 std::string catalog_contents; 52 std::string catalog_contents;
56 base::FilePath exe_path; 53 base::FilePath exe_path;
57 base::PathService::Get(base::DIR_EXE, &exe_path); 54 base::PathService::Get(base::DIR_EXE, &exe_path);
58 base::FilePath catalog_path = exe_path.Append(kMashCatalogFilename); 55 base::FilePath catalog_path = exe_path.Append(kMashCatalogFilename);
59 bool result = base::ReadFileToString(catalog_path, &catalog_contents); 56 DCHECK(base::ReadFileToString(catalog_path, &catalog_contents));
60 DCHECK(result);
61 std::unique_ptr<base::Value> manifest_value = 57 std::unique_ptr<base::Value> manifest_value =
62 base::JSONReader::Read(catalog_contents); 58 base::JSONReader::Read(catalog_contents);
63 DCHECK(manifest_value); 59 DCHECK(manifest_value);
64 60
61 auto params = base::MakeUnique<service_manager::Context::InitParams>();
62 params->static_catalog = std::move(manifest_value);
63
65 #if defined(OS_WIN) && defined(COMPONENT_BUILD) 64 #if defined(OS_WIN) && defined(COMPONENT_BUILD)
66 // In Windows component builds, ensure that loaded service binaries always 65 // In Windows component builds, ensure that loaded service binaries always
67 // search this exe's dir for DLLs. 66 // search this exe's dir for DLLs.
68 SetDllDirectory(exe_path.value().c_str()); 67 SetDllDirectory(exe_path.value().c_str());
69 #endif 68 #endif
70 69
71 base::i18n::InitializeICU(); 70 // We want the Context to outlive the MessageLoop so that pipes are all
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));
72 77
73 mojo::edk::Init(); 78 message_loop.task_runner()->PostTask(
79 FROM_HERE,
80 base::Bind(&service_manager::Context::RunCommandLineApplication,
81 base::Unretained(&service_manager_context)));
74 82
75 base::Thread ipc_thread("IPC thread"); 83 base::RunLoop().Run();
76 ipc_thread.StartWithOptions(
77 base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
78 84
79 // We can use fast IPC shutdown here since service manager termination must 85 // Must be called before |message_loop| is destroyed.
80 // effectively bring down all services as well. 86 service_manager_context.Shutdown();
81 mojo::edk::ScopedIPCSupport ipc_support( 87 }
82 ipc_thread.task_runner(),
83 mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST);
84 88
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();
93 return 0; 89 return 0;
94 } 90 }
OLDNEW
« no previous file with comments | « mash/runner/DEPS ('k') | mash/test/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698