| 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 "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_url, | 23 const std::string& connection_url, |
| 24 const std::string& remote_url, | 24 const std::string& remote_url, |
| 25 uint32_t remote_id, | 25 uint32_t remote_id, |
| 26 InterfaceProviderPtr remote_interfaces, | 26 shell::mojom::InterfaceProviderPtr remote_interfaces, |
| 27 InterfaceRequest<InterfaceProvider> local_interfaces, | 27 shell::mojom::InterfaceProviderRequest local_interfaces, |
| 28 const std::set<std::string>& allowed_interfaces) | 28 const std::set<std::string>& allowed_interfaces) |
| 29 : connection_url_(connection_url), | 29 : connection_url_(connection_url), |
| 30 remote_url_(remote_url), | 30 remote_url_(remote_url), |
| 31 remote_id_(remote_id), | 31 remote_id_(remote_id), |
| 32 content_handler_id_(0u), | 32 content_handler_id_(0u), |
| 33 remote_ids_valid_(false), | 33 remote_ids_valid_(false), |
| 34 local_binding_(this), | 34 local_binding_(this), |
| 35 remote_interfaces_(std::move(remote_interfaces)), | 35 remote_interfaces_(std::move(remote_interfaces)), |
| 36 allowed_interfaces_(allowed_interfaces), | 36 allowed_interfaces_(allowed_interfaces), |
| 37 allow_all_interfaces_(allowed_interfaces_.size() == 1 && | 37 allow_all_interfaces_(allowed_interfaces_.size() == 1 && |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 } | 87 } |
| 88 | 88 |
| 89 const std::string& ConnectionImpl::GetConnectionURL() { | 89 const std::string& ConnectionImpl::GetConnectionURL() { |
| 90 return connection_url_; | 90 return connection_url_; |
| 91 } | 91 } |
| 92 | 92 |
| 93 const std::string& ConnectionImpl::GetRemoteApplicationURL() { | 93 const std::string& ConnectionImpl::GetRemoteApplicationURL() { |
| 94 return remote_url_; | 94 return remote_url_; |
| 95 } | 95 } |
| 96 | 96 |
| 97 InterfaceProvider* ConnectionImpl::GetRemoteInterfaces() { | 97 shell::mojom::InterfaceProvider* ConnectionImpl::GetRemoteInterfaces() { |
| 98 return remote_interfaces_.get(); | 98 return remote_interfaces_.get(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 InterfaceProvider* ConnectionImpl::GetLocalInterfaces() { | 101 shell::mojom::InterfaceProvider* ConnectionImpl::GetLocalInterfaces() { |
| 102 return this; | 102 return this; |
| 103 } | 103 } |
| 104 | 104 |
| 105 void ConnectionImpl::SetRemoteInterfaceProviderConnectionErrorHandler( | 105 void ConnectionImpl::SetRemoteInterfaceProviderConnectionErrorHandler( |
| 106 const Closure& handler) { | 106 const Closure& handler) { |
| 107 remote_interfaces_.set_connection_error_handler(handler); | 107 remote_interfaces_.set_connection_error_handler(handler); |
| 108 } | 108 } |
| 109 | 109 |
| 110 bool ConnectionImpl::GetRemoteApplicationID(uint32_t* remote_id) const { | 110 bool ConnectionImpl::GetRemoteApplicationID(uint32_t* remote_id) const { |
| 111 if (!remote_ids_valid_) | 111 if (!remote_ids_valid_) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 130 return; | 130 return; |
| 131 } | 131 } |
| 132 remote_id_callbacks_.push_back(callback); | 132 remote_id_callbacks_.push_back(callback); |
| 133 } | 133 } |
| 134 | 134 |
| 135 base::WeakPtr<Connection> ConnectionImpl::GetWeakPtr() { | 135 base::WeakPtr<Connection> ConnectionImpl::GetWeakPtr() { |
| 136 return weak_factory_.GetWeakPtr(); | 136 return weak_factory_.GetWeakPtr(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 //////////////////////////////////////////////////////////////////////////////// | 139 //////////////////////////////////////////////////////////////////////////////// |
| 140 // ConnectionImpl, InterfaceProvider implementation: | 140 // ConnectionImpl, shell::mojom::InterfaceProvider implementation: |
| 141 | 141 |
| 142 void ConnectionImpl::GetInterface(const mojo::String& interface_name, | 142 void ConnectionImpl::GetInterface(const mojo::String& interface_name, |
| 143 ScopedMessagePipeHandle handle) { | 143 ScopedMessagePipeHandle handle) { |
| 144 auto iter = name_to_binder_.find(interface_name); | 144 auto iter = name_to_binder_.find(interface_name); |
| 145 InterfaceBinder* binder = iter != name_to_binder_.end() ? iter->second : | 145 InterfaceBinder* binder = iter != name_to_binder_.end() ? iter->second : |
| 146 default_binder_; | 146 default_binder_; |
| 147 if (binder) | 147 if (binder) |
| 148 binder->BindInterface(this, interface_name, std::move(handle)); | 148 binder->BindInterface(this, interface_name, std::move(handle)); |
| 149 } | 149 } |
| 150 | 150 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 168 remote_id_ = target_application_id; | 168 remote_id_ = target_application_id; |
| 169 content_handler_id_ = content_handler_id; | 169 content_handler_id_ = content_handler_id; |
| 170 std::vector<Closure> callbacks; | 170 std::vector<Closure> callbacks; |
| 171 callbacks.swap(remote_id_callbacks_); | 171 callbacks.swap(remote_id_callbacks_); |
| 172 for (auto callback : callbacks) | 172 for (auto callback : callbacks) |
| 173 callback.Run(); | 173 callback.Run(); |
| 174 } | 174 } |
| 175 | 175 |
| 176 } // namespace internal | 176 } // namespace internal |
| 177 } // namespace mojo | 177 } // namespace mojo |
| OLD | NEW |