| 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/shell_client.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, base::RunLoop* loop, | 29 void ReceiveString(std::string* string, |
| 30 const std::string& response) { | 30 base::RunLoop* loop, |
| 31 mojo::String response) { |
| 31 *string = response; | 32 *string = response; |
| 32 loop->Quit(); | 33 loop->Quit(); |
| 33 } | 34 } |
| 34 | 35 |
| 35 } // namespace | 36 } // namespace |
| 36 | 37 |
| 37 using GetTitleCallback = test::mojom::ConnectTestService::GetTitleCallback; | 38 using GetTitleCallback = test::mojom::ConnectTestService::GetTitleCallback; |
| 38 | 39 |
| 39 class ConnectTestApp : public ShellClient, | 40 class ConnectTestApp : public ShellClient, |
| 40 public InterfaceFactory<test::mojom::ConnectTestService>, | 41 public InterfaceFactory<test::mojom::ConnectTestService>, |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 void OnConnectionBlocked( | 191 void OnConnectionBlocked( |
| 191 const ConnectToAllowedAppInBlockedPackageCallback& callback, | 192 const ConnectToAllowedAppInBlockedPackageCallback& callback, |
| 192 base::RunLoop* run_loop) { | 193 base::RunLoop* run_loop) { |
| 193 callback.Run("uninitialized"); | 194 callback.Run("uninitialized"); |
| 194 run_loop->Quit(); | 195 run_loop->Quit(); |
| 195 } | 196 } |
| 196 | 197 |
| 197 void OnGotTitle( | 198 void OnGotTitle( |
| 198 const ConnectToAllowedAppInBlockedPackageCallback& callback, | 199 const ConnectToAllowedAppInBlockedPackageCallback& callback, |
| 199 base::RunLoop* run_loop, | 200 base::RunLoop* run_loop, |
| 200 const mojo::String& title) { | 201 mojo::String title) { |
| 201 callback.Run(title); | 202 callback.Run(title); |
| 202 run_loop->Quit(); | 203 run_loop->Quit(); |
| 203 } | 204 } |
| 204 | 205 |
| 205 void OnConnectionError() { | 206 void OnConnectionError() { |
| 206 if (bindings_.empty() && standalone_bindings_.empty()) | 207 if (bindings_.empty() && standalone_bindings_.empty()) |
| 207 base::MessageLoop::current()->QuitWhenIdle(); | 208 base::MessageLoop::current()->QuitWhenIdle(); |
| 208 } | 209 } |
| 209 | 210 |
| 210 Connector* connector_ = nullptr; | 211 Connector* connector_ = nullptr; |
| 211 Identity identity_; | 212 Identity identity_; |
| 212 uint32_t id_ = mojom::kInvalidInstanceID; | 213 uint32_t id_ = mojom::kInvalidInstanceID; |
| 213 mojo::BindingSet<test::mojom::ConnectTestService> bindings_; | 214 mojo::BindingSet<test::mojom::ConnectTestService> bindings_; |
| 214 mojo::BindingSet<test::mojom::StandaloneApp> standalone_bindings_; | 215 mojo::BindingSet<test::mojom::StandaloneApp> standalone_bindings_; |
| 215 mojo::BindingSet<test::mojom::BlockedInterface> blocked_bindings_; | 216 mojo::BindingSet<test::mojom::BlockedInterface> blocked_bindings_; |
| 216 mojo::BindingSet<test::mojom::UserIdTest> user_id_test_bindings_; | 217 mojo::BindingSet<test::mojom::UserIdTest> user_id_test_bindings_; |
| 217 test::mojom::ExposedInterfacePtr caller_; | 218 test::mojom::ExposedInterfacePtr caller_; |
| 218 | 219 |
| 219 DISALLOW_COPY_AND_ASSIGN(ConnectTestApp); | 220 DISALLOW_COPY_AND_ASSIGN(ConnectTestApp); |
| 220 }; | 221 }; |
| 221 | 222 |
| 222 } // namespace shell | 223 } // namespace shell |
| 223 | 224 |
| 224 MojoResult MojoMain(MojoHandle shell_handle) { | 225 MojoResult MojoMain(MojoHandle shell_handle) { |
| 225 MojoResult rv = | 226 MojoResult rv = |
| 226 shell::ApplicationRunner(new shell::ConnectTestApp).Run(shell_handle); | 227 shell::ApplicationRunner(new shell::ConnectTestApp).Run(shell_handle); |
| 227 return rv; | 228 return rv; |
| 228 } | 229 } |
| OLD | NEW |