Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: services/service_manager/public/cpp/lib/interface_registry.cc

Issue 2478653003: Clean up dead InterfaceRegistry instances in ServiceContext (Closed)
Patch Set: . Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/interface_registry.h" 5 #include "services/service_manager/public/cpp/interface_registry.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 8
9 #include "mojo/public/cpp/bindings/message.h" 9 #include "mojo/public/cpp/bindings/message.h"
10 #include "services/service_manager/public/cpp/connection.h" 10 #include "services/service_manager/public/cpp/connection.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 const InterfaceProviderSpec& local_interface_provider_spec, 92 const InterfaceProviderSpec& local_interface_provider_spec,
93 const Identity& remote_identity, 93 const Identity& remote_identity,
94 const InterfaceProviderSpec& remote_interface_provider_spec) { 94 const InterfaceProviderSpec& remote_interface_provider_spec) {
95 DCHECK(!binding_.is_bound()); 95 DCHECK(!binding_.is_bound());
96 local_identity_ = local_identity; 96 local_identity_ = local_identity;
97 local_interface_provider_spec_ = local_interface_provider_spec; 97 local_interface_provider_spec_ = local_interface_provider_spec;
98 remote_identity_ = remote_identity; 98 remote_identity_ = remote_identity;
99 remote_interface_provider_spec_ = remote_interface_provider_spec; 99 remote_interface_provider_spec_ = remote_interface_provider_spec;
100 RebuildExposedInterfaces(); 100 RebuildExposedInterfaces();
101 binding_.Bind(std::move(local_interfaces_request)); 101 binding_.Bind(std::move(local_interfaces_request));
102 binding_.set_connection_error_handler(base::Bind(
103 &InterfaceRegistry::OnConnectionError, base::Unretained(this)));
102 } 104 }
103 105
104 void InterfaceRegistry::Serialize(std::stringstream* stream) { 106 void InterfaceRegistry::Serialize(std::stringstream* stream) {
105 *stream << "\n\nInterfaceRegistry(" << name_ << "):\n"; 107 *stream << "\n\nInterfaceRegistry(" << name_ << "):\n";
106 if (!binding_.is_bound()) { 108 if (!binding_.is_bound()) {
107 *stream << "\n --> InterfaceRegistry is not yet bound to a pipe.\n\n"; 109 *stream << "\n --> InterfaceRegistry is not yet bound to a pipe.\n\n";
108 return; 110 return;
109 } 111 }
110 112
111 *stream << "Owned by:\n "; 113 *stream << "Owned by:\n ";
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 } 172 }
171 } 173 }
172 174
173 void InterfaceRegistry::GetInterfaceNames( 175 void InterfaceRegistry::GetInterfaceNames(
174 std::set<std::string>* interface_names) { 176 std::set<std::string>* interface_names) {
175 DCHECK(interface_names); 177 DCHECK(interface_names);
176 for (auto& entry : name_to_binder_) 178 for (auto& entry : name_to_binder_)
177 interface_names->insert(entry.first); 179 interface_names->insert(entry.first);
178 } 180 }
179 181
180 void InterfaceRegistry::SetConnectionLostClosure( 182 void InterfaceRegistry::AddConnectionLostClosure(
181 const base::Closure& connection_lost_closure) { 183 const base::Closure& connection_lost_closure) {
182 binding_.set_connection_error_handler(connection_lost_closure); 184 connection_lost_closures_.push_back(connection_lost_closure);
183 } 185 }
184 186
185 // mojom::InterfaceProvider: 187 // mojom::InterfaceProvider:
186 void InterfaceRegistry::GetInterface(const std::string& interface_name, 188 void InterfaceRegistry::GetInterface(const std::string& interface_name,
187 mojo::ScopedMessagePipeHandle handle) { 189 mojo::ScopedMessagePipeHandle handle) {
188 if (is_paused_) { 190 if (is_paused_) {
189 pending_interface_requests_.emplace(interface_name, std::move(handle)); 191 pending_interface_requests_.emplace(interface_name, std::move(handle));
190 return; 192 return;
191 } 193 }
192 194
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 } 242 }
241 243
242 void InterfaceRegistry::RebuildExposedInterfaces() { 244 void InterfaceRegistry::RebuildExposedInterfaces() {
243 exposed_interfaces_ = GetInterfacesToExpose(remote_interface_provider_spec_, 245 exposed_interfaces_ = GetInterfacesToExpose(remote_interface_provider_spec_,
244 local_identity_, 246 local_identity_,
245 local_interface_provider_spec_); 247 local_interface_provider_spec_);
246 expose_all_interfaces_ = 248 expose_all_interfaces_ =
247 exposed_interfaces_.size() == 1 && exposed_interfaces_.count("*") == 1; 249 exposed_interfaces_.size() == 1 && exposed_interfaces_.count("*") == 1;
248 } 250 }
249 251
252 void InterfaceRegistry::OnConnectionError() {
253 for (const auto& closure : connection_lost_closures_)
254 closure.Run();
255 }
256
250 } // namespace service_manager 257 } // namespace service_manager
OLDNEW
« no previous file with comments | « services/service_manager/public/cpp/interface_registry.h ('k') | services/service_manager/public/cpp/lib/service_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698