OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/client/jni/chromoting_jni_instance.h" | 5 #include "remoting/client/jni/chromoting_jni_instance.h" |
6 | 6 |
7 #include <android/log.h> | 7 #include <android/log.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <utility> | 10 #include <utility> |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 const std::string& username, | 50 const std::string& username, |
51 const std::string& auth_token, | 51 const std::string& auth_token, |
52 const std::string& host_jid, | 52 const std::string& host_jid, |
53 const std::string& host_id, | 53 const std::string& host_id, |
54 const std::string& host_pubkey, | 54 const std::string& host_pubkey, |
55 const std::string& pairing_id, | 55 const std::string& pairing_id, |
56 const std::string& pairing_secret, | 56 const std::string& pairing_secret, |
57 const std::string& capabilities, | 57 const std::string& capabilities, |
58 const std::string& flags) | 58 const std::string& flags) |
59 : jni_runtime_(jni_runtime), | 59 : jni_runtime_(jni_runtime), |
60 host_id_(host_id), | |
61 host_jid_(host_jid), | 60 host_jid_(host_jid), |
62 flags_(flags), | 61 flags_(flags), |
63 create_pairing_(false), | |
64 stats_logging_enabled_(false), | |
65 capabilities_(capabilities), | 62 capabilities_(capabilities), |
66 weak_factory_(this) { | 63 weak_factory_(this) { |
67 DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread()); | 64 DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread()); |
68 | 65 |
69 // Initialize XMPP config. | 66 // Initialize XMPP config. |
70 xmpp_config_.host = kXmppServer; | 67 xmpp_config_.host = kXmppServer; |
71 xmpp_config_.port = kXmppPort; | 68 xmpp_config_.port = kXmppPort; |
72 xmpp_config_.use_tls = kXmppUseTls; | 69 xmpp_config_.use_tls = kXmppUseTls; |
73 xmpp_config_.username = username; | 70 xmpp_config_.username = username; |
74 xmpp_config_.auth_token = auth_token; | 71 xmpp_config_.auth_token = auth_token; |
75 | 72 |
76 // Initialize |authenticator_|. | 73 client_auth_config_.host_id = host_id; |
77 authenticator_.reset(new protocol::NegotiatingClientAuthenticator( | 74 client_auth_config_.pairing_client_id = pairing_id; |
78 pairing_id, pairing_secret, host_id_, | 75 client_auth_config_.pairing_secret = pairing_secret; |
79 base::Bind(&ChromotingJniInstance::FetchSecret, | 76 client_auth_config_.fetch_secret_callback = base::Bind( |
80 weak_factory_.GetWeakPtr()), | 77 &ChromotingJniInstance::FetchSecret, weak_factory_.GetWeakPtr()); |
| 78 client_auth_config_.fetch_third_party_token_callback = |
81 base::Bind(&ChromotingJniInstance::FetchThirdPartyToken, | 79 base::Bind(&ChromotingJniInstance::FetchThirdPartyToken, |
82 weak_factory_.GetWeakPtr(), host_pubkey))); | 80 weak_factory_.GetWeakPtr(), host_pubkey); |
83 | 81 |
84 // Post a task to start connection | 82 // Post a task to start connection |
85 jni_runtime_->network_task_runner()->PostTask( | 83 jni_runtime_->network_task_runner()->PostTask( |
86 FROM_HERE, | 84 FROM_HERE, |
87 base::Bind(&ChromotingJniInstance::ConnectToHostOnNetworkThread, this)); | 85 base::Bind(&ChromotingJniInstance::ConnectToHostOnNetworkThread, this)); |
88 } | 86 } |
89 | 87 |
90 ChromotingJniInstance::~ChromotingJniInstance() { | 88 ChromotingJniInstance::~ChromotingJniInstance() { |
91 // This object is ref-counted, so this dtor can execute on any thread. | 89 // This object is ref-counted, so this dtor can execute on any thread. |
92 // Ensure that all these objects have been freed already, so they are not | 90 // Ensure that all these objects have been freed already, so they are not |
93 // destroyed on some random thread. | 91 // destroyed on some random thread. |
94 DCHECK(!view_); | 92 DCHECK(!view_); |
95 DCHECK(!client_context_); | 93 DCHECK(!client_context_); |
96 DCHECK(!video_renderer_); | 94 DCHECK(!video_renderer_); |
97 DCHECK(!authenticator_); | |
98 DCHECK(!client_); | 95 DCHECK(!client_); |
99 DCHECK(!signaling_); | 96 DCHECK(!signaling_); |
100 DCHECK(!client_status_logger_); | 97 DCHECK(!client_status_logger_); |
101 } | 98 } |
102 | 99 |
103 void ChromotingJniInstance::Disconnect() { | 100 void ChromotingJniInstance::Disconnect() { |
104 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { | 101 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { |
105 jni_runtime_->network_task_runner()->PostTask( | 102 jni_runtime_->network_task_runner()->PostTask( |
106 FROM_HERE, | 103 FROM_HERE, |
107 base::Bind(&ChromotingJniInstance::Disconnect, this)); | 104 base::Bind(&ChromotingJniInstance::Disconnect, this)); |
108 return; | 105 return; |
109 } | 106 } |
110 | 107 |
111 host_id_.clear(); | |
112 | |
113 stats_logging_enabled_ = false; | 108 stats_logging_enabled_ = false; |
114 | 109 |
115 // |client_| must be torn down before |signaling_|. | 110 // |client_| must be torn down before |signaling_|. |
116 client_.reset(); | 111 client_.reset(); |
117 client_status_logger_.reset(); | 112 client_status_logger_.reset(); |
118 video_renderer_.reset(); | 113 video_renderer_.reset(); |
119 view_.reset(); | 114 view_.reset(); |
120 authenticator_.reset(); | |
121 signaling_.reset(); | 115 signaling_.reset(); |
122 perf_tracker_.reset(); | 116 perf_tracker_.reset(); |
123 client_context_.reset(); | 117 client_context_.reset(); |
124 } | 118 } |
125 | 119 |
126 void ChromotingJniInstance::FetchThirdPartyToken( | 120 void ChromotingJniInstance::FetchThirdPartyToken( |
127 const std::string& host_public_key, | 121 const std::string& host_public_key, |
128 const std::string& token_url, | 122 const std::string& token_url, |
129 const std::string& scope, | 123 const std::string& scope, |
130 const protocol::ThirdPartyTokenFetchedCallback& token_fetched_callback) { | 124 const protocol::ThirdPartyTokenFetchedCallback& token_fetched_callback) { |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 void ChromotingJniInstance::OnRouteChanged( | 320 void ChromotingJniInstance::OnRouteChanged( |
327 const std::string& channel_name, | 321 const std::string& channel_name, |
328 const protocol::TransportRoute& route) { | 322 const protocol::TransportRoute& route) { |
329 std::string message = "Channel " + channel_name + " using " + | 323 std::string message = "Channel " + channel_name + " using " + |
330 protocol::TransportRoute::GetTypeString(route.type) + " connection."; | 324 protocol::TransportRoute::GetTypeString(route.type) + " connection."; |
331 __android_log_print(ANDROID_LOG_INFO, "route", "%s", message.c_str()); | 325 __android_log_print(ANDROID_LOG_INFO, "route", "%s", message.c_str()); |
332 } | 326 } |
333 | 327 |
334 void ChromotingJniInstance::SetCapabilities(const std::string& capabilities) { | 328 void ChromotingJniInstance::SetCapabilities(const std::string& capabilities) { |
335 jni_runtime_->ui_task_runner()->PostTask( | 329 jni_runtime_->ui_task_runner()->PostTask( |
336 FROM_HERE, | 330 FROM_HERE, base::Bind(&ChromotingJniRuntime::SetCapabilities, |
337 base::Bind(&ChromotingJniRuntime::SetCapabilities, | 331 base::Unretained(jni_runtime_), capabilities)); |
338 base::Unretained(jni_runtime_), | |
339 capabilities)); | |
340 } | 332 } |
341 | 333 |
342 void ChromotingJniInstance::SetPairingResponse( | 334 void ChromotingJniInstance::SetPairingResponse( |
343 const protocol::PairingResponse& response) { | 335 const protocol::PairingResponse& response) { |
344 | |
345 jni_runtime_->ui_task_runner()->PostTask( | 336 jni_runtime_->ui_task_runner()->PostTask( |
346 FROM_HERE, | 337 FROM_HERE, |
347 base::Bind(&ChromotingJniRuntime::CommitPairingCredentials, | 338 base::Bind(&ChromotingJniRuntime::CommitPairingCredentials, |
348 base::Unretained(jni_runtime_), | 339 base::Unretained(jni_runtime_), client_auth_config_.host_id, |
349 host_id_, response.client_id(), response.shared_secret())); | 340 response.client_id(), response.shared_secret())); |
350 } | 341 } |
351 | 342 |
352 void ChromotingJniInstance::DeliverHostMessage( | 343 void ChromotingJniInstance::DeliverHostMessage( |
353 const protocol::ExtensionMessage& message) { | 344 const protocol::ExtensionMessage& message) { |
354 jni_runtime_->ui_task_runner()->PostTask( | 345 jni_runtime_->ui_task_runner()->PostTask( |
355 FROM_HERE, | 346 FROM_HERE, base::Bind(&ChromotingJniRuntime::HandleExtensionMessage, |
356 base::Bind(&ChromotingJniRuntime::HandleExtensionMessage, | 347 base::Unretained(jni_runtime_), message.type(), |
357 base::Unretained(jni_runtime_), | 348 message.data())); |
358 message.type(), | |
359 message.data())); | |
360 } | 349 } |
361 | 350 |
362 protocol::ClipboardStub* ChromotingJniInstance::GetClipboardStub() { | 351 protocol::ClipboardStub* ChromotingJniInstance::GetClipboardStub() { |
363 return this; | 352 return this; |
364 } | 353 } |
365 | 354 |
366 protocol::CursorShapeStub* ChromotingJniInstance::GetCursorShapeStub() { | 355 protocol::CursorShapeStub* ChromotingJniInstance::GetCursorShapeStub() { |
367 return this; | 356 return this; |
368 } | 357 } |
369 | 358 |
(...skipping 21 matching lines...) Expand all Loading... |
391 | 380 |
392 client_context_.reset(new ClientContext(jni_runtime_->network_task_runner())); | 381 client_context_.reset(new ClientContext(jni_runtime_->network_task_runner())); |
393 client_context_->Start(); | 382 client_context_->Start(); |
394 | 383 |
395 perf_tracker_.reset(new protocol::PerformanceTracker()); | 384 perf_tracker_.reset(new protocol::PerformanceTracker()); |
396 | 385 |
397 view_.reset(new JniFrameConsumer(jni_runtime_)); | 386 view_.reset(new JniFrameConsumer(jni_runtime_)); |
398 video_renderer_.reset(new SoftwareVideoRenderer( | 387 video_renderer_.reset(new SoftwareVideoRenderer( |
399 client_context_->decode_task_runner(), view_.get(), perf_tracker_.get())); | 388 client_context_->decode_task_runner(), view_.get(), perf_tracker_.get())); |
400 | 389 |
401 client_.reset(new ChromotingClient( | 390 client_.reset(new ChromotingClient(client_context_.get(), this, |
402 client_context_.get(), this, video_renderer_.get(), nullptr)); | 391 video_renderer_.get(), nullptr)); |
403 | 392 |
404 signaling_.reset(new XmppSignalStrategy( | 393 signaling_.reset( |
405 net::ClientSocketFactory::GetDefaultFactory(), | 394 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), |
406 jni_runtime_->url_requester(), xmpp_config_)); | 395 jni_runtime_->url_requester(), xmpp_config_)); |
407 | 396 |
408 client_status_logger_.reset( | 397 client_status_logger_.reset( |
409 new ClientStatusLogger(ServerLogEntry::ME2ME, | 398 new ClientStatusLogger(ServerLogEntry::ME2ME, signaling_.get(), |
410 signaling_.get(), | |
411 ServiceUrls::GetInstance()->directory_bot_jid())); | 399 ServiceUrls::GetInstance()->directory_bot_jid())); |
412 | 400 |
413 scoped_refptr<protocol::TransportContext> transport_context = | 401 scoped_refptr<protocol::TransportContext> transport_context = |
414 new protocol::TransportContext( | 402 new protocol::TransportContext( |
415 signaling_.get(), | 403 signaling_.get(), |
416 make_scoped_ptr(new protocol::ChromiumPortAllocatorFactory()), | 404 make_scoped_ptr(new protocol::ChromiumPortAllocatorFactory()), |
417 make_scoped_ptr( | 405 make_scoped_ptr( |
418 new ChromiumUrlRequestFactory(jni_runtime_->url_requester())), | 406 new ChromiumUrlRequestFactory(jni_runtime_->url_requester())), |
419 protocol::NetworkSettings( | 407 protocol::NetworkSettings( |
420 protocol::NetworkSettings::NAT_TRAVERSAL_FULL), | 408 protocol::NetworkSettings::NAT_TRAVERSAL_FULL), |
421 protocol::TransportRole::CLIENT); | 409 protocol::TransportRole::CLIENT); |
422 | 410 |
423 if (flags_.find("useWebrtc") != std::string::npos) { | 411 if (flags_.find("useWebrtc") != std::string::npos) { |
424 VLOG(0) << "Attempting to connect using WebRTC."; | 412 VLOG(0) << "Attempting to connect using WebRTC."; |
425 scoped_ptr<protocol::CandidateSessionConfig> protocol_config = | 413 scoped_ptr<protocol::CandidateSessionConfig> protocol_config = |
426 protocol::CandidateSessionConfig::CreateEmpty(); | 414 protocol::CandidateSessionConfig::CreateEmpty(); |
427 protocol_config->set_webrtc_supported(true); | 415 protocol_config->set_webrtc_supported(true); |
428 protocol_config->set_ice_supported(false); | 416 protocol_config->set_ice_supported(false); |
429 client_->set_protocol_config(std::move(protocol_config)); | 417 client_->set_protocol_config(std::move(protocol_config)); |
430 } | 418 } |
431 | 419 |
432 client_->Start(signaling_.get(), std::move(authenticator_), transport_context, | 420 client_->Start(signaling_.get(), client_auth_config_, transport_context, |
433 host_jid_, capabilities_); | 421 host_jid_, capabilities_); |
434 } | 422 } |
435 | 423 |
436 void ChromotingJniInstance::FetchSecret( | 424 void ChromotingJniInstance::FetchSecret( |
437 bool pairable, | 425 bool pairable, |
438 const protocol::SecretFetchedCallback& callback) { | 426 const protocol::SecretFetchedCallback& callback) { |
439 if (!jni_runtime_->ui_task_runner()->BelongsToCurrentThread()) { | 427 if (!jni_runtime_->ui_task_runner()->BelongsToCurrentThread()) { |
440 jni_runtime_->ui_task_runner()->PostTask( | 428 jni_runtime_->ui_task_runner()->PostTask( |
441 FROM_HERE, base::Bind(&ChromotingJniInstance::FetchSecret, | 429 FROM_HERE, base::Bind(&ChromotingJniInstance::FetchSecret, |
442 this, pairable, callback)); | 430 this, pairable, callback)); |
443 return; | 431 return; |
444 } | 432 } |
445 | 433 |
446 // Delete pairing credentials if they exist. | 434 // Delete pairing credentials if they exist. |
447 jni_runtime_->CommitPairingCredentials(host_id_, "", ""); | 435 jni_runtime_->CommitPairingCredentials(client_auth_config_.host_id, "", ""); |
448 | 436 |
449 pin_callback_ = callback; | 437 pin_callback_ = callback; |
450 jni_runtime_->DisplayAuthenticationPrompt(pairable); | 438 jni_runtime_->DisplayAuthenticationPrompt(pairable); |
451 } | 439 } |
452 | 440 |
453 void ChromotingJniInstance::SetDeviceName(const std::string& device_name) { | 441 void ChromotingJniInstance::SetDeviceName(const std::string& device_name) { |
454 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { | 442 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { |
455 jni_runtime_->network_task_runner()->PostTask( | 443 jni_runtime_->network_task_runner()->PostTask( |
456 FROM_HERE, base::Bind(&ChromotingJniInstance::SetDeviceName, this, | 444 FROM_HERE, base::Bind(&ChromotingJniInstance::SetDeviceName, this, |
457 device_name)); | 445 device_name)); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 perf_tracker_->round_trip_ms()); | 491 perf_tracker_->round_trip_ms()); |
504 | 492 |
505 client_status_logger_->LogStatistics(perf_tracker_.get()); | 493 client_status_logger_->LogStatistics(perf_tracker_.get()); |
506 | 494 |
507 jni_runtime_->network_task_runner()->PostDelayedTask( | 495 jni_runtime_->network_task_runner()->PostDelayedTask( |
508 FROM_HERE, base::Bind(&ChromotingJniInstance::LogPerfStats, this), | 496 FROM_HERE, base::Bind(&ChromotingJniInstance::LogPerfStats, this), |
509 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); | 497 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); |
510 } | 498 } |
511 | 499 |
512 } // namespace remoting | 500 } // namespace remoting |
OLD | NEW |