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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 91 |
92 void ServiceContext::OnConnect( | 92 void ServiceContext::OnConnect( |
93 const ServiceInfo& source_info, | 93 const ServiceInfo& source_info, |
94 mojom::InterfaceProviderRequest interfaces, | 94 mojom::InterfaceProviderRequest interfaces, |
95 const OnConnectCallback& callback) { | 95 const OnConnectCallback& callback) { |
96 InterfaceProviderSpec source_spec, target_spec; | 96 InterfaceProviderSpec source_spec, target_spec; |
97 GetInterfaceProviderSpec(mojom::kServiceManager_ConnectorSpec, | 97 GetInterfaceProviderSpec(mojom::kServiceManager_ConnectorSpec, |
98 local_info_.interface_provider_specs, &target_spec); | 98 local_info_.interface_provider_specs, &target_spec); |
99 GetInterfaceProviderSpec(mojom::kServiceManager_ConnectorSpec, | 99 GetInterfaceProviderSpec(mojom::kServiceManager_ConnectorSpec, |
100 source_info.interface_provider_specs, &source_spec); | 100 source_info.interface_provider_specs, &source_spec); |
| 101 |
| 102 // Acknowledge the request regardless of whether it's accepted. |
| 103 callback.Run(); |
| 104 |
| 105 CallOnConnect(source_info, source_spec, target_spec, std::move(interfaces)); |
| 106 } |
| 107 |
| 108 void ServiceContext::OnBindInterface( |
| 109 const ServiceInfo& source_info, |
| 110 const std::string& interface_name, |
| 111 mojo::ScopedMessagePipeHandle interface_pipe, |
| 112 const OnBindInterfaceCallback& callback) { |
| 113 // Acknowledge the request regardless of whether it's accepted. |
| 114 callback.Run(); |
| 115 |
| 116 mojom::InterfaceProviderPtr interface_provider; |
| 117 // TODO(beng): This should be replaced with a call to OnBindInterface() in a |
| 118 // subsequent change. |
| 119 InterfaceProviderSpec source_spec, target_spec; |
| 120 GetInterfaceProviderSpec(mojom::kServiceManager_ConnectorSpec, |
| 121 local_info_.interface_provider_specs, &target_spec); |
| 122 GetInterfaceProviderSpec(mojom::kServiceManager_ConnectorSpec, |
| 123 source_info.interface_provider_specs, &source_spec); |
| 124 CallOnConnect(source_info, source_spec, target_spec, |
| 125 MakeRequest(&interface_provider)); |
| 126 interface_provider->GetInterface(interface_name, std::move(interface_pipe)); |
| 127 } |
| 128 |
| 129 //////////////////////////////////////////////////////////////////////////////// |
| 130 // ServiceContext, private: |
| 131 |
| 132 void ServiceContext::CallOnConnect(const ServiceInfo& source_info, |
| 133 const InterfaceProviderSpec& source_spec, |
| 134 const InterfaceProviderSpec& target_spec, |
| 135 mojom::InterfaceProviderRequest interfaces) { |
101 auto registry = | 136 auto registry = |
102 base::MakeUnique<InterfaceRegistry>(mojom::kServiceManager_ConnectorSpec); | 137 base::MakeUnique<InterfaceRegistry>(mojom::kServiceManager_ConnectorSpec); |
103 registry->Bind(std::move(interfaces), local_info_.identity, target_spec, | 138 registry->Bind(std::move(interfaces), local_info_.identity, target_spec, |
104 source_info.identity, source_spec); | 139 source_info.identity, source_spec); |
105 | 140 |
106 // Acknowledge the request regardless of whether it's accepted. | |
107 callback.Run(); | |
108 | |
109 if (!service_->OnConnect(source_info, registry.get())) | 141 if (!service_->OnConnect(source_info, registry.get())) |
110 return; | 142 return; |
111 | 143 |
112 InterfaceRegistry* raw_registry = registry.get(); | 144 InterfaceRegistry* raw_registry = registry.get(); |
113 registry->AddConnectionLostClosure(base::Bind( | 145 registry->AddConnectionLostClosure(base::Bind( |
114 &ServiceContext::OnRegistryConnectionError, base::Unretained(this), | 146 &ServiceContext::OnRegistryConnectionError, base::Unretained(this), |
115 raw_registry)); | 147 raw_registry)); |
116 connection_interface_registries_.insert( | 148 connection_interface_registries_.insert( |
117 std::make_pair(raw_registry, std::move(registry))); | 149 std::make_pair(raw_registry, std::move(registry))); |
118 } | 150 } |
119 | 151 |
120 //////////////////////////////////////////////////////////////////////////////// | |
121 // ServiceContext, private: | |
122 | |
123 void ServiceContext::OnConnectionError() { | 152 void ServiceContext::OnConnectionError() { |
124 // Note that the Service doesn't technically have to quit now, it may live | 153 // Note that the Service doesn't technically have to quit now, it may live |
125 // on to service existing connections. All existing Connectors however are | 154 // on to service existing connections. All existing Connectors however are |
126 // invalid. | 155 // invalid. |
127 service_quit_ = service_->OnStop(); | 156 service_quit_ = service_->OnStop(); |
128 if (service_quit_) { | 157 if (service_quit_) { |
129 QuitNow(); | 158 QuitNow(); |
130 // NOTE: This call may delete |this|, so don't access any ServiceContext | 159 // NOTE: This call may delete |this|, so don't access any ServiceContext |
131 // state beyond this point. | 160 // state beyond this point. |
132 return; | 161 return; |
(...skipping 14 matching lines...) Expand all Loading... |
147 } | 176 } |
148 | 177 |
149 void ServiceContext::DestroyConnectionInterfaceRegistry( | 178 void ServiceContext::DestroyConnectionInterfaceRegistry( |
150 InterfaceRegistry* registry) { | 179 InterfaceRegistry* registry) { |
151 auto it = connection_interface_registries_.find(registry); | 180 auto it = connection_interface_registries_.find(registry); |
152 CHECK(it != connection_interface_registries_.end()); | 181 CHECK(it != connection_interface_registries_.end()); |
153 connection_interface_registries_.erase(it); | 182 connection_interface_registries_.erase(it); |
154 } | 183 } |
155 | 184 |
156 } // namespace service_manager | 185 } // namespace service_manager |
OLD | NEW |