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

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

Issue 1781913003: 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 std::set<std::string>& allowed_interfaces, 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 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 allowed_interfaces_(allowed_interfaces), 36 capability_request_(capability_request),
37 allow_all_interfaces_(allowed_interfaces_.size() == 1 && 37 allow_all_interfaces_(capability_request.interfaces.size() == 1 &&
38 allowed_interfaces_.count("*") == 1), 38 capability_request.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
56 const std::string& ConnectionImpl::GetConnectionName() { 60 const std::string& ConnectionImpl::GetConnectionName() {
57 return connection_name_; 61 return connection_name_;
58 } 62 }
59 63
60 const Identity& ConnectionImpl::GetRemoteIdentity() const { 64 const Identity& ConnectionImpl::GetRemoteIdentity() const {
61 return remote_; 65 return remote_;
62 } 66 }
63 67
64 void ConnectionImpl::SetConnectionLostClosure(const Closure& handler) { 68 void ConnectionImpl::SetConnectionLostClosure(const Closure& handler) {
65 remote_interfaces_.set_connection_error_handler(handler); 69 remote_interfaces_.set_connection_error_handler(handler);
(...skipping 12 matching lines...) Expand all
78 } 82 }
79 83
80 void ConnectionImpl::AddConnectionCompletedClosure(const Closure& callback) { 84 void ConnectionImpl::AddConnectionCompletedClosure(const Closure& callback) {
81 if (IsPending()) 85 if (IsPending())
82 connection_completed_callbacks_.push_back(callback); 86 connection_completed_callbacks_.push_back(callback);
83 else 87 else
84 callback.Run(); 88 callback.Run();
85 } 89 }
86 90
87 bool ConnectionImpl::AllowsInterface(const std::string& interface_name) const { 91 bool ConnectionImpl::AllowsInterface(const std::string& interface_name) const {
88 return allow_all_interfaces_ || allowed_interfaces_.count(interface_name); 92 return allow_all_interfaces_ ||
93 capability_request_.interfaces.count(interface_name);
89 } 94 }
90 95
91 shell::mojom::InterfaceProvider* ConnectionImpl::GetRemoteInterfaces() { 96 shell::mojom::InterfaceProvider* ConnectionImpl::GetRemoteInterfaces() {
92 return remote_interfaces_.get(); 97 return remote_interfaces_.get();
93 } 98 }
94 99
95 InterfaceRegistry* ConnectionImpl::GetLocalRegistry() { 100 InterfaceRegistry* ConnectionImpl::GetLocalRegistry() {
96 return &local_registry_; 101 return &local_registry_;
97 } 102 }
98 103
(...skipping 15 matching lines...) Expand all
114 remote_id_ = target_application_id; 119 remote_id_ = target_application_id;
115 remote_.set_user_id(target_user_id); 120 remote_.set_user_id(target_user_id);
116 std::vector<Closure> callbacks; 121 std::vector<Closure> callbacks;
117 callbacks.swap(connection_completed_callbacks_); 122 callbacks.swap(connection_completed_callbacks_);
118 for (auto callback : callbacks) 123 for (auto callback : callbacks)
119 callback.Run(); 124 callback.Run();
120 } 125 }
121 126
122 } // namespace internal 127 } // namespace internal
123 } // namespace mojo 128 } // 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