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

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

Issue 1783303002: Revert of Capability Classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@45class
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 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 std::set<std::string>& allowed_interfaces,
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 local_registry_(std::move(local_interfaces), this), 34 local_registry_(std::move(local_interfaces), this),
35 remote_interfaces_(std::move(remote_interfaces)), 35 remote_interfaces_(std::move(remote_interfaces)),
36 capability_request_(capability_request), 36 allowed_interfaces_(allowed_interfaces),
37 allow_all_interfaces_(capability_request.interfaces.size() == 1 && 37 allow_all_interfaces_(allowed_interfaces_.size() == 1 &&
38 capability_request.interfaces.count("*") == 1), 38 allowed_interfaces_.count("*") == 1),
39 weak_factory_(this) {} 39 weak_factory_(this) {}
40 40
41 ConnectionImpl::ConnectionImpl() 41 ConnectionImpl::ConnectionImpl()
42 : local_registry_(shell::mojom::InterfaceProviderRequest(), this), 42 : local_registry_(shell::mojom::InterfaceProviderRequest(), this),
43 allow_all_interfaces_(true), 43 allow_all_interfaces_(true),
44 weak_factory_(this) {} 44 weak_factory_(this) {}
45 45
46 ConnectionImpl::~ConnectionImpl() {} 46 ConnectionImpl::~ConnectionImpl() {}
47 47
48 shell::mojom::Connector::ConnectCallback ConnectionImpl::GetConnectCallback() { 48 shell::mojom::Connector::ConnectCallback ConnectionImpl::GetConnectCallback() {
49 return base::Bind(&ConnectionImpl::OnConnectionCompleted, 49 return base::Bind(&ConnectionImpl::OnConnectionCompleted,
50 weak_factory_.GetWeakPtr()); 50 weak_factory_.GetWeakPtr());
51 } 51 }
52 52
53 //////////////////////////////////////////////////////////////////////////////// 53 ////////////////////////////////////////////////////////////////////////////////
54 // ConnectionImpl, Connection implementation: 54 // ConnectionImpl, Connection implementation:
55 55
56 bool ConnectionImpl::HasCapabilityClass(const std::string& class_name) const {
57 return capability_request_.classes.count(class_name) > 0;
58 }
59
60 const std::string& ConnectionImpl::GetConnectionName() { 56 const std::string& ConnectionImpl::GetConnectionName() {
61 return connection_name_; 57 return connection_name_;
62 } 58 }
63 59
64 const Identity& ConnectionImpl::GetRemoteIdentity() const { 60 const Identity& ConnectionImpl::GetRemoteIdentity() const {
65 return remote_; 61 return remote_;
66 } 62 }
67 63
68 void ConnectionImpl::SetConnectionLostClosure(const Closure& handler) { 64 void ConnectionImpl::SetConnectionLostClosure(const Closure& handler) {
69 remote_interfaces_.set_connection_error_handler(handler); 65 remote_interfaces_.set_connection_error_handler(handler);
(...skipping 12 matching lines...) Expand all
82 } 78 }
83 79
84 void ConnectionImpl::AddConnectionCompletedClosure(const Closure& callback) { 80 void ConnectionImpl::AddConnectionCompletedClosure(const Closure& callback) {
85 if (IsPending()) 81 if (IsPending())
86 connection_completed_callbacks_.push_back(callback); 82 connection_completed_callbacks_.push_back(callback);
87 else 83 else
88 callback.Run(); 84 callback.Run();
89 } 85 }
90 86
91 bool ConnectionImpl::AllowsInterface(const std::string& interface_name) const { 87 bool ConnectionImpl::AllowsInterface(const std::string& interface_name) const {
92 return allow_all_interfaces_ || 88 return allow_all_interfaces_ || allowed_interfaces_.count(interface_name);
93 capability_request_.interfaces.count(interface_name);
94 } 89 }
95 90
96 shell::mojom::InterfaceProvider* ConnectionImpl::GetRemoteInterfaces() { 91 shell::mojom::InterfaceProvider* ConnectionImpl::GetRemoteInterfaces() {
97 return remote_interfaces_.get(); 92 return remote_interfaces_.get();
98 } 93 }
99 94
100 InterfaceRegistry* ConnectionImpl::GetLocalRegistry() { 95 InterfaceRegistry* ConnectionImpl::GetLocalRegistry() {
101 return &local_registry_; 96 return &local_registry_;
102 } 97 }
103 98
(...skipping 15 matching lines...) Expand all
119 remote_id_ = target_application_id; 114 remote_id_ = target_application_id;
120 remote_.set_user_id(target_user_id); 115 remote_.set_user_id(target_user_id);
121 std::vector<Closure> callbacks; 116 std::vector<Closure> callbacks;
122 callbacks.swap(connection_completed_callbacks_); 117 callbacks.swap(connection_completed_callbacks_);
123 for (auto callback : callbacks) 118 for (auto callback : callbacks)
124 callback.Run(); 119 callback.Run();
125 } 120 }
126 121
127 } // namespace internal 122 } // namespace internal
128 } // 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