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

Side by Side Diff: mojo/shell/public/cpp/lib/interface_registry.cc

Issue 1877753003: Move mojo\shell to services\shell (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@62scan
Patch Set: . Created 4 years, 8 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
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(nullptr, 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 request = GetProxy(&client_handle_);
22 binding_.Bind(std::move(request));
23 }
24
25 InterfaceRegistry::~InterfaceRegistry() {
26 for (auto& i : name_to_binder_)
27 delete i.second;
28 name_to_binder_.clear();
29 }
30
31 shell::mojom::InterfaceProviderPtr InterfaceRegistry::TakeClientHandle() {
32 return std::move(client_handle_);
33 }
34
35 // shell::mojom::InterfaceProvider:
36 void InterfaceRegistry::GetInterface(const String& interface_name,
37 ScopedMessagePipeHandle handle) {
38 auto iter = name_to_binder_.find(interface_name);
39 InterfaceBinder* binder = iter != name_to_binder_.end() ? iter->second :
40 default_binder_;
41 if (binder)
42 binder->BindInterface(connection_, interface_name, std::move(handle));
43 }
44
45 bool InterfaceRegistry::SetInterfaceBinderForName(
46 InterfaceBinder* binder,
47 const std::string& interface_name) {
48 if (!connection_ ||
49 (connection_ && connection_->AllowsInterface(interface_name))) {
50 RemoveInterfaceBinderForName(interface_name);
51 name_to_binder_[interface_name] = binder;
52 return true;
53 }
54 LOG(WARNING) << "Connection CapabilityFilter prevented binding to interface: "
55 << interface_name << " connection_name:"
56 << connection_->GetConnectionName() << " remote_name:"
57 << connection_->GetRemoteIdentity().name();
58 return false;
59 }
60
61 void InterfaceRegistry::RemoveInterfaceBinderForName(
62 const std::string& interface_name) {
63 NameToInterfaceBinderMap::iterator it = name_to_binder_.find(interface_name);
64 if (it == name_to_binder_.end())
65 return;
66 delete it->second;
67 name_to_binder_.erase(it);
68 }
69
70 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/public/cpp/lib/interface_factory_binder.h ('k') | mojo/shell/public/cpp/lib/message_loop_ref.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698