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

Side by Side Diff: remoting/test/protocol_perftest.cc

Issue 1521883006: Add TransportContext class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « remoting/test/fake_port_allocator.cc ('k') | remoting/test/test_chromoting_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/base64.h" 5 #include "base/base64.h"
6 #include "base/files/file_util.h" 6 #include "base/files/file_util.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/synchronization/waitable_event.h" 11 #include "base/synchronization/waitable_event.h"
12 #include "base/thread_task_runner_handle.h" 12 #include "base/thread_task_runner_handle.h"
13 #include "jingle/glue/thread_wrapper.h" 13 #include "jingle/glue/thread_wrapper.h"
14 #include "net/base/test_data_directory.h" 14 #include "net/base/test_data_directory.h"
15 #include "net/url_request/url_request_context_getter.h" 15 #include "net/url_request/url_request_context_getter.h"
16 #include "remoting/base/rsa_key_pair.h" 16 #include "remoting/base/rsa_key_pair.h"
17 #include "remoting/client/audio_player.h" 17 #include "remoting/client/audio_player.h"
18 #include "remoting/client/chromoting_client.h" 18 #include "remoting/client/chromoting_client.h"
19 #include "remoting/client/client_context.h" 19 #include "remoting/client/client_context.h"
20 #include "remoting/client/client_user_interface.h" 20 #include "remoting/client/client_user_interface.h"
21 #include "remoting/client/video_renderer.h" 21 #include "remoting/client/video_renderer.h"
22 #include "remoting/host/chromoting_host.h" 22 #include "remoting/host/chromoting_host.h"
23 #include "remoting/host/chromoting_host_context.h" 23 #include "remoting/host/chromoting_host_context.h"
24 #include "remoting/host/fake_desktop_environment.h" 24 #include "remoting/host/fake_desktop_environment.h"
25 #include "remoting/protocol/ice_transport_factory.h" 25 #include "remoting/protocol/ice_transport.h"
26 #include "remoting/protocol/jingle_session_manager.h" 26 #include "remoting/protocol/jingle_session_manager.h"
27 #include "remoting/protocol/me2me_host_authenticator_factory.h" 27 #include "remoting/protocol/me2me_host_authenticator_factory.h"
28 #include "remoting/protocol/negotiating_client_authenticator.h" 28 #include "remoting/protocol/negotiating_client_authenticator.h"
29 #include "remoting/protocol/session_config.h" 29 #include "remoting/protocol/session_config.h"
30 #include "remoting/protocol/transport_context.h"
30 #include "remoting/protocol/video_frame_pump.h" 31 #include "remoting/protocol/video_frame_pump.h"
31 #include "remoting/signaling/fake_signal_strategy.h" 32 #include "remoting/signaling/fake_signal_strategy.h"
32 #include "remoting/test/fake_network_dispatcher.h" 33 #include "remoting/test/fake_network_dispatcher.h"
33 #include "remoting/test/fake_port_allocator.h" 34 #include "remoting/test/fake_port_allocator.h"
34 #include "remoting/test/fake_socket_factory.h" 35 #include "remoting/test/fake_socket_factory.h"
35 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
36 37
37 namespace remoting { 38 namespace remoting {
38 39
39 using protocol::ChannelConfig; 40 using protocol::ChannelConfig;
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 DCHECK(host_thread_.task_runner()->BelongsToCurrentThread()); 218 DCHECK(host_thread_.task_runner()->BelongsToCurrentThread());
218 219
219 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); 220 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop();
220 221
221 host_signaling_.reset(new FakeSignalStrategy(kHostJid)); 222 host_signaling_.reset(new FakeSignalStrategy(kHostJid));
222 host_signaling_->ConnectTo(client_signaling_.get()); 223 host_signaling_->ConnectTo(client_signaling_.get());
223 224
224 protocol::NetworkSettings network_settings( 225 protocol::NetworkSettings network_settings(
225 protocol::NetworkSettings::NAT_TRAVERSAL_OUTGOING); 226 protocol::NetworkSettings::NAT_TRAVERSAL_OUTGOING);
226 227
227 scoped_ptr<FakePortAllocator> port_allocator( 228 scoped_ptr<FakePortAllocatorFactory> port_allocator_factory(
228 FakePortAllocator::Create(fake_network_dispatcher_)); 229 new FakePortAllocatorFactory(fake_network_dispatcher_));
229 port_allocator->socket_factory()->SetBandwidth(GetParam().bandwidth, 230 port_allocator_factory->socket_factory()->SetBandwidth(
230 GetParam().max_buffers); 231 GetParam().bandwidth, GetParam().max_buffers);
231 port_allocator->socket_factory()->SetLatency(GetParam().latency_average, 232 port_allocator_factory->socket_factory()->SetLatency(
232 GetParam().latency_stddev); 233 GetParam().latency_average, GetParam().latency_stddev);
233 port_allocator->socket_factory()->set_out_of_order_rate( 234 port_allocator_factory->socket_factory()->set_out_of_order_rate(
234 GetParam().out_of_order_rate); 235 GetParam().out_of_order_rate);
235 scoped_ptr<protocol::TransportFactory> host_transport_factory( 236 scoped_refptr<protocol::TransportContext> transport_context(
236 new protocol::IceTransportFactory( 237 new protocol::TransportContext(
237 host_signaling_.get(), port_allocator.Pass(), network_settings, 238 host_signaling_.get(), port_allocator_factory.Pass(),
238 protocol::TransportRole::SERVER)); 239 network_settings, protocol::TransportRole::SERVER));
239 240
240 scoped_ptr<protocol::SessionManager> session_manager( 241 scoped_ptr<protocol::SessionManager> session_manager(
241 new protocol::JingleSessionManager(host_transport_factory.Pass())); 242 new protocol::JingleSessionManager(make_scoped_ptr(
243 new protocol::IceTransportFactory(transport_context))));
242 session_manager->set_protocol_config(protocol_config_->Clone()); 244 session_manager->set_protocol_config(protocol_config_->Clone());
243 245
244 // Encoder runs on a separate thread, main thread is used for everything 246 // Encoder runs on a separate thread, main thread is used for everything
245 // else. 247 // else.
246 host_.reset(new ChromotingHost(host_signaling_.get(), 248 host_.reset(new ChromotingHost(host_signaling_.get(),
247 &desktop_environment_factory_, 249 &desktop_environment_factory_,
248 session_manager.Pass(), 250 session_manager.Pass(),
249 host_thread_.task_runner(), 251 host_thread_.task_runner(),
250 host_thread_.task_runner(), 252 host_thread_.task_runner(),
251 capture_thread_.task_runner(), 253 capture_thread_.task_runner(),
252 encode_thread_.task_runner(), 254 encode_thread_.task_runner(),
253 host_thread_.task_runner(), 255 host_thread_.task_runner(),
254 host_thread_.task_runner())); 256 host_thread_.task_runner()));
255 257
256 base::FilePath certs_dir(net::GetTestCertsDirectory()); 258 base::FilePath certs_dir(net::GetTestCertsDirectory());
257 259
258 std::string host_cert; 260 std::string host_cert;
259 ASSERT_TRUE(base::ReadFileToString( 261 ASSERT_TRUE(base::ReadFileToString(
260 certs_dir.AppendASCII("unittest.selfsigned.der"), &host_cert)); 262 certs_dir.AppendASCII("unittest.selfsigned.der"), &host_cert));
261 263
262 base::FilePath key_path = certs_dir.AppendASCII("unittest.key.bin"); 264 base::FilePath key_path = certs_dir.AppendASCII("unittest.key.bin");
263 std::string key_string; 265 std::string key_string;
264 ASSERT_TRUE(base::ReadFileToString(key_path, &key_string)); 266 ASSERT_TRUE(base::ReadFileToString(key_path, &key_string));
265 std::string key_base64; 267 std::string key_base64;
266 base::Base64Encode(key_string, &key_base64); 268 base::Base64Encode(key_string, &key_base64);
267 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::FromString(key_base64); 269 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::FromString(key_base64);
268 ASSERT_TRUE(key_pair.get()); 270 ASSERT_TRUE(key_pair.get());
269 271
270
271 protocol::SharedSecretHash host_secret; 272 protocol::SharedSecretHash host_secret;
272 host_secret.hash_function = protocol::AuthenticationMethod::NONE; 273 host_secret.hash_function = protocol::AuthenticationMethod::NONE;
273 host_secret.value = "123456"; 274 host_secret.value = "123456";
274 scoped_ptr<protocol::AuthenticatorFactory> auth_factory = 275 scoped_ptr<protocol::AuthenticatorFactory> auth_factory =
275 protocol::Me2MeHostAuthenticatorFactory::CreateWithSharedSecret( 276 protocol::Me2MeHostAuthenticatorFactory::CreateWithSharedSecret(
276 true, kHostOwner, host_cert, key_pair, host_secret, nullptr); 277 true, kHostOwner, host_cert, key_pair, host_secret, nullptr);
277 host_->SetAuthenticatorFactory(auth_factory.Pass()); 278 host_->SetAuthenticatorFactory(auth_factory.Pass());
278 279
279 host_->AddStatusObserver(this); 280 host_->AddStatusObserver(this);
280 host_->Start(kHostOwner); 281 host_->Start(kHostOwner);
281 282
282 message_loop_.PostTask(FROM_HERE, 283 message_loop_.PostTask(FROM_HERE,
283 base::Bind(&ProtocolPerfTest::StartClientAfterHost, 284 base::Bind(&ProtocolPerfTest::StartClientAfterHost,
284 base::Unretained(this))); 285 base::Unretained(this)));
285 } 286 }
286 287
287 void StartClientAfterHost() { 288 void StartClientAfterHost() {
288 client_signaling_->ConnectTo(host_signaling_.get()); 289 client_signaling_->ConnectTo(host_signaling_.get());
289 290
290 protocol::NetworkSettings network_settings( 291 protocol::NetworkSettings network_settings(
291 protocol::NetworkSettings::NAT_TRAVERSAL_OUTGOING); 292 protocol::NetworkSettings::NAT_TRAVERSAL_OUTGOING);
292 293
293 // Initialize client. 294 // Initialize client.
294 client_context_.reset( 295 client_context_.reset(
295 new ClientContext(base::ThreadTaskRunnerHandle::Get())); 296 new ClientContext(base::ThreadTaskRunnerHandle::Get()));
296 297
297 scoped_ptr<FakePortAllocator> port_allocator( 298 scoped_ptr<FakePortAllocatorFactory> port_allocator_factory(
298 FakePortAllocator::Create(fake_network_dispatcher_)); 299 new FakePortAllocatorFactory(fake_network_dispatcher_));
299 port_allocator->socket_factory()->SetBandwidth(GetParam().bandwidth, 300 port_allocator_factory->socket_factory()->SetBandwidth(
300 GetParam().max_buffers); 301 GetParam().bandwidth, GetParam().max_buffers);
301 port_allocator->socket_factory()->SetLatency(GetParam().latency_average, 302 port_allocator_factory->socket_factory()->SetLatency(
302 GetParam().latency_stddev); 303 GetParam().latency_average, GetParam().latency_stddev);
303 port_allocator->socket_factory()->set_out_of_order_rate( 304 port_allocator_factory->socket_factory()->set_out_of_order_rate(
304 GetParam().out_of_order_rate); 305 GetParam().out_of_order_rate);
305 scoped_ptr<protocol::TransportFactory> client_transport_factory( 306 scoped_refptr<protocol::TransportContext> transport_context(
306 new protocol::IceTransportFactory( 307 new protocol::TransportContext(
307 client_signaling_.get(), port_allocator.Pass(), network_settings, 308 host_signaling_.get(), port_allocator_factory.Pass(),
308 protocol::TransportRole::CLIENT)); 309 network_settings, protocol::TransportRole::SERVER));
309 310
310 std::vector<protocol::AuthenticationMethod> auth_methods; 311 std::vector<protocol::AuthenticationMethod> auth_methods;
311 auth_methods.push_back(protocol::AuthenticationMethod::Spake2( 312 auth_methods.push_back(protocol::AuthenticationMethod::Spake2(
312 protocol::AuthenticationMethod::NONE)); 313 protocol::AuthenticationMethod::NONE));
313 scoped_ptr<protocol::Authenticator> client_authenticator( 314 scoped_ptr<protocol::Authenticator> client_authenticator(
314 new protocol::NegotiatingClientAuthenticator( 315 new protocol::NegotiatingClientAuthenticator(
315 std::string(), // client_pairing_id 316 std::string(), // client_pairing_id
316 std::string(), // client_pairing_secret 317 std::string(), // client_pairing_secret
317 std::string(), // authentication_tag 318 std::string(), // authentication_tag
318 base::Bind(&ProtocolPerfTest::FetchPin, base::Unretained(this)), 319 base::Bind(&ProtocolPerfTest::FetchPin, base::Unretained(this)),
319 nullptr, 320 nullptr,
320 auth_methods)); 321 auth_methods));
321 client_.reset( 322 client_.reset(
322 new ChromotingClient(client_context_.get(), this, this, nullptr)); 323 new ChromotingClient(client_context_.get(), this, this, nullptr));
323 client_->set_protocol_config(protocol_config_->Clone()); 324 client_->set_protocol_config(protocol_config_->Clone());
324 client_->Start(client_signaling_.get(), client_authenticator.Pass(), 325 client_->Start(client_signaling_.get(), client_authenticator.Pass(),
325 client_transport_factory.Pass(), kHostJid, std::string()); 326 transport_context, kHostJid, std::string());
326 } 327 }
327 328
328 void FetchPin( 329 void FetchPin(
329 bool pairing_supported, 330 bool pairing_supported,
330 const protocol::SecretFetchedCallback& secret_fetched_callback) { 331 const protocol::SecretFetchedCallback& secret_fetched_callback) {
331 secret_fetched_callback.Run("123456"); 332 secret_fetched_callback.Run("123456");
332 } 333 }
333 334
334 base::MessageLoopForIO message_loop_; 335 base::MessageLoopForIO message_loop_;
335 336
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 << "ms Encode: " << last_video_packet_->encode_time_ms() 486 << "ms Encode: " << last_video_packet_->encode_time_ms()
486 << "ms Capture: " << last_video_packet_->capture_time_ms() 487 << "ms Capture: " << last_video_packet_->capture_time_ms()
487 << "ms"; 488 << "ms";
488 sum += latency; 489 sum += latency;
489 } 490 }
490 491
491 LOG(INFO) << "Average: " << (sum / kFrames).InMillisecondsF(); 492 LOG(INFO) << "Average: " << (sum / kFrames).InMillisecondsF();
492 } 493 }
493 494
494 } // namespace remoting 495 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/test/fake_port_allocator.cc ('k') | remoting/test/test_chromoting_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698