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