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

Unified Diff: mojo/shell/public/cpp/lib/interface_registry.cc

Issue 1681933005: Extracts InterfaceRegistry from ConnectionImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@nested
Patch Set: . Created 4 years, 10 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/shell/public/cpp/lib/connection_impl.cc ('k') | mojo/shell/public/cpp/tests/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/shell/public/cpp/lib/interface_registry.cc
diff --git a/mojo/shell/public/cpp/lib/interface_registry.cc b/mojo/shell/public/cpp/lib/interface_registry.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ee14f5a51664f4bca495c2571104a3a9d60ce4b0
--- /dev/null
+++ b/mojo/shell/public/cpp/lib/interface_registry.cc
@@ -0,0 +1,69 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/shell/public/cpp/interface_registry.h"
+
+#include "mojo/shell/public/cpp/connection.h"
+
+namespace mojo {
+
+InterfaceRegistry::InterfaceRegistry(Connection* connection)
+ : InterfaceRegistry(GetProxy(&client_handle_), connection) {}
+
+InterfaceRegistry::InterfaceRegistry(
+ shell::mojom::InterfaceProviderRequest request,
+ Connection* connection)
+ : binding_(this),
+ connection_(connection),
+ default_binder_(nullptr) {
+ if (request.is_pending())
+ binding_.Bind(std::move(request));
+}
+
+InterfaceRegistry::~InterfaceRegistry() {
+ for (auto& i : name_to_binder_)
+ delete i.second;
+ name_to_binder_.clear();
+}
+
+shell::mojom::InterfaceProviderPtr InterfaceRegistry::TakeClientHandle() {
+ return std::move(client_handle_);
+}
+
+// shell::mojom::InterfaceProvider:
+void InterfaceRegistry::GetInterface(const String& interface_name,
+ ScopedMessagePipeHandle handle) {
+ auto iter = name_to_binder_.find(interface_name);
+ InterfaceBinder* binder = iter != name_to_binder_.end() ? iter->second :
+ default_binder_;
+ if (binder)
+ binder->BindInterface(connection_, interface_name, std::move(handle));
+}
+
+bool InterfaceRegistry::SetInterfaceBinderForName(
+ InterfaceBinder* binder,
+ const std::string& interface_name) {
+ if (!connection_ ||
+ (connection_ && connection_->AllowsInterface(interface_name))) {
+ RemoveInterfaceBinderForName(interface_name);
+ name_to_binder_[interface_name] = binder;
+ return true;
+ }
+ LOG(WARNING) << "Connection CapabilityFilter prevented binding to interface: "
+ << interface_name << " connection_url:"
+ << connection_->GetConnectionURL() << " remote_url:"
+ << connection_->GetRemoteApplicationURL();
+ return false;
+}
+
+void InterfaceRegistry::RemoveInterfaceBinderForName(
+ const std::string& interface_name) {
+ NameToInterfaceBinderMap::iterator it = name_to_binder_.find(interface_name);
+ if (it == name_to_binder_.end())
+ return;
+ delete it->second;
+ name_to_binder_.erase(it);
+}
+
+} // namespace mojo
« no previous file with comments | « mojo/shell/public/cpp/lib/connection_impl.cc ('k') | mojo/shell/public/cpp/tests/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698