| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/macros.h" | 6 #include "base/macros.h" |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "mojo/public/c/system/main.h" | 9 #include "mojo/public/c/system/main.h" |
| 10 #include "mojo/public/cpp/bindings/binding_set.h" | 10 #include "mojo/public/cpp/bindings/binding_set.h" |
| 11 #include "services/shell/public/cpp/application_runner.h" | 11 #include "services/shell/public/cpp/application_runner.h" |
| 12 #include "services/shell/public/cpp/connector.h" | 12 #include "services/shell/public/cpp/connector.h" |
| 13 #include "services/shell/public/cpp/interface_factory.h" | 13 #include "services/shell/public/cpp/interface_factory.h" |
| 14 #include "services/shell/public/cpp/shell_client.h" | 14 #include "services/shell/public/cpp/shell_client.h" |
| 15 #include "services/shell/public/interfaces/connector.mojom.h" | 15 #include "services/shell/public/interfaces/connector.mojom.h" |
| 16 #include "services/shell/tests/connect/connect_test.mojom.h" | 16 #include "services/shell/tests/connect/connect_test.mojom.h" |
| 17 | 17 |
| 18 namespace mojo { | |
| 19 namespace shell { | 18 namespace shell { |
| 20 | 19 |
| 21 using GetTitleCallback = test::mojom::ConnectTestService::GetTitleCallback; | 20 using GetTitleCallback = test::mojom::ConnectTestService::GetTitleCallback; |
| 22 | 21 |
| 23 class ConnectTestClassApp | 22 class ConnectTestClassApp |
| 24 : public ShellClient, | 23 : public ShellClient, |
| 25 public InterfaceFactory<test::mojom::ConnectTestService>, | 24 public InterfaceFactory<test::mojom::ConnectTestService>, |
| 26 public InterfaceFactory<test::mojom::ClassInterface>, | 25 public InterfaceFactory<test::mojom::ClassInterface>, |
| 27 public test::mojom::ConnectTestService, | 26 public test::mojom::ConnectTestService, |
| 28 public test::mojom::ClassInterface { | 27 public test::mojom::ClassInterface { |
| 29 public: | 28 public: |
| 30 ConnectTestClassApp() {} | 29 ConnectTestClassApp() {} |
| 31 ~ConnectTestClassApp() override {} | 30 ~ConnectTestClassApp() override {} |
| 32 | 31 |
| 33 private: | 32 private: |
| 34 // mojo::ShellClient: | 33 // shell::ShellClient: |
| 35 void Initialize(Connector* connector, const Identity& identity, | 34 void Initialize(Connector* connector, const Identity& identity, |
| 36 uint32_t id) override { | 35 uint32_t id) override { |
| 37 connector_ = connector; | 36 connector_ = connector; |
| 38 identity_ = identity; | 37 identity_ = identity; |
| 39 } | 38 } |
| 40 bool AcceptConnection(Connection* connection) override { | 39 bool AcceptConnection(Connection* connection) override { |
| 41 CHECK(connection->HasCapabilityClass("class")); | 40 CHECK(connection->HasCapabilityClass("class")); |
| 42 connection->AddInterface<test::mojom::ConnectTestService>(this); | 41 connection->AddInterface<test::mojom::ConnectTestService>(this); |
| 43 connection->AddInterface<test::mojom::ClassInterface>(this); | 42 connection->AddInterface<test::mojom::ClassInterface>(this); |
| 44 inbound_connections_.insert(connection); | 43 inbound_connections_.insert(connection); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 auto it = inbound_connections_.find(connection); | 76 auto it = inbound_connections_.find(connection); |
| 78 DCHECK(it != inbound_connections_.end()); | 77 DCHECK(it != inbound_connections_.end()); |
| 79 inbound_connections_.erase(it); | 78 inbound_connections_.erase(it); |
| 80 if (inbound_connections_.empty()) | 79 if (inbound_connections_.empty()) |
| 81 base::MessageLoop::current()->QuitWhenIdle(); | 80 base::MessageLoop::current()->QuitWhenIdle(); |
| 82 } | 81 } |
| 83 | 82 |
| 84 Connector* connector_ = nullptr; | 83 Connector* connector_ = nullptr; |
| 85 Identity identity_; | 84 Identity identity_; |
| 86 std::set<Connection*> inbound_connections_; | 85 std::set<Connection*> inbound_connections_; |
| 87 BindingSet<test::mojom::ConnectTestService> bindings_; | 86 mojo::BindingSet<test::mojom::ConnectTestService> bindings_; |
| 88 BindingSet<test::mojom::ClassInterface> class_interface_bindings_; | 87 mojo::BindingSet<test::mojom::ClassInterface> class_interface_bindings_; |
| 89 | 88 |
| 90 DISALLOW_COPY_AND_ASSIGN(ConnectTestClassApp); | 89 DISALLOW_COPY_AND_ASSIGN(ConnectTestClassApp); |
| 91 }; | 90 }; |
| 92 | 91 |
| 93 } // namespace shell | 92 } // namespace shell |
| 94 } // namespace mojo | |
| 95 | 93 |
| 96 | 94 |
| 97 MojoResult MojoMain(MojoHandle shell_handle) { | 95 MojoResult MojoMain(MojoHandle shell_handle) { |
| 98 MojoResult rv = mojo::ApplicationRunner( | 96 MojoResult rv = shell::ApplicationRunner(new shell::ConnectTestClassApp) |
| 99 new mojo::shell::ConnectTestClassApp).Run(shell_handle); | 97 .Run(shell_handle); |
| 100 return rv; | 98 return rv; |
| 101 } | 99 } |
| OLD | NEW |