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