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

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

Issue 1769163002: Add a instance groups to Connect(), and introduce an Identity struct. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 9 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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "mojo/shell/public/cpp/connection.h" 13 #include "mojo/shell/public/cpp/connection.h"
14 #include "mojo/shell/public/cpp/interface_binder.h" 14 #include "mojo/shell/public/cpp/interface_binder.h"
15 15
16 namespace mojo { 16 namespace mojo {
17 namespace internal { 17 namespace internal {
18 18
19 //////////////////////////////////////////////////////////////////////////////// 19 ////////////////////////////////////////////////////////////////////////////////
20 // ConnectionImpl, public: 20 // ConnectionImpl, public:
21 21
22 ConnectionImpl::ConnectionImpl( 22 ConnectionImpl::ConnectionImpl(
23 const std::string& connection_name, 23 const std::string& connection_name,
24 const std::string& remote_name, 24 const Identity& remote,
25 uint32_t remote_id, 25 uint32_t remote_id,
26 const std::string& remote_user_id,
27 shell::mojom::InterfaceProviderPtr remote_interfaces, 26 shell::mojom::InterfaceProviderPtr remote_interfaces,
28 shell::mojom::InterfaceProviderRequest local_interfaces, 27 shell::mojom::InterfaceProviderRequest local_interfaces,
29 const std::set<std::string>& allowed_interfaces, 28 const std::set<std::string>& allowed_interfaces,
30 State initial_state) 29 State initial_state)
31 : connection_name_(connection_name), 30 : connection_name_(connection_name),
32 remote_name_(remote_name), 31 remote_(remote),
32 remote_id_(remote_id),
33 state_(initial_state), 33 state_(initial_state),
34 remote_id_(remote_id),
35 remote_user_id_(remote_user_id),
36 local_registry_(std::move(local_interfaces), this), 34 local_registry_(std::move(local_interfaces), this),
37 remote_interfaces_(std::move(remote_interfaces)), 35 remote_interfaces_(std::move(remote_interfaces)),
38 allowed_interfaces_(allowed_interfaces), 36 allowed_interfaces_(allowed_interfaces),
39 allow_all_interfaces_(allowed_interfaces_.size() == 1 && 37 allow_all_interfaces_(allowed_interfaces_.size() == 1 &&
40 allowed_interfaces_.count("*") == 1), 38 allowed_interfaces_.count("*") == 1),
41 weak_factory_(this) {} 39 weak_factory_(this) {}
42 40
43 ConnectionImpl::ConnectionImpl() 41 ConnectionImpl::ConnectionImpl()
44 : local_registry_(shell::mojom::InterfaceProviderRequest(), this), 42 : local_registry_(shell::mojom::InterfaceProviderRequest(), this),
45 allow_all_interfaces_(true), 43 allow_all_interfaces_(true),
46 weak_factory_(this) {} 44 weak_factory_(this) {}
47 45
48 ConnectionImpl::~ConnectionImpl() {} 46 ConnectionImpl::~ConnectionImpl() {}
49 47
50 shell::mojom::Connector::ConnectCallback ConnectionImpl::GetConnectCallback() { 48 shell::mojom::Connector::ConnectCallback ConnectionImpl::GetConnectCallback() {
51 return base::Bind(&ConnectionImpl::OnConnectionCompleted, 49 return base::Bind(&ConnectionImpl::OnConnectionCompleted,
52 weak_factory_.GetWeakPtr()); 50 weak_factory_.GetWeakPtr());
53 } 51 }
54 52
55 //////////////////////////////////////////////////////////////////////////////// 53 ////////////////////////////////////////////////////////////////////////////////
56 // ConnectionImpl, Connection implementation: 54 // ConnectionImpl, Connection implementation:
57 55
58 const std::string& ConnectionImpl::GetConnectionName() { 56 const std::string& ConnectionImpl::GetConnectionName() {
59 return connection_name_; 57 return connection_name_;
60 } 58 }
61 59
62 const std::string& ConnectionImpl::GetRemoteApplicationName() { 60 const Identity& ConnectionImpl::GetRemoteIdentity() const {
63 return remote_name_; 61 return remote_;
64 }
65
66 const std::string& ConnectionImpl::GetRemoteUserID() const {
67 return remote_user_id_;
68 } 62 }
69 63
70 void ConnectionImpl::SetConnectionLostClosure(const Closure& handler) { 64 void ConnectionImpl::SetConnectionLostClosure(const Closure& handler) {
71 remote_interfaces_.set_connection_error_handler(handler); 65 remote_interfaces_.set_connection_error_handler(handler);
72 } 66 }
73 67
74 shell::mojom::ConnectResult ConnectionImpl::GetResult() const { 68 shell::mojom::ConnectResult ConnectionImpl::GetResult() const {
75 return result_; 69 return result_;
76 } 70 }
77 71
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 105
112 void ConnectionImpl::OnConnectionCompleted(shell::mojom::ConnectResult result, 106 void ConnectionImpl::OnConnectionCompleted(shell::mojom::ConnectResult result,
113 const std::string& target_user_id, 107 const std::string& target_user_id,
114 uint32_t target_application_id) { 108 uint32_t target_application_id) {
115 DCHECK(State::PENDING == state_); 109 DCHECK(State::PENDING == state_);
116 110
117 result_ = result; 111 result_ = result;
118 state_ = result_ == shell::mojom::ConnectResult::SUCCEEDED ? 112 state_ = result_ == shell::mojom::ConnectResult::SUCCEEDED ?
119 State::CONNECTED : State::DISCONNECTED; 113 State::CONNECTED : State::DISCONNECTED;
120 remote_id_ = target_application_id; 114 remote_id_ = target_application_id;
121 remote_user_id_= target_user_id; 115 remote_.set_user_id(target_user_id);
122 std::vector<Closure> callbacks; 116 std::vector<Closure> callbacks;
123 callbacks.swap(connection_completed_callbacks_); 117 callbacks.swap(connection_completed_callbacks_);
124 for (auto callback : callbacks) 118 for (auto callback : callbacks)
125 callback.Run(); 119 callback.Run();
126 } 120 }
127 121
128 } // namespace internal 122 } // namespace internal
129 } // namespace mojo 123 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/public/cpp/lib/connection_impl.h ('k') | mojo/shell/public/cpp/lib/connector_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698