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 "chrome/app/mash/mash_runner.h" | 5 #include "chrome/app/mash/mash_runner.h" |
6 | 6 |
7 #include "ash/mus/window_manager_application.h" | 7 #include "ash/mus/window_manager_application.h" |
8 #include "ash/sysui/sysui_application.h" | 8 #include "ash/sysui/sysui_application.h" |
9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/debug/debugger.h" | 12 #include "base/debug/debugger.h" |
13 #include "base/i18n/icu_util.h" | 13 #include "base/i18n/icu_util.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/process/launch.h" | 17 #include "base/process/launch.h" |
18 #include "content/public/common/content_switches.h" | 18 #include "content/public/common/content_switches.h" |
19 #include "mash/app_driver/app_driver.h" | 19 #include "mash/app_driver/app_driver.h" |
20 #include "mash/quick_launch/quick_launch_application.h" | 20 #include "mash/quick_launch/quick_launch_application.h" |
21 #include "mash/session/session.h" | 21 #include "mash/session/session.h" |
22 #include "mash/task_viewer/task_viewer.h" | 22 #include "mash/task_viewer/task_viewer.h" |
23 #include "mojo/public/cpp/bindings/binding_set.h" | 23 #include "mojo/public/cpp/bindings/binding_set.h" |
24 #include "services/shell/background/background_shell.h" | 24 #include "services/shell/background/background_shell.h" |
25 #include "services/shell/native_runner_delegate.h" | 25 #include "services/shell/native_runner_delegate.h" |
26 #include "services/shell/public/cpp/connector.h" | 26 #include "services/shell/public/cpp/connector.h" |
27 #include "services/shell/public/cpp/identity.h" | 27 #include "services/shell/public/cpp/identity.h" |
28 #include "services/shell/public/cpp/shell_client.h" | 28 #include "services/shell/public/cpp/service.h" |
29 #include "services/shell/public/cpp/shell_connection.h" | 29 #include "services/shell/public/cpp/shell_connection.h" |
30 #include "services/shell/public/interfaces/shell_client_factory.mojom.h" | 30 #include "services/shell/public/interfaces/service_factory.mojom.h" |
31 #include "services/shell/runner/common/switches.h" | 31 #include "services/shell/runner/common/switches.h" |
32 #include "services/shell/runner/host/child_process_base.h" | 32 #include "services/shell/runner/host/child_process_base.h" |
33 #include "services/ui/service.h" | 33 #include "services/ui/service.h" |
34 | 34 |
35 #if defined(OS_LINUX) | 35 #if defined(OS_LINUX) |
36 #include "components/font_service/font_service_app.h" | 36 #include "components/font_service/font_service_app.h" |
37 #endif | 37 #endif |
38 | 38 |
39 using shell::mojom::ShellClientFactory; | 39 using shell::mojom::ServiceFactory; |
40 | 40 |
41 namespace { | 41 namespace { |
42 | 42 |
43 // kProcessType used to identify child processes. | 43 // kProcessType used to identify child processes. |
44 const char* kMashChild = "mash-child"; | 44 const char* kMashChild = "mash-child"; |
45 | 45 |
46 // ShellClient responsible for starting the appropriate app. | 46 // Service responsible for starting the appropriate app. |
47 class DefaultShellClient : public shell::ShellClient, | 47 class DefaultService : public shell::Service, |
48 public ShellClientFactory, | 48 public ServiceFactory, |
49 public shell::InterfaceFactory<ShellClientFactory> { | 49 public shell::InterfaceFactory<ServiceFactory> { |
50 public: | 50 public: |
51 DefaultShellClient() {} | 51 DefaultService() {} |
52 ~DefaultShellClient() override {} | 52 ~DefaultService() override {} |
53 | 53 |
54 // shell::ShellClient: | 54 // shell::Service: |
55 bool AcceptConnection(shell::Connection* connection) override { | 55 bool OnConnect(shell::Connection* connection) override { |
56 connection->AddInterface<ShellClientFactory>(this); | 56 connection->AddInterface<ServiceFactory>(this); |
57 return true; | 57 return true; |
58 } | 58 } |
59 | 59 |
60 // shell::InterfaceFactory<ShellClientFactory> | 60 // shell::InterfaceFactory<ServiceFactory> |
61 void Create(shell::Connection* connection, | 61 void Create(shell::Connection* connection, |
62 mojo::InterfaceRequest<ShellClientFactory> request) override { | 62 mojo::InterfaceRequest<ServiceFactory> request) override { |
63 shell_client_factory_bindings_.AddBinding(this, std::move(request)); | 63 service_factory_bindings_.AddBinding(this, std::move(request)); |
64 } | 64 } |
65 | 65 |
66 // ShellClientFactory: | 66 // ServiceFactory: |
67 void CreateShellClient(shell::mojom::ShellClientRequest request, | 67 void CreateService(shell::mojom::ServiceRequest request, |
68 const mojo::String& mojo_name) override { | 68 const mojo::String& mojo_name) override { |
69 if (shell_client_) { | 69 if (service_) { |
70 LOG(ERROR) << "request to create additional app " << mojo_name; | 70 LOG(ERROR) << "request to create additional service " << mojo_name; |
71 return; | 71 return; |
72 } | 72 } |
73 shell_client_ = CreateShellClient(mojo_name); | 73 service_ = CreateService(mojo_name); |
74 if (shell_client_) { | 74 if (service_) { |
75 shell_connection_.reset( | 75 shell_connection_.reset( |
76 new shell::ShellConnection(shell_client_.get(), std::move(request))); | 76 new shell::ShellConnection(service_.get(), std::move(request))); |
77 return; | 77 return; |
78 } | 78 } |
79 LOG(ERROR) << "unknown name " << mojo_name; | 79 LOG(ERROR) << "unknown name " << mojo_name; |
80 NOTREACHED(); | 80 NOTREACHED(); |
81 } | 81 } |
82 | 82 |
83 private: | 83 private: |
84 // TODO(sky): move this into mash. | 84 // TODO(sky): move this into mash. |
85 std::unique_ptr<shell::ShellClient> CreateShellClient( | 85 std::unique_ptr<shell::Service> CreateService( |
86 const std::string& name) { | 86 const std::string& name) { |
87 if (name == "mojo:ash_sysui") | 87 if (name == "mojo:ash_sysui") |
88 return base::WrapUnique(new ash::sysui::SysUIApplication); | 88 return base::WrapUnique(new ash::sysui::SysUIApplication); |
89 if (name == "mojo:ash") | 89 if (name == "mojo:ash") |
90 return base::WrapUnique(new ash::mus::WindowManagerApplication); | 90 return base::WrapUnique(new ash::mus::WindowManagerApplication); |
91 if (name == "mojo:mash_session") | 91 if (name == "mojo:mash_session") |
92 return base::WrapUnique(new mash::session::Session); | 92 return base::WrapUnique(new mash::session::Session); |
93 if (name == "mojo:ui") | 93 if (name == "mojo:ui") |
94 return base::WrapUnique(new ui::Service); | 94 return base::WrapUnique(new ui::Service); |
95 if (name == "mojo:quick_launch") | 95 if (name == "mojo:quick_launch") |
96 return base::WrapUnique(new mash::quick_launch::QuickLaunchApplication); | 96 return base::WrapUnique(new mash::quick_launch::QuickLaunchApplication); |
97 if (name == "mojo:task_viewer") | 97 if (name == "mojo:task_viewer") |
98 return base::WrapUnique(new mash::task_viewer::TaskViewer); | 98 return base::WrapUnique(new mash::task_viewer::TaskViewer); |
99 #if defined(OS_LINUX) | 99 #if defined(OS_LINUX) |
100 if (name == "mojo:font_service") | 100 if (name == "mojo:font_service") |
101 return base::WrapUnique(new font_service::FontServiceApp); | 101 return base::WrapUnique(new font_service::FontServiceApp); |
102 #endif | 102 #endif |
103 if (name == "mojo:app_driver") { | 103 if (name == "mojo:app_driver") { |
104 return base::WrapUnique(new mash::app_driver::AppDriver()); | 104 return base::WrapUnique(new mash::app_driver::AppDriver()); |
105 } | 105 } |
106 return nullptr; | 106 return nullptr; |
107 } | 107 } |
108 | 108 |
109 mojo::BindingSet<ShellClientFactory> shell_client_factory_bindings_; | 109 mojo::BindingSet<ServiceFactory> service_factory_bindings_; |
110 std::unique_ptr<shell::ShellClient> shell_client_; | 110 std::unique_ptr<shell::Service> service_; |
111 std::unique_ptr<shell::ShellConnection> shell_connection_; | 111 std::unique_ptr<shell::ShellConnection> shell_connection_; |
112 | 112 |
113 DISALLOW_COPY_AND_ASSIGN(DefaultShellClient); | 113 DISALLOW_COPY_AND_ASSIGN(DefaultService); |
114 }; | 114 }; |
115 | 115 |
116 bool IsChild() { | 116 bool IsChild() { |
117 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 117 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
118 switches::kProcessType) && | 118 switches::kProcessType) && |
119 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 119 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
120 switches::kProcessType) == kMashChild; | 120 switches::kProcessType) == kMashChild; |
121 } | 121 } |
122 | 122 |
123 // Convert the command line program from chrome_mash to chrome. This is | 123 // Convert the command line program from chrome_mash to chrome. This is |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 void MashRunner::RunMain() { | 179 void MashRunner::RunMain() { |
180 // TODO(sky): refactor backgroundshell so can supply own context, we | 180 // TODO(sky): refactor backgroundshell so can supply own context, we |
181 // shouldn't we using context as it has a lot of stuff we don't really want | 181 // shouldn't we using context as it has a lot of stuff we don't really want |
182 // in chrome. | 182 // in chrome. |
183 NativeRunnerDelegateImpl native_runner_delegate; | 183 NativeRunnerDelegateImpl native_runner_delegate; |
184 shell::BackgroundShell background_shell; | 184 shell::BackgroundShell background_shell; |
185 std::unique_ptr<shell::BackgroundShell::InitParams> init_params( | 185 std::unique_ptr<shell::BackgroundShell::InitParams> init_params( |
186 new shell::BackgroundShell::InitParams); | 186 new shell::BackgroundShell::InitParams); |
187 init_params->native_runner_delegate = &native_runner_delegate; | 187 init_params->native_runner_delegate = &native_runner_delegate; |
188 background_shell.Init(std::move(init_params)); | 188 background_shell.Init(std::move(init_params)); |
189 shell_client_.reset(new DefaultShellClient); | 189 service_.reset(new DefaultService); |
190 shell_connection_.reset(new shell::ShellConnection( | 190 shell_connection_.reset(new shell::ShellConnection( |
191 shell_client_.get(), | 191 service_.get(), |
192 background_shell.CreateShellClientRequest("exe:chrome_mash"))); | 192 background_shell.CreateServiceRequest("exe:chrome_mash"))); |
193 shell_connection_->connector()->Connect("mojo:mash_session"); | 193 shell_connection_->connector()->Connect("mojo:mash_session"); |
194 base::MessageLoop::current()->Run(); | 194 base::MessageLoop::current()->Run(); |
195 } | 195 } |
196 | 196 |
197 void MashRunner::RunChild() { | 197 void MashRunner::RunChild() { |
198 base::i18n::InitializeICU(); | 198 base::i18n::InitializeICU(); |
199 shell::ChildProcessMainWithCallback( | 199 shell::ChildProcessMainWithCallback( |
200 base::Bind(&MashRunner::StartChildApp, base::Unretained(this))); | 200 base::Bind(&MashRunner::StartChildApp, base::Unretained(this))); |
201 } | 201 } |
202 | 202 |
203 void MashRunner::StartChildApp( | 203 void MashRunner::StartChildApp( |
204 shell::mojom::ShellClientRequest client_request) { | 204 shell::mojom::ServiceRequest service_request) { |
205 // TODO(sky): use MessagePumpMojo. | 205 // TODO(sky): use MessagePumpMojo. |
206 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI); | 206 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI); |
207 shell_client_.reset(new DefaultShellClient); | 207 service_.reset(new DefaultService); |
208 shell_connection_.reset(new shell::ShellConnection( | 208 shell_connection_.reset(new shell::ShellConnection( |
209 shell_client_.get(), std::move(client_request))); | 209 service_.get(), std::move(service_request))); |
210 message_loop.Run(); | 210 message_loop.Run(); |
211 } | 211 } |
212 | 212 |
213 int MashMain() { | 213 int MashMain() { |
214 #if defined(OS_WIN) | 214 #if defined(OS_WIN) |
215 base::RouteStdioToConsole(false); | 215 base::RouteStdioToConsole(false); |
216 #endif | 216 #endif |
217 // TODO(sky): wire this up correctly. | 217 // TODO(sky): wire this up correctly. |
218 logging::LoggingSettings settings; | 218 logging::LoggingSettings settings; |
219 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 219 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
220 logging::InitLogging(settings); | 220 logging::InitLogging(settings); |
221 // To view log output with IDs and timestamps use "adb logcat -v threadtime". | 221 // To view log output with IDs and timestamps use "adb logcat -v threadtime". |
222 logging::SetLogItems(true, // Process ID | 222 logging::SetLogItems(true, // Process ID |
223 true, // Thread ID | 223 true, // Thread ID |
224 true, // Timestamp | 224 true, // Timestamp |
225 true); // Tick count | 225 true); // Tick count |
226 | 226 |
227 // TODO(sky): use MessagePumpMojo. | 227 // TODO(sky): use MessagePumpMojo. |
228 std::unique_ptr<base::MessageLoop> message_loop; | 228 std::unique_ptr<base::MessageLoop> message_loop; |
229 #if defined(OS_LINUX) | 229 #if defined(OS_LINUX) |
230 base::AtExitManager exit_manager; | 230 base::AtExitManager exit_manager; |
231 #endif | 231 #endif |
232 if (!IsChild()) | 232 if (!IsChild()) |
233 message_loop.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI)); | 233 message_loop.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI)); |
234 MashRunner mash_runner; | 234 MashRunner mash_runner; |
235 mash_runner.Run(); | 235 mash_runner.Run(); |
236 return 0; | 236 return 0; |
237 } | 237 } |
OLD | NEW |