| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 const char kCapability_InstanceName[] = "service_manager:instance_name"; | 44 const char kCapability_InstanceName[] = "service_manager:instance_name"; |
| 45 const char kCapability_AllUsers[] = "service_manager:all_users"; | 45 const char kCapability_AllUsers[] = "service_manager:all_users"; |
| 46 const char kCapability_InstancePerChild[] = | 46 const char kCapability_InstancePerChild[] = |
| 47 "service_manager:instance_per_child"; | 47 "service_manager:instance_per_child"; |
| 48 const char kCapability_ServiceManager[] = "service_manager:service_manager"; | 48 const char kCapability_ServiceManager[] = "service_manager:service_manager"; |
| 49 | 49 |
| 50 bool Succeeded(mojom::ConnectResult result) { | 50 bool Succeeded(mojom::ConnectResult result) { |
| 51 return result == mojom::ConnectResult::SUCCEEDED; | 51 return result == mojom::ConnectResult::SUCCEEDED; |
| 52 } | 52 } |
| 53 | 53 |
| 54 bool RunConnectCallback(ConnectParams* params, | |
| 55 mojom::ConnectResult result, | |
| 56 const std::string& user_id) { | |
| 57 if (!params->connect_callback().is_null()) { | |
| 58 params->connect_callback().Run(result, user_id); | |
| 59 return true; | |
| 60 } | |
| 61 return false; | |
| 62 } | |
| 63 | |
| 64 void RunBindInterfaceCallback(ConnectParams* params, | |
| 65 mojom::ConnectResult result, | |
| 66 const std::string& user_id) { | |
| 67 if (!params->bind_interface_callback().is_null()) | |
| 68 params->bind_interface_callback().Run(result, user_id); | |
| 69 } | |
| 70 | |
| 71 void RunCallback(ConnectParams* params, | |
| 72 mojom::ConnectResult result, | |
| 73 const std::string& user_id) { | |
| 74 if (!RunConnectCallback(params, result, user_id)) | |
| 75 RunBindInterfaceCallback(params, result, user_id); | |
| 76 } | |
| 77 | |
| 78 } // namespace | 54 } // namespace |
| 79 | 55 |
| 80 Identity CreateServiceManagerIdentity() { | 56 Identity CreateServiceManagerIdentity() { |
| 81 return Identity(service_manager::mojom::kServiceName, mojom::kRootUserID); | 57 return Identity(service_manager::mojom::kServiceName, mojom::kRootUserID); |
| 82 } | 58 } |
| 83 | 59 |
| 84 Identity CreateCatalogIdentity() { | 60 Identity CreateCatalogIdentity() { |
| 85 return Identity(catalog::mojom::kServiceName, mojom::kRootUserID); | 61 return Identity(catalog::mojom::kServiceName, mojom::kRootUserID); |
| 86 } | 62 } |
| 87 | 63 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 } else { | 121 } else { |
| 146 // Notify the ServiceManager that this Instance is really going away. | 122 // Notify the ServiceManager that this Instance is really going away. |
| 147 service_manager_->OnInstanceStopped(identity_); | 123 service_manager_->OnInstanceStopped(identity_); |
| 148 } | 124 } |
| 149 } | 125 } |
| 150 | 126 |
| 151 ~Instance() override { | 127 ~Instance() override { |
| 152 Stop(); | 128 Stop(); |
| 153 } | 129 } |
| 154 | 130 |
| 155 bool CallOnConnect(std::unique_ptr<ConnectParams>* in_params) { | |
| 156 if (!service_.is_bound()) { | |
| 157 RunConnectCallback(in_params->get(), mojom::ConnectResult::ACCESS_DENIED, | |
| 158 identity_.user_id()); | |
| 159 return false; | |
| 160 } | |
| 161 | |
| 162 std::unique_ptr<ConnectParams> params(std::move(*in_params)); | |
| 163 RunConnectCallback(params.get(), mojom::ConnectResult::SUCCEEDED, | |
| 164 identity_.user_id()); | |
| 165 | |
| 166 InterfaceProviderSpecMap specs; | |
| 167 Instance* source = | |
| 168 service_manager_->GetExistingInstance(params->source()); | |
| 169 if (source) | |
| 170 specs = source->interface_provider_specs_; | |
| 171 | |
| 172 pending_service_connections_++; | |
| 173 service_->OnConnect(ServiceInfo(params->source(), specs), | |
| 174 params->TakeRemoteInterfaces(), | |
| 175 base::Bind(&Instance::OnConnectComplete, | |
| 176 base::Unretained(this))); | |
| 177 return true; | |
| 178 } | |
| 179 | |
| 180 bool CallOnBindInterface(std::unique_ptr<ConnectParams>* in_params) { | 131 bool CallOnBindInterface(std::unique_ptr<ConnectParams>* in_params) { |
| 181 if (!service_.is_bound()) { | 132 if (!service_.is_bound()) { |
| 182 RunBindInterfaceCallback(in_params->get(), | 133 (*in_params) |
| 183 mojom::ConnectResult::ACCESS_DENIED, | 134 ->set_response_data(mojom::ConnectResult::ACCESS_DENIED, identity_); |
| 184 identity_.user_id()); | |
| 185 return false; | 135 return false; |
| 186 } | 136 } |
| 187 | 137 |
| 188 std::unique_ptr<ConnectParams> params(std::move(*in_params)); | 138 std::unique_ptr<ConnectParams> params(std::move(*in_params)); |
| 189 InterfaceProviderSpecMap source_specs; | 139 InterfaceProviderSpecMap source_specs; |
| 190 InterfaceProviderSpec source_connection_spec; | 140 InterfaceProviderSpec source_connection_spec; |
| 191 Instance* source = | 141 Instance* source = |
| 192 service_manager_->GetExistingInstance(params->source()); | 142 service_manager_->GetExistingInstance(params->source()); |
| 193 if (source) { | 143 if (source) { |
| 194 source_specs = source->interface_provider_specs_; | 144 source_specs = source->interface_provider_specs_; |
| 195 source_connection_spec = source->GetConnectionSpec(); | 145 source_connection_spec = source->GetConnectionSpec(); |
| 196 } | 146 } |
| 197 | 147 |
| 198 InterfaceSet exposed = GetInterfacesToExpose(source_connection_spec, | 148 InterfaceSet exposed = GetInterfacesToExpose(source_connection_spec, |
| 199 identity_, | 149 identity_, |
| 200 GetConnectionSpec()); | 150 GetConnectionSpec()); |
| 201 bool allowed = (exposed.size() == 1 && exposed.count("*") == 1) || | 151 bool allowed = (exposed.size() == 1 && exposed.count("*") == 1) || |
| 202 exposed.count(params->interface_name()) > 0; | 152 exposed.count(params->interface_name()) > 0; |
| 203 if (!allowed) { | 153 if (!allowed) { |
| 204 std::stringstream ss; | 154 std::stringstream ss; |
| 205 ss << "Connection InterfaceProviderSpec prevented service: " | 155 ss << "Connection InterfaceProviderSpec prevented service: " |
| 206 << params->source().name() << " from binding interface: " | 156 << params->source().name() << " from binding interface: " |
| 207 << params->interface_name() << " exposed by: " << identity_.name(); | 157 << params->interface_name() << " exposed by: " << identity_.name(); |
| 208 LOG(ERROR) << ss.str(); | 158 LOG(ERROR) << ss.str(); |
| 209 params->bind_interface_callback().Run(mojom::ConnectResult::ACCESS_DENIED, | 159 params->set_response_data(mojom::ConnectResult::ACCESS_DENIED, identity_); |
| 210 identity_.user_id()); | |
| 211 return false; | 160 return false; |
| 212 } | 161 } |
| 213 | 162 |
| 214 if (!params->bind_interface_callback().is_null()) { | 163 params->set_response_data(mojom::ConnectResult::SUCCEEDED, identity_); |
| 215 params->bind_interface_callback().Run(mojom::ConnectResult::SUCCEEDED, | |
| 216 identity_.user_id()); | |
| 217 } | |
| 218 | 164 |
| 219 pending_service_connections_++; | 165 pending_service_connections_++; |
| 220 service_->OnBindInterface( | 166 service_->OnBindInterface( |
| 221 ServiceInfo(params->source(), source_specs), | 167 ServiceInfo(params->source(), source_specs), |
| 222 params->interface_name(), | 168 params->interface_name(), |
| 223 params->TakeInterfaceRequestPipe(), | 169 params->TakeInterfaceRequestPipe(), |
| 224 base::Bind(&Instance::OnConnectComplete, base::Unretained(this))); | 170 base::Bind(&Instance::OnConnectComplete, base::Unretained(this))); |
| 225 return true; | 171 return true; |
| 226 } | 172 } |
| 227 | 173 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 | 246 |
| 301 // The service was started but the service manager hasn't received the | 247 // The service was started but the service manager hasn't received the |
| 302 // initial response from it yet. | 248 // initial response from it yet. |
| 303 STARTING, | 249 STARTING, |
| 304 | 250 |
| 305 // The service was started successfully. | 251 // The service was started successfully. |
| 306 STARTED | 252 STARTED |
| 307 }; | 253 }; |
| 308 | 254 |
| 309 // mojom::Connector implementation: | 255 // mojom::Connector implementation: |
| 310 void StartService( | 256 void BindInterface(const service_manager::Identity& in_target, |
| 311 const Identity& in_target, | 257 const std::string& interface_name, |
| 312 mojo::ScopedMessagePipeHandle service_handle, | 258 mojo::ScopedMessagePipeHandle interface_pipe, |
| 313 mojom::PIDReceiverRequest pid_receiver_request) override { | 259 const BindInterfaceCallback& callback) override { |
| 314 Identity target = in_target; | 260 Identity target = in_target; |
| 315 mojom::ConnectResult result = | 261 mojom::ConnectResult result = |
| 316 ValidateConnectParams(&target, nullptr, nullptr); | 262 ValidateConnectParams(&target, nullptr, nullptr); |
| 317 if (!Succeeded(result)) | 263 if (!Succeeded(result)) { |
| 318 return; | 264 callback.Run(result, Identity()); |
| 265 return; |
| 266 } |
| 319 | 267 |
| 320 std::unique_ptr<ConnectParams> params(new ConnectParams); | 268 std::unique_ptr<ConnectParams> params(new ConnectParams); |
| 321 params->set_source(identity_); | 269 params->set_source(identity_); |
| 322 params->set_target(target); | 270 params->set_target(target); |
| 271 params->set_interface_request_info(interface_name, |
| 272 std::move(interface_pipe)); |
| 273 params->set_start_service_callback(callback); |
| 274 service_manager_->Connect(std::move(params), weak_factory_.GetWeakPtr()); |
| 275 } |
| 323 | 276 |
| 324 mojom::ServicePtr service; | 277 void StartService(const Identity& in_target, |
| 325 service.Bind(mojom::ServicePtrInfo(std::move(service_handle), 0)); | 278 const StartServiceCallback& callback) override { |
| 326 params->set_client_process_info(std::move(service), | 279 Identity target = in_target; |
| 327 std::move(pid_receiver_request)); | 280 mojom::ConnectResult result = |
| 328 service_manager_->Connect(std::move(params), weak_factory_.GetWeakPtr()); | 281 ValidateConnectParams(&target, nullptr, nullptr); |
| 329 } | 282 if (!Succeeded(result)) { |
| 283 callback.Run(result, Identity()); |
| 284 return; |
| 285 } |
| 330 | 286 |
| 331 void Connect(const service_manager::Identity& in_target, | 287 std::unique_ptr<ConnectParams> params(new ConnectParams); |
| 332 mojom::InterfaceProviderRequest remote_interfaces, | 288 params->set_source(identity_); |
| 333 const ConnectCallback& callback) override { | 289 params->set_target(target); |
| 334 Identity target = in_target; | 290 params->set_start_service_callback(callback); |
| 335 mojom::ConnectResult result = | 291 service_manager_->Connect(std::move(params), weak_factory_.GetWeakPtr()); |
| 336 ValidateConnectParams(&target, nullptr, nullptr); | 292 } |
| 337 if (!Succeeded(result)) { | |
| 338 callback.Run(result, mojom::kInheritUserID); | |
| 339 return; | |
| 340 } | |
| 341 | 293 |
| 342 std::unique_ptr<ConnectParams> params(new ConnectParams); | 294 void StartServiceWithProcess( |
| 343 params->set_source(identity_); | 295 const Identity& in_target, |
| 344 params->set_target(target); | 296 mojo::ScopedMessagePipeHandle service_handle, |
| 345 params->set_remote_interfaces(std::move(remote_interfaces)); | 297 mojom::PIDReceiverRequest pid_receiver_request, |
| 346 params->set_connect_callback(callback); | 298 const StartServiceWithProcessCallback& callback) override { |
| 347 service_manager_->Connect(std::move(params), weak_factory_.GetWeakPtr()); | 299 Identity target = in_target; |
| 348 } | 300 mojom::ConnectResult result = |
| 301 ValidateConnectParams(&target, nullptr, nullptr); |
| 302 if (!Succeeded(result)) { |
| 303 callback.Run(result, Identity()); |
| 304 return; |
| 305 } |
| 349 | 306 |
| 350 void BindInterface(const service_manager::Identity& in_target, | 307 std::unique_ptr<ConnectParams> params(new ConnectParams); |
| 351 const std::string& interface_name, | 308 params->set_source(identity_); |
| 352 mojo::ScopedMessagePipeHandle interface_pipe, | 309 params->set_target(target); |
| 353 const BindInterfaceCallback& callback) override { | |
| 354 Identity target = in_target; | |
| 355 mojom::ConnectResult result = | |
| 356 ValidateConnectParams(&target, nullptr, nullptr); | |
| 357 if (!Succeeded(result)) { | |
| 358 callback.Run(result, mojom::kInheritUserID); | |
| 359 return; | |
| 360 } | |
| 361 | 310 |
| 362 std::unique_ptr<ConnectParams> params(new ConnectParams); | 311 mojom::ServicePtr service; |
| 363 params->set_source(identity_); | 312 service.Bind(mojom::ServicePtrInfo(std::move(service_handle), 0)); |
| 364 params->set_target(target); | 313 params->set_client_process_info(std::move(service), |
| 365 params->set_interface_request_info(interface_name, | 314 std::move(pid_receiver_request)); |
| 366 std::move(interface_pipe)); | 315 params->set_start_service_callback(callback); |
| 367 params->set_bind_interface_callback(callback); | 316 service_manager_->Connect(std::move(params), weak_factory_.GetWeakPtr()); |
| 368 service_manager_->Connect(std::move(params), weak_factory_.GetWeakPtr()); | |
| 369 } | 317 } |
| 370 | 318 |
| 371 void Clone(mojom::ConnectorRequest request) override { | 319 void Clone(mojom::ConnectorRequest request) override { |
| 372 connectors_.AddBinding(this, std::move(request)); | 320 connectors_.AddBinding(this, std::move(request)); |
| 373 } | 321 } |
| 374 | 322 |
| 375 // mojom::PIDReceiver: | 323 // mojom::PIDReceiver: |
| 376 void SetPID(uint32_t pid) override { | 324 void SetPID(uint32_t pid) override { |
| 377 PIDAvailable(pid); | 325 PIDAvailable(pid); |
| 378 } | 326 } |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 service_manager_->NotifyServiceStarted(identity_, pid_); | 474 service_manager_->NotifyServiceStarted(identity_, pid_); |
| 527 } | 475 } |
| 528 | 476 |
| 529 // mojom::ServiceControl: | 477 // mojom::ServiceControl: |
| 530 void RequestQuit() override { | 478 void RequestQuit() override { |
| 531 // If quit is requested, oblige when there are no pending OnConnects. | 479 // If quit is requested, oblige when there are no pending OnConnects. |
| 532 if (!pending_service_connections_) | 480 if (!pending_service_connections_) |
| 533 OnServiceLost(service_manager_->GetWeakPtr()); | 481 OnServiceLost(service_manager_->GetWeakPtr()); |
| 534 } | 482 } |
| 535 | 483 |
| 536 void EmptyConnectCallback(mojom::ConnectResult result, | |
| 537 const std::string& user_id) {} | |
| 538 void BindCallbackWrapper(const BindInterfaceCallback& wrapped, | |
| 539 mojom::ConnectResult result, | |
| 540 const std::string& user_id) { | |
| 541 wrapped.Run(result, user_id); | |
| 542 } | |
| 543 | |
| 544 service_manager::ServiceManager* const service_manager_; | 484 service_manager::ServiceManager* const service_manager_; |
| 545 | 485 |
| 546 // An id that identifies this instance. Distinct from pid, as a single process | 486 // An id that identifies this instance. Distinct from pid, as a single process |
| 547 // may vend multiple application instances, and this object may exist before a | 487 // may vend multiple application instances, and this object may exist before a |
| 548 // process is launched. | 488 // process is launched. |
| 549 const uint32_t id_; | 489 const uint32_t id_; |
| 550 Identity identity_; | 490 Identity identity_; |
| 551 const InterfaceProviderSpecMap interface_provider_specs_; | 491 const InterfaceProviderSpecMap interface_provider_specs_; |
| 552 const InterfaceProviderSpec empty_spec_; | 492 const InterfaceProviderSpec empty_spec_; |
| 553 const bool allow_any_application_; | 493 const bool allow_any_application_; |
| 554 std::unique_ptr<ServiceProcessLauncher> runner_; | 494 std::unique_ptr<ServiceProcessLauncher> runner_; |
| 555 mojom::ServicePtr service_; | 495 mojom::ServicePtr service_; |
| 556 mojo::Binding<mojom::PIDReceiver> pid_receiver_binding_; | 496 mojo::Binding<mojom::PIDReceiver> pid_receiver_binding_; |
| 557 mojo::BindingSet<mojom::Connector> connectors_; | 497 mojo::BindingSet<mojom::Connector> connectors_; |
| 558 mojo::BindingSet<mojom::ServiceManager> service_manager_bindings_; | 498 mojo::BindingSet<mojom::ServiceManager> service_manager_bindings_; |
| 559 mojo::AssociatedBinding<mojom::ServiceControl> control_binding_; | 499 mojo::AssociatedBinding<mojom::ServiceControl> control_binding_; |
| 560 base::ProcessId pid_ = base::kNullProcessId; | 500 base::ProcessId pid_ = base::kNullProcessId; |
| 561 State state_; | 501 State state_; |
| 562 | 502 |
| 563 // The number of outstanding OnConnect requests which are in flight. | 503 // The number of outstanding OnBindInterface requests which are in flight. |
| 564 int pending_service_connections_ = 0; | 504 int pending_service_connections_ = 0; |
| 565 | 505 |
| 566 base::WeakPtrFactory<Instance> weak_factory_; | 506 base::WeakPtrFactory<Instance> weak_factory_; |
| 567 | 507 |
| 568 DISALLOW_COPY_AND_ASSIGN(Instance); | 508 DISALLOW_COPY_AND_ASSIGN(Instance); |
| 569 }; | 509 }; |
| 570 | 510 |
| 571 class ServiceManager::ServiceImpl : public Service { | 511 class ServiceManager::ServiceImpl : public Service { |
| 572 public: | 512 public: |
| 573 explicit ServiceImpl(ServiceManager* service_manager) | 513 explicit ServiceImpl(ServiceManager* service_manager) |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 void ServiceManager::NotifyServiceFailedToStart(const Identity& identity) { | 785 void ServiceManager::NotifyServiceFailedToStart(const Identity& identity) { |
| 846 listeners_.ForAllPtrs( | 786 listeners_.ForAllPtrs( |
| 847 [identity](mojom::ServiceManagerListener* listener) { | 787 [identity](mojom::ServiceManagerListener* listener) { |
| 848 listener->OnServiceFailedToStart(identity); | 788 listener->OnServiceFailedToStart(identity); |
| 849 }); | 789 }); |
| 850 } | 790 } |
| 851 | 791 |
| 852 bool ServiceManager::ConnectToExistingInstance( | 792 bool ServiceManager::ConnectToExistingInstance( |
| 853 std::unique_ptr<ConnectParams>* params) { | 793 std::unique_ptr<ConnectParams>* params) { |
| 854 Instance* instance = GetExistingInstance((*params)->target()); | 794 Instance* instance = GetExistingInstance((*params)->target()); |
| 855 if (instance) { | 795 if (!instance) |
| 856 if ((*params)->HasInterfaceRequestInfo()) { | 796 return false; |
| 857 instance->CallOnBindInterface(params); | 797 |
| 858 return true; | 798 if ((*params)->HasInterfaceRequestInfo()) |
| 859 } | 799 instance->CallOnBindInterface(params); |
| 860 return instance->CallOnConnect(params); | 800 return true; |
| 861 } | |
| 862 return false; | |
| 863 } | 801 } |
| 864 | 802 |
| 865 ServiceManager::Instance* ServiceManager::CreateInstance( | 803 ServiceManager::Instance* ServiceManager::CreateInstance( |
| 866 const Identity& source, | 804 const Identity& source, |
| 867 const Identity& target, | 805 const Identity& target, |
| 868 const InterfaceProviderSpecMap& specs) { | 806 const InterfaceProviderSpecMap& specs) { |
| 869 CHECK(target.user_id() != mojom::kInheritUserID); | 807 CHECK(target.user_id() != mojom::kInheritUserID); |
| 870 | 808 |
| 871 auto instance = base::MakeUnique<Instance>(this, target, specs); | 809 auto instance = base::MakeUnique<Instance>(this, target, specs); |
| 872 Instance* raw_instance = instance.get(); | 810 Instance* raw_instance = instance.get(); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 mojom::ResolveResultPtr result, | 875 mojom::ResolveResultPtr result, |
| 938 mojom::ResolveResultPtr parent) { | 876 mojom::ResolveResultPtr parent) { |
| 939 // If this request was originated by a specific Instance and that Instance is | 877 // If this request was originated by a specific Instance and that Instance is |
| 940 // no longer around, we ignore this response. | 878 // no longer around, we ignore this response. |
| 941 if (has_source_instance && !source_instance) | 879 if (has_source_instance && !source_instance) |
| 942 return; | 880 return; |
| 943 | 881 |
| 944 // If name resolution failed, we drop the connection. | 882 // If name resolution failed, we drop the connection. |
| 945 if (!result) { | 883 if (!result) { |
| 946 LOG(ERROR) << "Failed to resolve service name: " << params->target().name(); | 884 LOG(ERROR) << "Failed to resolve service name: " << params->target().name(); |
| 947 RunCallback(params.get(), mojom::ConnectResult::INVALID_ARGUMENT, ""); | 885 params->set_response_data(mojom::ConnectResult::INVALID_ARGUMENT, |
| 886 Identity()); |
| 948 return; | 887 return; |
| 949 } | 888 } |
| 950 | 889 |
| 951 std::string instance_name = params->target().instance(); | 890 std::string instance_name = params->target().instance(); |
| 952 | 891 |
| 953 // |result->interface_provider_specs| can be empty when there is no manifest. | 892 // |result->interface_provider_specs| can be empty when there is no manifest. |
| 954 InterfaceProviderSpec connection_spec = GetPermissiveInterfaceProviderSpec(); | 893 InterfaceProviderSpec connection_spec = GetPermissiveInterfaceProviderSpec(); |
| 955 auto it = result->interface_provider_specs.find( | 894 auto it = result->interface_provider_specs.find( |
| 956 mojom::kServiceManager_ConnectorSpec); | 895 mojom::kServiceManager_ConnectorSpec); |
| 957 if (it != result->interface_provider_specs.end()) | 896 if (it != result->interface_provider_specs.end()) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1004 mojom::ServiceRequest request(&service); | 943 mojom::ServiceRequest request(&service); |
| 1005 | 944 |
| 1006 // The catalog was unable to read a manifest for this service. We can't do | 945 // The catalog was unable to read a manifest for this service. We can't do |
| 1007 // anything more. | 946 // anything more. |
| 1008 // TODO(beng): There may be some cases where it's valid to have an empty | 947 // TODO(beng): There may be some cases where it's valid to have an empty |
| 1009 // spec, so we should probably include a return value in |result|. | 948 // spec, so we should probably include a return value in |result|. |
| 1010 if (result->interface_provider_specs.empty()) { | 949 if (result->interface_provider_specs.empty()) { |
| 1011 LOG(ERROR) | 950 LOG(ERROR) |
| 1012 << "Error: The catalog was unable to read a manifest for service \"" | 951 << "Error: The catalog was unable to read a manifest for service \"" |
| 1013 << result->name << "\"."; | 952 << result->name << "\"."; |
| 1014 RunCallback(params.get(), mojom::ConnectResult::ACCESS_DENIED, ""); | 953 params->set_response_data(mojom::ConnectResult::ACCESS_DENIED, |
| 954 Identity()); |
| 1015 return; | 955 return; |
| 1016 } | 956 } |
| 1017 | 957 |
| 1018 if (parent) { | 958 if (parent) { |
| 1019 // This service is provided by another service via a ServiceFactory. | 959 // This service is provided by another service via a ServiceFactory. |
| 1020 std::string target_user_id = target.user_id(); | 960 std::string target_user_id = target.user_id(); |
| 1021 std::string factory_instance_name = instance_name; | 961 std::string factory_instance_name = instance_name; |
| 1022 | 962 |
| 1023 auto spec_iter = parent->interface_provider_specs.find( | 963 auto spec_iter = parent->interface_provider_specs.find( |
| 1024 mojom::kServiceManager_ConnectorSpec); | 964 mojom::kServiceManager_ConnectorSpec); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1042 } else { | 982 } else { |
| 1043 base::FilePath package_path; | 983 base::FilePath package_path; |
| 1044 if (!service_overrides_ || !service_overrides_->GetExecutablePathOverride( | 984 if (!service_overrides_ || !service_overrides_->GetExecutablePathOverride( |
| 1045 target.name(), &package_path)) { | 985 target.name(), &package_path)) { |
| 1046 package_path = result->package_path; | 986 package_path = result->package_path; |
| 1047 } | 987 } |
| 1048 DCHECK(!package_path.empty()); | 988 DCHECK(!package_path.empty()); |
| 1049 | 989 |
| 1050 if (!instance->StartWithFilePath(package_path)) { | 990 if (!instance->StartWithFilePath(package_path)) { |
| 1051 OnInstanceError(instance); | 991 OnInstanceError(instance); |
| 1052 RunCallback(params.get(), mojom::ConnectResult::INVALID_ARGUMENT, ""); | 992 params->set_response_data(mojom::ConnectResult::INVALID_ARGUMENT, |
| 993 Identity()); |
| 1053 return; | 994 return; |
| 1054 } | 995 } |
| 1055 } | 996 } |
| 1056 } | 997 } |
| 1057 | 998 |
| 1058 // Now that the instance has a Service, we can connect to it. | 999 params->set_response_data(mojom::ConnectResult::SUCCEEDED, |
| 1059 if (params->HasInterfaceRequestInfo()) { | 1000 instance->identity()); |
| 1001 if (params->HasInterfaceRequestInfo()) |
| 1060 instance->CallOnBindInterface(¶ms); | 1002 instance->CallOnBindInterface(¶ms); |
| 1061 } else { | |
| 1062 bool connected = instance->CallOnConnect(¶ms); | |
| 1063 DCHECK(connected); | |
| 1064 } | |
| 1065 } | 1003 } |
| 1066 | 1004 |
| 1067 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { | 1005 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { |
| 1068 return weak_ptr_factory_.GetWeakPtr(); | 1006 return weak_ptr_factory_.GetWeakPtr(); |
| 1069 } | 1007 } |
| 1070 | 1008 |
| 1071 } // namespace service_manager | 1009 } // namespace service_manager |
| OLD | NEW |