| OLD | NEW |
| 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 Loading... |
| 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_(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) { |
| 40 interfaces_.Bind(std::move(local_interfaces)); |
| 41 } |
| 41 | 42 |
| 42 ConnectionImpl::ConnectionImpl() | 43 ConnectionImpl::ConnectionImpl() |
| 43 : interfaces_(shell::mojom::InterfaceProviderPtr(), | 44 : interfaces_(this), |
| 44 shell::mojom::InterfaceProviderRequest(), | 45 remote_interfaces_(nullptr), |
| 45 this), | |
| 46 allow_all_interfaces_(true), | 46 allow_all_interfaces_(true), |
| 47 weak_factory_(this) {} | 47 weak_factory_(this) {} |
| 48 | 48 |
| 49 ConnectionImpl::~ConnectionImpl() {} | 49 ConnectionImpl::~ConnectionImpl() {} |
| 50 | 50 |
| 51 shell::mojom::Connector::ConnectCallback ConnectionImpl::GetConnectCallback() { | 51 shell::mojom::Connector::ConnectCallback ConnectionImpl::GetConnectCallback() { |
| 52 return base::Bind(&ConnectionImpl::OnConnectionCompleted, | 52 return base::Bind(&ConnectionImpl::OnConnectionCompleted, |
| 53 weak_factory_.GetWeakPtr()); | 53 weak_factory_.GetWeakPtr()); |
| 54 } | 54 } |
| 55 | 55 |
| 56 //////////////////////////////////////////////////////////////////////////////// | 56 //////////////////////////////////////////////////////////////////////////////// |
| 57 // ConnectionImpl, Connection implementation: | 57 // ConnectionImpl, Connection implementation: |
| 58 | 58 |
| 59 bool ConnectionImpl::HasCapabilityClass(const std::string& class_name) const { | 59 bool ConnectionImpl::HasCapabilityClass(const std::string& class_name) const { |
| 60 return capability_request_.classes.count(class_name) > 0; | 60 return capability_request_.classes.count(class_name) > 0; |
| 61 } | 61 } |
| 62 | 62 |
| 63 const std::string& ConnectionImpl::GetConnectionName() { | 63 const std::string& ConnectionImpl::GetConnectionName() { |
| 64 return connection_name_; | 64 return connection_name_; |
| 65 } | 65 } |
| 66 | 66 |
| 67 const Identity& ConnectionImpl::GetRemoteIdentity() const { | 67 const Identity& ConnectionImpl::GetRemoteIdentity() const { |
| 68 return remote_; | 68 return remote_; |
| 69 } | 69 } |
| 70 | 70 |
| 71 void ConnectionImpl::SetConnectionLostClosure(const base::Closure& handler) { | 71 void ConnectionImpl::SetConnectionLostClosure(const base::Closure& handler) { |
| 72 interfaces_.SetRemoteInterfacesConnectionLostClosure(handler); | 72 remote_interfaces_.SetConnectionLostClosure(handler); |
| 73 } | 73 } |
| 74 | 74 |
| 75 shell::mojom::ConnectResult ConnectionImpl::GetResult() const { | 75 shell::mojom::ConnectResult ConnectionImpl::GetResult() const { |
| 76 return result_; | 76 return result_; |
| 77 } | 77 } |
| 78 | 78 |
| 79 bool ConnectionImpl::IsPending() const { | 79 bool ConnectionImpl::IsPending() const { |
| 80 return state_ == State::PENDING; | 80 return state_ == State::PENDING; |
| 81 } | 81 } |
| 82 | 82 |
| 83 uint32_t ConnectionImpl::GetRemoteInstanceID() const { | 83 uint32_t ConnectionImpl::GetRemoteInstanceID() const { |
| 84 return remote_id_; | 84 return remote_id_; |
| 85 } | 85 } |
| 86 | 86 |
| 87 void ConnectionImpl::AddConnectionCompletedClosure( | 87 void ConnectionImpl::AddConnectionCompletedClosure( |
| 88 const mojo::Closure& callback) { | 88 const mojo::Closure& callback) { |
| 89 if (IsPending()) | 89 if (IsPending()) |
| 90 connection_completed_callbacks_.push_back(callback); | 90 connection_completed_callbacks_.push_back(callback); |
| 91 else | 91 else |
| 92 callback.Run(); | 92 callback.Run(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 bool ConnectionImpl::AllowsInterface(const std::string& interface_name) const { | 95 bool ConnectionImpl::AllowsInterface(const std::string& interface_name) const { |
| 96 return allow_all_interfaces_ || | 96 return allow_all_interfaces_ || |
| 97 capability_request_.interfaces.count(interface_name); | 97 capability_request_.interfaces.count(interface_name); |
| 98 } | 98 } |
| 99 | 99 |
| 100 mojom::InterfaceProvider* ConnectionImpl::GetRemoteInterfaceProvider() { |
| 101 return remote_interfaces_.GetInterfaceProvider(); |
| 102 } |
| 103 |
| 100 InterfaceRegistry* ConnectionImpl::GetInterfaceRegistry() { | 104 InterfaceRegistry* ConnectionImpl::GetInterfaceRegistry() { |
| 101 return &interfaces_; | 105 return &interfaces_; |
| 102 } | 106 } |
| 103 | 107 |
| 108 RemoteInterfaceRegistry* ConnectionImpl::GetRemoteInterfaceRegistry() { |
| 109 return &remote_interfaces_; |
| 110 } |
| 111 |
| 104 base::WeakPtr<Connection> ConnectionImpl::GetWeakPtr() { | 112 base::WeakPtr<Connection> ConnectionImpl::GetWeakPtr() { |
| 105 return weak_factory_.GetWeakPtr(); | 113 return weak_factory_.GetWeakPtr(); |
| 106 } | 114 } |
| 107 | 115 |
| 108 //////////////////////////////////////////////////////////////////////////////// | 116 //////////////////////////////////////////////////////////////////////////////// |
| 109 // ConnectionImpl, private: | 117 // ConnectionImpl, private: |
| 110 | 118 |
| 111 void ConnectionImpl::OnConnectionCompleted(shell::mojom::ConnectResult result, | 119 void ConnectionImpl::OnConnectionCompleted(shell::mojom::ConnectResult result, |
| 112 const std::string& target_user_id, | 120 const std::string& target_user_id, |
| 113 uint32_t target_application_id) { | 121 uint32_t target_application_id) { |
| 114 DCHECK(State::PENDING == state_); | 122 DCHECK(State::PENDING == state_); |
| 115 | 123 |
| 116 result_ = result; | 124 result_ = result; |
| 117 state_ = result_ == shell::mojom::ConnectResult::SUCCEEDED ? | 125 state_ = result_ == shell::mojom::ConnectResult::SUCCEEDED ? |
| 118 State::CONNECTED : State::DISCONNECTED; | 126 State::CONNECTED : State::DISCONNECTED; |
| 119 remote_id_ = target_application_id; | 127 remote_id_ = target_application_id; |
| 120 remote_.set_user_id(target_user_id); | 128 remote_.set_user_id(target_user_id); |
| 121 std::vector<mojo::Closure> callbacks; | 129 std::vector<mojo::Closure> callbacks; |
| 122 callbacks.swap(connection_completed_callbacks_); | 130 callbacks.swap(connection_completed_callbacks_); |
| 123 for (auto callback : callbacks) | 131 for (auto callback : callbacks) |
| 124 callback.Run(); | 132 callback.Run(); |
| 125 } | 133 } |
| 126 | 134 |
| 127 } // namespace internal | 135 } // namespace internal |
| 128 } // namespace shell | 136 } // namespace shell |
| OLD | NEW |