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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "mojo/shell/public/cpp/interface_registry.h"
6
7 #include "mojo/shell/public/cpp/connection.h"
8
9 namespace mojo {
10
11 InterfaceRegistry::InterfaceRegistry(Connection* connection)
12 : InterfaceRegistry(GetProxy(&client_handle_), connection) {}
13
14 InterfaceRegistry::InterfaceRegistry(
15 shell::mojom::InterfaceProviderRequest request,
16 Connection* connection)
17 : binding_(this),
18 connection_(connection),
19 default_binder_(nullptr) {
20 if (request.is_pending())
21 binding_.Bind(std::move(request));
22 }
23
24 InterfaceRegistry::~InterfaceRegistry() {
25 for (auto& i : name_to_binder_)
26 delete i.second;
27 name_to_binder_.clear();
28 }
29
30 shell::mojom::InterfaceProviderPtr InterfaceRegistry::TakeClientHandle() {
31 return std::move(client_handle_);
32 }
33
34 // shell::mojom::InterfaceProvider:
35 void InterfaceRegistry::GetInterface(const String& interface_name,
36 ScopedMessagePipeHandle handle) {
37 auto iter = name_to_binder_.find(interface_name);
38 InterfaceBinder* binder = iter != name_to_binder_.end() ? iter->second :
39 default_binder_;
40 if (binder)
41 binder->BindInterface(connection_, interface_name, std::move(handle));
42 }
43
44 bool InterfaceRegistry::SetInterfaceBinderForName(
45 InterfaceBinder* binder,
46 const std::string& interface_name) {
47 if (!connection_ ||
48 (connection_ && connection_->AllowsInterface(interface_name))) {
49 RemoveInterfaceBinderForName(interface_name);
50 name_to_binder_[interface_name] = binder;
51 return true;
52 }
53 LOG(WARNING) << "Connection CapabilityFilter prevented binding to interface: "
54 << interface_name << " connection_url:"
55 << connection_->GetConnectionURL() << " remote_url:"
56 << connection_->GetRemoteApplicationURL();
57 return false;
58 }
59
60 void InterfaceRegistry::RemoveInterfaceBinderForName(
61 const std::string& interface_name) {
62 NameToInterfaceBinderMap::iterator it = name_to_binder_.find(interface_name);
63 if (it == name_to_binder_.end())
64 return;
65 delete it->second;
66 name_to_binder_.erase(it);
67 }
68
69 } // namespace mojo
OLDNEW
« 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