| 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" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 public test::mojom::ConnectTestService, | 47 public test::mojom::ConnectTestService, |
| 48 public test::mojom::StandaloneApp, | 48 public test::mojom::StandaloneApp, |
| 49 public test::mojom::BlockedInterface, | 49 public test::mojom::BlockedInterface, |
| 50 public test::mojom::UserIdTest { | 50 public test::mojom::UserIdTest { |
| 51 public: | 51 public: |
| 52 ConnectTestApp() {} | 52 ConnectTestApp() {} |
| 53 ~ConnectTestApp() override {} | 53 ~ConnectTestApp() override {} |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 // service_manager::Service: | 56 // service_manager::Service: |
| 57 void OnStart(ServiceContext* context) override { | 57 void OnStart() override { |
| 58 context_ = context; | |
| 59 bindings_.set_connection_error_handler( | 58 bindings_.set_connection_error_handler( |
| 60 base::Bind(&ConnectTestApp::OnConnectionError, | 59 base::Bind(&ConnectTestApp::OnConnectionError, |
| 61 base::Unretained(this))); | 60 base::Unretained(this))); |
| 62 standalone_bindings_.set_connection_error_handler( | 61 standalone_bindings_.set_connection_error_handler( |
| 63 base::Bind(&ConnectTestApp::OnConnectionError, | 62 base::Bind(&ConnectTestApp::OnConnectionError, |
| 64 base::Unretained(this))); | 63 base::Unretained(this))); |
| 65 } | 64 } |
| 65 |
| 66 bool OnConnect(const ServiceInfo& remote_info, | 66 bool OnConnect(const ServiceInfo& remote_info, |
| 67 InterfaceRegistry* registry) override { | 67 InterfaceRegistry* registry) override { |
| 68 registry->AddInterface<test::mojom::ConnectTestService>(this); | 68 registry->AddInterface<test::mojom::ConnectTestService>(this); |
| 69 registry->AddInterface<test::mojom::StandaloneApp>(this); | 69 registry->AddInterface<test::mojom::StandaloneApp>(this); |
| 70 registry->AddInterface<test::mojom::BlockedInterface>(this); | 70 registry->AddInterface<test::mojom::BlockedInterface>(this); |
| 71 registry->AddInterface<test::mojom::UserIdTest>(this); | 71 registry->AddInterface<test::mojom::UserIdTest>(this); |
| 72 | 72 |
| 73 test::mojom::ConnectionStatePtr state(test::mojom::ConnectionState::New()); | 73 test::mojom::ConnectionStatePtr state(test::mojom::ConnectionState::New()); |
| 74 state->connection_remote_name = remote_info.identity.name(); | 74 state->connection_remote_name = remote_info.identity.name(); |
| 75 state->connection_remote_userid = remote_info.identity.user_id(); | 75 state->connection_remote_userid = remote_info.identity.user_id(); |
| 76 state->initialize_local_name = context_->identity().name(); | 76 state->initialize_local_name = context()->identity().name(); |
| 77 state->initialize_userid = context_->identity().user_id(); | 77 state->initialize_userid = context()->identity().user_id(); |
| 78 | 78 |
| 79 context_->connector()->ConnectToInterface(remote_info.identity, &caller_); | 79 context()->connector()->ConnectToInterface(remote_info.identity, &caller_); |
| 80 caller_->ConnectionAccepted(std::move(state)); | 80 caller_->ConnectionAccepted(std::move(state)); |
| 81 | 81 |
| 82 return true; | 82 return true; |
| 83 } | 83 } |
| 84 | 84 |
| 85 // InterfaceFactory<test::mojom::ConnectTestService>: | 85 // InterfaceFactory<test::mojom::ConnectTestService>: |
| 86 void Create(const Identity& remote_identity, | 86 void Create(const Identity& remote_identity, |
| 87 test::mojom::ConnectTestServiceRequest request) override { | 87 test::mojom::ConnectTestServiceRequest request) override { |
| 88 bindings_.AddBinding(this, std::move(request)); | 88 bindings_.AddBinding(this, std::move(request)); |
| 89 } | 89 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 104 void Create(const Identity& remote_identity, | 104 void Create(const Identity& remote_identity, |
| 105 test::mojom::UserIdTestRequest request) override { | 105 test::mojom::UserIdTestRequest request) override { |
| 106 user_id_test_bindings_.AddBinding(this, std::move(request)); | 106 user_id_test_bindings_.AddBinding(this, std::move(request)); |
| 107 } | 107 } |
| 108 | 108 |
| 109 // test::mojom::ConnectTestService: | 109 // test::mojom::ConnectTestService: |
| 110 void GetTitle(const GetTitleCallback& callback) override { | 110 void GetTitle(const GetTitleCallback& callback) override { |
| 111 callback.Run("APP"); | 111 callback.Run("APP"); |
| 112 } | 112 } |
| 113 void GetInstance(const GetInstanceCallback& callback) override { | 113 void GetInstance(const GetInstanceCallback& callback) override { |
| 114 callback.Run(context_->identity().instance()); | 114 callback.Run(context()->identity().instance()); |
| 115 } | 115 } |
| 116 | 116 |
| 117 // test::mojom::StandaloneApp: | 117 // test::mojom::StandaloneApp: |
| 118 void ConnectToAllowedAppInBlockedPackage( | 118 void ConnectToAllowedAppInBlockedPackage( |
| 119 const ConnectToAllowedAppInBlockedPackageCallback& callback) override { | 119 const ConnectToAllowedAppInBlockedPackageCallback& callback) override { |
| 120 base::RunLoop run_loop; | 120 base::RunLoop run_loop; |
| 121 std::unique_ptr<Connection> connection = | 121 std::unique_ptr<Connection> connection = |
| 122 context_->connector()->Connect("service:connect_test_a"); | 122 context()->connector()->Connect("service:connect_test_a"); |
| 123 connection->SetConnectionLostClosure( | 123 connection->SetConnectionLostClosure( |
| 124 base::Bind(&ConnectTestApp::OnConnectionBlocked, | 124 base::Bind(&ConnectTestApp::OnConnectionBlocked, |
| 125 base::Unretained(this), callback, &run_loop)); | 125 base::Unretained(this), callback, &run_loop)); |
| 126 test::mojom::ConnectTestServicePtr test_service; | 126 test::mojom::ConnectTestServicePtr test_service; |
| 127 connection->GetInterface(&test_service); | 127 connection->GetInterface(&test_service); |
| 128 test_service->GetTitle( | 128 test_service->GetTitle( |
| 129 base::Bind(&ConnectTestApp::OnGotTitle, base::Unretained(this), | 129 base::Bind(&ConnectTestApp::OnGotTitle, base::Unretained(this), |
| 130 callback, &run_loop)); | 130 callback, &run_loop)); |
| 131 { | 131 { |
| 132 // This message is dispatched as a task on the same run loop, so we need | 132 // This message is dispatched as a task on the same run loop, so we need |
| 133 // to allow nesting in order to pump additional signals. | 133 // to allow nesting in order to pump additional signals. |
| 134 base::MessageLoop::ScopedNestableTaskAllower allow( | 134 base::MessageLoop::ScopedNestableTaskAllower allow( |
| 135 base::MessageLoop::current()); | 135 base::MessageLoop::current()); |
| 136 run_loop.Run(); | 136 run_loop.Run(); |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 void ConnectToClassInterface( | 139 void ConnectToClassInterface( |
| 140 const ConnectToClassInterfaceCallback& callback) override { | 140 const ConnectToClassInterfaceCallback& callback) override { |
| 141 std::unique_ptr<Connection> connection = | 141 std::unique_ptr<Connection> connection = |
| 142 context_->connector()->Connect("service:connect_test_class_app"); | 142 context()->connector()->Connect("service:connect_test_class_app"); |
| 143 test::mojom::ClassInterfacePtr class_interface; | 143 test::mojom::ClassInterfacePtr class_interface; |
| 144 connection->GetInterface(&class_interface); | 144 connection->GetInterface(&class_interface); |
| 145 std::string ping_response; | 145 std::string ping_response; |
| 146 { | 146 { |
| 147 base::RunLoop loop; | 147 base::RunLoop loop; |
| 148 class_interface->Ping(base::Bind(&ReceiveString, &ping_response, &loop)); | 148 class_interface->Ping(base::Bind(&ReceiveString, &ping_response, &loop)); |
| 149 base::MessageLoop::ScopedNestableTaskAllower allow( | 149 base::MessageLoop::ScopedNestableTaskAllower allow( |
| 150 base::MessageLoop::current()); | 150 base::MessageLoop::current()); |
| 151 loop.Run(); | 151 loop.Run(); |
| 152 } | 152 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 167 void GetTitleBlocked(const GetTitleBlockedCallback& callback) override { | 167 void GetTitleBlocked(const GetTitleBlockedCallback& callback) override { |
| 168 callback.Run("Called Blocked Interface!"); | 168 callback.Run("Called Blocked Interface!"); |
| 169 } | 169 } |
| 170 | 170 |
| 171 // test::mojom::UserIdTest: | 171 // test::mojom::UserIdTest: |
| 172 void ConnectToClassAppAsDifferentUser( | 172 void ConnectToClassAppAsDifferentUser( |
| 173 const service_manager::Identity& target, | 173 const service_manager::Identity& target, |
| 174 const ConnectToClassAppAsDifferentUserCallback& callback) override { | 174 const ConnectToClassAppAsDifferentUserCallback& callback) override { |
| 175 Connector::ConnectParams params(target); | 175 Connector::ConnectParams params(target); |
| 176 std::unique_ptr<Connection> connection = | 176 std::unique_ptr<Connection> connection = |
| 177 context_->connector()->Connect(¶ms); | 177 context()->connector()->Connect(¶ms); |
| 178 { | 178 { |
| 179 base::RunLoop loop; | 179 base::RunLoop loop; |
| 180 connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop)); | 180 connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop)); |
| 181 base::MessageLoop::ScopedNestableTaskAllower allow( | 181 base::MessageLoop::ScopedNestableTaskAllower allow( |
| 182 base::MessageLoop::current()); | 182 base::MessageLoop::current()); |
| 183 loop.Run(); | 183 loop.Run(); |
| 184 } | 184 } |
| 185 callback.Run(static_cast<int32_t>(connection->GetResult()), | 185 callback.Run(static_cast<int32_t>(connection->GetResult()), |
| 186 connection->GetRemoteIdentity()); | 186 connection->GetRemoteIdentity()); |
| 187 } | 187 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 199 const std::string& title) { | 199 const std::string& title) { |
| 200 callback.Run(title); | 200 callback.Run(title); |
| 201 run_loop->Quit(); | 201 run_loop->Quit(); |
| 202 } | 202 } |
| 203 | 203 |
| 204 void OnConnectionError() { | 204 void OnConnectionError() { |
| 205 if (bindings_.empty() && standalone_bindings_.empty()) | 205 if (bindings_.empty() && standalone_bindings_.empty()) |
| 206 base::MessageLoop::current()->QuitWhenIdle(); | 206 base::MessageLoop::current()->QuitWhenIdle(); |
| 207 } | 207 } |
| 208 | 208 |
| 209 ServiceContext* context_ = nullptr; | |
| 210 mojo::BindingSet<test::mojom::ConnectTestService> bindings_; | 209 mojo::BindingSet<test::mojom::ConnectTestService> bindings_; |
| 211 mojo::BindingSet<test::mojom::StandaloneApp> standalone_bindings_; | 210 mojo::BindingSet<test::mojom::StandaloneApp> standalone_bindings_; |
| 212 mojo::BindingSet<test::mojom::BlockedInterface> blocked_bindings_; | 211 mojo::BindingSet<test::mojom::BlockedInterface> blocked_bindings_; |
| 213 mojo::BindingSet<test::mojom::UserIdTest> user_id_test_bindings_; | 212 mojo::BindingSet<test::mojom::UserIdTest> user_id_test_bindings_; |
| 214 test::mojom::ExposedInterfacePtr caller_; | 213 test::mojom::ExposedInterfacePtr caller_; |
| 215 | 214 |
| 216 DISALLOW_COPY_AND_ASSIGN(ConnectTestApp); | 215 DISALLOW_COPY_AND_ASSIGN(ConnectTestApp); |
| 217 }; | 216 }; |
| 218 | 217 |
| 219 } // namespace service_manager | 218 } // namespace service_manager |
| 220 | 219 |
| 221 MojoResult ServiceMain(MojoHandle service_request_handle) { | 220 MojoResult ServiceMain(MojoHandle service_request_handle) { |
| 222 service_manager::ServiceRunner runner(new service_manager::ConnectTestApp); | 221 service_manager::ServiceRunner runner(new service_manager::ConnectTestApp); |
| 223 return runner.Run(service_request_handle); | 222 return runner.Run(service_request_handle); |
| 224 } | 223 } |
| OLD | NEW |