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

Side by Side Diff: examples/native_run_app/native_run_app.cc

Issue 1975253002: ApplicationConnection devolution, part 2.1. (Closed) Base URL: https://github.com/domokit/mojo.git@work792-x-work791_service_registry_spimpl
Patch Set: Created 4 years, 7 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 // This is a terminal client (i.e., a "raw" |mojo.terminal.Terminal| -- e.g., 5 // This is a terminal client (i.e., a "raw" |mojo.terminal.Terminal| -- e.g.,
6 // moterm -- can be asked to talk to this) that prompts the user for a native 6 // moterm -- can be asked to talk to this) that prompts the user for a native
7 // (Linux) binary to run and then does so (via mojo:native_support). 7 // (Linux) binary to run and then does so (via mojo:native_support).
8 // 8 //
9 // E.g., first run mojo:moterm_example_app (embedded by a window manager). Then, 9 // E.g., first run mojo:moterm_example_app (embedded by a window manager). Then,
10 // at the prompt, enter "mojo:native_run_app". At the next prompt, enter "bash" 10 // at the prompt, enter "mojo:native_run_app". At the next prompt, enter "bash"
(...skipping 10 matching lines...) Expand all
21 21
22 #include "base/logging.h" 22 #include "base/logging.h"
23 #include "base/macros.h" 23 #include "base/macros.h"
24 #include "base/strings/string_split.h" 24 #include "base/strings/string_split.h"
25 #include "mojo/application/application_runner_chromium.h" 25 #include "mojo/application/application_runner_chromium.h"
26 #include "mojo/public/c/system/main.h" 26 #include "mojo/public/c/system/main.h"
27 #include "mojo/public/cpp/application/application_connection.h" 27 #include "mojo/public/cpp/application/application_connection.h"
28 #include "mojo/public/cpp/application/application_delegate.h" 28 #include "mojo/public/cpp/application/application_delegate.h"
29 #include "mojo/public/cpp/application/application_impl.h" 29 #include "mojo/public/cpp/application/application_impl.h"
30 #include "mojo/public/cpp/application/connect.h" 30 #include "mojo/public/cpp/application/connect.h"
31 #include "mojo/public/cpp/application/interface_factory.h"
32 #include "mojo/public/cpp/bindings/interface_request.h" 31 #include "mojo/public/cpp/bindings/interface_request.h"
33 #include "mojo/public/cpp/bindings/strong_binding.h" 32 #include "mojo/public/cpp/bindings/strong_binding.h"
34 #include "mojo/services/files/interfaces/files.mojom.h" 33 #include "mojo/services/files/interfaces/files.mojom.h"
35 #include "mojo/services/files/interfaces/ioctl.mojom.h" 34 #include "mojo/services/files/interfaces/ioctl.mojom.h"
36 #include "mojo/services/files/interfaces/ioctl_terminal.mojom.h" 35 #include "mojo/services/files/interfaces/ioctl_terminal.mojom.h"
37 #include "mojo/services/files/interfaces/types.mojom.h" 36 #include "mojo/services/files/interfaces/types.mojom.h"
38 #include "mojo/services/native_support/interfaces/process.mojom.h" 37 #include "mojo/services/native_support/interfaces/process.mojom.h"
39 #include "mojo/services/terminal/interfaces/terminal_client.mojom.h" 38 #include "mojo/services/terminal/interfaces/terminal_client.mojom.h"
40 39
41 using mojo::terminal::TerminalClient; 40 using mojo::terminal::TerminalClient;
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 } 213 }
215 } 214 }
216 215
217 private: 216 private:
218 mojo::StrongBinding<TerminalClient> binding_; 217 mojo::StrongBinding<TerminalClient> binding_;
219 native_support::Process* native_support_process_; 218 native_support::Process* native_support_process_;
220 219
221 DISALLOW_COPY_AND_ASSIGN(TerminalClientImpl); 220 DISALLOW_COPY_AND_ASSIGN(TerminalClientImpl);
222 }; 221 };
223 222
224 class NativeRunApp : public mojo::ApplicationDelegate, 223 class NativeRunApp : public mojo::ApplicationDelegate {
225 public mojo::InterfaceFactory<TerminalClient> {
226 public: 224 public:
227 NativeRunApp() : application_impl_(nullptr) {} 225 NativeRunApp() : application_impl_(nullptr) {}
228 ~NativeRunApp() override {} 226 ~NativeRunApp() override {}
229 227
230 private: 228 private:
231 // |mojo::ApplicationDelegate|: 229 // |mojo::ApplicationDelegate|:
232 void Initialize(mojo::ApplicationImpl* application_impl) override { 230 void Initialize(mojo::ApplicationImpl* application_impl) override {
233 DCHECK(!application_impl_); 231 DCHECK(!application_impl_);
234 application_impl_ = application_impl; 232 application_impl_ = application_impl;
235 mojo::ConnectToService(application_impl_->shell(), "mojo:native_support", 233 mojo::ConnectToService(application_impl_->shell(), "mojo:native_support",
236 GetProxy(&native_support_process_)); 234 GetProxy(&native_support_process_));
237 } 235 }
238 236
239 bool ConfigureIncomingConnection( 237 bool ConfigureIncomingConnection(
240 mojo::ApplicationConnection* connection) override { 238 mojo::ApplicationConnection* connection) override {
241 connection->AddService<TerminalClient>(this); 239 connection->GetServiceProviderImpl().AddService<TerminalClient>(
240 [this](const mojo::ConnectionContext& connection_context,
241 mojo::InterfaceRequest<TerminalClient> terminal_client_request) {
242 new TerminalClientImpl(terminal_client_request.Pass(),
243 native_support_process_.get());
244 });
242 return true; 245 return true;
243 } 246 }
244 247
245 // |InterfaceFactory<TerminalClient>| implementation:
246 void Create(const mojo::ConnectionContext& /*connection_context*/,
247 mojo::InterfaceRequest<TerminalClient> request) override {
248 new TerminalClientImpl(request.Pass(), native_support_process_.get());
249 }
250
251 mojo::ApplicationImpl* application_impl_; 248 mojo::ApplicationImpl* application_impl_;
252 native_support::ProcessPtr native_support_process_; 249 native_support::ProcessPtr native_support_process_;
253 250
254 DISALLOW_COPY_AND_ASSIGN(NativeRunApp); 251 DISALLOW_COPY_AND_ASSIGN(NativeRunApp);
255 }; 252 };
256 253
257 MojoResult MojoMain(MojoHandle application_request) { 254 MojoResult MojoMain(MojoHandle application_request) {
258 mojo::ApplicationRunnerChromium runner(new NativeRunApp()); 255 mojo::ApplicationRunnerChromium runner(new NativeRunApp());
259 return runner.Run(application_request); 256 return runner.Run(application_request);
260 } 257 }
OLDNEW
« no previous file with comments | « examples/indirect_service/integer_service.cc ('k') | mojo/public/cpp/bindings/tests/versioning_test_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698