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

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

Issue 2075003002: Separate Remote InterfaceProvider again, and add a new client lib type for it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 6 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
(...skipping 13 matching lines...) Expand all
24 const Identity& remote, 24 const Identity& remote,
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 CapabilityRequest& capability_request, 28 const CapabilityRequest& capability_request,
29 State initial_state) 29 State initial_state)
30 : connection_name_(connection_name), 30 : connection_name_(connection_name),
31 remote_(remote), 31 remote_(remote),
32 remote_id_(remote_id), 32 remote_id_(remote_id),
33 state_(initial_state), 33 state_(initial_state),
34 interfaces_(std::move(remote_interfaces), 34 interfaces_(std::move(local_interfaces), this),
35 std::move(local_interfaces), 35 remote_interfaces_(std::move(remote_interfaces)),
36 this),
37 capability_request_(capability_request), 36 capability_request_(capability_request),
38 allow_all_interfaces_(capability_request.interfaces.size() == 1 && 37 allow_all_interfaces_(capability_request.interfaces.size() == 1 &&
39 capability_request.interfaces.count("*") == 1), 38 capability_request.interfaces.count("*") == 1),
40 weak_factory_(this) {} 39 weak_factory_(this) {}
41 40
42 ConnectionImpl::ConnectionImpl() 41 ConnectionImpl::ConnectionImpl()
43 : interfaces_(shell::mojom::InterfaceProviderPtr(), 42 : interfaces_(nullptr, this),
44 shell::mojom::InterfaceProviderRequest(), 43 remote_interfaces_(nullptr),
45 this),
46 allow_all_interfaces_(true), 44 allow_all_interfaces_(true),
47 weak_factory_(this) {} 45 weak_factory_(this) {}
48 46
49 ConnectionImpl::~ConnectionImpl() {} 47 ConnectionImpl::~ConnectionImpl() {}
50 48
51 shell::mojom::Connector::ConnectCallback ConnectionImpl::GetConnectCallback() { 49 shell::mojom::Connector::ConnectCallback ConnectionImpl::GetConnectCallback() {
52 return base::Bind(&ConnectionImpl::OnConnectionCompleted, 50 return base::Bind(&ConnectionImpl::OnConnectionCompleted,
53 weak_factory_.GetWeakPtr()); 51 weak_factory_.GetWeakPtr());
54 } 52 }
55 53
56 //////////////////////////////////////////////////////////////////////////////// 54 ////////////////////////////////////////////////////////////////////////////////
57 // ConnectionImpl, Connection implementation: 55 // ConnectionImpl, Connection implementation:
58 56
59 bool ConnectionImpl::HasCapabilityClass(const std::string& class_name) const { 57 bool ConnectionImpl::HasCapabilityClass(const std::string& class_name) const {
60 return capability_request_.classes.count(class_name) > 0; 58 return capability_request_.classes.count(class_name) > 0;
61 } 59 }
62 60
63 const std::string& ConnectionImpl::GetConnectionName() { 61 const std::string& ConnectionImpl::GetConnectionName() {
64 return connection_name_; 62 return connection_name_;
65 } 63 }
66 64
67 const Identity& ConnectionImpl::GetRemoteIdentity() const { 65 const Identity& ConnectionImpl::GetRemoteIdentity() const {
68 return remote_; 66 return remote_;
69 } 67 }
70 68
71 void ConnectionImpl::SetConnectionLostClosure(const base::Closure& handler) { 69 void ConnectionImpl::SetConnectionLostClosure(const base::Closure& handler) {
72 interfaces_.SetRemoteInterfacesConnectionLostClosure(handler); 70 remote_interfaces_.SetConnectionLostClosure(handler);
73 } 71 }
74 72
75 shell::mojom::ConnectResult ConnectionImpl::GetResult() const { 73 shell::mojom::ConnectResult ConnectionImpl::GetResult() const {
76 return result_; 74 return result_;
77 } 75 }
78 76
79 bool ConnectionImpl::IsPending() const { 77 bool ConnectionImpl::IsPending() const {
80 return state_ == State::PENDING; 78 return state_ == State::PENDING;
81 } 79 }
82 80
(...skipping 11 matching lines...) Expand all
94 92
95 bool ConnectionImpl::AllowsInterface(const std::string& interface_name) const { 93 bool ConnectionImpl::AllowsInterface(const std::string& interface_name) const {
96 return allow_all_interfaces_ || 94 return allow_all_interfaces_ ||
97 capability_request_.interfaces.count(interface_name); 95 capability_request_.interfaces.count(interface_name);
98 } 96 }
99 97
100 InterfaceRegistry* ConnectionImpl::GetInterfaceRegistry() { 98 InterfaceRegistry* ConnectionImpl::GetInterfaceRegistry() {
101 return &interfaces_; 99 return &interfaces_;
102 } 100 }
103 101
102 RemoteInterfaceRegistry* ConnectionImpl::GetRemoteInterfaceRegistry() {
103 return &remote_interfaces_;
104 }
105
104 base::WeakPtr<Connection> ConnectionImpl::GetWeakPtr() { 106 base::WeakPtr<Connection> ConnectionImpl::GetWeakPtr() {
105 return weak_factory_.GetWeakPtr(); 107 return weak_factory_.GetWeakPtr();
106 } 108 }
107 109
108 //////////////////////////////////////////////////////////////////////////////// 110 ////////////////////////////////////////////////////////////////////////////////
109 // ConnectionImpl, private: 111 // ConnectionImpl, private:
110 112
111 void ConnectionImpl::OnConnectionCompleted(shell::mojom::ConnectResult result, 113 void ConnectionImpl::OnConnectionCompleted(shell::mojom::ConnectResult result,
112 const std::string& target_user_id, 114 const std::string& target_user_id,
113 uint32_t target_application_id) { 115 uint32_t target_application_id) {
114 DCHECK(State::PENDING == state_); 116 DCHECK(State::PENDING == state_);
115 117
116 result_ = result; 118 result_ = result;
117 state_ = result_ == shell::mojom::ConnectResult::SUCCEEDED ? 119 state_ = result_ == shell::mojom::ConnectResult::SUCCEEDED ?
118 State::CONNECTED : State::DISCONNECTED; 120 State::CONNECTED : State::DISCONNECTED;
119 remote_id_ = target_application_id; 121 remote_id_ = target_application_id;
120 remote_.set_user_id(target_user_id); 122 remote_.set_user_id(target_user_id);
121 std::vector<mojo::Closure> callbacks; 123 std::vector<mojo::Closure> callbacks;
122 callbacks.swap(connection_completed_callbacks_); 124 callbacks.swap(connection_completed_callbacks_);
123 for (auto callback : callbacks) 125 for (auto callback : callbacks)
124 callback.Run(); 126 callback.Run();
125 } 127 }
126 128
127 } // namespace internal 129 } // namespace internal
128 } // namespace shell 130 } // namespace shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698