| 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 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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 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 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 shell_client_factory_id_(0u), | |
| 33 remote_ids_valid_(false), | 32 remote_ids_valid_(false), |
| 34 local_registry_(std::move(local_interfaces), this), | 33 local_registry_(std::move(local_interfaces), this), |
| 35 remote_interfaces_(std::move(remote_interfaces)), | 34 remote_interfaces_(std::move(remote_interfaces)), |
| 36 allowed_interfaces_(allowed_interfaces), | 35 allowed_interfaces_(allowed_interfaces), |
| 37 allow_all_interfaces_(allowed_interfaces_.size() == 1 && | 36 allow_all_interfaces_(allowed_interfaces_.size() == 1 && |
| 38 allowed_interfaces_.count("*") == 1), | 37 allowed_interfaces_.count("*") == 1), |
| 39 weak_factory_(this) {} | 38 weak_factory_(this) {} |
| 40 | 39 |
| 41 ConnectionImpl::ConnectionImpl() | 40 ConnectionImpl::ConnectionImpl() |
| 42 : remote_id_(shell::mojom::Shell::kInvalidApplicationID), | 41 : remote_id_(shell::mojom::Shell::kInvalidApplicationID), |
| 43 shell_client_factory_id_(shell::mojom::Shell::kInvalidApplicationID), | |
| 44 remote_ids_valid_(false), | 42 remote_ids_valid_(false), |
| 45 local_registry_(shell::mojom::InterfaceProviderRequest(), this), | 43 local_registry_(shell::mojom::InterfaceProviderRequest(), this), |
| 46 allow_all_interfaces_(true), | 44 allow_all_interfaces_(true), |
| 47 weak_factory_(this) {} | 45 weak_factory_(this) {} |
| 48 | 46 |
| 49 ConnectionImpl::~ConnectionImpl() {} | 47 ConnectionImpl::~ConnectionImpl() {} |
| 50 | 48 |
| 51 shell::mojom::Shell::ConnectToApplicationCallback | 49 shell::mojom::Shell::ConnectToApplicationCallback |
| 52 ConnectionImpl::GetConnectToApplicationCallback() { | 50 ConnectionImpl::GetConnectToApplicationCallback() { |
| 53 return base::Bind(&ConnectionImpl::OnGotRemoteIDs, | 51 return base::Bind(&ConnectionImpl::OnGotInstanceID, |
| 54 weak_factory_.GetWeakPtr()); | 52 weak_factory_.GetWeakPtr()); |
| 55 } | 53 } |
| 56 | 54 |
| 57 //////////////////////////////////////////////////////////////////////////////// | 55 //////////////////////////////////////////////////////////////////////////////// |
| 58 // ConnectionImpl, Connection implementation: | 56 // ConnectionImpl, Connection implementation: |
| 59 | 57 |
| 60 const std::string& ConnectionImpl::GetConnectionURL() { | 58 const std::string& ConnectionImpl::GetConnectionURL() { |
| 61 return connection_url_; | 59 return connection_url_; |
| 62 } | 60 } |
| 63 | 61 |
| 64 const std::string& ConnectionImpl::GetRemoteApplicationURL() { | 62 const std::string& ConnectionImpl::GetRemoteApplicationURL() { |
| 65 return remote_url_; | 63 return remote_url_; |
| 66 } | 64 } |
| 67 | 65 |
| 68 void ConnectionImpl::SetRemoteInterfaceProviderConnectionErrorHandler( | 66 void ConnectionImpl::SetRemoteInterfaceProviderConnectionErrorHandler( |
| 69 const Closure& handler) { | 67 const Closure& handler) { |
| 70 remote_interfaces_.set_connection_error_handler(handler); | 68 remote_interfaces_.set_connection_error_handler(handler); |
| 71 } | 69 } |
| 72 | 70 |
| 73 bool ConnectionImpl::GetRemoteApplicationID(uint32_t* remote_id) const { | 71 bool ConnectionImpl::GetRemoteApplicationID(uint32_t* remote_id) const { |
| 74 if (!remote_ids_valid_) | 72 if (!remote_ids_valid_) |
| 75 return false; | 73 return false; |
| 76 | 74 |
| 77 *remote_id = remote_id_; | 75 *remote_id = remote_id_; |
| 78 return true; | 76 return true; |
| 79 } | 77 } |
| 80 | 78 |
| 81 bool ConnectionImpl::GetRemoteShellClientFactoryID( | |
| 82 uint32_t* shell_client_factory_id) const { | |
| 83 if (!remote_ids_valid_) | |
| 84 return false; | |
| 85 | |
| 86 *shell_client_factory_id = shell_client_factory_id_; | |
| 87 return true; | |
| 88 } | |
| 89 | |
| 90 void ConnectionImpl::AddRemoteIDCallback(const Closure& callback) { | 79 void ConnectionImpl::AddRemoteIDCallback(const Closure& callback) { |
| 91 if (remote_ids_valid_) { | 80 if (remote_ids_valid_) { |
| 92 callback.Run(); | 81 callback.Run(); |
| 93 return; | 82 return; |
| 94 } | 83 } |
| 95 remote_id_callbacks_.push_back(callback); | 84 remote_id_callbacks_.push_back(callback); |
| 96 } | 85 } |
| 97 | 86 |
| 98 bool ConnectionImpl::AllowsInterface(const std::string& interface_name) const { | 87 bool ConnectionImpl::AllowsInterface(const std::string& interface_name) const { |
| 99 return allow_all_interfaces_ || allowed_interfaces_.count(interface_name); | 88 return allow_all_interfaces_ || allowed_interfaces_.count(interface_name); |
| 100 } | 89 } |
| 101 | 90 |
| 102 shell::mojom::InterfaceProvider* ConnectionImpl::GetRemoteInterfaces() { | 91 shell::mojom::InterfaceProvider* ConnectionImpl::GetRemoteInterfaces() { |
| 103 return remote_interfaces_.get(); | 92 return remote_interfaces_.get(); |
| 104 } | 93 } |
| 105 | 94 |
| 106 InterfaceRegistry* ConnectionImpl::GetLocalRegistry() { | 95 InterfaceRegistry* ConnectionImpl::GetLocalRegistry() { |
| 107 return &local_registry_; | 96 return &local_registry_; |
| 108 } | 97 } |
| 109 | 98 |
| 110 base::WeakPtr<Connection> ConnectionImpl::GetWeakPtr() { | 99 base::WeakPtr<Connection> ConnectionImpl::GetWeakPtr() { |
| 111 return weak_factory_.GetWeakPtr(); | 100 return weak_factory_.GetWeakPtr(); |
| 112 } | 101 } |
| 113 | 102 |
| 114 //////////////////////////////////////////////////////////////////////////////// | 103 //////////////////////////////////////////////////////////////////////////////// |
| 115 // ConnectionImpl, private: | 104 // ConnectionImpl, private: |
| 116 | 105 |
| 117 void ConnectionImpl::OnGotRemoteIDs(uint32_t target_application_id, | 106 void ConnectionImpl::OnGotInstanceID(uint32_t target_application_id) { |
| 118 uint32_t shell_client_factory_id) { | |
| 119 DCHECK(!remote_ids_valid_); | 107 DCHECK(!remote_ids_valid_); |
| 120 remote_ids_valid_ = true; | 108 remote_ids_valid_ = true; |
| 121 | 109 |
| 122 remote_id_ = target_application_id; | 110 remote_id_ = target_application_id; |
| 123 shell_client_factory_id_ = shell_client_factory_id; | |
| 124 std::vector<Closure> callbacks; | 111 std::vector<Closure> callbacks; |
| 125 callbacks.swap(remote_id_callbacks_); | 112 callbacks.swap(remote_id_callbacks_); |
| 126 for (auto callback : callbacks) | 113 for (auto callback : callbacks) |
| 127 callback.Run(); | 114 callback.Run(); |
| 128 } | 115 } |
| 129 | 116 |
| 130 } // namespace internal | 117 } // namespace internal |
| 131 } // namespace mojo | 118 } // namespace mojo |
| OLD | NEW |