| 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 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // shell::Service: |
| 64 void OnStart(Connector* connector, const Identity& identity, | 64 void OnStart(const Identity& identity) override { |
| 65 uint32_t id) override { | |
| 66 connector_ = connector; | |
| 67 identity_ = identity; | 65 identity_ = identity; |
| 68 id_ = id; | |
| 69 bindings_.set_connection_error_handler( | 66 bindings_.set_connection_error_handler( |
| 70 base::Bind(&ProvidedService::OnConnectionError, | 67 base::Bind(&ProvidedService::OnConnectionError, |
| 71 base::Unretained(this))); | 68 base::Unretained(this))); |
| 72 } | 69 } |
| 73 bool OnConnect(Connection* connection) override { | 70 bool OnConnect(Connection* connection) override { |
| 74 connection->AddInterface<test::mojom::ConnectTestService>(this); | 71 connection->AddInterface<test::mojom::ConnectTestService>(this); |
| 75 connection->AddInterface<test::mojom::BlockedInterface>(this); | 72 connection->AddInterface<test::mojom::BlockedInterface>(this); |
| 76 connection->AddInterface<test::mojom::UserIdTest>(this); | 73 connection->AddInterface<test::mojom::UserIdTest>(this); |
| 77 | 74 |
| 78 uint32_t remote_id = connection->GetRemoteInstanceID(); | 75 uint32_t remote_id = connection->GetRemoteInstanceID(); |
| 79 test::mojom::ConnectionStatePtr state(test::mojom::ConnectionState::New()); | 76 test::mojom::ConnectionStatePtr state(test::mojom::ConnectionState::New()); |
| 80 state->connection_local_name = connection->GetConnectionName(); | 77 state->connection_local_name = connection->GetConnectionName(); |
| 81 state->connection_remote_name = connection->GetRemoteIdentity().name(); | 78 state->connection_remote_name = connection->GetRemoteIdentity().name(); |
| 82 state->connection_remote_userid = connection->GetRemoteIdentity().user_id(); | 79 state->connection_remote_userid = connection->GetRemoteIdentity().user_id(); |
| 83 state->connection_remote_id = remote_id; | 80 state->connection_remote_id = remote_id; |
| 84 state->initialize_local_name = identity_.name(); | 81 state->initialize_local_name = identity_.name(); |
| 85 state->initialize_id = id_; | |
| 86 state->initialize_userid = identity_.user_id(); | 82 state->initialize_userid = identity_.user_id(); |
| 87 connection->GetInterface(&caller_); | 83 connection->GetInterface(&caller_); |
| 88 caller_->ConnectionAccepted(std::move(state)); | 84 caller_->ConnectionAccepted(std::move(state)); |
| 89 | 85 |
| 90 return true; | 86 return true; |
| 91 } | 87 } |
| 92 | 88 |
| 93 // InterfaceFactory<test::mojom::ConnectTestService>: | 89 // InterfaceFactory<test::mojom::ConnectTestService>: |
| 94 void Create(const Identity& remote_identity, | 90 void Create(const Identity& remote_identity, |
| 95 test::mojom::ConnectTestServiceRequest request) override { | 91 test::mojom::ConnectTestServiceRequest request) override { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 119 // test::mojom::BlockedInterface: | 115 // test::mojom::BlockedInterface: |
| 120 void GetTitleBlocked(const GetTitleBlockedCallback& callback) override { | 116 void GetTitleBlocked(const GetTitleBlockedCallback& callback) override { |
| 121 callback.Run("Called Blocked Interface!"); | 117 callback.Run("Called Blocked Interface!"); |
| 122 } | 118 } |
| 123 | 119 |
| 124 // test::mojom::UserIdTest: | 120 // test::mojom::UserIdTest: |
| 125 void ConnectToClassAppAsDifferentUser( | 121 void ConnectToClassAppAsDifferentUser( |
| 126 mojom::IdentityPtr target, | 122 mojom::IdentityPtr target, |
| 127 const ConnectToClassAppAsDifferentUserCallback& callback) override { | 123 const ConnectToClassAppAsDifferentUserCallback& callback) override { |
| 128 Connector::ConnectParams params(target.To<Identity>()); | 124 Connector::ConnectParams params(target.To<Identity>()); |
| 129 std::unique_ptr<Connection> connection = connector_->Connect(¶ms); | 125 std::unique_ptr<Connection> connection = |
| 126 connector()->Connect(¶ms); |
| 130 { | 127 { |
| 131 base::RunLoop loop; | 128 base::RunLoop loop; |
| 132 connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop)); | 129 connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop)); |
| 133 base::MessageLoop::ScopedNestableTaskAllower allow( | 130 base::MessageLoop::ScopedNestableTaskAllower allow( |
| 134 base::MessageLoop::current()); | 131 base::MessageLoop::current()); |
| 135 loop.Run(); | 132 loop.Run(); |
| 136 } | 133 } |
| 137 callback.Run(static_cast<int32_t>(connection->GetResult()), | 134 callback.Run(static_cast<int32_t>(connection->GetResult()), |
| 138 mojom::Identity::From(connection->GetRemoteIdentity())); | 135 mojom::Identity::From(connection->GetRemoteIdentity())); |
| 139 } | 136 } |
| 140 | 137 |
| 141 // base::SimpleThread: | 138 // base::SimpleThread: |
| 142 void Run() override { | 139 void Run() override { |
| 143 ServiceRunner(this).Run(request_.PassMessagePipe().release().value(), | 140 ServiceRunner(this).Run(request_.PassMessagePipe().release().value(), |
| 144 false); | 141 false); |
| 145 delete this; | 142 delete this; |
| 146 } | 143 } |
| 147 | 144 |
| 148 void OnConnectionError() { | 145 void OnConnectionError() { |
| 149 if (bindings_.empty()) | 146 if (bindings_.empty()) |
| 150 base::MessageLoop::current()->QuitWhenIdle(); | 147 base::MessageLoop::current()->QuitWhenIdle(); |
| 151 } | 148 } |
| 152 | 149 |
| 153 Connector* connector_ = nullptr; | |
| 154 Identity identity_; | 150 Identity identity_; |
| 155 uint32_t id_ = shell::mojom::kInvalidInstanceID; | |
| 156 const std::string title_; | 151 const std::string title_; |
| 157 mojom::ServiceRequest request_; | 152 mojom::ServiceRequest request_; |
| 158 test::mojom::ExposedInterfacePtr caller_; | 153 test::mojom::ExposedInterfacePtr caller_; |
| 159 mojo::BindingSet<test::mojom::ConnectTestService> bindings_; | 154 mojo::BindingSet<test::mojom::ConnectTestService> bindings_; |
| 160 mojo::BindingSet<test::mojom::BlockedInterface> blocked_bindings_; | 155 mojo::BindingSet<test::mojom::BlockedInterface> blocked_bindings_; |
| 161 mojo::BindingSet<test::mojom::UserIdTest> user_id_test_bindings_; | 156 mojo::BindingSet<test::mojom::UserIdTest> user_id_test_bindings_; |
| 162 | 157 |
| 163 DISALLOW_COPY_AND_ASSIGN(ProvidedService); | 158 DISALLOW_COPY_AND_ASSIGN(ProvidedService); |
| 164 }; | 159 }; |
| 165 | 160 |
| 166 class ConnectTestService | 161 class ConnectTestService |
| 167 : public Service, | 162 : public Service, |
| 168 public InterfaceFactory<mojom::ServiceFactory>, | 163 public InterfaceFactory<mojom::ServiceFactory>, |
| 169 public InterfaceFactory<test::mojom::ConnectTestService>, | 164 public InterfaceFactory<test::mojom::ConnectTestService>, |
| 170 public mojom::ServiceFactory, | 165 public mojom::ServiceFactory, |
| 171 public test::mojom::ConnectTestService { | 166 public test::mojom::ConnectTestService { |
| 172 public: | 167 public: |
| 173 ConnectTestService() {} | 168 ConnectTestService() {} |
| 174 ~ConnectTestService() override {} | 169 ~ConnectTestService() override {} |
| 175 | 170 |
| 176 private: | 171 private: |
| 177 // shell::Service: | 172 // shell::Service: |
| 178 void OnStart(Connector* connector, const Identity& identity, | 173 void OnStart(const Identity& identity) override { |
| 179 uint32_t id) override { | |
| 180 identity_ = identity; | 174 identity_ = identity; |
| 181 bindings_.set_connection_error_handler( | 175 bindings_.set_connection_error_handler( |
| 182 base::Bind(&ConnectTestService::OnConnectionError, | 176 base::Bind(&ConnectTestService::OnConnectionError, |
| 183 base::Unretained(this))); | 177 base::Unretained(this))); |
| 184 } | 178 } |
| 185 bool OnConnect(Connection* connection) override { | 179 bool OnConnect(Connection* connection) override { |
| 186 connection->AddInterface<ServiceFactory>(this); | 180 connection->AddInterface<ServiceFactory>(this); |
| 187 connection->AddInterface<test::mojom::ConnectTestService>(this); | 181 connection->AddInterface<test::mojom::ConnectTestService>(this); |
| 188 return true; | 182 return true; |
| 189 } | 183 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 DISALLOW_COPY_AND_ASSIGN(ConnectTestService); | 224 DISALLOW_COPY_AND_ASSIGN(ConnectTestService); |
| 231 }; | 225 }; |
| 232 | 226 |
| 233 } // namespace shell | 227 } // namespace shell |
| 234 | 228 |
| 235 MojoResult MojoMain(MojoHandle shell_handle) { | 229 MojoResult MojoMain(MojoHandle shell_handle) { |
| 236 MojoResult rv = shell::ServiceRunner(new shell::ConnectTestService) | 230 MojoResult rv = shell::ServiceRunner(new shell::ConnectTestService) |
| 237 .Run(shell_handle); | 231 .Run(shell_handle); |
| 238 return rv; | 232 return rv; |
| 239 } | 233 } |
| OLD | NEW |