| 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 } | |
| 27 | 20 |
| 28 using GetTitleCallback = test::mojom::ConnectTestService::GetTitleCallback; | 21 using GetTitleCallback = test::mojom::ConnectTestService::GetTitleCallback; |
| 29 | 22 |
| 30 class ConnectTestApp : public ShellClient, | 23 class ConnectTestApp : public ShellClient, |
| 31 public InterfaceFactory<test::mojom::ConnectTestService>, | 24 public InterfaceFactory<test::mojom::ConnectTestService>, |
| 32 public InterfaceFactory<test::mojom::StandaloneApp>, | 25 public InterfaceFactory<test::mojom::StandaloneApp>, |
| 33 public InterfaceFactory<test::mojom::BlockedInterface>, | 26 public InterfaceFactory<test::mojom::BlockedInterface>, |
| 34 public test::mojom::ConnectTestService, | 27 public test::mojom::ConnectTestService, |
| 35 public test::mojom::StandaloneApp, | 28 public test::mojom::StandaloneApp, |
| 36 public test::mojom::BlockedInterface { | 29 public test::mojom::BlockedInterface { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 base::Bind(&ConnectTestApp::OnGotTitle, base::Unretained(this), | 112 base::Bind(&ConnectTestApp::OnGotTitle, base::Unretained(this), |
| 120 callback, &run_loop)); | 113 callback, &run_loop)); |
| 121 { | 114 { |
| 122 // This message is dispatched as a task on the same run loop, so we need | 115 // This message is dispatched as a task on the same run loop, so we need |
| 123 // to allow nesting in order to pump additional signals. | 116 // to allow nesting in order to pump additional signals. |
| 124 base::MessageLoop::ScopedNestableTaskAllower allow( | 117 base::MessageLoop::ScopedNestableTaskAllower allow( |
| 125 base::MessageLoop::current()); | 118 base::MessageLoop::current()); |
| 126 run_loop.Run(); | 119 run_loop.Run(); |
| 127 } | 120 } |
| 128 } | 121 } |
| 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 } | |
| 155 | 122 |
| 156 // test::mojom::BlockedInterface: | 123 // test::mojom::BlockedInterface: |
| 157 void GetTitleBlocked(const GetTitleBlockedCallback& callback) override { | 124 void GetTitleBlocked(const GetTitleBlockedCallback& callback) override { |
| 158 callback.Run("Called Blocked Interface!"); | 125 callback.Run("Called Blocked Interface!"); |
| 159 } | 126 } |
| 160 | 127 |
| 161 void OnConnectionBlocked( | 128 void OnConnectionBlocked( |
| 162 const ConnectToAllowedAppInBlockedPackageCallback& callback, | 129 const ConnectToAllowedAppInBlockedPackageCallback& callback, |
| 163 base::RunLoop* run_loop) { | 130 base::RunLoop* run_loop) { |
| 164 callback.Run("uninitialized"); | 131 callback.Run("uninitialized"); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 191 | 158 |
| 192 } // namespace shell | 159 } // namespace shell |
| 193 } // namespace mojo | 160 } // namespace mojo |
| 194 | 161 |
| 195 | 162 |
| 196 MojoResult MojoMain(MojoHandle shell_handle) { | 163 MojoResult MojoMain(MojoHandle shell_handle) { |
| 197 MojoResult rv = mojo::ApplicationRunner( | 164 MojoResult rv = mojo::ApplicationRunner( |
| 198 new mojo::shell::ConnectTestApp).Run(shell_handle); | 165 new mojo::shell::ConnectTestApp).Run(shell_handle); |
| 199 return rv; | 166 return rv; |
| 200 } | 167 } |
| OLD | NEW |