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 <memory> | 5 #include <memory> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/guid.h" | 8 #include "base/guid.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "mojo/public/c/system/main.h" | 12 #include "mojo/public/c/system/main.h" |
13 #include "mojo/public/cpp/bindings/binding_set.h" | 13 #include "mojo/public/cpp/bindings/binding_set.h" |
14 #include "services/shell/public/cpp/application_runner.h" | 14 #include "services/shell/public/cpp/application_runner.h" |
15 #include "services/shell/public/cpp/connector.h" | 15 #include "services/shell/public/cpp/connector.h" |
16 #include "services/shell/public/cpp/interface_factory.h" | 16 #include "services/shell/public/cpp/interface_factory.h" |
17 #include "services/shell/public/cpp/shell_client.h" | 17 #include "services/shell/public/cpp/service.h" |
18 #include "services/shell/public/interfaces/connector.mojom.h" | 18 #include "services/shell/public/interfaces/connector.mojom.h" |
19 #include "services/shell/tests/connect/connect_test.mojom.h" | 19 #include "services/shell/tests/connect/connect_test.mojom.h" |
20 | 20 |
21 namespace shell { | 21 namespace shell { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 void QuitLoop(base::RunLoop* loop) { | 25 void QuitLoop(base::RunLoop* loop) { |
26 loop->Quit(); | 26 loop->Quit(); |
27 } | 27 } |
28 | 28 |
29 void ReceiveString(std::string* string, | 29 void ReceiveString(std::string* string, |
30 base::RunLoop* loop, | 30 base::RunLoop* loop, |
31 mojo::String response) { | 31 mojo::String response) { |
32 *string = response; | 32 *string = response; |
33 loop->Quit(); | 33 loop->Quit(); |
34 } | 34 } |
35 | 35 |
36 } // namespace | 36 } // namespace |
37 | 37 |
38 using GetTitleCallback = test::mojom::ConnectTestService::GetTitleCallback; | 38 using GetTitleCallback = test::mojom::ConnectTestService::GetTitleCallback; |
39 | 39 |
40 class ConnectTestApp : public ShellClient, | 40 class ConnectTestApp : public Service, |
41 public InterfaceFactory<test::mojom::ConnectTestService>, | 41 public InterfaceFactory<test::mojom::ConnectTestService>, |
42 public InterfaceFactory<test::mojom::StandaloneApp>, | 42 public InterfaceFactory<test::mojom::StandaloneApp>, |
43 public InterfaceFactory<test::mojom::BlockedInterface>, | 43 public InterfaceFactory<test::mojom::BlockedInterface>, |
44 public InterfaceFactory<test::mojom::UserIdTest>, | 44 public InterfaceFactory<test::mojom::UserIdTest>, |
45 public test::mojom::ConnectTestService, | 45 public test::mojom::ConnectTestService, |
46 public test::mojom::StandaloneApp, | 46 public test::mojom::StandaloneApp, |
47 public test::mojom::BlockedInterface, | 47 public test::mojom::BlockedInterface, |
48 public test::mojom::UserIdTest { | 48 public test::mojom::UserIdTest { |
49 public: | 49 public: |
50 ConnectTestApp() {} | 50 ConnectTestApp() {} |
51 ~ConnectTestApp() override {} | 51 ~ConnectTestApp() override {} |
52 | 52 |
53 private: | 53 private: |
54 // shell::ShellClient: | 54 // shell::Service: |
55 void Initialize(Connector* connector, const Identity& identity, | 55 void OnStart(Connector* connector, const Identity& identity, |
56 uint32_t id) override { | 56 uint32_t id) override { |
57 connector_ = connector; | 57 connector_ = connector; |
58 identity_ = identity; | 58 identity_ = identity; |
59 id_ = id; | 59 id_ = id; |
60 bindings_.set_connection_error_handler( | 60 bindings_.set_connection_error_handler( |
61 base::Bind(&ConnectTestApp::OnConnectionError, | 61 base::Bind(&ConnectTestApp::OnConnectionError, |
62 base::Unretained(this))); | 62 base::Unretained(this))); |
63 standalone_bindings_.set_connection_error_handler( | 63 standalone_bindings_.set_connection_error_handler( |
64 base::Bind(&ConnectTestApp::OnConnectionError, | 64 base::Bind(&ConnectTestApp::OnConnectionError, |
65 base::Unretained(this))); | 65 base::Unretained(this))); |
66 } | 66 } |
67 bool AcceptConnection(Connection* connection) override { | 67 bool OnConnect(Connection* connection) override { |
68 connection->AddInterface<test::mojom::ConnectTestService>(this); | 68 connection->AddInterface<test::mojom::ConnectTestService>(this); |
69 connection->AddInterface<test::mojom::StandaloneApp>(this); | 69 connection->AddInterface<test::mojom::StandaloneApp>(this); |
70 connection->AddInterface<test::mojom::BlockedInterface>(this); | 70 connection->AddInterface<test::mojom::BlockedInterface>(this); |
71 connection->AddInterface<test::mojom::UserIdTest>(this); | 71 connection->AddInterface<test::mojom::UserIdTest>(this); |
72 | 72 |
73 uint32_t remote_id = connection->GetRemoteInstanceID(); | 73 uint32_t remote_id = connection->GetRemoteInstanceID(); |
74 test::mojom::ConnectionStatePtr state(test::mojom::ConnectionState::New()); | 74 test::mojom::ConnectionStatePtr state(test::mojom::ConnectionState::New()); |
75 state->connection_local_name = connection->GetConnectionName(); | 75 state->connection_local_name = connection->GetConnectionName(); |
76 state->connection_remote_name = connection->GetRemoteIdentity().name(); | 76 state->connection_remote_name = connection->GetRemoteIdentity().name(); |
77 state->connection_remote_userid = connection->GetRemoteIdentity().user_id(); | 77 state->connection_remote_userid = connection->GetRemoteIdentity().user_id(); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 DISALLOW_COPY_AND_ASSIGN(ConnectTestApp); | 220 DISALLOW_COPY_AND_ASSIGN(ConnectTestApp); |
221 }; | 221 }; |
222 | 222 |
223 } // namespace shell | 223 } // namespace shell |
224 | 224 |
225 MojoResult MojoMain(MojoHandle shell_handle) { | 225 MojoResult MojoMain(MojoHandle shell_handle) { |
226 MojoResult rv = | 226 MojoResult rv = |
227 shell::ApplicationRunner(new shell::ConnectTestApp).Run(shell_handle); | 227 shell::ApplicationRunner(new shell::ConnectTestApp).Run(shell_handle); |
228 return rv; | 228 return rv; |
229 } | 229 } |
OLD | NEW |