OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "services/service_manager/service_manager.h" | 5 #include "services/service_manager/service_manager.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 if (!AllowsInterface(params->source(), source_connection_spec, identity_, | 211 if (!AllowsInterface(params->source(), source_connection_spec, identity_, |
212 GetConnectionSpec(), params->interface_name())) { | 212 GetConnectionSpec(), params->interface_name())) { |
213 params->set_response_data(mojom::ConnectResult::ACCESS_DENIED, identity_); | 213 params->set_response_data(mojom::ConnectResult::ACCESS_DENIED, identity_); |
214 return false; | 214 return false; |
215 } | 215 } |
216 | 216 |
217 params->set_response_data(mojom::ConnectResult::SUCCEEDED, identity_); | 217 params->set_response_data(mojom::ConnectResult::SUCCEEDED, identity_); |
218 | 218 |
219 pending_service_connections_++; | 219 pending_service_connections_++; |
220 service_->OnBindInterface( | 220 service_->OnBindInterface( |
221 ServiceInfo(params->source(), source_specs), | 221 BindSourceInfo( |
222 params->interface_name(), | 222 params->source(), |
223 params->TakeInterfaceRequestPipe(), | 223 GetRequestedCapabilities(source_connection_spec, identity_)), |
| 224 params->interface_name(), params->TakeInterfaceRequestPipe(), |
224 base::Bind(&Instance::OnConnectComplete, base::Unretained(this))); | 225 base::Bind(&Instance::OnConnectComplete, base::Unretained(this))); |
225 return true; | 226 return true; |
226 } | 227 } |
227 | 228 |
228 void OnConnectComplete() { | 229 void OnConnectComplete() { |
229 DCHECK_GT(pending_service_connections_, 0); | 230 DCHECK_GT(pending_service_connections_, 0); |
230 pending_service_connections_--; | 231 pending_service_connections_--; |
231 } | 232 } |
232 | 233 |
233 void StartWithService(mojom::ServicePtr service) { | 234 void StartWithService(mojom::ServicePtr service) { |
234 CHECK(!service_); | 235 CHECK(!service_); |
235 state_ = State::STARTING; | 236 state_ = State::STARTING; |
236 service_ = std::move(service); | 237 service_ = std::move(service); |
237 service_.set_connection_error_handler( | 238 service_.set_connection_error_handler( |
238 base::Bind(&Instance::OnServiceLost, base::Unretained(this), | 239 base::Bind(&Instance::OnServiceLost, base::Unretained(this), |
239 service_manager_->GetWeakPtr())); | 240 service_manager_->GetWeakPtr())); |
240 service_->OnStart(ServiceInfo(identity_, interface_provider_specs_), | 241 service_->OnStart(identity_, base::Bind(&Instance::OnStartComplete, |
241 base::Bind(&Instance::OnStartComplete, | 242 base::Unretained(this))); |
242 base::Unretained(this))); | |
243 } | 243 } |
244 | 244 |
245 bool StartWithFilePath(const base::FilePath& path) { | 245 bool StartWithFilePath(const base::FilePath& path) { |
246 DCHECK(!service_); | 246 DCHECK(!service_); |
247 DCHECK(!path.empty()); | 247 DCHECK(!path.empty()); |
248 runner_ = service_manager_->service_process_launcher_factory_->Create(path); | 248 runner_ = service_manager_->service_process_launcher_factory_->Create(path); |
249 if (!runner_) | 249 if (!runner_) |
250 return false; | 250 return false; |
251 bool start_sandboxed = false; | 251 bool start_sandboxed = false; |
252 mojom::ServicePtr service = runner_->Start( | 252 mojom::ServicePtr service = runner_->Start( |
(...skipping 25 matching lines...) Expand all Loading... |
278 const InterfaceProviderSpec& GetSpec(const std::string& spec) const { | 278 const InterfaceProviderSpec& GetSpec(const std::string& spec) const { |
279 auto it = interface_provider_specs_.find(spec); | 279 auto it = interface_provider_specs_.find(spec); |
280 return it != interface_provider_specs_.end() ? it->second : empty_spec_; | 280 return it != interface_provider_specs_.end() ? it->second : empty_spec_; |
281 } | 281 } |
282 | 282 |
283 const Identity& identity() const { return identity_; } | 283 const Identity& identity() const { return identity_; } |
284 void set_identity(const Identity& identity) { identity_ = identity; } | 284 void set_identity(const Identity& identity) { identity_ = identity; } |
285 uint32_t id() const { return id_; } | 285 uint32_t id() const { return id_; } |
286 | 286 |
287 // Service: | 287 // Service: |
288 void OnBindInterface(const ServiceInfo& source_info, | 288 void OnBindInterface(const BindSourceInfo& source_info, |
289 const std::string& interface_name, | 289 const std::string& interface_name, |
290 mojo::ScopedMessagePipeHandle interface_pipe) override { | 290 mojo::ScopedMessagePipeHandle interface_pipe) override { |
291 Instance* source = | 291 Instance* source = |
292 service_manager_->GetExistingInstance(source_info.identity); | 292 service_manager_->GetExistingInstance(source_info.identity); |
293 DCHECK(source); | 293 DCHECK(source); |
294 if (interface_name == mojom::ServiceManager::Name_ && | 294 if (interface_name == mojom::ServiceManager::Name_ && |
295 HasCapability(source->GetConnectionSpec(), | 295 HasCapability(source->GetConnectionSpec(), |
296 kCapability_ServiceManager)) { | 296 kCapability_ServiceManager)) { |
297 mojom::ServiceManagerRequest request = | 297 mojom::ServiceManagerRequest request = |
298 mojo::MakeRequest<mojom::ServiceManager>(std::move(interface_pipe)); | 298 mojo::MakeRequest<mojom::ServiceManager>(std::move(interface_pipe)); |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 DISALLOW_COPY_AND_ASSIGN(Instance); | 636 DISALLOW_COPY_AND_ASSIGN(Instance); |
637 }; | 637 }; |
638 | 638 |
639 class ServiceManager::ServiceImpl : public Service { | 639 class ServiceManager::ServiceImpl : public Service { |
640 public: | 640 public: |
641 explicit ServiceImpl(ServiceManager* service_manager) | 641 explicit ServiceImpl(ServiceManager* service_manager) |
642 : service_manager_(service_manager) {} | 642 : service_manager_(service_manager) {} |
643 ~ServiceImpl() override {} | 643 ~ServiceImpl() override {} |
644 | 644 |
645 // Service: | 645 // Service: |
646 void OnBindInterface(const ServiceInfo& source_info, | 646 void OnBindInterface(const BindSourceInfo& source_info, |
647 const std::string& interface_name, | 647 const std::string& interface_name, |
648 mojo::ScopedMessagePipeHandle interface_pipe) override { | 648 mojo::ScopedMessagePipeHandle interface_pipe) override { |
649 // The only interface ServiceManager exposes is mojom::ServiceManager, and | 649 // The only interface ServiceManager exposes is mojom::ServiceManager, and |
650 // access to this interface is brokered by a policy specific to each caller, | 650 // access to this interface is brokered by a policy specific to each caller, |
651 // managed by the caller's instance. Here we look to see who's calling, | 651 // managed by the caller's instance. Here we look to see who's calling, |
652 // and forward to the caller's instance to continue. | 652 // and forward to the caller's instance to continue. |
653 Instance* instance = nullptr; | 653 Instance* instance = nullptr; |
654 for (const auto& entry : service_manager_->identity_to_instance_) { | 654 for (const auto& entry : service_manager_->identity_to_instance_) { |
655 if (entry.first == source_info.identity) { | 655 if (entry.first == source_info.identity) { |
656 instance = entry.second; | 656 instance = entry.second; |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1140 instance->identity()); | 1140 instance->identity()); |
1141 if (params->HasInterfaceRequestInfo()) | 1141 if (params->HasInterfaceRequestInfo()) |
1142 instance->CallOnBindInterface(¶ms); | 1142 instance->CallOnBindInterface(¶ms); |
1143 } | 1143 } |
1144 | 1144 |
1145 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { | 1145 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { |
1146 return weak_ptr_factory_.GetWeakPtr(); | 1146 return weak_ptr_factory_.GetWeakPtr(); |
1147 } | 1147 } |
1148 | 1148 |
1149 } // namespace service_manager | 1149 } // namespace service_manager |
OLD | NEW |