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

Side by Side Diff: services/shell/public/cpp/lib/connection_impl.cc

Issue 2090773003: Add ability to bind a different InterfaceRegistry/InterfaceProvider to an incoming Connection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 5 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 "services/shell/public/cpp/lib/connection_impl.h" 5 #include "services/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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "services/shell/public/cpp/connection.h" 13 #include "services/shell/public/cpp/connection.h"
14 #include "services/shell/public/cpp/interface_binder.h" 14 #include "services/shell/public/cpp/interface_binder.h"
15 15
16 namespace shell { 16 namespace shell {
17 namespace internal { 17 namespace internal {
18 18
19 //////////////////////////////////////////////////////////////////////////////// 19 ////////////////////////////////////////////////////////////////////////////////
20 // ConnectionImpl, public: 20 // ConnectionImpl, public:
21 21
22 ConnectionImpl::ConnectionImpl()
23 : allow_all_interfaces_(true),
24 weak_factory_(this) {}
25
22 ConnectionImpl::ConnectionImpl( 26 ConnectionImpl::ConnectionImpl(
23 const std::string& connection_name, 27 const std::string& connection_name,
24 const Identity& remote, 28 const Identity& remote,
25 uint32_t remote_id, 29 uint32_t remote_id,
26 shell::mojom::InterfaceProviderPtr remote_interfaces,
27 shell::mojom::InterfaceProviderRequest local_interfaces,
28 const CapabilityRequest& capability_request, 30 const CapabilityRequest& capability_request,
29 State initial_state) 31 State initial_state)
30 : connection_name_(connection_name), 32 : connection_name_(connection_name),
31 remote_(remote), 33 remote_(remote),
32 remote_id_(remote_id), 34 remote_id_(remote_id),
33 state_(initial_state), 35 state_(initial_state),
34 interfaces_(this),
35 remote_interfaces_(std::move(remote_interfaces)),
36 capability_request_(capability_request), 36 capability_request_(capability_request),
37 allow_all_interfaces_(capability_request.interfaces.size() == 1 && 37 allow_all_interfaces_(capability_request.interfaces.size() == 1 &&
38 capability_request.interfaces.count("*") == 1), 38 capability_request.interfaces.count("*") == 1),
39 weak_factory_(this) { 39 weak_factory_(this) {
40 interfaces_.Bind(std::move(local_interfaces));
41 } 40 }
42 41
43 ConnectionImpl::ConnectionImpl() 42 ConnectionImpl::~ConnectionImpl() {}
44 : interfaces_(this),
45 remote_interfaces_(nullptr),
46 allow_all_interfaces_(true),
47 weak_factory_(this) {}
48 43
49 ConnectionImpl::~ConnectionImpl() {} 44 void ConnectionImpl::SetExposedInterfaces(
45 std::unique_ptr<InterfaceRegistry> exposed_interfaces) {
46 exposed_interfaces_owner_ = std::move(exposed_interfaces);
47 set_exposed_interfaces(exposed_interfaces_owner_.get());
48 }
49
50 void ConnectionImpl::SetRemoteInterfaces(
51 std::unique_ptr<InterfaceProvider> remote_interfaces) {
52 remote_interfaces_owner_ = std::move(remote_interfaces);
53 set_remote_interfaces(remote_interfaces_owner_.get());
54 }
50 55
51 shell::mojom::Connector::ConnectCallback ConnectionImpl::GetConnectCallback() { 56 shell::mojom::Connector::ConnectCallback ConnectionImpl::GetConnectCallback() {
52 return base::Bind(&ConnectionImpl::OnConnectionCompleted, 57 return base::Bind(&ConnectionImpl::OnConnectionCompleted,
53 weak_factory_.GetWeakPtr()); 58 weak_factory_.GetWeakPtr());
54 } 59 }
55 60
56 //////////////////////////////////////////////////////////////////////////////// 61 ////////////////////////////////////////////////////////////////////////////////
57 // ConnectionImpl, Connection implementation: 62 // ConnectionImpl, Connection implementation:
58 63
59 bool ConnectionImpl::HasCapabilityClass(const std::string& class_name) const { 64 bool ConnectionImpl::HasCapabilityClass(const std::string& class_name) const {
60 return capability_request_.classes.count(class_name) > 0; 65 return capability_request_.classes.count(class_name) > 0;
61 } 66 }
62 67
63 const std::string& ConnectionImpl::GetConnectionName() { 68 const std::string& ConnectionImpl::GetConnectionName() {
64 return connection_name_; 69 return connection_name_;
65 } 70 }
66 71
67 const Identity& ConnectionImpl::GetRemoteIdentity() const { 72 const Identity& ConnectionImpl::GetRemoteIdentity() const {
68 return remote_; 73 return remote_;
69 } 74 }
70 75
71 void ConnectionImpl::SetConnectionLostClosure(const base::Closure& handler) { 76 void ConnectionImpl::SetConnectionLostClosure(const base::Closure& handler) {
72 remote_interfaces_.SetConnectionLostClosure(handler); 77 remote_interfaces_->SetConnectionLostClosure(handler);
73 } 78 }
74 79
75 shell::mojom::ConnectResult ConnectionImpl::GetResult() const { 80 shell::mojom::ConnectResult ConnectionImpl::GetResult() const {
76 return result_; 81 return result_;
77 } 82 }
78 83
79 bool ConnectionImpl::IsPending() const { 84 bool ConnectionImpl::IsPending() const {
80 return state_ == State::PENDING; 85 return state_ == State::PENDING;
81 } 86 }
82 87
83 uint32_t ConnectionImpl::GetRemoteInstanceID() const { 88 uint32_t ConnectionImpl::GetRemoteInstanceID() const {
84 return remote_id_; 89 return remote_id_;
85 } 90 }
86 91
87 void ConnectionImpl::AddConnectionCompletedClosure( 92 void ConnectionImpl::AddConnectionCompletedClosure(
88 const base::Closure& callback) { 93 const base::Closure& callback) {
89 if (IsPending()) 94 if (IsPending())
90 connection_completed_callbacks_.push_back(callback); 95 connection_completed_callbacks_.push_back(callback);
91 else 96 else
92 callback.Run(); 97 callback.Run();
93 } 98 }
94 99
95 bool ConnectionImpl::AllowsInterface(const std::string& interface_name) const { 100 bool ConnectionImpl::AllowsInterface(const std::string& interface_name) const {
96 return allow_all_interfaces_ || 101 return allow_all_interfaces_ ||
97 capability_request_.interfaces.count(interface_name); 102 capability_request_.interfaces.count(interface_name);
98 } 103 }
99 104
100 mojom::InterfaceProvider* ConnectionImpl::GetRemoteInterfaceProvider() { 105 mojom::InterfaceProvider* ConnectionImpl::GetRemoteInterfaceProvider() {
101 return remote_interfaces_.get(); 106 return remote_interfaces_->get();
102 } 107 }
103 108
104 InterfaceRegistry* ConnectionImpl::GetInterfaceRegistry() { 109 InterfaceRegistry* ConnectionImpl::GetInterfaceRegistry() {
105 return &interfaces_; 110 return exposed_interfaces_;
106 } 111 }
107 112
108 InterfaceProvider* ConnectionImpl::GetRemoteInterfaces() { 113 InterfaceProvider* ConnectionImpl::GetRemoteInterfaces() {
109 return &remote_interfaces_; 114 return remote_interfaces_;
110 } 115 }
111 116
112 base::WeakPtr<Connection> ConnectionImpl::GetWeakPtr() { 117 base::WeakPtr<Connection> ConnectionImpl::GetWeakPtr() {
113 return weak_factory_.GetWeakPtr(); 118 return weak_factory_.GetWeakPtr();
114 } 119 }
115 120
116 //////////////////////////////////////////////////////////////////////////////// 121 ////////////////////////////////////////////////////////////////////////////////
117 // ConnectionImpl, private: 122 // ConnectionImpl, private:
118 123
119 void ConnectionImpl::OnConnectionCompleted(shell::mojom::ConnectResult result, 124 void ConnectionImpl::OnConnectionCompleted(shell::mojom::ConnectResult result,
120 mojo::String target_user_id, 125 mojo::String target_user_id,
121 uint32_t target_application_id) { 126 uint32_t target_application_id) {
122 DCHECK(State::PENDING == state_); 127 DCHECK(State::PENDING == state_);
123 128
124 result_ = result; 129 result_ = result;
125 state_ = result_ == shell::mojom::ConnectResult::SUCCEEDED ? 130 state_ = result_ == shell::mojom::ConnectResult::SUCCEEDED ?
126 State::CONNECTED : State::DISCONNECTED; 131 State::CONNECTED : State::DISCONNECTED;
127 remote_id_ = target_application_id; 132 remote_id_ = target_application_id;
128 remote_.set_user_id(target_user_id); 133 remote_.set_user_id(target_user_id);
129 std::vector<base::Closure> callbacks; 134 std::vector<base::Closure> callbacks;
130 callbacks.swap(connection_completed_callbacks_); 135 callbacks.swap(connection_completed_callbacks_);
131 for (auto callback : callbacks) 136 for (auto callback : callbacks)
132 callback.Run(); 137 callback.Run();
133 } 138 }
134 139
135 } // namespace internal 140 } // namespace internal
136 } // namespace shell 141 } // namespace shell
OLDNEW
« no previous file with comments | « services/shell/public/cpp/lib/connection_impl.h ('k') | services/shell/public/cpp/lib/connector_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698