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

Side by Side Diff: mojo/shell/public/cpp/lib/connection_impl.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
OLDNEW
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 "mojo/shell/public/cpp/lib/connection_impl.h" 5 #include "mojo/shell/public/cpp/lib/connection_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 13 matching lines...) Expand all
24 const std::string& remote_url, 24 const std::string& remote_url,
25 uint32_t remote_id, 25 uint32_t remote_id,
26 shell::mojom::InterfaceProviderPtr remote_interfaces, 26 shell::mojom::InterfaceProviderPtr remote_interfaces,
27 shell::mojom::InterfaceProviderRequest local_interfaces, 27 shell::mojom::InterfaceProviderRequest local_interfaces,
28 const std::set<std::string>& allowed_interfaces) 28 const std::set<std::string>& allowed_interfaces)
29 : connection_url_(connection_url), 29 : connection_url_(connection_url),
30 remote_url_(remote_url), 30 remote_url_(remote_url),
31 remote_id_(remote_id), 31 remote_id_(remote_id),
32 content_handler_id_(0u), 32 content_handler_id_(0u),
33 remote_ids_valid_(false), 33 remote_ids_valid_(false),
34 local_binding_(this), 34 local_registry_(std::move(local_interfaces), this),
35 remote_interfaces_(std::move(remote_interfaces)), 35 remote_interfaces_(std::move(remote_interfaces)),
36 allowed_interfaces_(allowed_interfaces), 36 allowed_interfaces_(allowed_interfaces),
37 allow_all_interfaces_(allowed_interfaces_.size() == 1 && 37 allow_all_interfaces_(allowed_interfaces_.size() == 1 &&
38 allowed_interfaces_.count("*") == 1), 38 allowed_interfaces_.count("*") == 1),
39 default_binder_(nullptr), 39 weak_factory_(this) {}
40 weak_factory_(this) {
41 if (local_interfaces.is_pending())
42 local_binding_.Bind(std::move(local_interfaces));
43 }
44 40
45 ConnectionImpl::ConnectionImpl() 41 ConnectionImpl::ConnectionImpl()
46 : remote_id_(shell::mojom::Shell::kInvalidApplicationID), 42 : remote_id_(shell::mojom::Shell::kInvalidApplicationID),
47 content_handler_id_(shell::mojom::Shell::kInvalidApplicationID), 43 content_handler_id_(shell::mojom::Shell::kInvalidApplicationID),
48 remote_ids_valid_(false), 44 remote_ids_valid_(false),
49 local_binding_(this), 45 local_registry_(shell::mojom::InterfaceProviderRequest(), this),
50 allow_all_interfaces_(true), 46 allow_all_interfaces_(true),
51 default_binder_(nullptr), 47 weak_factory_(this) {}
52 weak_factory_(this) {
53 }
54 48
55 ConnectionImpl::~ConnectionImpl() { 49 ConnectionImpl::~ConnectionImpl() {}
56 for (auto& i : name_to_binder_)
57 delete i.second;
58 name_to_binder_.clear();
59 }
60 50
61 shell::mojom::Shell::ConnectToApplicationCallback 51 shell::mojom::Shell::ConnectToApplicationCallback
62 ConnectionImpl::GetConnectToApplicationCallback() { 52 ConnectionImpl::GetConnectToApplicationCallback() {
63 return base::Bind(&ConnectionImpl::OnGotRemoteIDs, 53 return base::Bind(&ConnectionImpl::OnGotRemoteIDs,
64 weak_factory_.GetWeakPtr()); 54 weak_factory_.GetWeakPtr());
65 } 55 }
66 56
67 //////////////////////////////////////////////////////////////////////////////// 57 ////////////////////////////////////////////////////////////////////////////////
68 // ConnectionImpl, Connection implementation: 58 // ConnectionImpl, Connection implementation:
69 59
70 void ConnectionImpl::SetDefaultInterfaceBinder(InterfaceBinder* binder) {
71 default_binder_ = binder;
72 }
73
74 bool ConnectionImpl::SetInterfaceBinderForName(
75 InterfaceBinder* binder,
76 const std::string& interface_name) {
77 if (allow_all_interfaces_ ||
78 allowed_interfaces_.count(interface_name)) {
79 RemoveInterfaceBinderForName(interface_name);
80 name_to_binder_[interface_name] = binder;
81 return true;
82 }
83 LOG(WARNING) << "CapabilityFilter prevented connection to interface: "
84 << interface_name << " connection_url:" << connection_url_
85 << " remote_url:" << remote_url_;
86 return false;
87 }
88
89 const std::string& ConnectionImpl::GetConnectionURL() { 60 const std::string& ConnectionImpl::GetConnectionURL() {
90 return connection_url_; 61 return connection_url_;
91 } 62 }
92 63
93 const std::string& ConnectionImpl::GetRemoteApplicationURL() { 64 const std::string& ConnectionImpl::GetRemoteApplicationURL() {
94 return remote_url_; 65 return remote_url_;
95 } 66 }
96 67
97 shell::mojom::InterfaceProvider* ConnectionImpl::GetRemoteInterfaces() {
98 return remote_interfaces_.get();
99 }
100
101 shell::mojom::InterfaceProvider* ConnectionImpl::GetLocalInterfaces() {
102 return this;
103 }
104
105 void ConnectionImpl::SetRemoteInterfaceProviderConnectionErrorHandler( 68 void ConnectionImpl::SetRemoteInterfaceProviderConnectionErrorHandler(
106 const Closure& handler) { 69 const Closure& handler) {
107 remote_interfaces_.set_connection_error_handler(handler); 70 remote_interfaces_.set_connection_error_handler(handler);
108 } 71 }
109 72
110 bool ConnectionImpl::GetRemoteApplicationID(uint32_t* remote_id) const { 73 bool ConnectionImpl::GetRemoteApplicationID(uint32_t* remote_id) const {
111 if (!remote_ids_valid_) 74 if (!remote_ids_valid_)
112 return false; 75 return false;
113 76
114 *remote_id = remote_id_; 77 *remote_id = remote_id_;
(...skipping 10 matching lines...) Expand all
125 } 88 }
126 89
127 void ConnectionImpl::AddRemoteIDCallback(const Closure& callback) { 90 void ConnectionImpl::AddRemoteIDCallback(const Closure& callback) {
128 if (remote_ids_valid_) { 91 if (remote_ids_valid_) {
129 callback.Run(); 92 callback.Run();
130 return; 93 return;
131 } 94 }
132 remote_id_callbacks_.push_back(callback); 95 remote_id_callbacks_.push_back(callback);
133 } 96 }
134 97
98 bool ConnectionImpl::AllowsInterface(const std::string& interface_name) const {
99 return allow_all_interfaces_ || allowed_interfaces_.count(interface_name);
100 }
101
102 shell::mojom::InterfaceProvider* ConnectionImpl::GetRemoteInterfaces() {
103 return remote_interfaces_.get();
104 }
105
106 InterfaceRegistry* ConnectionImpl::GetLocalRegistry() {
107 return &local_registry_;
108 }
109
135 base::WeakPtr<Connection> ConnectionImpl::GetWeakPtr() { 110 base::WeakPtr<Connection> ConnectionImpl::GetWeakPtr() {
136 return weak_factory_.GetWeakPtr(); 111 return weak_factory_.GetWeakPtr();
137 } 112 }
138 113
139 //////////////////////////////////////////////////////////////////////////////// 114 ////////////////////////////////////////////////////////////////////////////////
140 // ConnectionImpl, shell::mojom::InterfaceProvider implementation:
141
142 void ConnectionImpl::GetInterface(const mojo::String& interface_name,
143 ScopedMessagePipeHandle handle) {
144 auto iter = name_to_binder_.find(interface_name);
145 InterfaceBinder* binder = iter != name_to_binder_.end() ? iter->second :
146 default_binder_;
147 if (binder)
148 binder->BindInterface(this, interface_name, std::move(handle));
149 }
150
151 ////////////////////////////////////////////////////////////////////////////////
152 // ConnectionImpl, private: 115 // ConnectionImpl, private:
153 116
154 void ConnectionImpl::RemoveInterfaceBinderForName(
155 const std::string& interface_name) {
156 NameToInterfaceBinderMap::iterator it = name_to_binder_.find(interface_name);
157 if (it == name_to_binder_.end())
158 return;
159 delete it->second;
160 name_to_binder_.erase(it);
161 }
162
163 void ConnectionImpl::OnGotRemoteIDs(uint32_t target_application_id, 117 void ConnectionImpl::OnGotRemoteIDs(uint32_t target_application_id,
164 uint32_t content_handler_id) { 118 uint32_t content_handler_id) {
165 DCHECK(!remote_ids_valid_); 119 DCHECK(!remote_ids_valid_);
166 remote_ids_valid_ = true; 120 remote_ids_valid_ = true;
167 121
168 remote_id_ = target_application_id; 122 remote_id_ = target_application_id;
169 content_handler_id_ = content_handler_id; 123 content_handler_id_ = content_handler_id;
170 std::vector<Closure> callbacks; 124 std::vector<Closure> callbacks;
171 callbacks.swap(remote_id_callbacks_); 125 callbacks.swap(remote_id_callbacks_);
172 for (auto callback : callbacks) 126 for (auto callback : callbacks)
173 callback.Run(); 127 callback.Run();
174 } 128 }
175 129
176 } // namespace internal 130 } // namespace internal
177 } // namespace mojo 131 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/public/cpp/lib/connection_impl.h ('k') | mojo/shell/public/cpp/lib/interface_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698