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/chromoting_session.h" |
| 6 | 6 |
| 7 #include <android/log.h> | |
| 8 #include <stdint.h> | 7 #include <stdint.h> |
| 9 | 8 |
| 10 #include "base/bind.h" | 9 #include "base/bind.h" |
| 11 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 12 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
| 13 #include "base/logging.h" | 12 #include "base/logging.h" |
| 14 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 15 #include "jingle/glue/thread_wrapper.h" | 14 #include "jingle/glue/thread_wrapper.h" |
| 16 #include "net/socket/client_socket_factory.h" | 15 #include "net/socket/client_socket_factory.h" |
| 17 #include "remoting/base/chromium_url_request.h" | 16 #include "remoting/base/chromium_url_request.h" |
| 18 #include "remoting/base/chromoting_event.h" | 17 #include "remoting/base/chromoting_event.h" |
| 19 #include "remoting/client/audio_player_android.h" | 18 #include "remoting/client/audio_player.h" |
| 20 #include "remoting/client/chromoting_client_runtime.h" | 19 #include "remoting/client/chromoting_client_runtime.h" |
| 21 #include "remoting/client/client_telemetry_logger.h" | 20 #include "remoting/client/client_telemetry_logger.h" |
| 22 #include "remoting/client/jni/android_keymap.h" | 21 #include "remoting/client/native_device_keymap.h" |
| 23 #include "remoting/client/jni/jni_client.h" | |
| 24 #include "remoting/client/jni/jni_pairing_secret_fetcher.h" | |
| 25 #include "remoting/protocol/chromium_port_allocator_factory.h" | 22 #include "remoting/protocol/chromium_port_allocator_factory.h" |
| 26 #include "remoting/protocol/chromium_socket_factory.h" | 23 #include "remoting/protocol/chromium_socket_factory.h" |
| 27 #include "remoting/protocol/client_authentication_config.h" | 24 #include "remoting/protocol/client_authentication_config.h" |
| 28 #include "remoting/protocol/frame_consumer.h" | 25 #include "remoting/protocol/frame_consumer.h" |
| 29 #include "remoting/protocol/host_stub.h" | 26 #include "remoting/protocol/host_stub.h" |
| 30 #include "remoting/protocol/network_settings.h" | 27 #include "remoting/protocol/network_settings.h" |
| 31 #include "remoting/protocol/performance_tracker.h" | 28 #include "remoting/protocol/performance_tracker.h" |
| 32 #include "remoting/protocol/transport_context.h" | 29 #include "remoting/protocol/transport_context.h" |
| 33 #include "remoting/protocol/video_renderer.h" | 30 #include "remoting/protocol/video_renderer.h" |
| 34 #include "remoting/signaling/server_log_entry.h" | 31 #include "remoting/signaling/server_log_entry.h" |
| 35 #include "ui/events/keycodes/dom/keycode_converter.h" | 32 #include "ui/events/keycodes/dom/keycode_converter.h" |
| 36 | 33 |
| 37 namespace remoting { | 34 namespace remoting { |
| 38 | 35 |
| 39 namespace { | 36 namespace { |
| 40 | 37 |
| 41 // TODO(solb) Move into location shared with client plugin. | |
| 42 const char* const kXmppServer = "talk.google.com"; | 38 const char* const kXmppServer = "talk.google.com"; |
| 43 const int kXmppPort = 5222; | 39 const int kXmppPort = 5222; |
| 44 const bool kXmppUseTls = true; | 40 const bool kXmppUseTls = true; |
| 45 | 41 |
| 46 // Interval at which to log performance statistics, if enabled. | 42 // Interval at which to log performance statistics, if enabled. |
| 47 const int kPerfStatsIntervalMs = 60000; | 43 const int kPerfStatsIntervalMs = 60000; |
| 48 | 44 |
| 49 } // namespace | 45 } // namespace |
| 50 | 46 |
| 51 ChromotingJniInstance::ChromotingJniInstance( | 47 ChromotingSession::ChromotingSession( |
| 52 base::WeakPtr<JniClient> jni_client, | 48 ChromotingSession::Delegate* delegate, |
| 53 base::WeakPtr<JniPairingSecretFetcher> secret_fetcher, | |
| 54 std::unique_ptr<protocol::CursorShapeStub> cursor_shape_stub, | 49 std::unique_ptr<protocol::CursorShapeStub> cursor_shape_stub, |
| 55 std::unique_ptr<protocol::VideoRenderer> video_renderer, | 50 std::unique_ptr<protocol::VideoRenderer> video_renderer, |
| 56 const ConnectToHostInfo& info) | 51 base::WeakPtr<protocol::AudioStub> audio_player, |
|
Yuwei
2017/03/21 20:40:29
Could we keep those stuff either all WeakPtr or al
nicholss
2017/03/29 20:32:35
Well this is an interesting one... I think this wi
| |
| 57 : jni_client_(jni_client), | 52 const ConnectToHostInfo& info, |
| 58 secret_fetcher_(secret_fetcher), | 53 protocol::ClientAuthenticationConfig& client_auth_config) |
| 54 : delegate_(delegate), | |
| 59 connection_info_(info), | 55 connection_info_(info), |
| 56 client_auth_config_(client_auth_config), | |
| 60 cursor_shape_stub_(std::move(cursor_shape_stub)), | 57 cursor_shape_stub_(std::move(cursor_shape_stub)), |
| 61 video_renderer_(std::move(video_renderer)), | 58 video_renderer_(std::move(video_renderer)), |
| 59 audio_player_(audio_player), | |
| 62 capabilities_(info.capabilities), | 60 capabilities_(info.capabilities), |
| 63 weak_factory_(this) { | 61 weak_factory_(this) { |
| 64 runtime_ = ChromotingClientRuntime::GetInstance(); | 62 runtime_ = ChromotingClientRuntime::GetInstance(); |
| 65 DCHECK(runtime_->ui_task_runner()->BelongsToCurrentThread()); | 63 DCHECK(runtime_->ui_task_runner()->BelongsToCurrentThread()); |
| 66 weak_ptr_ = weak_factory_.GetWeakPtr(); | 64 weak_ptr_ = weak_factory_.GetWeakPtr(); |
| 67 | 65 |
| 68 // Initialize XMPP config. | 66 // Initialize XMPP config. |
| 69 xmpp_config_.host = kXmppServer; | 67 xmpp_config_.host = kXmppServer; |
| 70 xmpp_config_.port = kXmppPort; | 68 xmpp_config_.port = kXmppPort; |
| 71 xmpp_config_.use_tls = kXmppUseTls; | 69 xmpp_config_.use_tls = kXmppUseTls; |
| 72 xmpp_config_.username = info.username; | 70 xmpp_config_.username = info.username; |
| 73 xmpp_config_.auth_token = info.auth_token; | 71 xmpp_config_.auth_token = info.auth_token; |
| 74 | 72 |
| 75 client_auth_config_.host_id = info.host_id; | |
| 76 client_auth_config_.pairing_client_id = info.pairing_id; | |
| 77 client_auth_config_.pairing_secret = info.pairing_secret; | |
| 78 client_auth_config_.fetch_secret_callback = | |
| 79 base::Bind(&JniPairingSecretFetcher::FetchSecret, secret_fetcher); | |
| 80 client_auth_config_.fetch_third_party_token_callback = base::Bind( | 73 client_auth_config_.fetch_third_party_token_callback = base::Bind( |
| 81 &ChromotingJniInstance::FetchThirdPartyToken, GetWeakPtr(), | 74 &ChromotingSession::FetchThirdPartyToken, GetWeakPtr(), info.host_pubkey); |
| 82 info.host_pubkey); | |
| 83 } | 75 } |
| 84 | 76 |
| 85 ChromotingJniInstance::~ChromotingJniInstance() { | 77 ChromotingSession::~ChromotingSession() { |
| 86 DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread()); | 78 DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 87 if (client_) { | 79 if (client_) { |
| 88 ReleaseResources(); | 80 ReleaseResources(); |
| 89 } | 81 } |
| 90 } | 82 } |
| 91 | 83 |
| 92 void ChromotingJniInstance::Connect() { | 84 void ChromotingSession::Connect() { |
| 93 if (runtime_->network_task_runner()->BelongsToCurrentThread()) { | 85 if (runtime_->network_task_runner()->BelongsToCurrentThread()) { |
| 94 ConnectToHostOnNetworkThread(); | 86 ConnectToHostOnNetworkThread(); |
| 95 } else { | 87 } else { |
| 96 runtime_->network_task_runner()->PostTask( | 88 runtime_->network_task_runner()->PostTask( |
| 97 FROM_HERE, | 89 FROM_HERE, base::Bind(&ChromotingSession::ConnectToHostOnNetworkThread, |
| 98 base::Bind(&ChromotingJniInstance::ConnectToHostOnNetworkThread, | 90 GetWeakPtr())); |
| 99 GetWeakPtr())); | |
| 100 } | 91 } |
| 101 } | 92 } |
| 102 | 93 |
| 103 void ChromotingJniInstance::Disconnect() { | 94 void ChromotingSession::Disconnect() { |
| 104 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) { | 95 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) { |
| 105 runtime_->network_task_runner()->PostTask( | 96 runtime_->network_task_runner()->PostTask( |
| 106 FROM_HERE, | 97 FROM_HERE, base::Bind(&ChromotingSession::Disconnect, GetWeakPtr())); |
| 107 base::Bind(&ChromotingJniInstance::Disconnect, GetWeakPtr())); | |
| 108 return; | 98 return; |
| 109 } | 99 } |
| 110 | 100 |
| 111 stats_logging_enabled_ = false; | 101 stats_logging_enabled_ = false; |
| 112 | 102 |
| 113 // User disconnection will not trigger OnConnectionState(Closed, OK). | 103 // User disconnection will not trigger OnConnectionState(Closed, OK). |
| 114 // Remote disconnection will trigger OnConnectionState(...) and later trigger | 104 // Remote disconnection will trigger OnConnectionState(...) and later trigger |
| 115 // Disconnect(). | 105 // Disconnect(). |
| 116 if (connected_) { | 106 if (connected_) { |
| 117 logger_->LogSessionStateChange( | 107 logger_->LogSessionStateChange(ChromotingEvent::SessionState::CLOSED, |
| 118 ChromotingEvent::SessionState::CLOSED, | 108 ChromotingEvent::ConnectionError::NONE); |
| 119 ChromotingEvent::ConnectionError::NONE); | |
| 120 connected_ = false; | 109 connected_ = false; |
| 121 } | 110 } |
| 122 | 111 |
| 123 ReleaseResources(); | 112 ReleaseResources(); |
| 124 } | 113 } |
| 125 | 114 |
| 126 void ChromotingJniInstance::FetchThirdPartyToken( | 115 void ChromotingSession::FetchThirdPartyToken( |
| 127 const std::string& host_public_key, | 116 const std::string& host_public_key, |
| 128 const std::string& token_url, | 117 const std::string& token_url, |
| 129 const std::string& scope, | 118 const std::string& scope, |
| 130 const protocol::ThirdPartyTokenFetchedCallback& token_fetched_callback) { | 119 const protocol::ThirdPartyTokenFetchedCallback& token_fetched_callback) { |
| 131 DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread()); | 120 DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 132 DCHECK(third_party_token_fetched_callback_.is_null()); | 121 DCHECK(third_party_token_fetched_callback_.is_null()); |
| 133 | 122 |
| 134 __android_log_print(ANDROID_LOG_INFO, | 123 VLOG(1) << "ThirdPartyAuth: Fetching Third Party Token from user."; |
| 135 "ThirdPartyAuth", | |
| 136 "Fetching Third Party Token from user."); | |
| 137 | 124 |
| 138 third_party_token_fetched_callback_ = token_fetched_callback; | 125 third_party_token_fetched_callback_ = token_fetched_callback; |
| 139 runtime_->ui_task_runner()->PostTask( | 126 runtime_->ui_task_runner()->PostTask( |
| 140 FROM_HERE, base::Bind(&JniClient::FetchThirdPartyToken, jni_client_, | 127 FROM_HERE, base::Bind(&ChromotingSession::Delegate::FetchThirdPartyToken, |
| 141 token_url, host_public_key, scope)); | 128 base::Unretained(delegate_), token_url, |
|
Lambros
2017/03/24 00:07:15
Please add a comment to say why base::Unretained i
nicholss
2017/03/29 20:32:36
Done.
| |
| 129 host_public_key, scope)); | |
| 142 } | 130 } |
| 143 | 131 |
| 144 void ChromotingJniInstance::HandleOnThirdPartyTokenFetched( | 132 void ChromotingSession::HandleOnThirdPartyTokenFetched( |
| 145 const std::string& token, | 133 const std::string& token, |
| 146 const std::string& shared_secret) { | 134 const std::string& shared_secret) { |
| 147 DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread()); | 135 DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 148 | 136 |
| 149 __android_log_print( | 137 VLOG(1) << "ThirdPartyAuth: Third Party Token Fetched."; |
| 150 ANDROID_LOG_INFO, "ThirdPartyAuth", "Third Party Token Fetched."); | |
| 151 | 138 |
| 152 if (!third_party_token_fetched_callback_.is_null()) { | 139 if (!third_party_token_fetched_callback_.is_null()) { |
| 153 base::ResetAndReturn(&third_party_token_fetched_callback_) | 140 base::ResetAndReturn(&third_party_token_fetched_callback_) |
| 154 .Run(token, shared_secret); | 141 .Run(token, shared_secret); |
| 155 } else { | 142 } else { |
| 156 __android_log_print( | 143 LOG(WARNING) << "ThirdPartyAuth: Ignored OnThirdPartyTokenFetched()" |
| 157 ANDROID_LOG_WARN, | 144 " without a pending fetch."; |
| 158 "ThirdPartyAuth", | |
| 159 "Ignored OnThirdPartyTokenFetched() without a pending fetch."); | |
| 160 } | 145 } |
| 161 } | 146 } |
| 162 | 147 |
| 163 void ChromotingJniInstance::ProvideSecret(const std::string& pin, | 148 void ChromotingSession::ProvideSecret(const std::string& pin, |
| 164 bool create_pairing, | 149 bool create_pairing, |
| 165 const std::string& device_name) { | 150 const std::string& device_name) { |
| 166 DCHECK(runtime_->ui_task_runner()->BelongsToCurrentThread()); | 151 DCHECK(runtime_->ui_task_runner()->BelongsToCurrentThread()); |
| 167 | 152 |
| 168 create_pairing_ = create_pairing; | 153 create_pairing_ = create_pairing; |
| 169 | 154 |
| 170 if (create_pairing) | 155 if (create_pairing) |
| 171 SetDeviceName(device_name); | 156 SetDeviceName(device_name); |
| 172 | |
| 173 runtime_->network_task_runner()->PostTask( | |
| 174 FROM_HERE, base::Bind(&JniPairingSecretFetcher::ProvideSecret, | |
| 175 secret_fetcher_, pin)); | |
| 176 } | 157 } |
| 177 | 158 |
| 178 void ChromotingJniInstance::SendMouseEvent( | 159 void ChromotingSession::SendMouseEvent(int x, |
| 179 int x, int y, | 160 int y, |
| 180 protocol::MouseEvent_MouseButton button, | 161 protocol::MouseEvent_MouseButton button, |
| 181 bool button_down) { | 162 bool button_down) { |
| 182 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) { | 163 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) { |
| 183 runtime_->network_task_runner()->PostTask( | 164 runtime_->network_task_runner()->PostTask( |
| 184 FROM_HERE, base::Bind(&ChromotingJniInstance::SendMouseEvent, | 165 FROM_HERE, base::Bind(&ChromotingSession::SendMouseEvent, GetWeakPtr(), |
| 185 GetWeakPtr(), x, y, button, button_down)); | 166 x, y, button, button_down)); |
| 186 return; | 167 return; |
| 187 } | 168 } |
| 188 | 169 |
| 189 protocol::MouseEvent event; | 170 protocol::MouseEvent event; |
| 190 event.set_x(x); | 171 event.set_x(x); |
| 191 event.set_y(y); | 172 event.set_y(y); |
| 192 event.set_button(button); | 173 event.set_button(button); |
| 193 if (button != protocol::MouseEvent::BUTTON_UNDEFINED) | 174 if (button != protocol::MouseEvent::BUTTON_UNDEFINED) |
| 194 event.set_button_down(button_down); | 175 event.set_button_down(button_down); |
| 195 | 176 |
| 196 client_->input_stub()->InjectMouseEvent(event); | 177 client_->input_stub()->InjectMouseEvent(event); |
| 197 } | 178 } |
| 198 | 179 |
| 199 void ChromotingJniInstance::SendMouseWheelEvent(int delta_x, int delta_y) { | 180 void ChromotingSession::SendMouseWheelEvent(int delta_x, int delta_y) { |
| 200 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) { | 181 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) { |
| 201 runtime_->network_task_runner()->PostTask( | 182 runtime_->network_task_runner()->PostTask( |
| 202 FROM_HERE, base::Bind(&ChromotingJniInstance::SendMouseWheelEvent, | 183 FROM_HERE, base::Bind(&ChromotingSession::SendMouseWheelEvent, |
| 203 GetWeakPtr(), delta_x, delta_y)); | 184 GetWeakPtr(), delta_x, delta_y)); |
| 204 return; | 185 return; |
| 205 } | 186 } |
| 206 | 187 |
| 207 protocol::MouseEvent event; | 188 protocol::MouseEvent event; |
| 208 event.set_wheel_delta_x(delta_x); | 189 event.set_wheel_delta_x(delta_x); |
| 209 event.set_wheel_delta_y(delta_y); | 190 event.set_wheel_delta_y(delta_y); |
| 210 client_->input_stub()->InjectMouseEvent(event); | 191 client_->input_stub()->InjectMouseEvent(event); |
| 211 } | 192 } |
| 212 | 193 |
| 213 bool ChromotingJniInstance::SendKeyEvent(int scan_code, | 194 bool ChromotingSession::SendKeyEvent(int scan_code, |
| 214 int key_code, | 195 int key_code, |
| 215 bool key_down) { | 196 bool key_down) { |
| 216 // For software keyboards |scan_code| is set to 0, in which case the | 197 // For software keyboards |scan_code| is set to 0, in which case the |
| 217 // |key_code| is used instead. | 198 // |key_code| is used instead. |
| 218 uint32_t usb_key_code = | 199 uint32_t usb_key_code = |
| 219 scan_code ? ui::KeycodeConverter::NativeKeycodeToUsbKeycode(scan_code) | 200 scan_code ? ui::KeycodeConverter::NativeKeycodeToUsbKeycode(scan_code) |
| 220 : AndroidKeycodeToUsbKeycode(key_code); | 201 : NativeDeviceKeycodeToUsbKeycode(key_code); |
| 221 if (!usb_key_code) { | 202 if (!usb_key_code) { |
| 222 LOG(WARNING) << "Ignoring unknown key code: " << key_code | 203 LOG(WARNING) << "Ignoring unknown key code: " << key_code |
| 223 << " scan code: " << scan_code; | 204 << " scan code: " << scan_code; |
| 224 return false; | 205 return false; |
| 225 } | 206 } |
| 226 | 207 |
| 227 SendKeyEventInternal(usb_key_code, key_down); | 208 SendKeyEventInternal(usb_key_code, key_down); |
| 228 return true; | 209 return true; |
| 229 } | 210 } |
| 230 | 211 |
| 231 void ChromotingJniInstance::SendTextEvent(const std::string& text) { | 212 void ChromotingSession::SendTextEvent(const std::string& text) { |
| 232 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) { | 213 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) { |
| 233 runtime_->network_task_runner()->PostTask( | 214 runtime_->network_task_runner()->PostTask( |
| 234 FROM_HERE, | 215 FROM_HERE, |
| 235 base::Bind(&ChromotingJniInstance::SendTextEvent, GetWeakPtr(), text)); | 216 base::Bind(&ChromotingSession::SendTextEvent, GetWeakPtr(), text)); |
| 236 return; | 217 return; |
| 237 } | 218 } |
| 238 | 219 |
| 239 protocol::TextEvent event; | 220 protocol::TextEvent event; |
| 240 event.set_text(text); | 221 event.set_text(text); |
| 241 client_->input_stub()->InjectTextEvent(event); | 222 client_->input_stub()->InjectTextEvent(event); |
| 242 } | 223 } |
| 243 | 224 |
| 244 void ChromotingJniInstance::SendTouchEvent( | 225 void ChromotingSession::SendTouchEvent( |
| 245 const protocol::TouchEvent& touch_event) { | 226 const protocol::TouchEvent& touch_event) { |
| 246 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) { | 227 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) { |
| 247 runtime_->network_task_runner()->PostTask( | 228 runtime_->network_task_runner()->PostTask( |
| 248 FROM_HERE, base::Bind(&ChromotingJniInstance::SendTouchEvent, | 229 FROM_HERE, base::Bind(&ChromotingSession::SendTouchEvent, GetWeakPtr(), |
| 249 GetWeakPtr(), touch_event)); | 230 touch_event)); |
| 250 return; | 231 return; |
| 251 } | 232 } |
| 252 | 233 |
| 253 client_->input_stub()->InjectTouchEvent(touch_event); | 234 client_->input_stub()->InjectTouchEvent(touch_event); |
| 254 } | 235 } |
| 255 | 236 |
| 256 void ChromotingJniInstance::EnableVideoChannel(bool enable) { | 237 void ChromotingSession::EnableVideoChannel(bool enable) { |
| 257 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) { | 238 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) { |
| 258 runtime_->network_task_runner()->PostTask( | 239 runtime_->network_task_runner()->PostTask( |
| 259 FROM_HERE, base::Bind(&ChromotingJniInstance::EnableVideoChannel, | 240 FROM_HERE, base::Bind(&ChromotingSession::EnableVideoChannel, |
| 260 GetWeakPtr(), enable)); | 241 GetWeakPtr(), enable)); |
| 261 return; | 242 return; |
| 262 } | 243 } |
| 263 | 244 |
| 264 protocol::VideoControl video_control; | 245 protocol::VideoControl video_control; |
| 265 video_control.set_enable(enable); | 246 video_control.set_enable(enable); |
| 266 client_->host_stub()->ControlVideo(video_control); | 247 client_->host_stub()->ControlVideo(video_control); |
| 267 } | 248 } |
| 268 | 249 |
| 269 void ChromotingJniInstance::SendClientMessage(const std::string& type, | 250 void ChromotingSession::SendClientMessage(const std::string& type, |
| 270 const std::string& data) { | 251 const std::string& data) { |
| 271 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) { | 252 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) { |
| 272 runtime_->network_task_runner()->PostTask( | 253 runtime_->network_task_runner()->PostTask( |
| 273 FROM_HERE, base::Bind(&ChromotingJniInstance::SendClientMessage, | 254 FROM_HERE, base::Bind(&ChromotingSession::SendClientMessage, |
| 274 GetWeakPtr(), type, data)); | 255 GetWeakPtr(), type, data)); |
| 275 return; | 256 return; |
| 276 } | 257 } |
| 277 | 258 |
| 278 protocol::ExtensionMessage extension_message; | 259 protocol::ExtensionMessage extension_message; |
| 279 extension_message.set_type(type); | 260 extension_message.set_type(type); |
| 280 extension_message.set_data(data); | 261 extension_message.set_data(data); |
| 281 client_->host_stub()->DeliverClientMessage(extension_message); | 262 client_->host_stub()->DeliverClientMessage(extension_message); |
| 282 } | 263 } |
| 283 | 264 |
| 284 void ChromotingJniInstance::OnConnectionState( | 265 void ChromotingSession::OnConnectionState( |
| 285 protocol::ConnectionToHost::State state, | 266 protocol::ConnectionToHost::State state, |
| 286 protocol::ErrorCode error) { | 267 protocol::ErrorCode error) { |
| 287 DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread()); | 268 DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 288 | 269 |
| 289 // This code assumes no intermediate connection state between CONNECTED and | 270 // This code assumes no intermediate connection state between CONNECTED and |
| 290 // CLOSED/FAILED. | 271 // CLOSED/FAILED. |
| 291 connected_ = state == protocol::ConnectionToHost::CONNECTED; | 272 connected_ = state == protocol::ConnectionToHost::CONNECTED; |
| 292 EnableStatsLogging(connected_); | 273 EnableStatsLogging(connected_); |
| 293 | 274 |
| 294 logger_->LogSessionStateChange( | 275 logger_->LogSessionStateChange(ClientTelemetryLogger::TranslateState(state), |
| 295 ClientTelemetryLogger::TranslateState(state), | 276 ClientTelemetryLogger::TranslateError(error)); |
| 296 ClientTelemetryLogger::TranslateError(error)); | |
| 297 | 277 |
| 298 if (create_pairing_ && state == protocol::ConnectionToHost::CONNECTED) { | 278 if (create_pairing_ && state == protocol::ConnectionToHost::CONNECTED) { |
| 299 protocol::PairingRequest request; | 279 protocol::PairingRequest request; |
| 300 DCHECK(!device_name_.empty()); | 280 DCHECK(!device_name_.empty()); |
| 301 request.set_client_name(device_name_); | 281 request.set_client_name(device_name_); |
| 302 client_->host_stub()->RequestPairing(request); | 282 client_->host_stub()->RequestPairing(request); |
| 303 } | 283 } |
| 304 | 284 |
| 305 runtime_->ui_task_runner()->PostTask( | 285 runtime_->ui_task_runner()->PostTask( |
| 306 FROM_HERE, | 286 FROM_HERE, base::Bind(&ChromotingSession::Delegate::OnConnectionState, |
| 307 base::Bind(&JniClient::OnConnectionState, jni_client_, state, error)); | 287 base::Unretained(delegate_), state, error)); |
| 308 } | 288 } |
| 309 | 289 |
| 310 void ChromotingJniInstance::OnConnectionReady(bool ready) { | 290 void ChromotingSession::OnConnectionReady(bool ready) { |
| 311 // We ignore this message, since OnConnectionState tells us the same thing. | 291 // We ignore this message, since OnConnectionState tells us the same thing. |
| 312 } | 292 } |
| 313 | 293 |
| 314 void ChromotingJniInstance::OnRouteChanged( | 294 void ChromotingSession::OnRouteChanged(const std::string& channel_name, |
| 315 const std::string& channel_name, | 295 const protocol::TransportRoute& route) { |
| 316 const protocol::TransportRoute& route) { | |
| 317 std::string message = "Channel " + channel_name + " using " + | 296 std::string message = "Channel " + channel_name + " using " + |
| 318 protocol::TransportRoute::GetTypeString(route.type) + " connection."; | 297 protocol::TransportRoute::GetTypeString(route.type) + |
| 319 __android_log_print(ANDROID_LOG_INFO, "route", "%s", message.c_str()); | 298 " connection."; |
| 299 VLOG(1) << "Route: " << message.c_str(); | |
|
Yuwei
2017/03/21 20:40:29
You probably don't need c_str() any more. You can
nicholss
2017/03/29 20:32:35
Lambros says the android log is for debugging in a
Yuwei
2017/03/29 21:52:15
LOG(INFO) on Android is already defined as __andro
| |
| 320 } | 300 } |
| 321 | 301 |
| 322 void ChromotingJniInstance::SetCapabilities(const std::string& capabilities) { | 302 void ChromotingSession::SetCapabilities(const std::string& capabilities) { |
| 303 runtime_->ui_task_runner()->PostTask( | |
| 304 FROM_HERE, base::Bind(&ChromotingSession::Delegate::SetCapabilities, | |
| 305 base::Unretained(delegate_), capabilities)); | |
| 306 } | |
| 307 | |
| 308 void ChromotingSession::SetPairingResponse( | |
| 309 const protocol::PairingResponse& response) { | |
| 323 runtime_->ui_task_runner()->PostTask( | 310 runtime_->ui_task_runner()->PostTask( |
| 324 FROM_HERE, | 311 FROM_HERE, |
| 325 base::Bind(&JniClient::SetCapabilities, jni_client_, capabilities)); | 312 base::Bind(&ChromotingSession::Delegate::CommitPairingCredentials, |
| 313 base::Unretained(delegate_), client_auth_config_.host_id, | |
| 314 response.client_id(), response.shared_secret())); | |
| 326 } | 315 } |
| 327 | 316 |
| 328 void ChromotingJniInstance::SetPairingResponse( | 317 void ChromotingSession::DeliverHostMessage( |
| 329 const protocol::PairingResponse& response) { | 318 const protocol::ExtensionMessage& message) { |
| 330 runtime_->ui_task_runner()->PostTask( | 319 runtime_->ui_task_runner()->PostTask( |
| 331 FROM_HERE, base::Bind(&JniClient::CommitPairingCredentials, jni_client_, | 320 FROM_HERE, |
| 332 client_auth_config_.host_id, response.client_id(), | 321 base::Bind(&ChromotingSession::Delegate::HandleExtensionMessage, |
| 333 response.shared_secret())); | 322 base::Unretained(delegate_), message.type(), message.data())); |
| 334 } | 323 } |
| 335 | 324 |
| 336 void ChromotingJniInstance::DeliverHostMessage( | 325 void ChromotingSession::SetDesktopSize(const webrtc::DesktopSize& size, |
| 337 const protocol::ExtensionMessage& message) { | 326 const webrtc::DesktopVector& dpi) { |
| 338 runtime_->ui_task_runner()->PostTask( | |
| 339 FROM_HERE, base::Bind(&JniClient::HandleExtensionMessage, jni_client_, | |
| 340 message.type(), message.data())); | |
| 341 } | |
| 342 | |
| 343 void ChromotingJniInstance::SetDesktopSize(const webrtc::DesktopSize& size, | |
| 344 const webrtc::DesktopVector& dpi) { | |
| 345 // JniFrameConsumer get size from the frames and it doesn't use DPI, so this | 327 // JniFrameConsumer get size from the frames and it doesn't use DPI, so this |
|
Yuwei
2017/03/21 20:40:29
Fix this comment.
| |
| 346 // call can be ignored. | 328 // call can be ignored. |
| 347 } | 329 } |
| 348 | 330 |
| 349 protocol::ClipboardStub* ChromotingJniInstance::GetClipboardStub() { | 331 protocol::ClipboardStub* ChromotingSession::GetClipboardStub() { |
| 350 return this; | 332 return this; |
| 351 } | 333 } |
| 352 | 334 |
| 353 protocol::CursorShapeStub* ChromotingJniInstance::GetCursorShapeStub() { | 335 protocol::CursorShapeStub* ChromotingSession::GetCursorShapeStub() { |
| 354 return cursor_shape_stub_.get(); | 336 return cursor_shape_stub_.get(); |
| 355 } | 337 } |
| 356 | 338 |
| 357 void ChromotingJniInstance::InjectClipboardEvent( | 339 void ChromotingSession::InjectClipboardEvent( |
| 358 const protocol::ClipboardEvent& event) { | 340 const protocol::ClipboardEvent& event) { |
| 359 NOTIMPLEMENTED(); | 341 NOTIMPLEMENTED(); |
| 360 } | 342 } |
| 361 | 343 |
| 362 base::WeakPtr<ChromotingJniInstance> ChromotingJniInstance::GetWeakPtr() { | 344 base::WeakPtr<ChromotingSession> ChromotingSession::GetWeakPtr() { |
| 363 return weak_ptr_; | 345 return weak_ptr_; |
| 364 } | 346 } |
| 365 | 347 |
| 366 void ChromotingJniInstance::ConnectToHostOnNetworkThread() { | 348 void ChromotingSession::ConnectToHostOnNetworkThread() { |
| 367 DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread()); | 349 DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 368 | 350 |
| 369 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); | 351 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); |
| 370 | 352 |
| 371 client_context_.reset(new ClientContext(runtime_->network_task_runner())); | 353 client_context_.reset(new ClientContext(runtime_->network_task_runner())); |
| 372 client_context_->Start(); | 354 client_context_->Start(); |
| 373 | 355 |
| 374 perf_tracker_.reset(new protocol::PerformanceTracker()); | 356 perf_tracker_.reset(new protocol::PerformanceTracker()); |
| 375 | 357 |
| 376 video_renderer_->Initialize(*client_context_, | 358 video_renderer_->Initialize(*client_context_, perf_tracker_.get()); |
| 377 perf_tracker_.get()); | |
| 378 | |
| 379 if (!audio_player_) { | |
| 380 audio_player_.reset(new AudioPlayerAndroid()); | |
| 381 } | |
| 382 | 359 |
| 383 logger_.reset(new ClientTelemetryLogger(runtime_->log_writer(), | 360 logger_.reset(new ClientTelemetryLogger(runtime_->log_writer(), |
| 384 ChromotingEvent::Mode::ME2ME)); | 361 ChromotingEvent::Mode::ME2ME)); |
| 385 logger_->SetHostInfo( | 362 logger_->SetHostInfo( |
| 386 connection_info_.host_version, | 363 connection_info_.host_version, |
| 387 ChromotingEvent::ParseOsFromString(connection_info_.host_os), | 364 ChromotingEvent::ParseOsFromString(connection_info_.host_os), |
| 388 connection_info_.host_os_version); | 365 connection_info_.host_os_version); |
| 389 | 366 |
| 390 client_.reset(new ChromotingClient(client_context_.get(), this, | 367 client_.reset(new ChromotingClient(client_context_.get(), this, |
| 391 video_renderer_.get(), | 368 video_renderer_.get(), audio_player_)); |
| 392 audio_player_->GetWeakPtr())); | |
| 393 | 369 |
| 394 signaling_.reset( | 370 signaling_.reset( |
| 395 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), | 371 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), |
| 396 runtime_->url_requester(), xmpp_config_)); | 372 runtime_->url_requester(), xmpp_config_)); |
| 397 | 373 |
| 398 scoped_refptr<protocol::TransportContext> transport_context = | 374 scoped_refptr<protocol::TransportContext> transport_context = |
| 399 new protocol::TransportContext( | 375 new protocol::TransportContext( |
| 400 signaling_.get(), | 376 signaling_.get(), |
| 401 base::MakeUnique<protocol::ChromiumPortAllocatorFactory>(), | 377 base::MakeUnique<protocol::ChromiumPortAllocatorFactory>(), |
| 402 base::MakeUnique<ChromiumUrlRequestFactory>( | 378 base::MakeUnique<ChromiumUrlRequestFactory>( |
| 403 runtime_->url_requester()), | 379 runtime_->url_requester()), |
| 404 protocol::NetworkSettings( | 380 protocol::NetworkSettings( |
| 405 protocol::NetworkSettings::NAT_TRAVERSAL_FULL), | 381 protocol::NetworkSettings::NAT_TRAVERSAL_FULL), |
| 406 protocol::TransportRole::CLIENT); | 382 protocol::TransportRole::CLIENT); |
| 407 | 383 |
| 408 #if defined(ENABLE_WEBRTC_REMOTING_CLIENT) | 384 #if defined(ENABLE_WEBRTC_REMOTING_CLIENT) |
| 409 if (connection_info_.flags.find("useWebrtc") != std::string::npos) { | 385 if (connection_info_.flags.find("useWebrtc") != std::string::npos) { |
| 410 VLOG(0) << "Attempting to connect using WebRTC."; | 386 VLOG(0) << "Attempting to connect using WebRTC."; |
| 411 std::unique_ptr<protocol::CandidateSessionConfig> protocol_config = | 387 std::unique_ptr<protocol::CandidateSessionConfig> protocol_config = |
| 412 protocol::CandidateSessionConfig::CreateEmpty(); | 388 protocol::CandidateSessionConfig::CreateEmpty(); |
| 413 protocol_config->set_webrtc_supported(true); | 389 protocol_config->set_webrtc_supported(true); |
| 414 protocol_config->set_ice_supported(false); | 390 protocol_config->set_ice_supported(false); |
| 415 client_->set_protocol_config(std::move(protocol_config)); | 391 client_->set_protocol_config(std::move(protocol_config)); |
| 416 } | 392 } |
| 417 #endif // defined(ENABLE_WEBRTC_REMOTING_CLIENT) | 393 #endif // defined(ENABLE_WEBRTC_REMOTING_CLIENT) |
| 418 client_->Start(signaling_.get(), client_auth_config_, transport_context, | 394 client_->Start(signaling_.get(), client_auth_config_, transport_context, |
| 419 connection_info_.host_jid, capabilities_); | 395 connection_info_.host_jid, capabilities_); |
| 420 } | 396 } |
| 421 | 397 |
| 422 void ChromotingJniInstance::SetDeviceName(const std::string& device_name) { | 398 void ChromotingSession::SetDeviceName(const std::string& device_name) { |
| 423 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) { | 399 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) { |
| 424 runtime_->network_task_runner()->PostTask( | 400 runtime_->network_task_runner()->PostTask( |
| 425 FROM_HERE, base::Bind(&ChromotingJniInstance::SetDeviceName, | 401 FROM_HERE, base::Bind(&ChromotingSession::SetDeviceName, GetWeakPtr(), |
| 426 GetWeakPtr(), device_name)); | 402 device_name)); |
| 427 return; | 403 return; |
| 428 } | 404 } |
| 429 | 405 |
| 430 device_name_ = device_name; | 406 device_name_ = device_name; |
| 431 } | 407 } |
| 432 | 408 |
| 433 void ChromotingJniInstance::SendKeyEventInternal(int usb_key_code, | 409 void ChromotingSession::SendKeyEventInternal(int usb_key_code, bool key_down) { |
| 434 bool key_down) { | |
| 435 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) { | 410 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) { |
| 436 runtime_->network_task_runner()->PostTask( | 411 runtime_->network_task_runner()->PostTask( |
| 437 FROM_HERE, base::Bind(&ChromotingJniInstance::SendKeyEventInternal, | 412 FROM_HERE, base::Bind(&ChromotingSession::SendKeyEventInternal, |
| 438 GetWeakPtr(), usb_key_code, key_down)); | 413 GetWeakPtr(), usb_key_code, key_down)); |
| 439 return; | 414 return; |
| 440 } | 415 } |
| 441 | 416 |
| 442 protocol::KeyEvent event; | 417 protocol::KeyEvent event; |
| 443 event.set_usb_keycode(usb_key_code); | 418 event.set_usb_keycode(usb_key_code); |
| 444 event.set_pressed(key_down); | 419 event.set_pressed(key_down); |
| 445 client_->input_stub()->InjectKeyEvent(event); | 420 client_->input_stub()->InjectKeyEvent(event); |
| 446 } | 421 } |
| 447 | 422 |
| 448 void ChromotingJniInstance::EnableStatsLogging(bool enabled) { | 423 void ChromotingSession::EnableStatsLogging(bool enabled) { |
| 449 DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread()); | 424 DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 450 | 425 |
| 451 if (enabled && !stats_logging_enabled_) { | 426 if (enabled && !stats_logging_enabled_) { |
| 452 runtime_->network_task_runner()->PostDelayedTask( | 427 runtime_->network_task_runner()->PostDelayedTask( |
| 453 FROM_HERE, | 428 FROM_HERE, base::Bind(&ChromotingSession::LogPerfStats, GetWeakPtr()), |
| 454 base::Bind(&ChromotingJniInstance::LogPerfStats, GetWeakPtr()), | |
| 455 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); | 429 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); |
| 456 } | 430 } |
| 457 stats_logging_enabled_ = enabled; | 431 stats_logging_enabled_ = enabled; |
| 458 } | 432 } |
| 459 | 433 |
| 460 void ChromotingJniInstance::LogPerfStats() { | 434 void ChromotingSession::LogPerfStats() { |
| 461 DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread()); | 435 DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 462 | 436 |
| 463 if (!stats_logging_enabled_) | 437 if (!stats_logging_enabled_) |
| 464 return; | 438 return; |
| 465 | 439 |
| 466 __android_log_print( | 440 // TODO(nicholss): When this was JNI only logging to android was possible. |
|
Lambros
2017/03/24 00:07:14
These stats are logged for debugging. Note that th
nicholss
2017/04/03 17:37:16
I moved this log message to the logger. If this is
| |
| 467 ANDROID_LOG_INFO, "stats", | 441 // But now the component is shared, we could IFDEF for android here if this |
| 468 "Bandwidth:%.0f FrameRate:%.1f;" | 442 // log is useful to be logged to a users device. |
| 469 " (Avg, Max) Capture:%.1f, %" PRId64 " Encode:%.1f, %" PRId64 | 443 // __android_log_print( |
|
Yuwei
2017/03/21 20:40:29
Couldn't VLOG(1) work for iOS in this case?
We ca
| |
| 470 " Decode:%.1f, %" PRId64 " Render:%.1f, %" PRId64 " RTL:%.0f, %" PRId64, | 444 // ANDROID_LOG_INFO, "stats", |
| 471 perf_tracker_->video_bandwidth(), perf_tracker_->video_frame_rate(), | 445 // "Bandwidth:%.0f FrameRate:%.1f;" |
| 472 perf_tracker_->video_capture_ms().Average(), | 446 // " (Avg, Max) Capture:%.1f, %" PRId64 " Encode:%.1f, %" PRId64 |
| 473 perf_tracker_->video_capture_ms().Max(), | 447 // " Decode:%.1f, %" PRId64 " Render:%.1f, %" PRId64 " RTL:%.0f, %" |
| 474 perf_tracker_->video_encode_ms().Average(), | 448 // PRId64, perf_tracker_->video_bandwidth(), |
| 475 perf_tracker_->video_encode_ms().Max(), | 449 // perf_tracker_->video_frame_rate(), |
| 476 perf_tracker_->video_decode_ms().Average(), | 450 // perf_tracker_->video_capture_ms().Average(), |
| 477 perf_tracker_->video_decode_ms().Max(), | 451 // perf_tracker_->video_capture_ms().Max(), |
| 478 perf_tracker_->video_paint_ms().Average(), | 452 // perf_tracker_->video_encode_ms().Average(), |
| 479 perf_tracker_->video_paint_ms().Max(), | 453 // perf_tracker_->video_encode_ms().Max(), |
| 480 perf_tracker_->round_trip_ms().Average(), | 454 // perf_tracker_->video_decode_ms().Average(), |
| 481 perf_tracker_->round_trip_ms().Max()); | 455 // perf_tracker_->video_decode_ms().Max(), |
| 456 // perf_tracker_->video_paint_ms().Average(), | |
| 457 // perf_tracker_->video_paint_ms().Max(), | |
| 458 // perf_tracker_->round_trip_ms().Average(), | |
| 459 // perf_tracker_->round_trip_ms().Max()); | |
| 482 | 460 |
| 483 logger_->LogStatistics(perf_tracker_.get()); | 461 logger_->LogStatistics(perf_tracker_.get()); |
| 484 | 462 |
| 485 runtime_->network_task_runner()->PostDelayedTask( | 463 runtime_->network_task_runner()->PostDelayedTask( |
| 486 FROM_HERE, base::Bind(&ChromotingJniInstance::LogPerfStats, GetWeakPtr()), | 464 FROM_HERE, base::Bind(&ChromotingSession::LogPerfStats, GetWeakPtr()), |
| 487 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); | 465 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); |
| 488 } | 466 } |
| 489 | 467 |
| 490 void ChromotingJniInstance::ReleaseResources() { | 468 void ChromotingSession::ReleaseResources() { |
| 491 logger_.reset(); | 469 logger_.reset(); |
| 492 | 470 |
| 493 // |client_| must be torn down before |signaling_|. | 471 // |client_| must be torn down before |signaling_|. |
| 494 client_.reset(); | 472 client_.reset(); |
| 495 audio_player_.reset(); | 473 audio_player_.reset(); |
| 496 video_renderer_.reset(); | 474 video_renderer_.reset(); |
| 497 signaling_.reset(); | 475 signaling_.reset(); |
| 498 perf_tracker_.reset(); | 476 perf_tracker_.reset(); |
| 499 client_context_.reset(); | 477 client_context_.reset(); |
| 500 cursor_shape_stub_.reset(); | 478 cursor_shape_stub_.reset(); |
| 501 | 479 |
| 502 weak_factory_.InvalidateWeakPtrs(); | 480 weak_factory_.InvalidateWeakPtrs(); |
| 503 } | 481 } |
| 504 | 482 |
| 505 } // namespace remoting | 483 } // namespace remoting |
| OLD | NEW |