| 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 "mojo/public/c/system/main.h" | 5 #include "mojo/public/c/system/main.h" |
| 6 #include "mojo/public/cpp/bindings/binding_set.h" | 6 #include "mojo/public/cpp/bindings/binding_set.h" |
| 7 #include "mojo/shell/background/tests/test.mojom.h" | 7 #include "mojo/shell/background/tests/test.mojom.h" |
| 8 #include "mojo/shell/public/cpp/application_runner.h" | 8 #include "mojo/shell/public/cpp/application_runner.h" |
| 9 #include "mojo/shell/public/cpp/connection.h" | 9 #include "mojo/shell/public/cpp/connection.h" |
| 10 #include "mojo/shell/public/cpp/shell_client.h" | 10 #include "mojo/shell/public/cpp/shell_client.h" |
| 11 | 11 |
| 12 namespace mojo { | 12 namespace mojo { |
| 13 namespace shell { | 13 namespace shell { |
| 14 | 14 |
| 15 class TestClient : public ShellClient, | 15 class TestClient : public ShellClient, |
| 16 public InterfaceFactory<mojom::TestService>, | 16 public InterfaceFactory<mojom::TestService>, |
| 17 public mojom::TestService { | 17 public mojom::TestService { |
| 18 public: | 18 public: |
| 19 TestClient() {} | 19 explicit TestClient(mojo::ApplicationRunner* runner) : runner_(runner) {} |
| 20 ~TestClient() override {} | 20 ~TestClient() override {} |
| 21 | 21 |
| 22 private: | 22 private: |
| 23 // ShellClient: | 23 // ShellClient: |
| 24 bool AcceptConnection(Connection* connection) override { | 24 bool AcceptConnection(Connection* connection) override { |
| 25 connection->AddInterface(this); | 25 connection->AddInterface(this); |
| 26 return true; | 26 return true; |
| 27 } | 27 } |
| 28 void ShellConnectionLost() override { |
| 29 runner_->Quit(); |
| 30 } |
| 28 | 31 |
| 29 // InterfaceFactory<mojom::TestService>: | 32 // InterfaceFactory<mojom::TestService>: |
| 30 void Create(Connection* connection, | 33 void Create(Connection* connection, |
| 31 InterfaceRequest<mojom::TestService> request) override { | 34 InterfaceRequest<mojom::TestService> request) override { |
| 32 bindings_.AddBinding(this, std::move(request)); | 35 bindings_.AddBinding(this, std::move(request)); |
| 33 } | 36 } |
| 34 | 37 |
| 35 // mojom::TestService | 38 // mojom::TestService |
| 36 void Test(const TestCallback& callback) override { callback.Run(); } | 39 void Test(const TestCallback& callback) override { callback.Run(); } |
| 37 | 40 |
| 41 mojo::ApplicationRunner* const runner_; |
| 38 BindingSet<mojom::TestService> bindings_; | 42 BindingSet<mojom::TestService> bindings_; |
| 39 | 43 |
| 40 DISALLOW_COPY_AND_ASSIGN(TestClient); | 44 DISALLOW_COPY_AND_ASSIGN(TestClient); |
| 41 }; | 45 }; |
| 42 | 46 |
| 43 } // namespace shell | 47 } // namespace shell |
| 44 } // namespace mojo | 48 } // namespace mojo |
| 45 | 49 |
| 46 MojoResult MojoMain(MojoHandle shell_handle) { | 50 MojoResult MojoMain(MojoHandle shell_handle) { |
| 47 mojo::ApplicationRunner runner(new mojo::shell::TestClient); | 51 mojo::ApplicationRunner runner(new mojo::shell::TestClient(&runner)); |
| 48 return runner.Run(shell_handle); | 52 return runner.Run(shell_handle); |
| 49 } | 53 } |
| OLD | NEW |