| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "remoting/test/test_chromoting_client.h" | 5 #include "remoting/test/test_chromoting_client.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> |
| 8 #include <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
| 12 #include "jingle/glue/thread_wrapper.h" | 13 #include "jingle/glue/thread_wrapper.h" |
| 13 #include "net/base/request_priority.h" | 14 #include "net/base/request_priority.h" |
| 14 #include "net/socket/client_socket_factory.h" | 15 #include "net/socket/client_socket_factory.h" |
| 15 #include "remoting/base/url_request_context_getter.h" | 16 #include "remoting/base/url_request_context_getter.h" |
| 16 #include "remoting/client/audio_player.h" | 17 #include "remoting/client/audio_player.h" |
| 17 #include "remoting/client/chromoting_client.h" | 18 #include "remoting/client/chromoting_client.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 namespace remoting { | 66 namespace remoting { |
| 66 namespace test { | 67 namespace test { |
| 67 | 68 |
| 68 TestChromotingClient::TestChromotingClient() | 69 TestChromotingClient::TestChromotingClient() |
| 69 : TestChromotingClient(nullptr) {} | 70 : TestChromotingClient(nullptr) {} |
| 70 | 71 |
| 71 TestChromotingClient::TestChromotingClient( | 72 TestChromotingClient::TestChromotingClient( |
| 72 scoped_ptr<VideoRenderer> video_renderer) | 73 scoped_ptr<VideoRenderer> video_renderer) |
| 73 : connection_to_host_state_(protocol::ConnectionToHost::INITIALIZING), | 74 : connection_to_host_state_(protocol::ConnectionToHost::INITIALIZING), |
| 74 connection_error_code_(protocol::OK), | 75 connection_error_code_(protocol::OK), |
| 75 video_renderer_(video_renderer.Pass()) {} | 76 video_renderer_(std::move(video_renderer)) {} |
| 76 | 77 |
| 77 TestChromotingClient::~TestChromotingClient() { | 78 TestChromotingClient::~TestChromotingClient() { |
| 78 // Ensure any connections are closed and the members are destroyed in the | 79 // Ensure any connections are closed and the members are destroyed in the |
| 79 // appropriate order. | 80 // appropriate order. |
| 80 EndConnection(); | 81 EndConnection(); |
| 81 } | 82 } |
| 82 | 83 |
| 83 void TestChromotingClient::StartConnection( | 84 void TestChromotingClient::StartConnection( |
| 84 const ConnectionSetupInfo& connection_setup_info) { | 85 const ConnectionSetupInfo& connection_setup_info) { |
| 85 // Required to establish a connection to the host. | 86 // Required to establish a connection to the host. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 97 video_renderer_.reset(new TestVideoRenderer()); | 98 video_renderer_.reset(new TestVideoRenderer()); |
| 98 } | 99 } |
| 99 | 100 |
| 100 chromoting_client_.reset(new ChromotingClient(client_context_.get(), | 101 chromoting_client_.reset(new ChromotingClient(client_context_.get(), |
| 101 this, // client_user_interface. | 102 this, // client_user_interface. |
| 102 video_renderer_.get(), | 103 video_renderer_.get(), |
| 103 nullptr)); // audio_player | 104 nullptr)); // audio_player |
| 104 | 105 |
| 105 if (test_connection_to_host_) { | 106 if (test_connection_to_host_) { |
| 106 chromoting_client_->SetConnectionToHostForTests( | 107 chromoting_client_->SetConnectionToHostForTests( |
| 107 test_connection_to_host_.Pass()); | 108 std::move(test_connection_to_host_)); |
| 108 } | 109 } |
| 109 | 110 |
| 110 if (!signal_strategy_) { | 111 if (!signal_strategy_) { |
| 111 XmppSignalStrategy::XmppServerConfig xmpp_server_config; | 112 XmppSignalStrategy::XmppServerConfig xmpp_server_config; |
| 112 xmpp_server_config.host = kXmppHostName; | 113 xmpp_server_config.host = kXmppHostName; |
| 113 xmpp_server_config.port = kXmppPortNumber; | 114 xmpp_server_config.port = kXmppPortNumber; |
| 114 xmpp_server_config.use_tls = true; | 115 xmpp_server_config.use_tls = true; |
| 115 xmpp_server_config.username = connection_setup_info.user_name; | 116 xmpp_server_config.username = connection_setup_info.user_name; |
| 116 xmpp_server_config.auth_token = connection_setup_info.access_token; | 117 xmpp_server_config.auth_token = connection_setup_info.access_token; |
| 117 | 118 |
| 118 // Set up the signal strategy. This must outlive the client object. | 119 // Set up the signal strategy. This must outlive the client object. |
| 119 signal_strategy_.reset( | 120 signal_strategy_.reset( |
| 120 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), | 121 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), |
| 121 request_context_getter, xmpp_server_config)); | 122 request_context_getter, xmpp_server_config)); |
| 122 } | 123 } |
| 123 | 124 |
| 124 protocol::NetworkSettings network_settings( | 125 protocol::NetworkSettings network_settings( |
| 125 protocol::NetworkSettings::NAT_TRAVERSAL_FULL); | 126 protocol::NetworkSettings::NAT_TRAVERSAL_FULL); |
| 126 | 127 |
| 127 scoped_ptr<protocol::ChromiumPortAllocatorFactory> port_allocator_factory( | 128 scoped_ptr<protocol::ChromiumPortAllocatorFactory> port_allocator_factory( |
| 128 new protocol::ChromiumPortAllocatorFactory(request_context_getter)); | 129 new protocol::ChromiumPortAllocatorFactory(request_context_getter)); |
| 129 | 130 |
| 130 scoped_refptr<protocol::TransportContext> transport_context( | 131 scoped_refptr<protocol::TransportContext> transport_context( |
| 131 new protocol::TransportContext( | 132 new protocol::TransportContext( |
| 132 signal_strategy_.get(), port_allocator_factory.Pass(), | 133 signal_strategy_.get(), std::move(port_allocator_factory), |
| 133 network_settings, protocol::TransportRole::CLIENT)); | 134 network_settings, protocol::TransportRole::CLIENT)); |
| 134 | 135 |
| 135 scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> | 136 scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> |
| 136 token_fetcher(new TokenFetcherProxy( | 137 token_fetcher(new TokenFetcherProxy( |
| 137 base::Bind(&FetchThirdPartyToken, | 138 base::Bind(&FetchThirdPartyToken, |
| 138 connection_setup_info.authorization_code, | 139 connection_setup_info.authorization_code, |
| 139 connection_setup_info.shared_secret), | 140 connection_setup_info.shared_secret), |
| 140 connection_setup_info.public_key)); | 141 connection_setup_info.public_key)); |
| 141 | 142 |
| 142 protocol::FetchSecretCallback fetch_secret_callback; | 143 protocol::FetchSecretCallback fetch_secret_callback; |
| 143 if (!connection_setup_info.pin.empty()) { | 144 if (!connection_setup_info.pin.empty()) { |
| 144 fetch_secret_callback = base::Bind(&FetchSecret, connection_setup_info.pin); | 145 fetch_secret_callback = base::Bind(&FetchSecret, connection_setup_info.pin); |
| 145 } | 146 } |
| 146 | 147 |
| 147 scoped_ptr<protocol::Authenticator> authenticator( | 148 scoped_ptr<protocol::Authenticator> authenticator( |
| 148 new protocol::NegotiatingClientAuthenticator( | 149 new protocol::NegotiatingClientAuthenticator( |
| 149 connection_setup_info.pairing_id, | 150 connection_setup_info.pairing_id, connection_setup_info.shared_secret, |
| 150 connection_setup_info.shared_secret, | 151 connection_setup_info.host_id, fetch_secret_callback, |
| 151 connection_setup_info.host_id, | 152 std::move(token_fetcher), connection_setup_info.auth_methods)); |
| 152 fetch_secret_callback, | |
| 153 token_fetcher.Pass(), | |
| 154 connection_setup_info.auth_methods)); | |
| 155 | 153 |
| 156 chromoting_client_->Start( | 154 chromoting_client_->Start( |
| 157 signal_strategy_.get(), authenticator.Pass(), transport_context, | 155 signal_strategy_.get(), std::move(authenticator), transport_context, |
| 158 connection_setup_info.host_jid, connection_setup_info.capabilities); | 156 connection_setup_info.host_jid, connection_setup_info.capabilities); |
| 159 } | 157 } |
| 160 | 158 |
| 161 void TestChromotingClient::EndConnection() { | 159 void TestChromotingClient::EndConnection() { |
| 162 // Clearing out the client will close the connection. | 160 // Clearing out the client will close the connection. |
| 163 chromoting_client_.reset(); | 161 chromoting_client_.reset(); |
| 164 | 162 |
| 165 // The signal strategy object must outlive the client so destroy it next. | 163 // The signal strategy object must outlive the client so destroy it next. |
| 166 signal_strategy_.reset(); | 164 signal_strategy_.reset(); |
| 167 | 165 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 184 | 182 |
| 185 void TestChromotingClient::RemoveRemoteConnectionObserver( | 183 void TestChromotingClient::RemoveRemoteConnectionObserver( |
| 186 RemoteConnectionObserver* observer) { | 184 RemoteConnectionObserver* observer) { |
| 187 DCHECK(observer); | 185 DCHECK(observer); |
| 188 | 186 |
| 189 connection_observers_.RemoveObserver(observer); | 187 connection_observers_.RemoveObserver(observer); |
| 190 } | 188 } |
| 191 | 189 |
| 192 void TestChromotingClient::SetSignalStrategyForTests( | 190 void TestChromotingClient::SetSignalStrategyForTests( |
| 193 scoped_ptr<SignalStrategy> signal_strategy) { | 191 scoped_ptr<SignalStrategy> signal_strategy) { |
| 194 signal_strategy_ = signal_strategy.Pass(); | 192 signal_strategy_ = std::move(signal_strategy); |
| 195 } | 193 } |
| 196 | 194 |
| 197 void TestChromotingClient::SetConnectionToHostForTests( | 195 void TestChromotingClient::SetConnectionToHostForTests( |
| 198 scoped_ptr<protocol::ConnectionToHost> connection_to_host) { | 196 scoped_ptr<protocol::ConnectionToHost> connection_to_host) { |
| 199 test_connection_to_host_ = connection_to_host.Pass(); | 197 test_connection_to_host_ = std::move(connection_to_host); |
| 200 } | 198 } |
| 201 | 199 |
| 202 void TestChromotingClient::OnConnectionState( | 200 void TestChromotingClient::OnConnectionState( |
| 203 protocol::ConnectionToHost::State state, | 201 protocol::ConnectionToHost::State state, |
| 204 protocol::ErrorCode error_code) { | 202 protocol::ErrorCode error_code) { |
| 205 VLOG(1) << "TestChromotingClient::OnConnectionState(" | 203 VLOG(1) << "TestChromotingClient::OnConnectionState(" |
| 206 << "state: " << protocol::ConnectionToHost::StateToString(state) | 204 << "state: " << protocol::ConnectionToHost::StateToString(state) |
| 207 << ", error_code: " << protocol::ErrorCodeToString(error_code) | 205 << ", error_code: " << protocol::ErrorCodeToString(error_code) |
| 208 << ") Called"; | 206 << ") Called"; |
| 209 | 207 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 VLOG(1) << "TestChromotingClient::InjectClipboardEvent() Called"; | 276 VLOG(1) << "TestChromotingClient::InjectClipboardEvent() Called"; |
| 279 } | 277 } |
| 280 | 278 |
| 281 void TestChromotingClient::SetCursorShape( | 279 void TestChromotingClient::SetCursorShape( |
| 282 const protocol::CursorShapeInfo& cursor_shape) { | 280 const protocol::CursorShapeInfo& cursor_shape) { |
| 283 VLOG(1) << "TestChromotingClient::SetCursorShape() Called"; | 281 VLOG(1) << "TestChromotingClient::SetCursorShape() Called"; |
| 284 } | 282 } |
| 285 | 283 |
| 286 } // namespace test | 284 } // namespace test |
| 287 } // namespace remoting | 285 } // namespace remoting |
| OLD | NEW |