| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/threading/simple_thread.h" | 15 #include "base/threading/simple_thread.h" |
| 16 #include "mojo/public/cpp/bindings/binding_set.h" | 16 #include "mojo/public/cpp/bindings/binding_set.h" |
| 17 #include "services/service_manager/public/c/main.h" | 17 #include "services/service_manager/public/c/main.h" |
| 18 #include "services/service_manager/public/cpp/connector.h" | 18 #include "services/service_manager/public/cpp/connector.h" |
| 19 #include "services/service_manager/public/cpp/interface_factory.h" | 19 #include "services/service_manager/public/cpp/interface_factory.h" |
| 20 #include "services/service_manager/public/cpp/service.h" | 20 #include "services/service_manager/public/cpp/service.h" |
| 21 #include "services/service_manager/public/cpp/service_runner.h" | 21 #include "services/service_manager/public/cpp/service_runner.h" |
| 22 #include "services/service_manager/public/interfaces/service_factory.mojom.h" | 22 #include "services/service_manager/public/interfaces/service_factory.mojom.h" |
| 23 #include "services/service_manager/tests/connect/connect_test.mojom.h" | 23 #include "services/service_manager/tests/connect/connect_test.mojom.h" |
| 24 | 24 |
| 25 // Tests that multiple services can be packaged in a single service by | 25 // Tests that multiple services can be packaged in a single service by |
| 26 // implementing ServiceFactory; that these services can be specified by | 26 // implementing ServiceFactory; that these services can be specified by |
| 27 // the package's manifest and are thus registered with the PackageManager. | 27 // the package's manifest and are thus registered with the PackageManager. |
| 28 | 28 |
| 29 namespace shell { | 29 namespace service_manager { |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 void QuitLoop(base::RunLoop* loop) { | 33 void QuitLoop(base::RunLoop* loop) { |
| 34 loop->Quit(); | 34 loop->Quit(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 } // namespace | 37 } // namespace |
| 38 | 38 |
| 39 using GetTitleCallback = test::mojom::ConnectTestService::GetTitleCallback; | 39 using GetTitleCallback = test::mojom::ConnectTestService::GetTitleCallback; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 53 : base::SimpleThread(title), | 53 : base::SimpleThread(title), |
| 54 title_(title), | 54 title_(title), |
| 55 request_(std::move(request)) { | 55 request_(std::move(request)) { |
| 56 Start(); | 56 Start(); |
| 57 } | 57 } |
| 58 ~ProvidedService() override { | 58 ~ProvidedService() override { |
| 59 Join(); | 59 Join(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 private: | 62 private: |
| 63 // shell::Service: | 63 // service_manager::Service: |
| 64 void OnStart(const Identity& identity) override { | 64 void OnStart(const Identity& identity) override { |
| 65 identity_ = identity; | 65 identity_ = identity; |
| 66 bindings_.set_connection_error_handler( | 66 bindings_.set_connection_error_handler( |
| 67 base::Bind(&ProvidedService::OnConnectionError, | 67 base::Bind(&ProvidedService::OnConnectionError, |
| 68 base::Unretained(this))); | 68 base::Unretained(this))); |
| 69 } | 69 } |
| 70 bool OnConnect(const Identity& remote_identity, | 70 bool OnConnect(const Identity& remote_identity, |
| 71 InterfaceRegistry* registry) override { | 71 InterfaceRegistry* registry) override { |
| 72 registry->AddInterface<test::mojom::ConnectTestService>(this); | 72 registry->AddInterface<test::mojom::ConnectTestService>(this); |
| 73 registry->AddInterface<test::mojom::BlockedInterface>(this); | 73 registry->AddInterface<test::mojom::BlockedInterface>(this); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 callback.Run(identity_.instance()); | 111 callback.Run(identity_.instance()); |
| 112 } | 112 } |
| 113 | 113 |
| 114 // test::mojom::BlockedInterface: | 114 // test::mojom::BlockedInterface: |
| 115 void GetTitleBlocked(const GetTitleBlockedCallback& callback) override { | 115 void GetTitleBlocked(const GetTitleBlockedCallback& callback) override { |
| 116 callback.Run("Called Blocked Interface!"); | 116 callback.Run("Called Blocked Interface!"); |
| 117 } | 117 } |
| 118 | 118 |
| 119 // test::mojom::UserIdTest: | 119 // test::mojom::UserIdTest: |
| 120 void ConnectToClassAppAsDifferentUser( | 120 void ConnectToClassAppAsDifferentUser( |
| 121 const shell::Identity& target, | 121 const service_manager::Identity& target, |
| 122 const ConnectToClassAppAsDifferentUserCallback& callback) override { | 122 const ConnectToClassAppAsDifferentUserCallback& callback) override { |
| 123 Connector::ConnectParams params(target); | 123 Connector::ConnectParams params(target); |
| 124 std::unique_ptr<Connection> connection = | 124 std::unique_ptr<Connection> connection = |
| 125 connector()->Connect(¶ms); | 125 connector()->Connect(¶ms); |
| 126 { | 126 { |
| 127 base::RunLoop loop; | 127 base::RunLoop loop; |
| 128 connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop)); | 128 connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop)); |
| 129 base::MessageLoop::ScopedNestableTaskAllower allow( | 129 base::MessageLoop::ScopedNestableTaskAllower allow( |
| 130 base::MessageLoop::current()); | 130 base::MessageLoop::current()); |
| 131 loop.Run(); | 131 loop.Run(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 161 : public Service, | 161 : public Service, |
| 162 public InterfaceFactory<mojom::ServiceFactory>, | 162 public InterfaceFactory<mojom::ServiceFactory>, |
| 163 public InterfaceFactory<test::mojom::ConnectTestService>, | 163 public InterfaceFactory<test::mojom::ConnectTestService>, |
| 164 public mojom::ServiceFactory, | 164 public mojom::ServiceFactory, |
| 165 public test::mojom::ConnectTestService { | 165 public test::mojom::ConnectTestService { |
| 166 public: | 166 public: |
| 167 ConnectTestService() {} | 167 ConnectTestService() {} |
| 168 ~ConnectTestService() override {} | 168 ~ConnectTestService() override {} |
| 169 | 169 |
| 170 private: | 170 private: |
| 171 // shell::Service: | 171 // service_manager::Service: |
| 172 void OnStart(const Identity& identity) override { | 172 void OnStart(const Identity& identity) override { |
| 173 identity_ = identity; | 173 identity_ = identity; |
| 174 bindings_.set_connection_error_handler( | 174 bindings_.set_connection_error_handler( |
| 175 base::Bind(&ConnectTestService::OnConnectionError, | 175 base::Bind(&ConnectTestService::OnConnectionError, |
| 176 base::Unretained(this))); | 176 base::Unretained(this))); |
| 177 } | 177 } |
| 178 bool OnConnect(const Identity& remote_identity, | 178 bool OnConnect(const Identity& remote_identity, |
| 179 InterfaceRegistry* registry) override { | 179 InterfaceRegistry* registry) override { |
| 180 registry->AddInterface<ServiceFactory>(this); | 180 registry->AddInterface<ServiceFactory>(this); |
| 181 registry->AddInterface<test::mojom::ConnectTestService>(this); | 181 registry->AddInterface<test::mojom::ConnectTestService>(this); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 } | 217 } |
| 218 | 218 |
| 219 Identity identity_; | 219 Identity identity_; |
| 220 std::vector<std::unique_ptr<Service>> delegates_; | 220 std::vector<std::unique_ptr<Service>> delegates_; |
| 221 mojo::BindingSet<mojom::ServiceFactory> service_factory_bindings_; | 221 mojo::BindingSet<mojom::ServiceFactory> service_factory_bindings_; |
| 222 mojo::BindingSet<test::mojom::ConnectTestService> bindings_; | 222 mojo::BindingSet<test::mojom::ConnectTestService> bindings_; |
| 223 | 223 |
| 224 DISALLOW_COPY_AND_ASSIGN(ConnectTestService); | 224 DISALLOW_COPY_AND_ASSIGN(ConnectTestService); |
| 225 }; | 225 }; |
| 226 | 226 |
| 227 } // namespace shell | 227 } // namespace service_manager |
| 228 | 228 |
| 229 MojoResult ServiceMain(MojoHandle service_request_handle) { | 229 MojoResult ServiceMain(MojoHandle service_request_handle) { |
| 230 shell::ServiceRunner runner(new shell::ConnectTestService); | 230 service_manager::ServiceRunner runner( |
| 231 new service_manager::ConnectTestService); |
| 231 return runner.Run(service_request_handle); | 232 return runner.Run(service_request_handle); |
| 232 } | 233 } |
| OLD | NEW |