Chromium Code Reviews| 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 "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 const int kPerfStatsIntervalMs = 60000; | 47 const int kPerfStatsIntervalMs = 60000; |
| 48 | 48 |
| 49 } // namespace | 49 } // namespace |
| 50 | 50 |
| 51 ChromotingJniInstance::ChromotingJniInstance( | 51 ChromotingJniInstance::ChromotingJniInstance( |
| 52 ChromotingJniRuntime* jni_runtime, | 52 ChromotingJniRuntime* jni_runtime, |
| 53 base::WeakPtr<JniClient> jni_client, | 53 base::WeakPtr<JniClient> jni_client, |
| 54 base::WeakPtr<JniPairingSecretFetcher> secret_fetcher, | 54 base::WeakPtr<JniPairingSecretFetcher> secret_fetcher, |
| 55 std::unique_ptr<protocol::CursorShapeStub> cursor_shape_stub, | 55 std::unique_ptr<protocol::CursorShapeStub> cursor_shape_stub, |
| 56 std::unique_ptr<protocol::VideoRenderer> video_renderer, | 56 std::unique_ptr<protocol::VideoRenderer> video_renderer, |
| 57 const std::string& username, | 57 const ConnectToHostInfo& info) |
| 58 const std::string& auth_token, | |
| 59 const std::string& host_jid, | |
| 60 const std::string& host_id, | |
| 61 const std::string& host_pubkey, | |
| 62 const std::string& pairing_id, | |
| 63 const std::string& pairing_secret, | |
| 64 const std::string& capabilities, | |
| 65 const std::string& flags, | |
| 66 const std::string& host_version, | |
| 67 const std::string& host_os, | |
| 68 const std::string& host_os_version) | |
| 69 : jni_runtime_(jni_runtime), | 58 : jni_runtime_(jni_runtime), |
| 70 jni_client_(jni_client), | 59 jni_client_(jni_client), |
| 71 secret_fetcher_(secret_fetcher), | 60 secret_fetcher_(secret_fetcher), |
| 72 host_jid_(host_jid), | 61 connection_info_(info), |
| 73 flags_(flags), | |
| 74 cursor_shape_stub_(std::move(cursor_shape_stub)), | 62 cursor_shape_stub_(std::move(cursor_shape_stub)), |
| 75 video_renderer_(std::move(video_renderer)), | 63 video_renderer_(std::move(video_renderer)), |
| 76 capabilities_(capabilities), | 64 capabilities_(info.capabilities), |
| 77 host_version_(host_version), | |
| 78 host_os_(host_os), | |
| 79 host_os_version_(host_os_version), | |
| 80 weak_factory_(this) { | 65 weak_factory_(this) { |
| 81 DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread()); | 66 DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread()); |
| 82 weak_ptr_ = weak_factory_.GetWeakPtr(); | 67 weak_ptr_ = weak_factory_.GetWeakPtr(); |
| 83 | 68 |
| 84 // Initialize XMPP config. | 69 // Initialize XMPP config. |
| 85 xmpp_config_.host = kXmppServer; | 70 xmpp_config_.host = kXmppServer; |
| 86 xmpp_config_.port = kXmppPort; | 71 xmpp_config_.port = kXmppPort; |
| 87 xmpp_config_.use_tls = kXmppUseTls; | 72 xmpp_config_.use_tls = kXmppUseTls; |
| 88 xmpp_config_.username = username; | 73 xmpp_config_.username = info.username; |
| 89 xmpp_config_.auth_token = auth_token; | 74 xmpp_config_.auth_token = info.auth_token; |
| 90 | 75 |
| 91 client_auth_config_.host_id = host_id; | 76 client_auth_config_.host_id = info.host_id; |
| 92 client_auth_config_.pairing_client_id = pairing_id; | 77 client_auth_config_.pairing_client_id = info.pairing_id; |
| 93 client_auth_config_.pairing_secret = pairing_secret; | 78 client_auth_config_.pairing_secret = info.pairing_secret; |
| 94 client_auth_config_.fetch_secret_callback = | 79 client_auth_config_.fetch_secret_callback = |
| 95 base::Bind(&JniPairingSecretFetcher::FetchSecret, secret_fetcher); | 80 base::Bind(&JniPairingSecretFetcher::FetchSecret, secret_fetcher); |
| 96 client_auth_config_.fetch_third_party_token_callback = base::Bind( | 81 client_auth_config_.fetch_third_party_token_callback = base::Bind( |
| 97 &ChromotingJniInstance::FetchThirdPartyToken, GetWeakPtr(), host_pubkey); | 82 &ChromotingJniInstance::FetchThirdPartyToken, GetWeakPtr(), |
| 83 info.host_pubkey); | |
| 98 } | 84 } |
| 99 | 85 |
| 100 ChromotingJniInstance::~ChromotingJniInstance() { | 86 ChromotingJniInstance::~ChromotingJniInstance() { |
| 101 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); | 87 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 102 if (client_) { | 88 if (client_) { |
| 103 ReleaseResources(); | 89 ReleaseResources(); |
| 104 } | 90 } |
| 105 } | 91 } |
| 106 | 92 |
| 107 void ChromotingJniInstance::Connect() { | 93 void ChromotingJniInstance::Connect() { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 122 base::Bind(&ChromotingJniInstance::Disconnect, GetWeakPtr())); | 108 base::Bind(&ChromotingJniInstance::Disconnect, GetWeakPtr())); |
| 123 return; | 109 return; |
| 124 } | 110 } |
| 125 | 111 |
| 126 stats_logging_enabled_ = false; | 112 stats_logging_enabled_ = false; |
| 127 | 113 |
| 128 // User disconnection will not trigger OnConnectionState(Closed, OK). | 114 // User disconnection will not trigger OnConnectionState(Closed, OK). |
| 129 // Remote disconnection will trigger OnConnectionState(...) and later trigger | 115 // Remote disconnection will trigger OnConnectionState(...) and later trigger |
| 130 // Disconnect(). | 116 // Disconnect(). |
| 131 if (connected_) { | 117 if (connected_) { |
| 132 jni_runtime_->logger()->LogSessionStateChange( | 118 logger_->LogSessionStateChange( |
| 133 ChromotingEvent::SessionState::CLOSED, | 119 ChromotingEvent::SessionState::CLOSED, |
| 134 ChromotingEvent::ConnectionError::NONE); | 120 ChromotingEvent::ConnectionError::NONE); |
| 135 connected_ = false; | 121 connected_ = false; |
| 136 } | 122 } |
| 137 | 123 |
| 138 ReleaseResources(); | 124 ReleaseResources(); |
| 139 } | 125 } |
| 140 | 126 |
| 141 void ChromotingJniInstance::FetchThirdPartyToken( | 127 void ChromotingJniInstance::FetchThirdPartyToken( |
| 142 const std::string& host_public_key, | 128 const std::string& host_public_key, |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 void ChromotingJniInstance::OnConnectionState( | 285 void ChromotingJniInstance::OnConnectionState( |
| 300 protocol::ConnectionToHost::State state, | 286 protocol::ConnectionToHost::State state, |
| 301 protocol::ErrorCode error) { | 287 protocol::ErrorCode error) { |
| 302 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); | 288 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 303 | 289 |
| 304 // This code assumes no intermediate connection state between CONNECTED and | 290 // This code assumes no intermediate connection state between CONNECTED and |
| 305 // CLOSED/FAILED. | 291 // CLOSED/FAILED. |
| 306 connected_ = state == protocol::ConnectionToHost::CONNECTED; | 292 connected_ = state == protocol::ConnectionToHost::CONNECTED; |
| 307 EnableStatsLogging(connected_); | 293 EnableStatsLogging(connected_); |
| 308 | 294 |
| 309 jni_runtime_->logger()->LogSessionStateChange( | 295 logger_->LogSessionStateChange( |
| 310 ClientTelemetryLogger::TranslateState(state), | 296 ClientTelemetryLogger::TranslateState(state), |
| 311 ClientTelemetryLogger::TranslateError(error)); | 297 ClientTelemetryLogger::TranslateError(error)); |
| 312 | 298 |
| 313 if (create_pairing_ && state == protocol::ConnectionToHost::CONNECTED) { | 299 if (create_pairing_ && state == protocol::ConnectionToHost::CONNECTED) { |
| 314 protocol::PairingRequest request; | 300 protocol::PairingRequest request; |
| 315 DCHECK(!device_name_.empty()); | 301 DCHECK(!device_name_.empty()); |
| 316 request.set_client_name(device_name_); | 302 request.set_client_name(device_name_); |
| 317 client_->host_stub()->RequestPairing(request); | 303 client_->host_stub()->RequestPairing(request); |
| 318 } | 304 } |
| 319 | 305 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 NOTIMPLEMENTED(); | 360 NOTIMPLEMENTED(); |
| 375 } | 361 } |
| 376 | 362 |
| 377 base::WeakPtr<ChromotingJniInstance> ChromotingJniInstance::GetWeakPtr() { | 363 base::WeakPtr<ChromotingJniInstance> ChromotingJniInstance::GetWeakPtr() { |
| 378 return weak_ptr_; | 364 return weak_ptr_; |
| 379 } | 365 } |
| 380 | 366 |
| 381 void ChromotingJniInstance::ConnectToHostOnNetworkThread() { | 367 void ChromotingJniInstance::ConnectToHostOnNetworkThread() { |
| 382 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); | 368 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 383 | 369 |
| 384 jni_runtime_->logger()->SetHostInfo( | |
| 385 host_version_, ChromotingEvent::ParseOsFromString(host_os_), | |
| 386 host_os_version_); | |
| 387 | |
| 388 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); | 370 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); |
| 389 | 371 |
| 390 client_context_.reset(new ClientContext(jni_runtime_->network_task_runner())); | 372 client_context_.reset(new ClientContext(jni_runtime_->network_task_runner())); |
| 391 client_context_->Start(); | 373 client_context_->Start(); |
| 392 | 374 |
| 393 perf_tracker_.reset(new protocol::PerformanceTracker()); | 375 perf_tracker_.reset(new protocol::PerformanceTracker()); |
| 394 | 376 |
| 395 video_renderer_->Initialize(*client_context_, | 377 video_renderer_->Initialize(*client_context_, |
| 396 perf_tracker_.get()); | 378 perf_tracker_.get()); |
| 397 | 379 |
| 398 if (!audio_player_) { | 380 if (!audio_player_) { |
| 399 audio_player_.reset(new AudioPlayerAndroid()); | 381 audio_player_.reset(new AudioPlayerAndroid()); |
| 400 } | 382 } |
| 401 | 383 |
| 384 logger_.reset(new ClientTelemetryLogger(jni_runtime_->log_writer(), | |
| 385 ChromotingEvent::Mode::ME2ME)); | |
| 386 logger_->SetHostInfo( | |
| 387 connection_info_.host_version, | |
| 388 ChromotingEvent::ParseOsFromString(connection_info_.host_os), | |
| 389 connection_info_.host_os_version); | |
| 390 | |
| 402 client_.reset(new ChromotingClient(client_context_.get(), this, | 391 client_.reset(new ChromotingClient(client_context_.get(), this, |
| 403 video_renderer_.get(), | 392 video_renderer_.get(), |
| 404 audio_player_->GetWeakPtr())); | 393 audio_player_->GetWeakPtr())); |
| 405 | 394 |
| 406 signaling_.reset( | 395 signaling_.reset( |
| 407 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), | 396 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), |
| 408 jni_runtime_->url_requester(), xmpp_config_)); | 397 jni_runtime_->url_requester(), xmpp_config_)); |
| 409 | 398 |
| 410 scoped_refptr<protocol::TransportContext> transport_context = | 399 scoped_refptr<protocol::TransportContext> transport_context = |
| 411 new protocol::TransportContext( | 400 new protocol::TransportContext( |
| 412 signaling_.get(), | 401 signaling_.get(), |
| 413 base::MakeUnique<protocol::ChromiumPortAllocatorFactory>(), | 402 base::MakeUnique<protocol::ChromiumPortAllocatorFactory>(), |
| 414 base::MakeUnique<ChromiumUrlRequestFactory>( | 403 base::MakeUnique<ChromiumUrlRequestFactory>( |
| 415 jni_runtime_->url_requester()), | 404 jni_runtime_->url_requester()), |
| 416 protocol::NetworkSettings( | 405 protocol::NetworkSettings( |
| 417 protocol::NetworkSettings::NAT_TRAVERSAL_FULL), | 406 protocol::NetworkSettings::NAT_TRAVERSAL_FULL), |
| 418 protocol::TransportRole::CLIENT); | 407 protocol::TransportRole::CLIENT); |
| 419 | 408 |
| 420 #if defined(ENABLE_WEBRTC_REMOTING_CLIENT) | 409 #if defined(ENABLE_WEBRTC_REMOTING_CLIENT) |
| 421 if (flags_.find("useWebrtc") != std::string::npos) { | 410 if (connection_info_.flags.find("useWebrtc") != std::string::npos) { |
| 422 VLOG(0) << "Attempting to connect using WebRTC."; | 411 VLOG(0) << "Attempting to connect using WebRTC."; |
| 423 std::unique_ptr<protocol::CandidateSessionConfig> protocol_config = | 412 std::unique_ptr<protocol::CandidateSessionConfig> protocol_config = |
| 424 protocol::CandidateSessionConfig::CreateEmpty(); | 413 protocol::CandidateSessionConfig::CreateEmpty(); |
| 425 protocol_config->set_webrtc_supported(true); | 414 protocol_config->set_webrtc_supported(true); |
| 426 protocol_config->set_ice_supported(false); | 415 protocol_config->set_ice_supported(false); |
| 427 client_->set_protocol_config(std::move(protocol_config)); | 416 client_->set_protocol_config(std::move(protocol_config)); |
| 428 } | 417 } |
| 429 #endif // defined(ENABLE_WEBRTC_REMOTING_CLIENT) | 418 #endif // defined(ENABLE_WEBRTC_REMOTING_CLIENT) |
| 430 client_->Start(signaling_.get(), client_auth_config_, transport_context, | 419 client_->Start(signaling_.get(), client_auth_config_, transport_context, |
| 431 host_jid_, capabilities_); | 420 connection_info_.host_jid, capabilities_); |
| 432 } | 421 } |
| 433 | 422 |
| 434 void ChromotingJniInstance::SetDeviceName(const std::string& device_name) { | 423 void ChromotingJniInstance::SetDeviceName(const std::string& device_name) { |
| 435 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { | 424 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { |
| 436 jni_runtime_->network_task_runner()->PostTask( | 425 jni_runtime_->network_task_runner()->PostTask( |
| 437 FROM_HERE, base::Bind(&ChromotingJniInstance::SetDeviceName, | 426 FROM_HERE, base::Bind(&ChromotingJniInstance::SetDeviceName, |
| 438 GetWeakPtr(), device_name)); | 427 GetWeakPtr(), device_name)); |
| 439 return; | 428 return; |
| 440 } | 429 } |
| 441 | 430 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 485 perf_tracker_->video_capture_ms().Max(), | 474 perf_tracker_->video_capture_ms().Max(), |
| 486 perf_tracker_->video_encode_ms().Average(), | 475 perf_tracker_->video_encode_ms().Average(), |
| 487 perf_tracker_->video_encode_ms().Max(), | 476 perf_tracker_->video_encode_ms().Max(), |
| 488 perf_tracker_->video_decode_ms().Average(), | 477 perf_tracker_->video_decode_ms().Average(), |
| 489 perf_tracker_->video_decode_ms().Max(), | 478 perf_tracker_->video_decode_ms().Max(), |
| 490 perf_tracker_->video_paint_ms().Average(), | 479 perf_tracker_->video_paint_ms().Average(), |
| 491 perf_tracker_->video_paint_ms().Max(), | 480 perf_tracker_->video_paint_ms().Max(), |
| 492 perf_tracker_->round_trip_ms().Average(), | 481 perf_tracker_->round_trip_ms().Average(), |
| 493 perf_tracker_->round_trip_ms().Max()); | 482 perf_tracker_->round_trip_ms().Max()); |
| 494 | 483 |
| 495 jni_runtime_->logger()->LogStatistics(perf_tracker_.get()); | 484 logger_->LogStatistics(perf_tracker_.get()); |
| 496 | 485 |
| 497 jni_runtime_->network_task_runner()->PostDelayedTask( | 486 jni_runtime_->network_task_runner()->PostDelayedTask( |
| 498 FROM_HERE, base::Bind(&ChromotingJniInstance::LogPerfStats, GetWeakPtr()), | 487 FROM_HERE, base::Bind(&ChromotingJniInstance::LogPerfStats, GetWeakPtr()), |
| 499 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); | 488 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); |
| 500 } | 489 } |
| 501 | 490 |
| 502 void ChromotingJniInstance::ReleaseResources() { | 491 void ChromotingJniInstance::ReleaseResources() { |
| 503 // |client_| must be torn down before |signaling_|. | 492 // |client_| must be torn down before |signaling_|. |
|
Sergey Ulanov
2017/01/19 00:50:38
best to keep this comment before client_.reset() c
Yuwei
2017/01/19 23:00:00
Done.
| |
| 493 logger_.reset(); | |
| 504 client_.reset(); | 494 client_.reset(); |
| 505 audio_player_.reset(); | 495 audio_player_.reset(); |
| 506 video_renderer_.reset(); | 496 video_renderer_.reset(); |
| 507 signaling_.reset(); | 497 signaling_.reset(); |
| 508 perf_tracker_.reset(); | 498 perf_tracker_.reset(); |
| 509 client_context_.reset(); | 499 client_context_.reset(); |
| 510 cursor_shape_stub_.reset(); | 500 cursor_shape_stub_.reset(); |
| 511 | 501 |
| 512 weak_factory_.InvalidateWeakPtrs(); | 502 weak_factory_.InvalidateWeakPtrs(); |
| 513 } | 503 } |
| 514 | 504 |
| 515 } // namespace remoting | 505 } // namespace remoting |
| OLD | NEW |