| 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/public/cpp/service_context.h" | 5 #include "services/service_manager/public/cpp/service_context.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 ServiceContext::~ServiceContext() {} | 45 ServiceContext::~ServiceContext() {} |
| 46 | 46 |
| 47 void ServiceContext::SetConnectionLostClosure(const base::Closure& closure) { | 47 void ServiceContext::SetConnectionLostClosure(const base::Closure& closure) { |
| 48 connection_lost_closure_ = closure; | 48 connection_lost_closure_ = closure; |
| 49 if (service_quit_) | 49 if (service_quit_) |
| 50 QuitNow(); | 50 QuitNow(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void ServiceContext::RequestQuit() { | 53 void ServiceContext::RequestQuit() { |
| 54 // TODO(rockot): Implement this. | 54 DCHECK(service_control_.is_bound()); |
| 55 service_control_->RequestQuit(); |
| 55 } | 56 } |
| 56 | 57 |
| 57 void ServiceContext::DisconnectFromServiceManager() { | 58 void ServiceContext::DisconnectFromServiceManager() { |
| 58 if (binding_.is_bound()) | 59 if (binding_.is_bound()) |
| 59 binding_.Close(); | 60 binding_.Close(); |
| 60 connector_.reset(); | 61 connector_.reset(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 void ServiceContext::QuitNow() { | 64 void ServiceContext::QuitNow() { |
| 64 if (binding_.is_bound()) | 65 if (binding_.is_bound()) |
| 65 binding_.Close(); | 66 binding_.Close(); |
| 66 if (!connection_lost_closure_.is_null()) | 67 if (!connection_lost_closure_.is_null()) |
| 67 base::ResetAndReturn(&connection_lost_closure_).Run(); | 68 base::ResetAndReturn(&connection_lost_closure_).Run(); |
| 68 } | 69 } |
| 69 | 70 |
| 70 void ServiceContext::DestroyService() { | 71 void ServiceContext::DestroyService() { |
| 71 QuitNow(); | 72 QuitNow(); |
| 72 service_.reset(); | 73 service_.reset(); |
| 73 } | 74 } |
| 74 | 75 |
| 75 //////////////////////////////////////////////////////////////////////////////// | 76 //////////////////////////////////////////////////////////////////////////////// |
| 76 // ServiceContext, mojom::Service implementation: | 77 // ServiceContext, mojom::Service implementation: |
| 77 | 78 |
| 78 void ServiceContext::OnStart(const ServiceInfo& info, | 79 void ServiceContext::OnStart(const ServiceInfo& info, |
| 79 const OnStartCallback& callback) { | 80 const OnStartCallback& callback) { |
| 80 local_info_ = info; | 81 local_info_ = info; |
| 81 callback.Run(std::move(pending_connector_request_)); | 82 callback.Run(std::move(pending_connector_request_), |
| 83 mojo::GetProxy(&service_control_, binding_.associated_group())); |
| 82 service_->OnStart(this); | 84 service_->OnStart(this); |
| 83 } | 85 } |
| 84 | 86 |
| 85 void ServiceContext::OnConnect( | 87 void ServiceContext::OnConnect( |
| 86 const ServiceInfo& source_info, | 88 const ServiceInfo& source_info, |
| 87 mojom::InterfaceProviderRequest interfaces) { | 89 mojom::InterfaceProviderRequest interfaces, |
| 90 const OnConnectCallback& callback) { |
| 88 InterfaceProviderSpec source_spec, target_spec; | 91 InterfaceProviderSpec source_spec, target_spec; |
| 89 GetInterfaceProviderSpec(mojom::kServiceManager_ConnectorSpec, | 92 GetInterfaceProviderSpec(mojom::kServiceManager_ConnectorSpec, |
| 90 local_info_.interface_provider_specs, &target_spec); | 93 local_info_.interface_provider_specs, &target_spec); |
| 91 GetInterfaceProviderSpec(mojom::kServiceManager_ConnectorSpec, | 94 GetInterfaceProviderSpec(mojom::kServiceManager_ConnectorSpec, |
| 92 source_info.interface_provider_specs, &source_spec); | 95 source_info.interface_provider_specs, &source_spec); |
| 93 auto registry = | 96 auto registry = |
| 94 base::MakeUnique<InterfaceRegistry>(mojom::kServiceManager_ConnectorSpec); | 97 base::MakeUnique<InterfaceRegistry>(mojom::kServiceManager_ConnectorSpec); |
| 95 registry->Bind(std::move(interfaces), local_info_.identity, target_spec, | 98 registry->Bind(std::move(interfaces), local_info_.identity, target_spec, |
| 96 source_info.identity, source_spec); | 99 source_info.identity, source_spec); |
| 97 | 100 |
| 101 // Acknowledge the request regardless of whether it's accepted. |
| 102 callback.Run(); |
| 103 |
| 98 if (!service_->OnConnect(source_info, registry.get())) | 104 if (!service_->OnConnect(source_info, registry.get())) |
| 99 return; | 105 return; |
| 100 | 106 |
| 101 InterfaceRegistry* raw_registry = registry.get(); | 107 InterfaceRegistry* raw_registry = registry.get(); |
| 102 registry->AddConnectionLostClosure(base::Bind( | 108 registry->AddConnectionLostClosure(base::Bind( |
| 103 &ServiceContext::OnRegistryConnectionError, base::Unretained(this), | 109 &ServiceContext::OnRegistryConnectionError, base::Unretained(this), |
| 104 raw_registry)); | 110 raw_registry)); |
| 105 connection_interface_registries_.insert( | 111 connection_interface_registries_.insert( |
| 106 std::make_pair(raw_registry, std::move(registry))); | 112 std::make_pair(raw_registry, std::move(registry))); |
| 107 } | 113 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 136 } | 142 } |
| 137 | 143 |
| 138 void ServiceContext::DestroyConnectionInterfaceRegistry( | 144 void ServiceContext::DestroyConnectionInterfaceRegistry( |
| 139 InterfaceRegistry* registry) { | 145 InterfaceRegistry* registry) { |
| 140 auto it = connection_interface_registries_.find(registry); | 146 auto it = connection_interface_registries_.find(registry); |
| 141 CHECK(it != connection_interface_registries_.end()); | 147 CHECK(it != connection_interface_registries_.end()); |
| 142 connection_interface_registries_.erase(it); | 148 connection_interface_registries_.erase(it); |
| 143 } | 149 } |
| 144 | 150 |
| 145 } // namespace service_manager | 151 } // namespace service_manager |
| OLD | NEW |