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 <utility> | |
| 11 | |
| 12 #include "base/bind.h" | 10 #include "base/bind.h" |
| 13 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 14 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
| 15 #include "base/logging.h" | 13 #include "base/logging.h" |
| 16 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 17 #include "jingle/glue/thread_wrapper.h" | 15 #include "jingle/glue/thread_wrapper.h" |
| 18 #include "net/socket/client_socket_factory.h" | 16 #include "net/socket/client_socket_factory.h" |
| 19 #include "remoting/base/chromium_url_request.h" | 17 #include "remoting/base/chromium_url_request.h" |
| 20 #include "remoting/client/audio_player_android.h" | 18 #include "remoting/client/audio_player_android.h" |
| 21 #include "remoting/client/client_telemetry_logger.h" | 19 #include "remoting/client/client_telemetry_logger.h" |
| 22 #include "remoting/client/jni/android_keymap.h" | 20 #include "remoting/client/jni/android_keymap.h" |
| 23 #include "remoting/client/jni/chromoting_jni_runtime.h" | 21 #include "remoting/client/jni/chromoting_jni_runtime.h" |
| 24 #include "remoting/client/jni/jni_client.h" | 22 #include "remoting/client/jni/jni_client.h" |
| 23 #include "remoting/client/jni/jni_display_handler.h" | |
| 25 #include "remoting/client/jni/jni_frame_consumer.h" | 24 #include "remoting/client/jni/jni_frame_consumer.h" |
| 26 #include "remoting/client/software_video_renderer.h" | 25 #include "remoting/client/software_video_renderer.h" |
| 27 #include "remoting/protocol/chromium_port_allocator_factory.h" | 26 #include "remoting/protocol/chromium_port_allocator_factory.h" |
| 28 #include "remoting/protocol/chromium_socket_factory.h" | 27 #include "remoting/protocol/chromium_socket_factory.h" |
| 29 #include "remoting/protocol/client_authentication_config.h" | 28 #include "remoting/protocol/client_authentication_config.h" |
| 30 #include "remoting/protocol/host_stub.h" | 29 #include "remoting/protocol/host_stub.h" |
| 31 #include "remoting/protocol/network_settings.h" | 30 #include "remoting/protocol/network_settings.h" |
| 32 #include "remoting/protocol/performance_tracker.h" | 31 #include "remoting/protocol/performance_tracker.h" |
| 33 #include "remoting/protocol/transport_context.h" | 32 #include "remoting/protocol/transport_context.h" |
| 34 #include "remoting/signaling/server_log_entry.h" | 33 #include "remoting/signaling/server_log_entry.h" |
| 35 #include "ui/events/keycodes/dom/keycode_converter.h" | 34 #include "ui/events/keycodes/dom/keycode_converter.h" |
| 36 | 35 |
| 37 namespace remoting { | 36 namespace remoting { |
| 38 | 37 |
| 39 namespace { | 38 namespace { |
| 40 | 39 |
| 41 // TODO(solb) Move into location shared with client plugin. | 40 // TODO(solb) Move into location shared with client plugin. |
| 42 const char* const kXmppServer = "talk.google.com"; | 41 const char* const kXmppServer = "talk.google.com"; |
| 43 const int kXmppPort = 5222; | 42 const int kXmppPort = 5222; |
| 44 const bool kXmppUseTls = true; | 43 const bool kXmppUseTls = true; |
| 45 | 44 |
| 46 // Interval at which to log performance statistics, if enabled. | 45 // Interval at which to log performance statistics, if enabled. |
| 47 const int kPerfStatsIntervalMs = 60000; | 46 const int kPerfStatsIntervalMs = 60000; |
| 48 | 47 |
| 49 } | 48 } |
| 50 | 49 |
| 51 ChromotingJniInstance::ChromotingJniInstance(ChromotingJniRuntime* jni_runtime, | 50 ChromotingJniInstance::ChromotingJniInstance( |
| 52 JniClient* jni_client, | 51 ChromotingJniRuntime* jni_runtime, |
| 53 const std::string& username, | 52 base::WeakPtr<JniClient> jni_client, |
| 54 const std::string& auth_token, | 53 base::WeakPtr<JniDisplayHandler> display, |
| 55 const std::string& host_jid, | 54 base::WeakPtr<JniSecretFetcher> secret_fetcher, |
| 56 const std::string& host_id, | 55 const std::string& username, |
| 57 const std::string& host_pubkey, | 56 const std::string& auth_token, |
| 58 const std::string& pairing_id, | 57 const std::string& host_jid, |
| 59 const std::string& pairing_secret, | 58 const std::string& host_id, |
| 60 const std::string& capabilities, | 59 const std::string& host_pubkey, |
| 61 const std::string& flags) | 60 const std::string& pairing_id, |
| 61 const std::string& pairing_secret, | |
| 62 const std::string& capabilities, | |
| 63 const std::string& flags) | |
| 62 : jni_runtime_(jni_runtime), | 64 : jni_runtime_(jni_runtime), |
| 63 jni_client_(jni_client), | 65 jni_client_(jni_client), |
| 66 display_handler_(display), | |
| 67 secret_fetcher_(secret_fetcher), | |
| 64 host_jid_(host_jid), | 68 host_jid_(host_jid), |
| 65 flags_(flags), | 69 flags_(flags), |
| 66 capabilities_(capabilities), | 70 capabilities_(capabilities), |
| 67 weak_factory_(this) { | 71 weak_factory_(this) { |
| 68 DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread()); | 72 DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread()); |
| 69 | 73 |
| 70 // Initialize XMPP config. | 74 // Initialize XMPP config. |
| 71 xmpp_config_.host = kXmppServer; | 75 xmpp_config_.host = kXmppServer; |
| 72 xmpp_config_.port = kXmppPort; | 76 xmpp_config_.port = kXmppPort; |
| 73 xmpp_config_.use_tls = kXmppUseTls; | 77 xmpp_config_.use_tls = kXmppUseTls; |
| 74 xmpp_config_.username = username; | 78 xmpp_config_.username = username; |
| 75 xmpp_config_.auth_token = auth_token; | 79 xmpp_config_.auth_token = auth_token; |
| 76 | 80 |
| 77 client_auth_config_.host_id = host_id; | 81 client_auth_config_.host_id = host_id; |
| 78 client_auth_config_.pairing_client_id = pairing_id; | 82 client_auth_config_.pairing_client_id = pairing_id; |
| 79 client_auth_config_.pairing_secret = pairing_secret; | 83 client_auth_config_.pairing_secret = pairing_secret; |
| 80 client_auth_config_.fetch_secret_callback = base::Bind( | 84 client_auth_config_.fetch_secret_callback = |
| 81 &ChromotingJniInstance::FetchSecret, weak_factory_.GetWeakPtr()); | 85 base::Bind(&ChromotingJniInstance::FetchSecret, GetWeakPtr()); |
| 82 client_auth_config_.fetch_third_party_token_callback = | 86 client_auth_config_.fetch_third_party_token_callback = base::Bind( |
| 83 base::Bind(&ChromotingJniInstance::FetchThirdPartyToken, | 87 &ChromotingJniInstance::FetchThirdPartyToken, GetWeakPtr(), host_pubkey); |
| 84 weak_factory_.GetWeakPtr(), host_pubkey); | |
| 85 | 88 |
| 86 // Post a task to start connection | 89 // Post a task to start connection |
| 87 jni_runtime_->network_task_runner()->PostTask( | 90 jni_runtime_->network_task_runner()->PostTask( |
| 88 FROM_HERE, | 91 FROM_HERE, |
| 89 base::Bind(&ChromotingJniInstance::ConnectToHostOnNetworkThread, this)); | 92 base::Bind(&ChromotingJniInstance::ConnectToHostOnNetworkThread, |
| 93 GetWeakPtr())); | |
| 90 } | 94 } |
| 91 | 95 |
| 92 ChromotingJniInstance::~ChromotingJniInstance() { | 96 ChromotingJniInstance::~ChromotingJniInstance() { |
| 93 // This object is ref-counted, so this dtor can execute on any thread. | 97 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 94 // Ensure that all these objects have been freed already, so they are not | 98 if (client_) { |
| 95 // destroyed on some random thread. | 99 Destroy(); |
| 96 DCHECK(!view_); | 100 } |
| 97 DCHECK(!client_context_); | |
| 98 DCHECK(!video_renderer_); | |
| 99 DCHECK(!client_); | |
| 100 DCHECK(!signaling_); | |
| 101 } | 101 } |
| 102 | 102 |
| 103 void ChromotingJniInstance::Disconnect() { | 103 void ChromotingJniInstance::Disconnect() { |
| 104 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { | 104 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { |
| 105 jni_runtime_->network_task_runner()->PostTask( | 105 jni_runtime_->network_task_runner()->PostTask( |
| 106 FROM_HERE, | 106 FROM_HERE, |
| 107 base::Bind(&ChromotingJniInstance::Disconnect, this)); | 107 base::Bind(&ChromotingJniInstance::Disconnect, GetWeakPtr())); |
| 108 return; | 108 return; |
| 109 } | 109 } |
| 110 | 110 |
| 111 stats_logging_enabled_ = false; | 111 stats_logging_enabled_ = false; |
| 112 | 112 |
| 113 // User disconnection will not trigger OnConnectionState(Closed, OK). | 113 // User disconnection will not trigger OnConnectionState(Closed, OK). |
| 114 // Remote disconnection will trigger OnConnectionState(...) and later trigger | 114 // Remote disconnection will trigger OnConnectionState(...) and later trigger |
| 115 // Disconnect(). | 115 // Disconnect(). |
| 116 if (connected_) { | 116 if (connected_) { |
| 117 jni_runtime_->logger()->LogSessionStateChange( | 117 jni_runtime_->logger()->LogSessionStateChange( |
| 118 ChromotingEvent::SessionState::CLOSED, | 118 ChromotingEvent::SessionState::CLOSED, |
| 119 ChromotingEvent::ConnectionError::NONE); | 119 ChromotingEvent::ConnectionError::NONE); |
| 120 connected_ = false; | 120 connected_ = false; |
| 121 } | 121 } |
| 122 | 122 |
| 123 // |client_| must be torn down before |signaling_|. | 123 Destroy(); |
| 124 client_.reset(); | |
| 125 video_renderer_.reset(); | |
| 126 view_.reset(); | |
| 127 signaling_.reset(); | |
| 128 perf_tracker_.reset(); | |
| 129 client_context_.reset(); | |
| 130 | |
| 131 weak_factory_.InvalidateWeakPtrs(); | |
| 132 } | 124 } |
| 133 | 125 |
| 134 void ChromotingJniInstance::FetchThirdPartyToken( | 126 void ChromotingJniInstance::FetchThirdPartyToken( |
| 135 const std::string& host_public_key, | 127 const std::string& host_public_key, |
| 136 const std::string& token_url, | 128 const std::string& token_url, |
| 137 const std::string& scope, | 129 const std::string& scope, |
| 138 const protocol::ThirdPartyTokenFetchedCallback& token_fetched_callback) { | 130 const protocol::ThirdPartyTokenFetchedCallback& token_fetched_callback) { |
| 139 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); | 131 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 140 DCHECK(third_party_token_fetched_callback_.is_null()); | 132 DCHECK(third_party_token_fetched_callback_.is_null()); |
| 141 | 133 |
| 142 __android_log_print(ANDROID_LOG_INFO, | 134 __android_log_print(ANDROID_LOG_INFO, |
| 143 "ThirdPartyAuth", | 135 "ThirdPartyAuth", |
| 144 "Fetching Third Party Token from user."); | 136 "Fetching Third Party Token from user."); |
| 145 | 137 |
| 146 third_party_token_fetched_callback_ = token_fetched_callback; | 138 third_party_token_fetched_callback_ = token_fetched_callback; |
| 147 jni_runtime_->ui_task_runner()->PostTask( | 139 jni_runtime_->ui_task_runner()->PostTask( |
| 148 FROM_HERE, base::Bind(&JniClient::FetchThirdPartyToken, | 140 FROM_HERE, base::Bind(&JniClient::FetchThirdPartyToken, jni_client_, |
| 149 jni_client_->GetWeakPtr(), token_url, | 141 token_url, host_public_key, scope)); |
| 150 host_public_key, scope)); | |
| 151 } | 142 } |
| 152 | 143 |
| 153 void ChromotingJniInstance::HandleOnThirdPartyTokenFetched( | 144 void ChromotingJniInstance::HandleOnThirdPartyTokenFetched( |
| 154 const std::string& token, | 145 const std::string& token, |
| 155 const std::string& shared_secret) { | 146 const std::string& shared_secret) { |
| 156 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); | 147 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 157 | 148 |
| 158 __android_log_print( | 149 __android_log_print( |
| 159 ANDROID_LOG_INFO, "ThirdPartyAuth", "Third Party Token Fetched."); | 150 ANDROID_LOG_INFO, "ThirdPartyAuth", "Third Party Token Fetched."); |
| 160 | 151 |
| 161 if (!third_party_token_fetched_callback_.is_null()) { | 152 if (!third_party_token_fetched_callback_.is_null()) { |
| 162 base::ResetAndReturn(&third_party_token_fetched_callback_) | 153 base::ResetAndReturn(&third_party_token_fetched_callback_) |
| 163 .Run(token, shared_secret); | 154 .Run(token, shared_secret); |
| 164 } else { | 155 } else { |
| 165 __android_log_print( | 156 __android_log_print( |
| 166 ANDROID_LOG_WARN, | 157 ANDROID_LOG_WARN, |
| 167 "ThirdPartyAuth", | 158 "ThirdPartyAuth", |
| 168 "Ignored OnThirdPartyTokenFetched() without a pending fetch."); | 159 "Ignored OnThirdPartyTokenFetched() without a pending fetch."); |
| 169 } | 160 } |
| 170 } | 161 } |
| 171 | 162 |
| 172 void ChromotingJniInstance::ProvideSecret(const std::string& pin, | 163 void ChromotingJniInstance::ProvideSecret(const std::string& pin, |
| 173 bool create_pairing, | 164 bool create_pairing, |
| 174 const std::string& device_name) { | 165 const std::string& device_name) { |
| 175 DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread()); | 166 DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread()); |
| 176 DCHECK(!pin_callback_.is_null()); | 167 |
| 168 if (!secret_fetcher_) { | |
| 169 return; | |
| 170 } | |
| 177 | 171 |
| 178 create_pairing_ = create_pairing; | 172 create_pairing_ = create_pairing; |
| 179 | 173 |
| 180 if (create_pairing) | 174 if (create_pairing) |
| 181 SetDeviceName(device_name); | 175 SetDeviceName(device_name); |
| 182 | 176 |
| 183 jni_runtime_->network_task_runner()->PostTask(FROM_HERE, | 177 secret_fetcher_->ProvideSecret(pin); |
| 184 base::Bind(pin_callback_, pin)); | |
| 185 } | |
| 186 | |
| 187 void ChromotingJniInstance::RedrawDesktop() { | |
| 188 if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) { | |
| 189 jni_runtime_->display_task_runner()->PostTask( | |
| 190 FROM_HERE, | |
| 191 base::Bind(&ChromotingJniInstance::RedrawDesktop, this)); | |
| 192 return; | |
| 193 } | |
| 194 | |
| 195 jni_client_->RedrawCanvas(); | |
| 196 } | 178 } |
| 197 | 179 |
| 198 void ChromotingJniInstance::SendMouseEvent( | 180 void ChromotingJniInstance::SendMouseEvent( |
| 199 int x, int y, | 181 int x, int y, |
| 200 protocol::MouseEvent_MouseButton button, | 182 protocol::MouseEvent_MouseButton button, |
| 201 bool button_down) { | 183 bool button_down) { |
| 202 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { | 184 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { |
| 203 jni_runtime_->network_task_runner()->PostTask( | 185 jni_runtime_->network_task_runner()->PostTask( |
| 204 FROM_HERE, base::Bind(&ChromotingJniInstance::SendMouseEvent, | 186 FROM_HERE, base::Bind(&ChromotingJniInstance::SendMouseEvent, |
| 205 this, x, y, button, button_down)); | 187 GetWeakPtr(), x, y, button, button_down)); |
| 206 return; | 188 return; |
| 207 } | 189 } |
| 208 | 190 |
| 209 protocol::MouseEvent event; | 191 protocol::MouseEvent event; |
| 210 event.set_x(x); | 192 event.set_x(x); |
| 211 event.set_y(y); | 193 event.set_y(y); |
| 212 event.set_button(button); | 194 event.set_button(button); |
| 213 if (button != protocol::MouseEvent::BUTTON_UNDEFINED) | 195 if (button != protocol::MouseEvent::BUTTON_UNDEFINED) |
| 214 event.set_button_down(button_down); | 196 event.set_button_down(button_down); |
| 215 | 197 |
| 216 client_->input_stub()->InjectMouseEvent(event); | 198 client_->input_stub()->InjectMouseEvent(event); |
| 217 } | 199 } |
| 218 | 200 |
| 219 void ChromotingJniInstance::SendMouseWheelEvent(int delta_x, int delta_y) { | 201 void ChromotingJniInstance::SendMouseWheelEvent(int delta_x, int delta_y) { |
| 220 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { | 202 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { |
| 221 jni_runtime_->network_task_runner()->PostTask( | 203 jni_runtime_->network_task_runner()->PostTask( |
| 222 FROM_HERE, | 204 FROM_HERE, base::Bind(&ChromotingJniInstance::SendMouseWheelEvent, |
| 223 base::Bind(&ChromotingJniInstance::SendMouseWheelEvent, this, | 205 GetWeakPtr(), delta_x, delta_y)); |
| 224 delta_x, delta_y)); | |
| 225 return; | 206 return; |
| 226 } | 207 } |
| 227 | 208 |
| 228 protocol::MouseEvent event; | 209 protocol::MouseEvent event; |
| 229 event.set_wheel_delta_x(delta_x); | 210 event.set_wheel_delta_x(delta_x); |
| 230 event.set_wheel_delta_y(delta_y); | 211 event.set_wheel_delta_y(delta_y); |
| 231 client_->input_stub()->InjectMouseEvent(event); | 212 client_->input_stub()->InjectMouseEvent(event); |
| 232 } | 213 } |
| 233 | 214 |
| 234 bool ChromotingJniInstance::SendKeyEvent(int scan_code, | 215 bool ChromotingJniInstance::SendKeyEvent(int scan_code, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 246 } | 227 } |
| 247 | 228 |
| 248 SendKeyEventInternal(usb_key_code, key_down); | 229 SendKeyEventInternal(usb_key_code, key_down); |
| 249 return true; | 230 return true; |
| 250 } | 231 } |
| 251 | 232 |
| 252 void ChromotingJniInstance::SendTextEvent(const std::string& text) { | 233 void ChromotingJniInstance::SendTextEvent(const std::string& text) { |
| 253 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { | 234 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { |
| 254 jni_runtime_->network_task_runner()->PostTask( | 235 jni_runtime_->network_task_runner()->PostTask( |
| 255 FROM_HERE, | 236 FROM_HERE, |
| 256 base::Bind(&ChromotingJniInstance::SendTextEvent, this, text)); | 237 base::Bind(&ChromotingJniInstance::SendTextEvent, GetWeakPtr(), text)); |
| 257 return; | 238 return; |
| 258 } | 239 } |
| 259 | 240 |
| 260 protocol::TextEvent event; | 241 protocol::TextEvent event; |
| 261 event.set_text(text); | 242 event.set_text(text); |
| 262 client_->input_stub()->InjectTextEvent(event); | 243 client_->input_stub()->InjectTextEvent(event); |
| 263 } | 244 } |
| 264 | 245 |
| 265 void ChromotingJniInstance::SendTouchEvent( | 246 void ChromotingJniInstance::SendTouchEvent( |
| 266 const protocol::TouchEvent& touch_event) { | 247 const protocol::TouchEvent& touch_event) { |
| 267 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { | 248 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { |
| 268 jni_runtime_->network_task_runner()->PostTask( | 249 jni_runtime_->network_task_runner()->PostTask( |
| 269 FROM_HERE, | 250 FROM_HERE, base::Bind(&ChromotingJniInstance::SendTouchEvent, |
| 270 base::Bind(&ChromotingJniInstance::SendTouchEvent, this, touch_event)); | 251 GetWeakPtr(), touch_event)); |
| 271 return; | 252 return; |
| 272 } | 253 } |
| 273 | 254 |
| 274 client_->input_stub()->InjectTouchEvent(touch_event); | 255 client_->input_stub()->InjectTouchEvent(touch_event); |
| 275 } | 256 } |
| 276 | 257 |
| 277 void ChromotingJniInstance::EnableVideoChannel(bool enable) { | 258 void ChromotingJniInstance::EnableVideoChannel(bool enable) { |
| 278 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { | 259 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { |
| 279 jni_runtime_->network_task_runner()->PostTask( | 260 jni_runtime_->network_task_runner()->PostTask( |
| 280 FROM_HERE, | 261 FROM_HERE, base::Bind(&ChromotingJniInstance::EnableVideoChannel, |
| 281 base::Bind(&ChromotingJniInstance::EnableVideoChannel, this, enable)); | 262 GetWeakPtr(), enable)); |
| 282 return; | 263 return; |
| 283 } | 264 } |
| 284 | 265 |
| 285 protocol::VideoControl video_control; | 266 protocol::VideoControl video_control; |
| 286 video_control.set_enable(enable); | 267 video_control.set_enable(enable); |
| 287 client_->host_stub()->ControlVideo(video_control); | 268 client_->host_stub()->ControlVideo(video_control); |
| 288 } | 269 } |
| 289 | 270 |
| 290 void ChromotingJniInstance::SendClientMessage(const std::string& type, | 271 void ChromotingJniInstance::SendClientMessage(const std::string& type, |
| 291 const std::string& data) { | 272 const std::string& data) { |
| 292 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { | 273 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { |
| 293 jni_runtime_->network_task_runner()->PostTask( | 274 jni_runtime_->network_task_runner()->PostTask( |
| 294 FROM_HERE, | 275 FROM_HERE, base::Bind(&ChromotingJniInstance::SendClientMessage, |
| 295 base::Bind( | 276 GetWeakPtr(), type, data)); |
| 296 &ChromotingJniInstance::SendClientMessage, this, type, data)); | |
| 297 return; | 277 return; |
| 298 } | 278 } |
| 299 | 279 |
| 300 protocol::ExtensionMessage extension_message; | 280 protocol::ExtensionMessage extension_message; |
| 301 extension_message.set_type(type); | 281 extension_message.set_type(type); |
| 302 extension_message.set_data(data); | 282 extension_message.set_data(data); |
| 303 client_->host_stub()->DeliverClientMessage(extension_message); | 283 client_->host_stub()->DeliverClientMessage(extension_message); |
| 304 } | 284 } |
| 305 | 285 |
| 306 void ChromotingJniInstance::OnConnectionState( | 286 void ChromotingJniInstance::OnConnectionState( |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 319 | 299 |
| 320 if (create_pairing_ && state == protocol::ConnectionToHost::CONNECTED) { | 300 if (create_pairing_ && state == protocol::ConnectionToHost::CONNECTED) { |
| 321 protocol::PairingRequest request; | 301 protocol::PairingRequest request; |
| 322 DCHECK(!device_name_.empty()); | 302 DCHECK(!device_name_.empty()); |
| 323 request.set_client_name(device_name_); | 303 request.set_client_name(device_name_); |
| 324 client_->host_stub()->RequestPairing(request); | 304 client_->host_stub()->RequestPairing(request); |
| 325 } | 305 } |
| 326 | 306 |
| 327 jni_runtime_->ui_task_runner()->PostTask( | 307 jni_runtime_->ui_task_runner()->PostTask( |
| 328 FROM_HERE, | 308 FROM_HERE, |
| 329 base::Bind(&JniClient::OnConnectionState, | 309 base::Bind(&JniClient::OnConnectionState, jni_client_, state, error)); |
| 330 jni_client_->GetWeakPtr(), | |
| 331 state, | |
| 332 error)); | |
| 333 } | 310 } |
| 334 | 311 |
| 335 void ChromotingJniInstance::OnConnectionReady(bool ready) { | 312 void ChromotingJniInstance::OnConnectionReady(bool ready) { |
| 336 // We ignore this message, since OnConnectionState tells us the same thing. | 313 // We ignore this message, since OnConnectionState tells us the same thing. |
| 337 } | 314 } |
| 338 | 315 |
| 339 void ChromotingJniInstance::OnRouteChanged( | 316 void ChromotingJniInstance::OnRouteChanged( |
| 340 const std::string& channel_name, | 317 const std::string& channel_name, |
| 341 const protocol::TransportRoute& route) { | 318 const protocol::TransportRoute& route) { |
| 342 std::string message = "Channel " + channel_name + " using " + | 319 std::string message = "Channel " + channel_name + " using " + |
| 343 protocol::TransportRoute::GetTypeString(route.type) + " connection."; | 320 protocol::TransportRoute::GetTypeString(route.type) + " connection."; |
| 344 __android_log_print(ANDROID_LOG_INFO, "route", "%s", message.c_str()); | 321 __android_log_print(ANDROID_LOG_INFO, "route", "%s", message.c_str()); |
| 345 } | 322 } |
| 346 | 323 |
| 347 void ChromotingJniInstance::SetCapabilities(const std::string& capabilities) { | 324 void ChromotingJniInstance::SetCapabilities(const std::string& capabilities) { |
| 348 jni_runtime_->ui_task_runner()->PostTask( | 325 jni_runtime_->ui_task_runner()->PostTask( |
| 349 FROM_HERE, base::Bind(&JniClient::SetCapabilities, | 326 FROM_HERE, |
| 350 jni_client_->GetWeakPtr(), capabilities)); | 327 base::Bind(&JniClient::SetCapabilities, jni_client_, capabilities)); |
| 351 } | 328 } |
| 352 | 329 |
| 353 void ChromotingJniInstance::SetPairingResponse( | 330 void ChromotingJniInstance::SetPairingResponse( |
| 354 const protocol::PairingResponse& response) { | 331 const protocol::PairingResponse& response) { |
| 355 jni_runtime_->ui_task_runner()->PostTask( | 332 jni_runtime_->ui_task_runner()->PostTask( |
| 356 FROM_HERE, | 333 FROM_HERE, base::Bind(&JniClient::CommitPairingCredentials, jni_client_, |
| 357 base::Bind(&JniClient::CommitPairingCredentials, | 334 client_auth_config_.host_id, response.client_id(), |
| 358 jni_client_->GetWeakPtr(), client_auth_config_.host_id, | 335 response.shared_secret())); |
| 359 response.client_id(), response.shared_secret())); | |
| 360 } | 336 } |
| 361 | 337 |
| 362 void ChromotingJniInstance::DeliverHostMessage( | 338 void ChromotingJniInstance::DeliverHostMessage( |
| 363 const protocol::ExtensionMessage& message) { | 339 const protocol::ExtensionMessage& message) { |
| 364 jni_runtime_->ui_task_runner()->PostTask( | 340 jni_runtime_->ui_task_runner()->PostTask( |
| 365 FROM_HERE, base::Bind(&JniClient::HandleExtensionMessage, | 341 FROM_HERE, base::Bind(&JniClient::HandleExtensionMessage, jni_client_, |
| 366 jni_client_->GetWeakPtr(), message.type(), | 342 message.type(), message.data())); |
| 367 message.data())); | |
| 368 } | 343 } |
| 369 | 344 |
| 370 void ChromotingJniInstance::SetDesktopSize(const webrtc::DesktopSize& size, | 345 void ChromotingJniInstance::SetDesktopSize(const webrtc::DesktopSize& size, |
| 371 const webrtc::DesktopVector& dpi) { | 346 const webrtc::DesktopVector& dpi) { |
| 372 // JniFrameConsumer get size from the frames and it doesn't use DPI, so this | 347 // JniFrameConsumer get size from the frames and it doesn't use DPI, so this |
| 373 // call can be ignored. | 348 // call can be ignored. |
| 374 } | 349 } |
| 375 | 350 |
| 376 protocol::ClipboardStub* ChromotingJniInstance::GetClipboardStub() { | 351 protocol::ClipboardStub* ChromotingJniInstance::GetClipboardStub() { |
| 377 return this; | 352 return this; |
| 378 } | 353 } |
| 379 | 354 |
| 380 protocol::CursorShapeStub* ChromotingJniInstance::GetCursorShapeStub() { | 355 protocol::CursorShapeStub* ChromotingJniInstance::GetCursorShapeStub() { |
| 381 return this; | 356 return this; |
| 382 } | 357 } |
| 383 | 358 |
| 384 void ChromotingJniInstance::InjectClipboardEvent( | 359 void ChromotingJniInstance::InjectClipboardEvent( |
| 385 const protocol::ClipboardEvent& event) { | 360 const protocol::ClipboardEvent& event) { |
| 386 NOTIMPLEMENTED(); | 361 NOTIMPLEMENTED(); |
| 387 } | 362 } |
| 388 | 363 |
| 389 void ChromotingJniInstance::SetCursorShape( | 364 void ChromotingJniInstance::SetCursorShape( |
| 390 const protocol::CursorShapeInfo& shape) { | 365 const protocol::CursorShapeInfo& shape) { |
| 391 if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) { | 366 if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) { |
| 392 jni_runtime_->display_task_runner()->PostTask( | 367 jni_runtime_->display_task_runner()->PostTask( |
| 393 FROM_HERE, | 368 FROM_HERE, base::Bind(&JniDisplayHandler::UpdateCursorShape, |
| 394 base::Bind(&ChromotingJniInstance::SetCursorShape, this, shape)); | 369 display_handler_, shape)); |
| 395 return; | 370 } else if (display_handler_) { |
| 371 display_handler_->UpdateCursorShape(shape); | |
| 396 } | 372 } |
| 373 } | |
| 397 | 374 |
| 398 jni_client_->UpdateCursorShape(shape); | 375 base::WeakPtr<ChromotingJniInstance> ChromotingJniInstance::GetWeakPtr() { |
| 376 return weak_factory_.GetWeakPtr(); | |
| 399 } | 377 } |
| 400 | 378 |
| 401 void ChromotingJniInstance::ConnectToHostOnNetworkThread() { | 379 void ChromotingJniInstance::ConnectToHostOnNetworkThread() { |
| 402 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); | 380 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 403 | 381 |
| 404 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); | 382 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); |
| 405 | 383 |
| 406 client_context_.reset(new ClientContext(jni_runtime_->network_task_runner())); | 384 client_context_.reset(new ClientContext(jni_runtime_->network_task_runner())); |
| 407 client_context_->Start(); | 385 client_context_->Start(); |
| 408 | 386 |
| 409 perf_tracker_.reset(new protocol::PerformanceTracker()); | 387 perf_tracker_.reset(new protocol::PerformanceTracker()); |
| 410 | 388 |
| 411 view_.reset(new JniFrameConsumer(jni_runtime_, jni_client_)); | 389 view_.reset(new JniFrameConsumer(jni_runtime_, display_handler_)); |
| 412 video_renderer_.reset(new SoftwareVideoRenderer( | 390 video_renderer_.reset(new SoftwareVideoRenderer( |
| 413 client_context_->decode_task_runner(), view_.get(), perf_tracker_.get())); | 391 client_context_->decode_task_runner(), view_.get(), perf_tracker_.get())); |
| 414 | 392 |
| 415 client_.reset( | 393 client_.reset( |
| 416 new ChromotingClient(client_context_.get(), this, video_renderer_.get(), | 394 new ChromotingClient(client_context_.get(), this, video_renderer_.get(), |
| 417 base::WrapUnique(new AudioPlayerAndroid()))); | 395 base::WrapUnique(new AudioPlayerAndroid()))); |
| 418 | 396 |
| 419 signaling_.reset( | 397 signaling_.reset( |
| 420 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), | 398 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), |
| 421 jni_runtime_->url_requester(), xmpp_config_)); | 399 jni_runtime_->url_requester(), xmpp_config_)); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 442 #endif // defined(ENABLE_WEBRTC_REMOTING_CLIENT) | 420 #endif // defined(ENABLE_WEBRTC_REMOTING_CLIENT) |
| 443 client_->Start(signaling_.get(), client_auth_config_, transport_context, | 421 client_->Start(signaling_.get(), client_auth_config_, transport_context, |
| 444 host_jid_, capabilities_); | 422 host_jid_, capabilities_); |
| 445 } | 423 } |
| 446 | 424 |
| 447 void ChromotingJniInstance::FetchSecret( | 425 void ChromotingJniInstance::FetchSecret( |
| 448 bool pairable, | 426 bool pairable, |
| 449 const protocol::SecretFetchedCallback& callback) { | 427 const protocol::SecretFetchedCallback& callback) { |
| 450 if (!jni_runtime_->ui_task_runner()->BelongsToCurrentThread()) { | 428 if (!jni_runtime_->ui_task_runner()->BelongsToCurrentThread()) { |
| 451 jni_runtime_->ui_task_runner()->PostTask( | 429 jni_runtime_->ui_task_runner()->PostTask( |
| 452 FROM_HERE, base::Bind(&ChromotingJniInstance::FetchSecret, | 430 FROM_HERE, base::Bind(&JniSecretFetcher::FetchSecret, secret_fetcher_, |
| 453 this, pairable, callback)); | 431 pairable, callback)); |
| 454 return; | 432 } else if (secret_fetcher_) { |
| 433 secret_fetcher_->FetchSecret(pairable, callback); | |
| 455 } | 434 } |
| 456 | |
| 457 // Delete pairing credentials if they exist. | |
| 458 jni_client_->CommitPairingCredentials(client_auth_config_.host_id, "", ""); | |
| 459 | |
| 460 pin_callback_ = callback; | |
| 461 jni_client_->DisplayAuthenticationPrompt(pairable); | |
| 462 } | 435 } |
| 463 | 436 |
| 464 void ChromotingJniInstance::SetDeviceName(const std::string& device_name) { | 437 void ChromotingJniInstance::SetDeviceName(const std::string& device_name) { |
| 465 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { | 438 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { |
| 466 jni_runtime_->network_task_runner()->PostTask( | 439 jni_runtime_->network_task_runner()->PostTask( |
| 467 FROM_HERE, base::Bind(&ChromotingJniInstance::SetDeviceName, this, | 440 FROM_HERE, base::Bind(&ChromotingJniInstance::SetDeviceName, |
| 468 device_name)); | 441 GetWeakPtr(), device_name)); |
| 469 return; | 442 return; |
| 470 } | 443 } |
| 471 | 444 |
| 472 device_name_ = device_name; | 445 device_name_ = device_name; |
| 473 } | 446 } |
| 474 | 447 |
| 475 void ChromotingJniInstance::SendKeyEventInternal(int usb_key_code, | 448 void ChromotingJniInstance::SendKeyEventInternal(int usb_key_code, |
| 476 bool key_down) { | 449 bool key_down) { |
| 477 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { | 450 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { |
| 478 jni_runtime_->network_task_runner()->PostTask( | 451 jni_runtime_->network_task_runner()->PostTask( |
| 479 FROM_HERE, base::Bind(&ChromotingJniInstance::SendKeyEventInternal, | 452 FROM_HERE, base::Bind(&ChromotingJniInstance::SendKeyEventInternal, |
| 480 this, usb_key_code, key_down)); | 453 GetWeakPtr(), usb_key_code, key_down)); |
| 481 return; | 454 return; |
| 482 } | 455 } |
| 483 | 456 |
| 484 protocol::KeyEvent event; | 457 protocol::KeyEvent event; |
| 485 event.set_usb_keycode(usb_key_code); | 458 event.set_usb_keycode(usb_key_code); |
| 486 event.set_pressed(key_down); | 459 event.set_pressed(key_down); |
| 487 client_->input_stub()->InjectKeyEvent(event); | 460 client_->input_stub()->InjectKeyEvent(event); |
| 488 } | 461 } |
| 489 | 462 |
| 490 void ChromotingJniInstance::EnableStatsLogging(bool enabled) { | 463 void ChromotingJniInstance::EnableStatsLogging(bool enabled) { |
| 491 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); | 464 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 492 | 465 |
| 493 if (enabled && !stats_logging_enabled_) { | 466 if (enabled && !stats_logging_enabled_) { |
| 494 jni_runtime_->network_task_runner()->PostDelayedTask( | 467 jni_runtime_->network_task_runner()->PostDelayedTask( |
| 495 FROM_HERE, base::Bind(&ChromotingJniInstance::LogPerfStats, this), | 468 FROM_HERE, |
| 469 base::Bind(&ChromotingJniInstance::LogPerfStats, GetWeakPtr()), | |
| 496 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); | 470 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); |
| 497 } | 471 } |
| 498 stats_logging_enabled_ = enabled; | 472 stats_logging_enabled_ = enabled; |
| 499 } | 473 } |
| 500 | 474 |
| 501 void ChromotingJniInstance::LogPerfStats() { | 475 void ChromotingJniInstance::LogPerfStats() { |
| 502 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); | 476 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 503 | 477 |
| 504 if (!stats_logging_enabled_) | 478 if (!stats_logging_enabled_) |
| 505 return; | 479 return; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 517 perf_tracker_->video_decode_ms().Average(), | 491 perf_tracker_->video_decode_ms().Average(), |
| 518 perf_tracker_->video_decode_ms().Max(), | 492 perf_tracker_->video_decode_ms().Max(), |
| 519 perf_tracker_->video_paint_ms().Average(), | 493 perf_tracker_->video_paint_ms().Average(), |
| 520 perf_tracker_->video_paint_ms().Max(), | 494 perf_tracker_->video_paint_ms().Max(), |
| 521 perf_tracker_->round_trip_ms().Average(), | 495 perf_tracker_->round_trip_ms().Average(), |
| 522 perf_tracker_->round_trip_ms().Max()); | 496 perf_tracker_->round_trip_ms().Max()); |
| 523 | 497 |
| 524 jni_runtime_->logger()->LogStatistics(perf_tracker_.get()); | 498 jni_runtime_->logger()->LogStatistics(perf_tracker_.get()); |
| 525 | 499 |
| 526 jni_runtime_->network_task_runner()->PostDelayedTask( | 500 jni_runtime_->network_task_runner()->PostDelayedTask( |
| 527 FROM_HERE, base::Bind(&ChromotingJniInstance::LogPerfStats, this), | 501 FROM_HERE, base::Bind(&ChromotingJniInstance::LogPerfStats, GetWeakPtr()), |
| 528 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); | 502 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); |
| 529 } | 503 } |
| 530 | 504 |
| 505 void ChromotingJniInstance::Destroy() { | |
| 506 // |client_| must be torn down before |signaling_|. | |
| 507 client_.reset(); | |
| 508 video_renderer_.reset(); | |
| 509 view_.reset(); | |
| 510 signaling_.reset(); | |
| 511 perf_tracker_.reset(); | |
| 512 client_context_.reset(); | |
|
Lambros
2016/05/28 00:43:05
Should we invalidate weak_factory_ here?
Yuwei
2016/06/01 21:30:10
Done.
| |
| 513 } | |
| 514 | |
| 531 } // namespace remoting | 515 } // namespace remoting |
| OLD | NEW |