OLD | NEW |
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 #include <memory> | 5 #include <memory> |
6 | 6 |
7 #include "mojo/public/c/system/main.h" | 7 #include "mojo/public/c/system/main.h" |
8 #include "mojo/public/cpp/application/application_delegate.h" | 8 #include "mojo/public/cpp/application/application_delegate.h" |
9 #include "mojo/public/cpp/application/application_impl.h" | 9 #include "mojo/public/cpp/application/application_impl.h" |
10 #include "mojo/public/cpp/application/application_runner.h" | 10 #include "mojo/public/cpp/application/application_runner.h" |
11 #include "mojo/public/cpp/application/interface_factory.h" | |
12 #include "mojo/public/cpp/bindings/callback.h" | 11 #include "mojo/public/cpp/bindings/callback.h" |
13 #include "mojo/public/cpp/bindings/interface_request.h" | 12 #include "mojo/public/cpp/bindings/interface_request.h" |
14 #include "mojo/public/cpp/bindings/strong_binding.h" | 13 #include "mojo/public/cpp/bindings/strong_binding.h" |
15 #include "shell/test/pingable.mojom.h" | 14 #include "shell/test/pingable.mojom.h" |
16 | 15 |
17 using mojo::String; | 16 using mojo::String; |
18 | 17 |
19 class PingableImpl : public Pingable { | 18 class PingableImpl : public Pingable { |
20 public: | 19 public: |
21 PingableImpl(mojo::InterfaceRequest<Pingable> request, | 20 PingableImpl(mojo::InterfaceRequest<Pingable> request, |
(...skipping 10 matching lines...) Expand all Loading... |
32 const String& message, | 31 const String& message, |
33 const mojo::Callback<void(String, String, String)>& callback) override { | 32 const mojo::Callback<void(String, String, String)>& callback) override { |
34 callback.Run(app_url_, connection_url_, message); | 33 callback.Run(app_url_, connection_url_, message); |
35 } | 34 } |
36 | 35 |
37 mojo::StrongBinding<Pingable> binding_; | 36 mojo::StrongBinding<Pingable> binding_; |
38 std::string app_url_; | 37 std::string app_url_; |
39 std::string connection_url_; | 38 std::string connection_url_; |
40 }; | 39 }; |
41 | 40 |
42 class PingableApp : public mojo::ApplicationDelegate, | 41 class PingableApp : public mojo::ApplicationDelegate { |
43 public mojo::InterfaceFactory<Pingable> { | |
44 public: | 42 public: |
45 PingableApp() {} | 43 PingableApp() {} |
46 ~PingableApp() override {} | 44 ~PingableApp() override {} |
47 | 45 |
48 private: | 46 private: |
49 // ApplicationDelegate: | 47 // ApplicationDelegate: |
50 void Initialize(mojo::ApplicationImpl* impl) override { | 48 void Initialize(mojo::ApplicationImpl* impl) override { |
51 app_url_ = impl->url(); | 49 app_url_ = impl->url(); |
52 } | 50 } |
53 | 51 |
54 bool ConfigureIncomingConnection( | 52 bool ConfigureIncomingConnection( |
55 mojo::ApplicationConnection* connection) override { | 53 mojo::ApplicationConnection* connection) override { |
56 connection->AddService(this); | 54 connection->GetServiceProviderImpl().AddService<Pingable>( |
| 55 [this](const mojo::ConnectionContext& connection_context, |
| 56 mojo::InterfaceRequest<Pingable> pingable_request) { |
| 57 new PingableImpl(pingable_request.Pass(), app_url_, |
| 58 connection_context.connection_url); |
| 59 }); |
57 return true; | 60 return true; |
58 } | 61 } |
59 | 62 |
60 // InterfaceFactory<Pingable>: | |
61 void Create(const mojo::ConnectionContext& connection_context, | |
62 mojo::InterfaceRequest<Pingable> request) override { | |
63 new PingableImpl(request.Pass(), app_url_, | |
64 connection_context.connection_url); | |
65 } | |
66 | |
67 std::string app_url_; | 63 std::string app_url_; |
68 }; | 64 }; |
69 | 65 |
70 MojoResult MojoMain(MojoHandle application_request) { | 66 MojoResult MojoMain(MojoHandle application_request) { |
71 mojo::ApplicationRunner runner( | 67 mojo::ApplicationRunner runner( |
72 std::unique_ptr<PingableApp>(new PingableApp())); | 68 std::unique_ptr<PingableApp>(new PingableApp())); |
73 return runner.Run(application_request); | 69 return runner.Run(application_request); |
74 } | 70 } |
OLD | NEW |