| 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 "mojo/shell/public/cpp/application_runner.h" | 11 #include "mojo/shell/public/cpp/application_runner.h" |
| 12 #include "mojo/shell/public/cpp/connector.h" | 12 #include "mojo/shell/public/cpp/connector.h" |
| 13 #include "mojo/shell/public/cpp/interface_factory.h" | 13 #include "mojo/shell/public/cpp/interface_factory.h" |
| 14 #include "mojo/shell/public/cpp/shell_client.h" | 14 #include "mojo/shell/public/cpp/shell_client.h" |
| 15 #include "mojo/shell/public/interfaces/connector.mojom.h" | 15 #include "mojo/shell/public/interfaces/connector.mojom.h" |
| 16 #include "mojo/shell/tests/connect/connect_test.mojom.h" | 16 #include "mojo/shell/tests/connect/connect_test.mojom.h" |
| 17 | 17 |
| 18 namespace mojo { | 18 namespace mojo { |
| 19 namespace shell { | 19 namespace shell { |
| 20 namespace { |
| 21 void ReceiveString(std::string* string, base::RunLoop* loop, |
| 22 const std::string& response) { |
| 23 *string = response; |
| 24 loop->Quit(); |
| 25 } |
| 26 } |
| 20 | 27 |
| 21 using GetTitleCallback = test::mojom::ConnectTestService::GetTitleCallback; | 28 using GetTitleCallback = test::mojom::ConnectTestService::GetTitleCallback; |
| 22 | 29 |
| 23 class ConnectTestApp : public ShellClient, | 30 class ConnectTestApp : public ShellClient, |
| 24 public InterfaceFactory<test::mojom::ConnectTestService>, | 31 public InterfaceFactory<test::mojom::ConnectTestService>, |
| 25 public InterfaceFactory<test::mojom::StandaloneApp>, | 32 public InterfaceFactory<test::mojom::StandaloneApp>, |
| 26 public InterfaceFactory<test::mojom::BlockedInterface>, | 33 public InterfaceFactory<test::mojom::BlockedInterface>, |
| 27 public test::mojom::ConnectTestService, | 34 public test::mojom::ConnectTestService, |
| 28 public test::mojom::StandaloneApp, | 35 public test::mojom::StandaloneApp, |
| 29 public test::mojom::BlockedInterface { | 36 public test::mojom::BlockedInterface { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 base::Bind(&ConnectTestApp::OnGotTitle, base::Unretained(this), | 119 base::Bind(&ConnectTestApp::OnGotTitle, base::Unretained(this), |
| 113 callback, &run_loop)); | 120 callback, &run_loop)); |
| 114 { | 121 { |
| 115 // This message is dispatched as a task on the same run loop, so we need | 122 // This message is dispatched as a task on the same run loop, so we need |
| 116 // to allow nesting in order to pump additional signals. | 123 // to allow nesting in order to pump additional signals. |
| 117 base::MessageLoop::ScopedNestableTaskAllower allow( | 124 base::MessageLoop::ScopedNestableTaskAllower allow( |
| 118 base::MessageLoop::current()); | 125 base::MessageLoop::current()); |
| 119 run_loop.Run(); | 126 run_loop.Run(); |
| 120 } | 127 } |
| 121 } | 128 } |
| 129 void ConnectToClassInterface( |
| 130 const ConnectToClassInterfaceCallback& callback) override { |
| 131 scoped_ptr<Connection> connection = |
| 132 connector_->Connect("mojo:connect_test_class_app"); |
| 133 test::mojom::ClassInterfacePtr class_interface; |
| 134 connection->GetInterface(&class_interface); |
| 135 std::string ping_response; |
| 136 { |
| 137 base::RunLoop loop; |
| 138 class_interface->Ping(base::Bind(&ReceiveString, &ping_response, &loop)); |
| 139 base::MessageLoop::ScopedNestableTaskAllower allow( |
| 140 base::MessageLoop::current()); |
| 141 loop.Run(); |
| 142 } |
| 143 test::mojom::ConnectTestServicePtr service; |
| 144 connection->GetInterface(&service); |
| 145 std::string title_response; |
| 146 { |
| 147 base::RunLoop loop; |
| 148 service->GetTitle(base::Bind(&ReceiveString, &title_response, &loop)); |
| 149 base::MessageLoop::ScopedNestableTaskAllower allow( |
| 150 base::MessageLoop::current()); |
| 151 loop.Run(); |
| 152 } |
| 153 callback.Run(ping_response, title_response); |
| 154 } |
| 122 | 155 |
| 123 // test::mojom::BlockedInterface: | 156 // test::mojom::BlockedInterface: |
| 124 void GetTitleBlocked(const GetTitleBlockedCallback& callback) override { | 157 void GetTitleBlocked(const GetTitleBlockedCallback& callback) override { |
| 125 callback.Run("Called Blocked Interface!"); | 158 callback.Run("Called Blocked Interface!"); |
| 126 } | 159 } |
| 127 | 160 |
| 128 void OnConnectionBlocked( | 161 void OnConnectionBlocked( |
| 129 const ConnectToAllowedAppInBlockedPackageCallback& callback, | 162 const ConnectToAllowedAppInBlockedPackageCallback& callback, |
| 130 base::RunLoop* run_loop) { | 163 base::RunLoop* run_loop) { |
| 131 callback.Run("uninitialized"); | 164 callback.Run("uninitialized"); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 158 | 191 |
| 159 } // namespace shell | 192 } // namespace shell |
| 160 } // namespace mojo | 193 } // namespace mojo |
| 161 | 194 |
| 162 | 195 |
| 163 MojoResult MojoMain(MojoHandle shell_handle) { | 196 MojoResult MojoMain(MojoHandle shell_handle) { |
| 164 MojoResult rv = mojo::ApplicationRunner( | 197 MojoResult rv = mojo::ApplicationRunner( |
| 165 new mojo::shell::ConnectTestApp).Run(shell_handle); | 198 new mojo::shell::ConnectTestApp).Run(shell_handle); |
| 166 return rv; | 199 return rv; |
| 167 } | 200 } |
| OLD | NEW |