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

Side by Side Diff: chrome/app/mash/mash_runner.cc

Issue 2295433003: Changes around how browser_tests are launched for mash (Closed)
Patch Set: make manifest chromeos specific Created 4 years, 3 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 | « chrome/app/mash/BUILD.gn ('k') | chrome/test/BUILD.gn » ('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 "chrome/app/mash/mash_runner.h" 5 #include "chrome/app/mash/mash_runner.h"
6 6
7 #include "ash/mus/window_manager_application.h"
8 #include "ash/touch_hud/mus/touch_hud_application.h"
9 #include "base/at_exit.h" 7 #include "base/at_exit.h"
10 #include "base/bind.h" 8 #include "base/bind.h"
11 #include "base/command_line.h" 9 #include "base/command_line.h"
12 #include "base/debug/debugger.h" 10 #include "base/debug/debugger.h"
13 #include "base/i18n/icu_util.h" 11 #include "base/i18n/icu_util.h"
14 #include "base/logging.h" 12 #include "base/logging.h"
15 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
16 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
17 #include "base/process/launch.h" 15 #include "base/process/launch.h"
18 #include "base/trace_event/trace_event.h" 16 #include "base/trace_event/trace_event.h"
19 #include "components/tracing/common/trace_to_console.h" 17 #include "components/tracing/common/trace_to_console.h"
20 #include "components/tracing/common/tracing_switches.h" 18 #include "components/tracing/common/tracing_switches.h"
21 #include "content/public/common/content_switches.h" 19 #include "content/public/common/content_switches.h"
22 #include "mash/app_driver/app_driver.h" 20 #include "mash/package/mash_packaged_service.h"
23 #include "mash/quick_launch/quick_launch.h"
24 #include "mash/session/session.h"
25 #include "mash/task_viewer/task_viewer.h"
26 #include "mojo/public/cpp/bindings/binding_set.h" 21 #include "mojo/public/cpp/bindings/binding_set.h"
27 #include "services/shell/background/background_shell.h" 22 #include "services/shell/background/background_shell.h"
28 #include "services/shell/native_runner_delegate.h" 23 #include "services/shell/native_runner_delegate.h"
29 #include "services/shell/public/cpp/connector.h" 24 #include "services/shell/public/cpp/connector.h"
30 #include "services/shell/public/cpp/identity.h" 25 #include "services/shell/public/cpp/identity.h"
31 #include "services/shell/public/cpp/service.h" 26 #include "services/shell/public/cpp/service.h"
32 #include "services/shell/public/cpp/service_context.h" 27 #include "services/shell/public/cpp/service_context.h"
33 #include "services/shell/public/interfaces/service_factory.mojom.h" 28 #include "services/shell/public/interfaces/service_factory.mojom.h"
34 #include "services/shell/runner/common/switches.h" 29 #include "services/shell/runner/common/switches.h"
35 #include "services/shell/runner/host/child_process_base.h" 30 #include "services/shell/runner/host/child_process_base.h"
36 #include "services/ui/service.h"
37
38 #if defined(OS_LINUX)
39 #include "components/font_service/font_service_app.h"
40 #endif
41 31
42 using shell::mojom::ServiceFactory; 32 using shell::mojom::ServiceFactory;
43 33
44 namespace { 34 namespace {
45 35
46 // kProcessType used to identify child processes. 36 // kProcessType used to identify child processes.
47 const char* kMashChild = "mash-child"; 37 const char* kMashChild = "mash-child";
48 38
49 // Service responsible for starting the appropriate app.
50 class DefaultService : public shell::Service,
51 public ServiceFactory,
52 public shell::InterfaceFactory<ServiceFactory> {
53 public:
54 DefaultService() {}
55 ~DefaultService() override {}
56
57 // shell::Service:
58 bool OnConnect(const shell::Identity& remote_identity,
59 shell::InterfaceRegistry* registry) override {
60 registry->AddInterface<ServiceFactory>(this);
61 return true;
62 }
63
64 // shell::InterfaceFactory<ServiceFactory>
65 void Create(const shell::Identity& remote_identity,
66 mojo::InterfaceRequest<ServiceFactory> request) override {
67 service_factory_bindings_.AddBinding(this, std::move(request));
68 }
69
70 // ServiceFactory:
71 void CreateService(shell::mojom::ServiceRequest request,
72 const std::string& mojo_name) override {
73 if (service_) {
74 LOG(ERROR) << "request to create additional service " << mojo_name;
75 return;
76 }
77 service_ = CreateService(mojo_name);
78 if (service_) {
79 service_->set_context(base::MakeUnique<shell::ServiceContext>(
80 service_.get(), std::move(request)));
81 return;
82 }
83 LOG(ERROR) << "unknown name " << mojo_name;
84 NOTREACHED();
85 }
86
87 private:
88 // TODO(sky): move this into mash.
89 std::unique_ptr<shell::Service> CreateService(
90 const std::string& name) {
91 if (name == "mojo:ash")
92 return base::WrapUnique(new ash::mus::WindowManagerApplication);
93 if (name == "mojo:touch_hud")
94 return base::WrapUnique(new ash::touch_hud::TouchHudApplication);
95 if (name == "mojo:mash_session")
96 return base::WrapUnique(new mash::session::Session);
97 if (name == "mojo:ui")
98 return base::WrapUnique(new ui::Service);
99 if (name == "mojo:quick_launch")
100 return base::WrapUnique(new mash::quick_launch::QuickLaunch);
101 if (name == "mojo:task_viewer")
102 return base::WrapUnique(new mash::task_viewer::TaskViewer);
103 #if defined(OS_LINUX)
104 if (name == "mojo:font_service")
105 return base::WrapUnique(new font_service::FontServiceApp);
106 #endif
107 if (name == "mojo:app_driver")
108 return base::WrapUnique(new mash::app_driver::AppDriver);
109 return nullptr;
110 }
111
112 mojo::BindingSet<ServiceFactory> service_factory_bindings_;
113 std::unique_ptr<shell::Service> service_;
114
115 DISALLOW_COPY_AND_ASSIGN(DefaultService);
116 };
117
118 bool IsChild() { 39 bool IsChild() {
119 return base::CommandLine::ForCurrentProcess()->HasSwitch( 40 return base::CommandLine::ForCurrentProcess()->HasSwitch(
120 switches::kProcessType) && 41 switches::kProcessType) &&
121 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 42 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
122 switches::kProcessType) == kMashChild; 43 switches::kProcessType) == kMashChild;
123 } 44 }
124 45
125 // Convert the command line program from chrome_mash to chrome. This is 46 // Convert the command line program from chrome_mash to chrome. This is
126 // necessary as the shell will attempt to start chrome_mash. We want chrome. 47 // necessary as the shell will attempt to start chrome_mash. We want chrome.
127 void ChangeChromeMashToChrome(base::CommandLine* command_line) { 48 void ChangeChromeMashToChrome(base::CommandLine* command_line) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 void MashRunner::RunMain() { 102 void MashRunner::RunMain() {
182 // TODO(sky): refactor backgroundshell so can supply own context, we 103 // TODO(sky): refactor backgroundshell so can supply own context, we
183 // shouldn't we using context as it has a lot of stuff we don't really want 104 // shouldn't we using context as it has a lot of stuff we don't really want
184 // in chrome. 105 // in chrome.
185 NativeRunnerDelegateImpl native_runner_delegate; 106 NativeRunnerDelegateImpl native_runner_delegate;
186 shell::BackgroundShell background_shell; 107 shell::BackgroundShell background_shell;
187 std::unique_ptr<shell::BackgroundShell::InitParams> init_params( 108 std::unique_ptr<shell::BackgroundShell::InitParams> init_params(
188 new shell::BackgroundShell::InitParams); 109 new shell::BackgroundShell::InitParams);
189 init_params->native_runner_delegate = &native_runner_delegate; 110 init_params->native_runner_delegate = &native_runner_delegate;
190 background_shell.Init(std::move(init_params)); 111 background_shell.Init(std::move(init_params));
191 service_.reset(new DefaultService); 112 service_.reset(new mash::MashPackagedService);
192 service_->set_context(base::MakeUnique<shell::ServiceContext>( 113 service_->set_context(base::MakeUnique<shell::ServiceContext>(
193 service_.get(), 114 service_.get(),
194 background_shell.CreateServiceRequest("exe:chrome_mash"))); 115 background_shell.CreateServiceRequest("exe:chrome_mash")));
195 service_->connector()->Connect("mojo:mash_session"); 116 service_->connector()->Connect("mojo:mash_session");
196 base::MessageLoop::current()->Run(); 117 base::MessageLoop::current()->Run();
197 } 118 }
198 119
199 void MashRunner::RunChild() { 120 void MashRunner::RunChild() {
200 base::i18n::InitializeICU(); 121 base::i18n::InitializeICU();
201 shell::ChildProcessMainWithCallback( 122 shell::ChildProcessMainWithCallback(
202 base::Bind(&MashRunner::StartChildApp, base::Unretained(this))); 123 base::Bind(&MashRunner::StartChildApp, base::Unretained(this)));
203 } 124 }
204 125
205 void MashRunner::StartChildApp( 126 void MashRunner::StartChildApp(
206 shell::mojom::ServiceRequest service_request) { 127 shell::mojom::ServiceRequest service_request) {
207 // TODO(sky): use MessagePumpMojo. 128 // TODO(sky): use MessagePumpMojo.
208 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI); 129 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI);
209 service_.reset(new DefaultService); 130 service_.reset(new mash::MashPackagedService);
210 service_->set_context(base::MakeUnique<shell::ServiceContext>( 131 service_->set_context(base::MakeUnique<shell::ServiceContext>(
211 service_.get(), std::move(service_request))); 132 service_.get(), std::move(service_request)));
212 message_loop.Run(); 133 message_loop.Run();
213 } 134 }
214 135
215 int MashMain() { 136 int MashMain() {
216 #if defined(OS_WIN) 137 #if defined(OS_WIN)
217 base::RouteStdioToConsole(false); 138 base::RouteStdioToConsole(false);
218 #endif 139 #endif
219 // TODO(sky): wire this up correctly. 140 // TODO(sky): wire this up correctly.
(...skipping 20 matching lines...) Expand all
240 tracing::GetConfigForTraceToConsole(); 161 tracing::GetConfigForTraceToConsole();
241 base::trace_event::TraceLog::GetInstance()->SetEnabled( 162 base::trace_event::TraceLog::GetInstance()->SetEnabled(
242 trace_config, 163 trace_config,
243 base::trace_event::TraceLog::RECORDING_MODE); 164 base::trace_event::TraceLog::RECORDING_MODE);
244 } 165 }
245 166
246 MashRunner mash_runner; 167 MashRunner mash_runner;
247 mash_runner.Run(); 168 mash_runner.Run();
248 return 0; 169 return 0;
249 } 170 }
OLDNEW
« no previous file with comments | « chrome/app/mash/BUILD.gn ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698