| 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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback_helpers.h" | 13 #include "base/callback_helpers.h" |
| 14 #include "base/format_macros.h" | 14 #include "base/format_macros.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "jingle/glue/thread_wrapper.h" | 17 #include "jingle/glue/thread_wrapper.h" |
| 18 #include "net/socket/client_socket_factory.h" | 18 #include "net/socket/client_socket_factory.h" |
| 19 #include "remoting/base/chromium_url_request.h" | 19 #include "remoting/base/chromium_url_request.h" |
| 20 #include "remoting/client/audio_player_android.h" | 20 #include "remoting/client/audio_player_android.h" |
| 21 #include "remoting/client/client_telemetry_logger.h" | 21 #include "remoting/client/client_telemetry_logger.h" |
| 22 #include "remoting/client/jni/android_keymap.h" | 22 #include "remoting/client/jni/android_keymap.h" |
| 23 #include "remoting/client/jni/chromoting_jni_runtime.h" | 23 #include "remoting/client/jni/chromoting_jni_runtime.h" |
| 24 #include "remoting/client/jni/jni_client.h" |
| 24 #include "remoting/client/jni/jni_frame_consumer.h" | 25 #include "remoting/client/jni/jni_frame_consumer.h" |
| 25 #include "remoting/client/software_video_renderer.h" | 26 #include "remoting/client/software_video_renderer.h" |
| 26 #include "remoting/protocol/chromium_port_allocator_factory.h" | 27 #include "remoting/protocol/chromium_port_allocator_factory.h" |
| 27 #include "remoting/protocol/chromium_socket_factory.h" | 28 #include "remoting/protocol/chromium_socket_factory.h" |
| 28 #include "remoting/protocol/client_authentication_config.h" | 29 #include "remoting/protocol/client_authentication_config.h" |
| 29 #include "remoting/protocol/host_stub.h" | 30 #include "remoting/protocol/host_stub.h" |
| 30 #include "remoting/protocol/network_settings.h" | 31 #include "remoting/protocol/network_settings.h" |
| 31 #include "remoting/protocol/performance_tracker.h" | 32 #include "remoting/protocol/performance_tracker.h" |
| 32 #include "remoting/protocol/transport_context.h" | 33 #include "remoting/protocol/transport_context.h" |
| 33 #include "remoting/signaling/server_log_entry.h" | 34 #include "remoting/signaling/server_log_entry.h" |
| 34 #include "ui/events/keycodes/dom/keycode_converter.h" | 35 #include "ui/events/keycodes/dom/keycode_converter.h" |
| 35 | 36 |
| 36 namespace remoting { | 37 namespace remoting { |
| 37 | 38 |
| 38 namespace { | 39 namespace { |
| 39 | 40 |
| 40 // TODO(solb) Move into location shared with client plugin. | 41 // TODO(solb) Move into location shared with client plugin. |
| 41 const char* const kXmppServer = "talk.google.com"; | 42 const char* const kXmppServer = "talk.google.com"; |
| 42 const int kXmppPort = 5222; | 43 const int kXmppPort = 5222; |
| 43 const bool kXmppUseTls = true; | 44 const bool kXmppUseTls = true; |
| 44 | 45 |
| 45 // Interval at which to log performance statistics, if enabled. | 46 // Interval at which to log performance statistics, if enabled. |
| 46 const int kPerfStatsIntervalMs = 60000; | 47 const int kPerfStatsIntervalMs = 60000; |
| 47 | 48 |
| 48 } | 49 } |
| 49 | 50 |
| 50 ChromotingJniInstance::ChromotingJniInstance(ChromotingJniRuntime* jni_runtime, | 51 ChromotingJniInstance::ChromotingJniInstance(ChromotingJniRuntime* jni_runtime, |
| 52 JniClient* jni_client, |
| 51 const std::string& username, | 53 const std::string& username, |
| 52 const std::string& auth_token, | 54 const std::string& auth_token, |
| 53 const std::string& host_jid, | 55 const std::string& host_jid, |
| 54 const std::string& host_id, | 56 const std::string& host_id, |
| 55 const std::string& host_pubkey, | 57 const std::string& host_pubkey, |
| 56 const std::string& pairing_id, | 58 const std::string& pairing_id, |
| 57 const std::string& pairing_secret, | 59 const std::string& pairing_secret, |
| 58 const std::string& capabilities, | 60 const std::string& capabilities, |
| 59 const std::string& flags) | 61 const std::string& flags) |
| 60 : jni_runtime_(jni_runtime), | 62 : jni_runtime_(jni_runtime), |
| 63 jni_client_(jni_client), |
| 61 host_jid_(host_jid), | 64 host_jid_(host_jid), |
| 62 flags_(flags), | 65 flags_(flags), |
| 63 capabilities_(capabilities), | 66 capabilities_(capabilities), |
| 64 weak_factory_(this) { | 67 weak_factory_(this) { |
| 65 DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread()); | 68 DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread()); |
| 66 | 69 |
| 67 // Initialize XMPP config. | 70 // Initialize XMPP config. |
| 68 xmpp_config_.host = kXmppServer; | 71 xmpp_config_.host = kXmppServer; |
| 69 xmpp_config_.port = kXmppPort; | 72 xmpp_config_.port = kXmppPort; |
| 70 xmpp_config_.use_tls = kXmppUseTls; | 73 xmpp_config_.use_tls = kXmppUseTls; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 const protocol::ThirdPartyTokenFetchedCallback& token_fetched_callback) { | 143 const protocol::ThirdPartyTokenFetchedCallback& token_fetched_callback) { |
| 141 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); | 144 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 142 DCHECK(third_party_token_fetched_callback_.is_null()); | 145 DCHECK(third_party_token_fetched_callback_.is_null()); |
| 143 | 146 |
| 144 __android_log_print(ANDROID_LOG_INFO, | 147 __android_log_print(ANDROID_LOG_INFO, |
| 145 "ThirdPartyAuth", | 148 "ThirdPartyAuth", |
| 146 "Fetching Third Party Token from user."); | 149 "Fetching Third Party Token from user."); |
| 147 | 150 |
| 148 third_party_token_fetched_callback_ = token_fetched_callback; | 151 third_party_token_fetched_callback_ = token_fetched_callback; |
| 149 jni_runtime_->ui_task_runner()->PostTask( | 152 jni_runtime_->ui_task_runner()->PostTask( |
| 150 FROM_HERE, base::Bind(&ChromotingJniRuntime::FetchThirdPartyToken, | 153 FROM_HERE, base::Bind(&JniClient::FetchThirdPartyToken, |
| 151 base::Unretained(jni_runtime_), token_url, | 154 jni_client_->GetWeakPtr(), token_url, |
| 152 host_public_key, scope)); | 155 host_public_key, scope)); |
| 153 } | 156 } |
| 154 | 157 |
| 155 void ChromotingJniInstance::HandleOnThirdPartyTokenFetched( | 158 void ChromotingJniInstance::HandleOnThirdPartyTokenFetched( |
| 156 const std::string& token, | 159 const std::string& token, |
| 157 const std::string& shared_secret) { | 160 const std::string& shared_secret) { |
| 158 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); | 161 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 159 | 162 |
| 160 __android_log_print( | 163 __android_log_print( |
| 161 ANDROID_LOG_INFO, "ThirdPartyAuth", "Third Party Token Fetched."); | 164 ANDROID_LOG_INFO, "ThirdPartyAuth", "Third Party Token Fetched."); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 187 } | 190 } |
| 188 | 191 |
| 189 void ChromotingJniInstance::RedrawDesktop() { | 192 void ChromotingJniInstance::RedrawDesktop() { |
| 190 if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) { | 193 if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) { |
| 191 jni_runtime_->display_task_runner()->PostTask( | 194 jni_runtime_->display_task_runner()->PostTask( |
| 192 FROM_HERE, | 195 FROM_HERE, |
| 193 base::Bind(&ChromotingJniInstance::RedrawDesktop, this)); | 196 base::Bind(&ChromotingJniInstance::RedrawDesktop, this)); |
| 194 return; | 197 return; |
| 195 } | 198 } |
| 196 | 199 |
| 197 jni_runtime_->RedrawCanvas(); | 200 jni_client_->RedrawCanvas(); |
| 198 } | 201 } |
| 199 | 202 |
| 200 void ChromotingJniInstance::SendMouseEvent( | 203 void ChromotingJniInstance::SendMouseEvent( |
| 201 int x, int y, | 204 int x, int y, |
| 202 protocol::MouseEvent_MouseButton button, | 205 protocol::MouseEvent_MouseButton button, |
| 203 bool button_down) { | 206 bool button_down) { |
| 204 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { | 207 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { |
| 205 jni_runtime_->network_task_runner()->PostTask( | 208 jni_runtime_->network_task_runner()->PostTask( |
| 206 FROM_HERE, base::Bind(&ChromotingJniInstance::SendMouseEvent, | 209 FROM_HERE, base::Bind(&ChromotingJniInstance::SendMouseEvent, |
| 207 this, x, y, button, button_down)); | 210 this, x, y, button, button_down)); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 | 324 |
| 322 if (create_pairing_ && state == protocol::ConnectionToHost::CONNECTED) { | 325 if (create_pairing_ && state == protocol::ConnectionToHost::CONNECTED) { |
| 323 protocol::PairingRequest request; | 326 protocol::PairingRequest request; |
| 324 DCHECK(!device_name_.empty()); | 327 DCHECK(!device_name_.empty()); |
| 325 request.set_client_name(device_name_); | 328 request.set_client_name(device_name_); |
| 326 client_->host_stub()->RequestPairing(request); | 329 client_->host_stub()->RequestPairing(request); |
| 327 } | 330 } |
| 328 | 331 |
| 329 jni_runtime_->ui_task_runner()->PostTask( | 332 jni_runtime_->ui_task_runner()->PostTask( |
| 330 FROM_HERE, | 333 FROM_HERE, |
| 331 base::Bind(&ChromotingJniRuntime::OnConnectionState, | 334 base::Bind(&JniClient::OnConnectionState, |
| 332 base::Unretained(jni_runtime_), | 335 jni_client_->GetWeakPtr(), |
| 333 state, | 336 state, |
| 334 error)); | 337 error)); |
| 335 } | 338 } |
| 336 | 339 |
| 337 void ChromotingJniInstance::OnConnectionReady(bool ready) { | 340 void ChromotingJniInstance::OnConnectionReady(bool ready) { |
| 338 // We ignore this message, since OnConnectionState tells us the same thing. | 341 // We ignore this message, since OnConnectionState tells us the same thing. |
| 339 } | 342 } |
| 340 | 343 |
| 341 void ChromotingJniInstance::OnRouteChanged( | 344 void ChromotingJniInstance::OnRouteChanged( |
| 342 const std::string& channel_name, | 345 const std::string& channel_name, |
| 343 const protocol::TransportRoute& route) { | 346 const protocol::TransportRoute& route) { |
| 344 std::string message = "Channel " + channel_name + " using " + | 347 std::string message = "Channel " + channel_name + " using " + |
| 345 protocol::TransportRoute::GetTypeString(route.type) + " connection."; | 348 protocol::TransportRoute::GetTypeString(route.type) + " connection."; |
| 346 __android_log_print(ANDROID_LOG_INFO, "route", "%s", message.c_str()); | 349 __android_log_print(ANDROID_LOG_INFO, "route", "%s", message.c_str()); |
| 347 } | 350 } |
| 348 | 351 |
| 349 void ChromotingJniInstance::SetCapabilities(const std::string& capabilities) { | 352 void ChromotingJniInstance::SetCapabilities(const std::string& capabilities) { |
| 350 jni_runtime_->ui_task_runner()->PostTask( | 353 jni_runtime_->ui_task_runner()->PostTask( |
| 351 FROM_HERE, base::Bind(&ChromotingJniRuntime::SetCapabilities, | 354 FROM_HERE, base::Bind(&JniClient::SetCapabilities, |
| 352 base::Unretained(jni_runtime_), capabilities)); | 355 jni_client_->GetWeakPtr(), capabilities)); |
| 353 } | 356 } |
| 354 | 357 |
| 355 void ChromotingJniInstance::SetPairingResponse( | 358 void ChromotingJniInstance::SetPairingResponse( |
| 356 const protocol::PairingResponse& response) { | 359 const protocol::PairingResponse& response) { |
| 357 jni_runtime_->ui_task_runner()->PostTask( | 360 jni_runtime_->ui_task_runner()->PostTask( |
| 358 FROM_HERE, | 361 FROM_HERE, |
| 359 base::Bind(&ChromotingJniRuntime::CommitPairingCredentials, | 362 base::Bind(&JniClient::CommitPairingCredentials, |
| 360 base::Unretained(jni_runtime_), client_auth_config_.host_id, | 363 jni_client_->GetWeakPtr(), client_auth_config_.host_id, |
| 361 response.client_id(), response.shared_secret())); | 364 response.client_id(), response.shared_secret())); |
| 362 } | 365 } |
| 363 | 366 |
| 364 void ChromotingJniInstance::DeliverHostMessage( | 367 void ChromotingJniInstance::DeliverHostMessage( |
| 365 const protocol::ExtensionMessage& message) { | 368 const protocol::ExtensionMessage& message) { |
| 366 jni_runtime_->ui_task_runner()->PostTask( | 369 jni_runtime_->ui_task_runner()->PostTask( |
| 367 FROM_HERE, base::Bind(&ChromotingJniRuntime::HandleExtensionMessage, | 370 FROM_HERE, base::Bind(&JniClient::HandleExtensionMessage, |
| 368 base::Unretained(jni_runtime_), message.type(), | 371 jni_client_->GetWeakPtr(), message.type(), |
| 369 message.data())); | 372 message.data())); |
| 370 } | 373 } |
| 371 | 374 |
| 372 void ChromotingJniInstance::SetDesktopSize(const webrtc::DesktopSize& size, | 375 void ChromotingJniInstance::SetDesktopSize(const webrtc::DesktopSize& size, |
| 373 const webrtc::DesktopVector& dpi) { | 376 const webrtc::DesktopVector& dpi) { |
| 374 // JniFrameConsumer get size from the frames and it doesn't use DPI, so this | 377 // JniFrameConsumer get size from the frames and it doesn't use DPI, so this |
| 375 // call can be ignored. | 378 // call can be ignored. |
| 376 } | 379 } |
| 377 | 380 |
| 378 protocol::ClipboardStub* ChromotingJniInstance::GetClipboardStub() { | 381 protocol::ClipboardStub* ChromotingJniInstance::GetClipboardStub() { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 390 | 393 |
| 391 void ChromotingJniInstance::SetCursorShape( | 394 void ChromotingJniInstance::SetCursorShape( |
| 392 const protocol::CursorShapeInfo& shape) { | 395 const protocol::CursorShapeInfo& shape) { |
| 393 if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) { | 396 if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) { |
| 394 jni_runtime_->display_task_runner()->PostTask( | 397 jni_runtime_->display_task_runner()->PostTask( |
| 395 FROM_HERE, | 398 FROM_HERE, |
| 396 base::Bind(&ChromotingJniInstance::SetCursorShape, this, shape)); | 399 base::Bind(&ChromotingJniInstance::SetCursorShape, this, shape)); |
| 397 return; | 400 return; |
| 398 } | 401 } |
| 399 | 402 |
| 400 jni_runtime_->UpdateCursorShape(shape); | 403 jni_client_->UpdateCursorShape(shape); |
| 401 } | 404 } |
| 402 | 405 |
| 403 void ChromotingJniInstance::ConnectToHostOnNetworkThread() { | 406 void ChromotingJniInstance::ConnectToHostOnNetworkThread() { |
| 404 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); | 407 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 405 | 408 |
| 406 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); | 409 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); |
| 407 | 410 |
| 408 client_context_.reset(new ClientContext(jni_runtime_->network_task_runner())); | 411 client_context_.reset(new ClientContext(jni_runtime_->network_task_runner())); |
| 409 client_context_->Start(); | 412 client_context_->Start(); |
| 410 | 413 |
| 411 perf_tracker_.reset(new protocol::PerformanceTracker()); | 414 perf_tracker_.reset(new protocol::PerformanceTracker()); |
| 412 | 415 |
| 413 view_.reset(new JniFrameConsumer(jni_runtime_)); | 416 view_.reset(new JniFrameConsumer(jni_runtime_, jni_client_)); |
| 414 video_renderer_.reset(new SoftwareVideoRenderer( | 417 video_renderer_.reset(new SoftwareVideoRenderer( |
| 415 client_context_->decode_task_runner(), view_.get(), perf_tracker_.get())); | 418 client_context_->decode_task_runner(), view_.get(), perf_tracker_.get())); |
| 416 | 419 |
| 417 client_.reset( | 420 client_.reset( |
| 418 new ChromotingClient(client_context_.get(), this, video_renderer_.get(), | 421 new ChromotingClient(client_context_.get(), this, video_renderer_.get(), |
| 419 base::WrapUnique(new AudioPlayerAndroid()))); | 422 base::WrapUnique(new AudioPlayerAndroid()))); |
| 420 | 423 |
| 421 signaling_.reset( | 424 signaling_.reset( |
| 422 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), | 425 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), |
| 423 jni_runtime_->url_requester(), xmpp_config_)); | 426 jni_runtime_->url_requester(), xmpp_config_)); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 450 bool pairable, | 453 bool pairable, |
| 451 const protocol::SecretFetchedCallback& callback) { | 454 const protocol::SecretFetchedCallback& callback) { |
| 452 if (!jni_runtime_->ui_task_runner()->BelongsToCurrentThread()) { | 455 if (!jni_runtime_->ui_task_runner()->BelongsToCurrentThread()) { |
| 453 jni_runtime_->ui_task_runner()->PostTask( | 456 jni_runtime_->ui_task_runner()->PostTask( |
| 454 FROM_HERE, base::Bind(&ChromotingJniInstance::FetchSecret, | 457 FROM_HERE, base::Bind(&ChromotingJniInstance::FetchSecret, |
| 455 this, pairable, callback)); | 458 this, pairable, callback)); |
| 456 return; | 459 return; |
| 457 } | 460 } |
| 458 | 461 |
| 459 // Delete pairing credentials if they exist. | 462 // Delete pairing credentials if they exist. |
| 460 jni_runtime_->CommitPairingCredentials(client_auth_config_.host_id, "", ""); | 463 jni_client_->CommitPairingCredentials(client_auth_config_.host_id, "", ""); |
| 461 | 464 |
| 462 pin_callback_ = callback; | 465 pin_callback_ = callback; |
| 463 jni_runtime_->DisplayAuthenticationPrompt(pairable); | 466 jni_client_->DisplayAuthenticationPrompt(pairable); |
| 464 } | 467 } |
| 465 | 468 |
| 466 void ChromotingJniInstance::SetDeviceName(const std::string& device_name) { | 469 void ChromotingJniInstance::SetDeviceName(const std::string& device_name) { |
| 467 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { | 470 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { |
| 468 jni_runtime_->network_task_runner()->PostTask( | 471 jni_runtime_->network_task_runner()->PostTask( |
| 469 FROM_HERE, base::Bind(&ChromotingJniInstance::SetDeviceName, this, | 472 FROM_HERE, base::Bind(&ChromotingJniInstance::SetDeviceName, this, |
| 470 device_name)); | 473 device_name)); |
| 471 return; | 474 return; |
| 472 } | 475 } |
| 473 | 476 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 perf_tracker_->round_trip_ms().Max()); | 527 perf_tracker_->round_trip_ms().Max()); |
| 525 | 528 |
| 526 jni_runtime_->logger()->LogStatistics(perf_tracker_.get()); | 529 jni_runtime_->logger()->LogStatistics(perf_tracker_.get()); |
| 527 | 530 |
| 528 jni_runtime_->network_task_runner()->PostDelayedTask( | 531 jni_runtime_->network_task_runner()->PostDelayedTask( |
| 529 FROM_HERE, base::Bind(&ChromotingJniInstance::LogPerfStats, this), | 532 FROM_HERE, base::Bind(&ChromotingJniInstance::LogPerfStats, this), |
| 530 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); | 533 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); |
| 531 } | 534 } |
| 532 | 535 |
| 533 } // namespace remoting | 536 } // namespace remoting |
| OLD | NEW |