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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 227 |
228 // The service was started but the service manager hasn't received the | 228 // The service was started but the service manager hasn't received the |
229 // initial response from it yet. | 229 // initial response from it yet. |
230 STARTING, | 230 STARTING, |
231 | 231 |
232 // The service was started successfully. | 232 // The service was started successfully. |
233 STARTED | 233 STARTED |
234 }; | 234 }; |
235 | 235 |
236 // mojom::Connector implementation: | 236 // mojom::Connector implementation: |
| 237 void RegisterService( |
| 238 const Identity& target, |
| 239 mojom::ClientProcessConnectionPtr client_process_connection) override { |
| 240 Connect( |
| 241 target, |
| 242 mojom::InterfaceProviderRequest(), |
| 243 std::move(client_process_connection), |
| 244 base::Bind( |
| 245 &service_manager::ServiceManager::Instance::EmptyConnectCallback, |
| 246 weak_factory_.GetWeakPtr())); |
| 247 } |
| 248 |
237 void Connect(const service_manager::Identity& in_target, | 249 void Connect(const service_manager::Identity& in_target, |
238 mojom::InterfaceProviderRequest remote_interfaces, | 250 mojom::InterfaceProviderRequest remote_interfaces, |
239 mojom::ClientProcessConnectionPtr client_process_connection, | 251 mojom::ClientProcessConnectionPtr client_process_connection, |
240 const ConnectCallback& callback) override { | 252 const ConnectCallback& callback) override { |
241 Identity target = in_target; | 253 Identity target = in_target; |
242 if (target.user_id() == mojom::kInheritUserID) | 254 if (target.user_id() == mojom::kInheritUserID) |
243 target.set_user_id(identity_.user_id()); | 255 target.set_user_id(identity_.user_id()); |
244 | 256 |
245 if (!ValidateIdentity(target, callback)) | 257 if (!ValidateIdentity(target, callback)) |
246 return; | 258 return; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 service_manager_->NotifyServiceStarted(identity_, pid_); | 437 service_manager_->NotifyServiceStarted(identity_, pid_); |
426 } | 438 } |
427 | 439 |
428 // mojom::ServiceControl: | 440 // mojom::ServiceControl: |
429 void RequestQuit() override { | 441 void RequestQuit() override { |
430 // If quit is requested, oblige when there are no pending OnConnects. | 442 // If quit is requested, oblige when there are no pending OnConnects. |
431 if (!pending_service_connections_) | 443 if (!pending_service_connections_) |
432 OnServiceLost(service_manager_->GetWeakPtr()); | 444 OnServiceLost(service_manager_->GetWeakPtr()); |
433 } | 445 } |
434 | 446 |
| 447 void EmptyConnectCallback(mojom::ConnectResult result, |
| 448 const std::string& user_id) {} |
| 449 |
435 service_manager::ServiceManager* const service_manager_; | 450 service_manager::ServiceManager* const service_manager_; |
436 | 451 |
437 // An id that identifies this instance. Distinct from pid, as a single process | 452 // An id that identifies this instance. Distinct from pid, as a single process |
438 // may vend multiple application instances, and this object may exist before a | 453 // may vend multiple application instances, and this object may exist before a |
439 // process is launched. | 454 // process is launched. |
440 const uint32_t id_; | 455 const uint32_t id_; |
441 Identity identity_; | 456 Identity identity_; |
442 const InterfaceProviderSpecMap interface_provider_specs_; | 457 const InterfaceProviderSpecMap interface_provider_specs_; |
443 const InterfaceProviderSpec empty_spec_; | 458 const InterfaceProviderSpec empty_spec_; |
444 const bool allow_any_application_; | 459 const bool allow_any_application_; |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 Instance* instance = CreateInstance(source_identity_for_creation, | 892 Instance* instance = CreateInstance(source_identity_for_creation, |
878 target, result->interface_provider_specs); | 893 target, result->interface_provider_specs); |
879 | 894 |
880 // Below are various paths through which a new Instance can be bound to a | 895 // Below are various paths through which a new Instance can be bound to a |
881 // Service proxy. | 896 // Service proxy. |
882 if (service.is_bound()) { | 897 if (service.is_bound()) { |
883 // If a ServicePtr was provided, there's no more work to do: someone | 898 // If a ServicePtr was provided, there's no more work to do: someone |
884 // is already holding a corresponding ServiceRequest. | 899 // is already holding a corresponding ServiceRequest. |
885 instance->StartWithService(std::move(service)); | 900 instance->StartWithService(std::move(service)); |
886 } else if (!client_process_connection.is_null()) { | 901 } else if (!client_process_connection.is_null()) { |
887 // Likewise if a ClientProcessConnection was given via Connect(), it | 902 // This branch should be reachable only via a call to RegisterService(). We |
888 // provides the Service proxy to use. | 903 // start the instance but return early before we connect to it. Clients will |
| 904 // call Connect() with the target identity subsequently. |
889 instance->StartWithClientProcessConnection( | 905 instance->StartWithClientProcessConnection( |
890 std::move(client_process_connection)); | 906 std::move(client_process_connection)); |
| 907 return; |
891 } else { | 908 } else { |
892 // Otherwise we create a new Service pipe. | 909 // Otherwise we create a new Service pipe. |
893 mojom::ServiceRequest request(&service); | 910 mojom::ServiceRequest request(&service); |
894 CHECK(!result->package_path.empty()); | 911 CHECK(!result->package_path.empty()); |
895 | 912 |
896 // The catalog was unable to read a manifest for this service. We can't do | 913 // The catalog was unable to read a manifest for this service. We can't do |
897 // anything more. | 914 // anything more. |
898 // TODO(beng): There may be some cases where it's valid to have an empty | 915 // TODO(beng): There may be some cases where it's valid to have an empty |
899 // spec, so we should probably include a return value in |result|. | 916 // spec, so we should probably include a return value in |result|. |
900 if (result->interface_provider_specs.empty()) { | 917 if (result->interface_provider_specs.empty()) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 // Now that the instance has a Service, we can connect to it. | 968 // Now that the instance has a Service, we can connect to it. |
952 bool connected = instance->ConnectToService(¶ms); | 969 bool connected = instance->ConnectToService(¶ms); |
953 DCHECK(connected); | 970 DCHECK(connected); |
954 } | 971 } |
955 | 972 |
956 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { | 973 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { |
957 return weak_ptr_factory_.GetWeakPtr(); | 974 return weak_ptr_factory_.GetWeakPtr(); |
958 } | 975 } |
959 | 976 |
960 } // namespace service_manager | 977 } // namespace service_manager |
OLD | NEW |