| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 connectors_.CloseAllBindings(); | 111 connectors_.CloseAllBindings(); |
| 112 service_manager_bindings_.CloseAllBindings(); | 112 service_manager_bindings_.CloseAllBindings(); |
| 113 service_manager_->OnInstanceUnreachable(this); | 113 service_manager_->OnInstanceUnreachable(this); |
| 114 | 114 |
| 115 if (state_ == State::STARTING) { | 115 if (state_ == State::STARTING) { |
| 116 service_manager_->NotifyServiceFailedToStart(identity_); | 116 service_manager_->NotifyServiceFailedToStart(identity_); |
| 117 } else { | 117 } else { |
| 118 // Notify the ServiceManager that this Instance is really going away. | 118 // Notify the ServiceManager that this Instance is really going away. |
| 119 service_manager_->OnInstanceStopped(identity_); | 119 service_manager_->OnInstanceStopped(identity_); |
| 120 } | 120 } |
| 121 | |
| 122 // Release |runner_| so that if we are called back to OnRunnerCompleted() | |
| 123 // we know we're in the destructor. | |
| 124 std::unique_ptr<NativeRunner> runner = std::move(runner_); | |
| 125 runner.reset(); | |
| 126 } | 121 } |
| 127 | 122 |
| 128 Instance* parent() const { return parent_; } | 123 Instance* parent() const { return parent_; } |
| 129 | 124 |
| 130 void AddChild(std::unique_ptr<Instance> child) { | 125 void AddChild(std::unique_ptr<Instance> child) { |
| 131 child->parent_ = this; | 126 child->parent_ = this; |
| 132 children_.insert(std::make_pair(child.get(), std::move(child))); | 127 children_.insert(std::make_pair(child.get(), std::move(child))); |
| 133 } | 128 } |
| 134 | 129 |
| 135 void RemoveChild(Instance* child) { | 130 void RemoveChild(Instance* child) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 service.Bind(mojom::ServicePtrInfo( | 181 service.Bind(mojom::ServicePtrInfo( |
| 187 std::move(client_process_connection->service), 0)); | 182 std::move(client_process_connection->service), 0)); |
| 188 pid_receiver_binding_.Bind( | 183 pid_receiver_binding_.Bind( |
| 189 std::move(client_process_connection->pid_receiver_request)); | 184 std::move(client_process_connection->pid_receiver_request)); |
| 190 StartWithService(std::move(service)); | 185 StartWithService(std::move(service)); |
| 191 } | 186 } |
| 192 | 187 |
| 193 bool StartWithFilePath(const base::FilePath& path) { | 188 bool StartWithFilePath(const base::FilePath& path) { |
| 194 DCHECK(!service_); | 189 DCHECK(!service_); |
| 195 DCHECK(!path.empty()); | 190 DCHECK(!path.empty()); |
| 196 runner_ = service_manager_->native_runner_factory_->Create(path); | 191 runner_ = service_manager_->service_process_launcher_factory_->Create(path); |
| 197 if (!runner_) | 192 if (!runner_) |
| 198 return false; | 193 return false; |
| 199 bool start_sandboxed = false; | 194 bool start_sandboxed = false; |
| 200 mojom::ServicePtr service = runner_->Start( | 195 mojom::ServicePtr service = runner_->Start( |
| 201 identity_, start_sandboxed, | 196 identity_, start_sandboxed, |
| 202 base::Bind(&Instance::PIDAvailable, weak_factory_.GetWeakPtr()), | 197 base::Bind(&Instance::PIDAvailable, weak_factory_.GetWeakPtr())); |
| 203 base::Bind(&Instance::OnRunnerCompleted, weak_factory_.GetWeakPtr())); | |
| 204 StartWithService(std::move(service)); | 198 StartWithService(std::move(service)); |
| 205 return true; | 199 return true; |
| 206 } | 200 } |
| 207 | 201 |
| 208 mojom::RunningServiceInfoPtr CreateRunningServiceInfo() const { | 202 mojom::RunningServiceInfoPtr CreateRunningServiceInfo() const { |
| 209 mojom::RunningServiceInfoPtr info(mojom::RunningServiceInfo::New()); | 203 mojom::RunningServiceInfoPtr info(mojom::RunningServiceInfo::New()); |
| 210 info->id = id_; | 204 info->id = id_; |
| 211 info->identity = identity_; | 205 info->identity = identity_; |
| 212 info->pid = pid_; | 206 info->pid = pid_; |
| 213 return info; | 207 return info; |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 connectors_.AddBinding(this, std::move(connector_request)); | 428 connectors_.AddBinding(this, std::move(connector_request)); |
| 435 connectors_.set_connection_error_handler( | 429 connectors_.set_connection_error_handler( |
| 436 base::Bind(&Instance::OnConnectionLost, base::Unretained(this), | 430 base::Bind(&Instance::OnConnectionLost, base::Unretained(this), |
| 437 service_manager_->GetWeakPtr())); | 431 service_manager_->GetWeakPtr())); |
| 438 } | 432 } |
| 439 if (control_request.is_pending()) | 433 if (control_request.is_pending()) |
| 440 control_binding_.Bind(std::move(control_request)); | 434 control_binding_.Bind(std::move(control_request)); |
| 441 service_manager_->NotifyServiceStarted(identity_, pid_); | 435 service_manager_->NotifyServiceStarted(identity_, pid_); |
| 442 } | 436 } |
| 443 | 437 |
| 444 // Callback when NativeRunner completes. | |
| 445 void OnRunnerCompleted() { | |
| 446 if (!runner_.get()) | |
| 447 return; // We're in the destructor. | |
| 448 | |
| 449 service_manager_->OnInstanceError(this); | |
| 450 } | |
| 451 | |
| 452 // mojom::ServiceControl: | 438 // mojom::ServiceControl: |
| 453 void RequestQuit() override { | 439 void RequestQuit() override { |
| 454 // If quit is requested, oblige when there are no pending OnConnects. | 440 // If quit is requested, oblige when there are no pending OnConnects. |
| 455 if (!pending_service_connections_) | 441 if (!pending_service_connections_) |
| 456 OnServiceLost(service_manager_->GetWeakPtr()); | 442 OnServiceLost(service_manager_->GetWeakPtr()); |
| 457 } | 443 } |
| 458 | 444 |
| 459 service_manager::ServiceManager* const service_manager_; | 445 service_manager::ServiceManager* const service_manager_; |
| 460 | 446 |
| 461 // An id that identifies this instance. Distinct from pid, as a single process | 447 // An id that identifies this instance. Distinct from pid, as a single process |
| 462 // may vend multiple application instances, and this object may exist before a | 448 // may vend multiple application instances, and this object may exist before a |
| 463 // process is launched. | 449 // process is launched. |
| 464 const uint32_t id_; | 450 const uint32_t id_; |
| 465 Identity identity_; | 451 Identity identity_; |
| 466 const InterfaceProviderSpecMap interface_provider_specs_; | 452 const InterfaceProviderSpecMap interface_provider_specs_; |
| 467 const InterfaceProviderSpec empty_spec_; | 453 const InterfaceProviderSpec empty_spec_; |
| 468 const bool allow_any_application_; | 454 const bool allow_any_application_; |
| 469 std::unique_ptr<NativeRunner> runner_; | 455 std::unique_ptr<ServiceProcessLauncher> runner_; |
| 470 mojom::ServicePtr service_; | 456 mojom::ServicePtr service_; |
| 471 mojo::Binding<mojom::PIDReceiver> pid_receiver_binding_; | 457 mojo::Binding<mojom::PIDReceiver> pid_receiver_binding_; |
| 472 mojo::BindingSet<mojom::Connector> connectors_; | 458 mojo::BindingSet<mojom::Connector> connectors_; |
| 473 mojo::BindingSet<mojom::ServiceManager> service_manager_bindings_; | 459 mojo::BindingSet<mojom::ServiceManager> service_manager_bindings_; |
| 474 mojo::AssociatedBinding<mojom::ServiceControl> control_binding_; | 460 mojo::AssociatedBinding<mojom::ServiceControl> control_binding_; |
| 475 base::ProcessId pid_ = base::kNullProcessId; | 461 base::ProcessId pid_ = base::kNullProcessId; |
| 476 Instance* parent_ = nullptr; | 462 Instance* parent_ = nullptr; |
| 477 InstanceMap children_; | 463 InstanceMap children_; |
| 478 State state_; | 464 State state_; |
| 479 | 465 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 if (entry.first.name() == name) | 513 if (entry.first.name() == name) |
| 528 return true; | 514 return true; |
| 529 } | 515 } |
| 530 return false; | 516 return false; |
| 531 } | 517 } |
| 532 | 518 |
| 533 //////////////////////////////////////////////////////////////////////////////// | 519 //////////////////////////////////////////////////////////////////////////////// |
| 534 // ServiceManager, public: | 520 // ServiceManager, public: |
| 535 | 521 |
| 536 ServiceManager::ServiceManager( | 522 ServiceManager::ServiceManager( |
| 537 std::unique_ptr<NativeRunnerFactory> native_runner_factory, | 523 std::unique_ptr<ServiceProcessLauncherFactory> |
| 524 service_process_launcher_factory, |
| 538 mojom::ServicePtr catalog) | 525 mojom::ServicePtr catalog) |
| 539 : native_runner_factory_(std::move(native_runner_factory)), | 526 : service_process_launcher_factory_( |
| 527 std::move(service_process_launcher_factory)), |
| 540 weak_ptr_factory_(this) { | 528 weak_ptr_factory_(this) { |
| 541 mojom::ServicePtr service; | 529 mojom::ServicePtr service; |
| 542 mojom::ServiceRequest request = mojo::GetProxy(&service); | 530 mojom::ServiceRequest request = mojo::GetProxy(&service); |
| 543 | 531 |
| 544 InterfaceProviderSpec spec; | 532 InterfaceProviderSpec spec; |
| 545 spec.provides[kCapability_ServiceManager].insert( | 533 spec.provides[kCapability_ServiceManager].insert( |
| 546 "service_manager::mojom::ServiceManager"); | 534 "service_manager::mojom::ServiceManager"); |
| 547 spec.requires["*"].insert("service_manager:service_factory"); | 535 spec.requires["*"].insert("service_manager:service_factory"); |
| 548 spec.requires[catalog::mojom::kServiceName].insert( | 536 spec.requires[catalog::mojom::kServiceName].insert( |
| 549 "service_manager:resolver"); | 537 "service_manager:resolver"); |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 // Now that the instance has a Service, we can connect to it. | 949 // Now that the instance has a Service, we can connect to it. |
| 962 bool connected = instance->ConnectToService(¶ms); | 950 bool connected = instance->ConnectToService(¶ms); |
| 963 DCHECK(connected); | 951 DCHECK(connected); |
| 964 } | 952 } |
| 965 | 953 |
| 966 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { | 954 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { |
| 967 return weak_ptr_factory_.GetWeakPtr(); | 955 return weak_ptr_factory_.GetWeakPtr(); |
| 968 } | 956 } |
| 969 | 957 |
| 970 } // namespace service_manager | 958 } // namespace service_manager |
| OLD | NEW |