Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: services/service_manager/service_manager.cc

Issue 2576233002: Consolidating the mojo NativeRunner functionality. (Closed)
Patch Set: Merged mojo_runner_host_unittests in service_manager_unittests Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 } 121 }
122 122
123 ~Instance() override { 123 ~Instance() override {
124 Stop(); 124 Stop();
125
126 // Release |runner_| so that if we are called back to OnRunnerCompleted()
127 // we know we're in the destructor.
128 std::unique_ptr<NativeRunner> runner = std::move(runner_);
129 runner.reset();
130 } 125 }
131 126
132 bool ConnectToService(std::unique_ptr<ConnectParams>* connect_params) { 127 bool ConnectToService(std::unique_ptr<ConnectParams>* connect_params) {
133 if (!service_.is_bound()) 128 if (!service_.is_bound())
134 return false; 129 return false;
135 130
136 std::unique_ptr<ConnectParams> params(std::move(*connect_params)); 131 std::unique_ptr<ConnectParams> params(std::move(*connect_params));
137 if (!params->connect_callback().is_null()) { 132 if (!params->connect_callback().is_null()) {
138 params->connect_callback().Run(mojom::ConnectResult::SUCCEEDED, 133 params->connect_callback().Run(mojom::ConnectResult::SUCCEEDED,
139 identity_.user_id()); 134 identity_.user_id());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 service.Bind(mojom::ServicePtrInfo( 170 service.Bind(mojom::ServicePtrInfo(
176 std::move(client_process_connection->service), 0)); 171 std::move(client_process_connection->service), 0));
177 pid_receiver_binding_.Bind( 172 pid_receiver_binding_.Bind(
178 std::move(client_process_connection->pid_receiver_request)); 173 std::move(client_process_connection->pid_receiver_request));
179 StartWithService(std::move(service)); 174 StartWithService(std::move(service));
180 } 175 }
181 176
182 bool StartWithFilePath(const base::FilePath& path) { 177 bool StartWithFilePath(const base::FilePath& path) {
183 DCHECK(!service_); 178 DCHECK(!service_);
184 DCHECK(!path.empty()); 179 DCHECK(!path.empty());
185 runner_ = service_manager_->native_runner_factory_->Create(path); 180 runner_ = service_manager_->service_process_launcher_factory_->Create(path);
186 if (!runner_) 181 if (!runner_)
187 return false; 182 return false;
188 bool start_sandboxed = false; 183 bool start_sandboxed = false;
189 mojom::ServicePtr service = runner_->Start( 184 mojom::ServicePtr service = runner_->Start(
190 identity_, start_sandboxed, 185 identity_, start_sandboxed,
191 base::Bind(&Instance::PIDAvailable, weak_factory_.GetWeakPtr()), 186 base::Bind(&Instance::PIDAvailable, weak_factory_.GetWeakPtr()));
192 base::Bind(&Instance::OnRunnerCompleted, weak_factory_.GetWeakPtr()));
193 StartWithService(std::move(service)); 187 StartWithService(std::move(service));
194 return true; 188 return true;
195 } 189 }
196 190
197 mojom::RunningServiceInfoPtr CreateRunningServiceInfo() const { 191 mojom::RunningServiceInfoPtr CreateRunningServiceInfo() const {
198 mojom::RunningServiceInfoPtr info(mojom::RunningServiceInfo::New()); 192 mojom::RunningServiceInfoPtr info(mojom::RunningServiceInfo::New());
199 info->id = id_; 193 info->id = id_;
200 info->identity = identity_; 194 info->identity = identity_;
201 info->pid = pid_; 195 info->pid = pid_;
202 return info; 196 return info;
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 connectors_.AddBinding(this, std::move(connector_request)); 417 connectors_.AddBinding(this, std::move(connector_request));
424 connectors_.set_connection_error_handler( 418 connectors_.set_connection_error_handler(
425 base::Bind(&Instance::OnConnectionLost, base::Unretained(this), 419 base::Bind(&Instance::OnConnectionLost, base::Unretained(this),
426 service_manager_->GetWeakPtr())); 420 service_manager_->GetWeakPtr()));
427 } 421 }
428 if (control_request.is_pending()) 422 if (control_request.is_pending())
429 control_binding_.Bind(std::move(control_request)); 423 control_binding_.Bind(std::move(control_request));
430 service_manager_->NotifyServiceStarted(identity_, pid_); 424 service_manager_->NotifyServiceStarted(identity_, pid_);
431 } 425 }
432 426
433 // Callback when NativeRunner completes.
434 void OnRunnerCompleted() {
435 if (!runner_.get())
436 return; // We're in the destructor.
437
438 service_manager_->OnInstanceError(this);
439 }
440
441 // mojom::ServiceControl: 427 // mojom::ServiceControl:
442 void RequestQuit() override { 428 void RequestQuit() override {
443 // If quit is requested, oblige when there are no pending OnConnects. 429 // If quit is requested, oblige when there are no pending OnConnects.
444 if (!pending_service_connections_) 430 if (!pending_service_connections_)
445 OnServiceLost(service_manager_->GetWeakPtr()); 431 OnServiceLost(service_manager_->GetWeakPtr());
446 } 432 }
447 433
448 service_manager::ServiceManager* const service_manager_; 434 service_manager::ServiceManager* const service_manager_;
449 435
450 // An id that identifies this instance. Distinct from pid, as a single process 436 // An id that identifies this instance. Distinct from pid, as a single process
451 // may vend multiple application instances, and this object may exist before a 437 // may vend multiple application instances, and this object may exist before a
452 // process is launched. 438 // process is launched.
453 const uint32_t id_; 439 const uint32_t id_;
454 Identity identity_; 440 Identity identity_;
455 const InterfaceProviderSpecMap interface_provider_specs_; 441 const InterfaceProviderSpecMap interface_provider_specs_;
456 const InterfaceProviderSpec empty_spec_; 442 const InterfaceProviderSpec empty_spec_;
457 const bool allow_any_application_; 443 const bool allow_any_application_;
458 std::unique_ptr<NativeRunner> runner_; 444 std::unique_ptr<ServiceProcessLauncher> runner_;
459 mojom::ServicePtr service_; 445 mojom::ServicePtr service_;
460 mojo::Binding<mojom::PIDReceiver> pid_receiver_binding_; 446 mojo::Binding<mojom::PIDReceiver> pid_receiver_binding_;
461 mojo::BindingSet<mojom::Connector> connectors_; 447 mojo::BindingSet<mojom::Connector> connectors_;
462 mojo::BindingSet<mojom::ServiceManager> service_manager_bindings_; 448 mojo::BindingSet<mojom::ServiceManager> service_manager_bindings_;
463 mojo::AssociatedBinding<mojom::ServiceControl> control_binding_; 449 mojo::AssociatedBinding<mojom::ServiceControl> control_binding_;
464 base::ProcessId pid_ = base::kNullProcessId; 450 base::ProcessId pid_ = base::kNullProcessId;
465 State state_; 451 State state_;
466 452
467 // The number of outstanding OnConnect requests which are in flight. 453 // The number of outstanding OnConnect requests which are in flight.
468 int pending_service_connections_ = 0; 454 int pending_service_connections_ = 0;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 if (entry.first.name() == name) 500 if (entry.first.name() == name)
515 return true; 501 return true;
516 } 502 }
517 return false; 503 return false;
518 } 504 }
519 505
520 //////////////////////////////////////////////////////////////////////////////// 506 ////////////////////////////////////////////////////////////////////////////////
521 // ServiceManager, public: 507 // ServiceManager, public:
522 508
523 ServiceManager::ServiceManager( 509 ServiceManager::ServiceManager(
524 std::unique_ptr<NativeRunnerFactory> native_runner_factory, 510 std::unique_ptr<ServiceProcessLauncherFactory>
511 service_process_launcher_factory,
525 mojom::ServicePtr catalog) 512 mojom::ServicePtr catalog)
526 : native_runner_factory_(std::move(native_runner_factory)), 513 : service_process_launcher_factory_(
514 std::move(service_process_launcher_factory)),
527 weak_ptr_factory_(this) { 515 weak_ptr_factory_(this) {
528 mojom::ServicePtr service; 516 mojom::ServicePtr service;
529 mojom::ServiceRequest request = mojo::GetProxy(&service); 517 mojom::ServiceRequest request = mojo::GetProxy(&service);
530 518
531 InterfaceProviderSpec spec; 519 InterfaceProviderSpec spec;
532 spec.provides[kCapability_ServiceManager].insert( 520 spec.provides[kCapability_ServiceManager].insert(
533 "service_manager::mojom::ServiceManager"); 521 "service_manager::mojom::ServiceManager");
534 spec.requires["*"].insert("service_manager:service_factory"); 522 spec.requires["*"].insert("service_manager:service_factory");
535 spec.requires[catalog::mojom::kServiceName].insert( 523 spec.requires[catalog::mojom::kServiceName].insert(
536 "service_manager:resolver"); 524 "service_manager:resolver");
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 // Now that the instance has a Service, we can connect to it. 936 // Now that the instance has a Service, we can connect to it.
949 bool connected = instance->ConnectToService(&params); 937 bool connected = instance->ConnectToService(&params);
950 DCHECK(connected); 938 DCHECK(connected);
951 } 939 }
952 940
953 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { 941 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() {
954 return weak_ptr_factory_.GetWeakPtr(); 942 return weak_ptr_factory_.GetWeakPtr();
955 } 943 }
956 944
957 } // namespace service_manager 945 } // namespace service_manager
OLDNEW
« no previous file with comments | « services/service_manager/service_manager.h ('k') | services/service_manager/standalone/context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698