Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: remoting/client/chromoting_session.cc

Issue 2753963002: Refactoring and rewriting the chromoting jni instance to be chromoting session. (Closed)
Patch Set: Release audio_player on the network thread. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 base::WeakPtr<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,
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 delegate_, token_url, host_public_key, scope));
142 } 129 }
143 130
144 void ChromotingJniInstance::HandleOnThirdPartyTokenFetched( 131 void ChromotingSession::HandleOnThirdPartyTokenFetched(
145 const std::string& token, 132 const std::string& token,
146 const std::string& shared_secret) { 133 const std::string& shared_secret) {
147 DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread()); 134 DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread());
148 135
149 __android_log_print( 136 VLOG(1) << "ThirdPartyAuth: Third Party Token Fetched.";
150 ANDROID_LOG_INFO, "ThirdPartyAuth", "Third Party Token Fetched.");
151 137
152 if (!third_party_token_fetched_callback_.is_null()) { 138 if (!third_party_token_fetched_callback_.is_null()) {
153 base::ResetAndReturn(&third_party_token_fetched_callback_) 139 base::ResetAndReturn(&third_party_token_fetched_callback_)
154 .Run(token, shared_secret); 140 .Run(token, shared_secret);
155 } else { 141 } else {
156 __android_log_print( 142 LOG(WARNING) << "ThirdPartyAuth: Ignored OnThirdPartyTokenFetched()"
157 ANDROID_LOG_WARN, 143 " without a pending fetch.";
158 "ThirdPartyAuth",
159 "Ignored OnThirdPartyTokenFetched() without a pending fetch.");
160 } 144 }
161 } 145 }
162 146
163 void ChromotingJniInstance::ProvideSecret(const std::string& pin, 147 void ChromotingSession::ProvideSecret(const std::string& pin,
164 bool create_pairing, 148 bool create_pairing,
165 const std::string& device_name) { 149 const std::string& device_name) {
166 DCHECK(runtime_->ui_task_runner()->BelongsToCurrentThread()); 150 DCHECK(runtime_->ui_task_runner()->BelongsToCurrentThread());
167 151
168 create_pairing_ = create_pairing; 152 create_pairing_ = create_pairing;
169 153
170 if (create_pairing) 154 if (create_pairing)
171 SetDeviceName(device_name); 155 SetDeviceName(device_name);
172
173 runtime_->network_task_runner()->PostTask(
174 FROM_HERE, base::Bind(&JniPairingSecretFetcher::ProvideSecret,
175 secret_fetcher_, pin));
176 } 156 }
177 157
178 void ChromotingJniInstance::SendMouseEvent( 158 void ChromotingSession::SendMouseEvent(int x,
179 int x, int y, 159 int y,
180 protocol::MouseEvent_MouseButton button, 160 protocol::MouseEvent_MouseButton button,
181 bool button_down) { 161 bool button_down) {
182 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) { 162 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) {
183 runtime_->network_task_runner()->PostTask( 163 runtime_->network_task_runner()->PostTask(
184 FROM_HERE, base::Bind(&ChromotingJniInstance::SendMouseEvent, 164 FROM_HERE, base::Bind(&ChromotingSession::SendMouseEvent, GetWeakPtr(),
185 GetWeakPtr(), x, y, button, button_down)); 165 x, y, button, button_down));
186 return; 166 return;
187 } 167 }
188 168
189 protocol::MouseEvent event; 169 protocol::MouseEvent event;
190 event.set_x(x); 170 event.set_x(x);
191 event.set_y(y); 171 event.set_y(y);
192 event.set_button(button); 172 event.set_button(button);
193 if (button != protocol::MouseEvent::BUTTON_UNDEFINED) 173 if (button != protocol::MouseEvent::BUTTON_UNDEFINED)
194 event.set_button_down(button_down); 174 event.set_button_down(button_down);
195 175
196 client_->input_stub()->InjectMouseEvent(event); 176 client_->input_stub()->InjectMouseEvent(event);
197 } 177 }
198 178
199 void ChromotingJniInstance::SendMouseWheelEvent(int delta_x, int delta_y) { 179 void ChromotingSession::SendMouseWheelEvent(int delta_x, int delta_y) {
200 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) { 180 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) {
201 runtime_->network_task_runner()->PostTask( 181 runtime_->network_task_runner()->PostTask(
202 FROM_HERE, base::Bind(&ChromotingJniInstance::SendMouseWheelEvent, 182 FROM_HERE, base::Bind(&ChromotingSession::SendMouseWheelEvent,
203 GetWeakPtr(), delta_x, delta_y)); 183 GetWeakPtr(), delta_x, delta_y));
204 return; 184 return;
205 } 185 }
206 186
207 protocol::MouseEvent event; 187 protocol::MouseEvent event;
208 event.set_wheel_delta_x(delta_x); 188 event.set_wheel_delta_x(delta_x);
209 event.set_wheel_delta_y(delta_y); 189 event.set_wheel_delta_y(delta_y);
210 client_->input_stub()->InjectMouseEvent(event); 190 client_->input_stub()->InjectMouseEvent(event);
211 } 191 }
212 192
213 bool ChromotingJniInstance::SendKeyEvent(int scan_code, 193 bool ChromotingSession::SendKeyEvent(int scan_code,
214 int key_code, 194 int key_code,
215 bool key_down) { 195 bool key_down) {
216 // For software keyboards |scan_code| is set to 0, in which case the 196 // For software keyboards |scan_code| is set to 0, in which case the
217 // |key_code| is used instead. 197 // |key_code| is used instead.
218 uint32_t usb_key_code = 198 uint32_t usb_key_code =
219 scan_code ? ui::KeycodeConverter::NativeKeycodeToUsbKeycode(scan_code) 199 scan_code ? ui::KeycodeConverter::NativeKeycodeToUsbKeycode(scan_code)
220 : AndroidKeycodeToUsbKeycode(key_code); 200 : NativeDeviceKeycodeToUsbKeycode(key_code);
221 if (!usb_key_code) { 201 if (!usb_key_code) {
222 LOG(WARNING) << "Ignoring unknown key code: " << key_code 202 LOG(WARNING) << "Ignoring unknown key code: " << key_code
223 << " scan code: " << scan_code; 203 << " scan code: " << scan_code;
224 return false; 204 return false;
225 } 205 }
226 206
227 SendKeyEventInternal(usb_key_code, key_down); 207 SendKeyEventInternal(usb_key_code, key_down);
228 return true; 208 return true;
229 } 209 }
230 210
231 void ChromotingJniInstance::SendTextEvent(const std::string& text) { 211 void ChromotingSession::SendTextEvent(const std::string& text) {
232 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) { 212 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) {
233 runtime_->network_task_runner()->PostTask( 213 runtime_->network_task_runner()->PostTask(
234 FROM_HERE, 214 FROM_HERE,
235 base::Bind(&ChromotingJniInstance::SendTextEvent, GetWeakPtr(), text)); 215 base::Bind(&ChromotingSession::SendTextEvent, GetWeakPtr(), text));
236 return; 216 return;
237 } 217 }
238 218
239 protocol::TextEvent event; 219 protocol::TextEvent event;
240 event.set_text(text); 220 event.set_text(text);
241 client_->input_stub()->InjectTextEvent(event); 221 client_->input_stub()->InjectTextEvent(event);
242 } 222 }
243 223
244 void ChromotingJniInstance::SendTouchEvent( 224 void ChromotingSession::SendTouchEvent(
245 const protocol::TouchEvent& touch_event) { 225 const protocol::TouchEvent& touch_event) {
246 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) { 226 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) {
247 runtime_->network_task_runner()->PostTask( 227 runtime_->network_task_runner()->PostTask(
248 FROM_HERE, base::Bind(&ChromotingJniInstance::SendTouchEvent, 228 FROM_HERE, base::Bind(&ChromotingSession::SendTouchEvent, GetWeakPtr(),
249 GetWeakPtr(), touch_event)); 229 touch_event));
250 return; 230 return;
251 } 231 }
252 232
253 client_->input_stub()->InjectTouchEvent(touch_event); 233 client_->input_stub()->InjectTouchEvent(touch_event);
254 } 234 }
255 235
256 void ChromotingJniInstance::EnableVideoChannel(bool enable) { 236 void ChromotingSession::EnableVideoChannel(bool enable) {
257 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) { 237 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) {
258 runtime_->network_task_runner()->PostTask( 238 runtime_->network_task_runner()->PostTask(
259 FROM_HERE, base::Bind(&ChromotingJniInstance::EnableVideoChannel, 239 FROM_HERE, base::Bind(&ChromotingSession::EnableVideoChannel,
260 GetWeakPtr(), enable)); 240 GetWeakPtr(), enable));
261 return; 241 return;
262 } 242 }
263 243
264 protocol::VideoControl video_control; 244 protocol::VideoControl video_control;
265 video_control.set_enable(enable); 245 video_control.set_enable(enable);
266 client_->host_stub()->ControlVideo(video_control); 246 client_->host_stub()->ControlVideo(video_control);
267 } 247 }
268 248
269 void ChromotingJniInstance::SendClientMessage(const std::string& type, 249 void ChromotingSession::SendClientMessage(const std::string& type,
270 const std::string& data) { 250 const std::string& data) {
271 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) { 251 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) {
272 runtime_->network_task_runner()->PostTask( 252 runtime_->network_task_runner()->PostTask(
273 FROM_HERE, base::Bind(&ChromotingJniInstance::SendClientMessage, 253 FROM_HERE, base::Bind(&ChromotingSession::SendClientMessage,
274 GetWeakPtr(), type, data)); 254 GetWeakPtr(), type, data));
275 return; 255 return;
276 } 256 }
277 257
278 protocol::ExtensionMessage extension_message; 258 protocol::ExtensionMessage extension_message;
279 extension_message.set_type(type); 259 extension_message.set_type(type);
280 extension_message.set_data(data); 260 extension_message.set_data(data);
281 client_->host_stub()->DeliverClientMessage(extension_message); 261 client_->host_stub()->DeliverClientMessage(extension_message);
282 } 262 }
283 263
284 void ChromotingJniInstance::OnConnectionState( 264 void ChromotingSession::OnConnectionState(
285 protocol::ConnectionToHost::State state, 265 protocol::ConnectionToHost::State state,
286 protocol::ErrorCode error) { 266 protocol::ErrorCode error) {
287 DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread()); 267 DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread());
288 268
289 // This code assumes no intermediate connection state between CONNECTED and 269 // This code assumes no intermediate connection state between CONNECTED and
290 // CLOSED/FAILED. 270 // CLOSED/FAILED.
291 connected_ = state == protocol::ConnectionToHost::CONNECTED; 271 connected_ = state == protocol::ConnectionToHost::CONNECTED;
292 EnableStatsLogging(connected_); 272 EnableStatsLogging(connected_);
293 273
294 logger_->LogSessionStateChange( 274 logger_->LogSessionStateChange(ClientTelemetryLogger::TranslateState(state),
295 ClientTelemetryLogger::TranslateState(state), 275 ClientTelemetryLogger::TranslateError(error));
296 ClientTelemetryLogger::TranslateError(error));
297 276
298 if (create_pairing_ && state == protocol::ConnectionToHost::CONNECTED) { 277 if (create_pairing_ && state == protocol::ConnectionToHost::CONNECTED) {
299 protocol::PairingRequest request; 278 protocol::PairingRequest request;
300 DCHECK(!device_name_.empty()); 279 DCHECK(!device_name_.empty());
301 request.set_client_name(device_name_); 280 request.set_client_name(device_name_);
302 client_->host_stub()->RequestPairing(request); 281 client_->host_stub()->RequestPairing(request);
303 } 282 }
304 283
305 runtime_->ui_task_runner()->PostTask( 284 runtime_->ui_task_runner()->PostTask(
306 FROM_HERE, 285 FROM_HERE, base::Bind(&ChromotingSession::Delegate::OnConnectionState,
307 base::Bind(&JniClient::OnConnectionState, jni_client_, state, error)); 286 delegate_, state, error));
308 } 287 }
309 288
310 void ChromotingJniInstance::OnConnectionReady(bool ready) { 289 void ChromotingSession::OnConnectionReady(bool ready) {
311 // We ignore this message, since OnConnectionState tells us the same thing. 290 // We ignore this message, since OnConnectionState tells us the same thing.
312 } 291 }
313 292
314 void ChromotingJniInstance::OnRouteChanged( 293 void ChromotingSession::OnRouteChanged(const std::string& channel_name,
315 const std::string& channel_name, 294 const protocol::TransportRoute& route) {
316 const protocol::TransportRoute& route) {
317 std::string message = "Channel " + channel_name + " using " + 295 std::string message = "Channel " + channel_name + " using " +
318 protocol::TransportRoute::GetTypeString(route.type) + " connection."; 296 protocol::TransportRoute::GetTypeString(route.type) +
319 __android_log_print(ANDROID_LOG_INFO, "route", "%s", message.c_str()); 297 " connection.";
298 VLOG(1) << "Route: " << message.c_str();
320 } 299 }
321 300
322 void ChromotingJniInstance::SetCapabilities(const std::string& capabilities) { 301 void ChromotingSession::SetCapabilities(const std::string& capabilities) {
302 runtime_->ui_task_runner()->PostTask(
303 FROM_HERE, base::Bind(&ChromotingSession::Delegate::SetCapabilities,
304 delegate_, capabilities));
305 }
306
307 void ChromotingSession::SetPairingResponse(
308 const protocol::PairingResponse& response) {
323 runtime_->ui_task_runner()->PostTask( 309 runtime_->ui_task_runner()->PostTask(
324 FROM_HERE, 310 FROM_HERE,
325 base::Bind(&JniClient::SetCapabilities, jni_client_, capabilities)); 311 base::Bind(&ChromotingSession::Delegate::CommitPairingCredentials,
312 delegate_, client_auth_config_.host_id, response.client_id(),
313 response.shared_secret()));
326 } 314 }
327 315
328 void ChromotingJniInstance::SetPairingResponse( 316 void ChromotingSession::DeliverHostMessage(
329 const protocol::PairingResponse& response) { 317 const protocol::ExtensionMessage& message) {
330 runtime_->ui_task_runner()->PostTask( 318 runtime_->ui_task_runner()->PostTask(
331 FROM_HERE, base::Bind(&JniClient::CommitPairingCredentials, jni_client_, 319 FROM_HERE,
332 client_auth_config_.host_id, response.client_id(), 320 base::Bind(&ChromotingSession::Delegate::HandleExtensionMessage,
333 response.shared_secret())); 321 delegate_, message.type(), message.data()));
334 } 322 }
335 323
336 void ChromotingJniInstance::DeliverHostMessage( 324 void ChromotingSession::SetDesktopSize(const webrtc::DesktopSize& size,
337 const protocol::ExtensionMessage& message) { 325 const webrtc::DesktopVector& dpi) {
338 runtime_->ui_task_runner()->PostTask( 326 // ChromotingSession's VideoRenderer gets size from the frames and it doesn't
339 FROM_HERE, base::Bind(&JniClient::HandleExtensionMessage, jni_client_, 327 // use DPI, so this call can be ignored.
340 message.type(), message.data()));
341 } 328 }
342 329
343 void ChromotingJniInstance::SetDesktopSize(const webrtc::DesktopSize& size, 330 protocol::ClipboardStub* ChromotingSession::GetClipboardStub() {
344 const webrtc::DesktopVector& dpi) {
345 // JniFrameConsumer get size from the frames and it doesn't use DPI, so this
346 // call can be ignored.
347 }
348
349 protocol::ClipboardStub* ChromotingJniInstance::GetClipboardStub() {
350 return this; 331 return this;
351 } 332 }
352 333
353 protocol::CursorShapeStub* ChromotingJniInstance::GetCursorShapeStub() { 334 protocol::CursorShapeStub* ChromotingSession::GetCursorShapeStub() {
354 return cursor_shape_stub_.get(); 335 return cursor_shape_stub_.get();
355 } 336 }
356 337
357 void ChromotingJniInstance::InjectClipboardEvent( 338 void ChromotingSession::InjectClipboardEvent(
358 const protocol::ClipboardEvent& event) { 339 const protocol::ClipboardEvent& event) {
359 NOTIMPLEMENTED(); 340 NOTIMPLEMENTED();
360 } 341 }
361 342
362 base::WeakPtr<ChromotingJniInstance> ChromotingJniInstance::GetWeakPtr() { 343 base::WeakPtr<ChromotingSession> ChromotingSession::GetWeakPtr() {
363 return weak_ptr_; 344 return weak_ptr_;
364 } 345 }
365 346
366 void ChromotingJniInstance::ConnectToHostOnNetworkThread() { 347 void ChromotingSession::ConnectToHostOnNetworkThread() {
367 DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread()); 348 DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread());
368 349
369 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); 350 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop();
370 351
371 client_context_.reset(new ClientContext(runtime_->network_task_runner())); 352 client_context_.reset(new ClientContext(runtime_->network_task_runner()));
372 client_context_->Start(); 353 client_context_->Start();
373 354
374 perf_tracker_.reset(new protocol::PerformanceTracker()); 355 perf_tracker_.reset(new protocol::PerformanceTracker());
375 356
376 video_renderer_->Initialize(*client_context_, 357 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 358
383 logger_.reset(new ClientTelemetryLogger(runtime_->log_writer(), 359 logger_.reset(new ClientTelemetryLogger(runtime_->log_writer(),
384 ChromotingEvent::Mode::ME2ME)); 360 ChromotingEvent::Mode::ME2ME));
385 logger_->SetHostInfo( 361 logger_->SetHostInfo(
386 connection_info_.host_version, 362 connection_info_.host_version,
387 ChromotingEvent::ParseOsFromString(connection_info_.host_os), 363 ChromotingEvent::ParseOsFromString(connection_info_.host_os),
388 connection_info_.host_os_version); 364 connection_info_.host_os_version);
389 365
390 client_.reset(new ChromotingClient(client_context_.get(), this, 366 client_.reset(new ChromotingClient(client_context_.get(), this,
391 video_renderer_.get(), 367 video_renderer_.get(), audio_player_));
392 audio_player_->GetWeakPtr()));
393 368
394 signaling_.reset( 369 signaling_.reset(
395 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), 370 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(),
396 runtime_->url_requester(), xmpp_config_)); 371 runtime_->url_requester(), xmpp_config_));
397 372
398 scoped_refptr<protocol::TransportContext> transport_context = 373 scoped_refptr<protocol::TransportContext> transport_context =
399 new protocol::TransportContext( 374 new protocol::TransportContext(
400 signaling_.get(), 375 signaling_.get(),
401 base::MakeUnique<protocol::ChromiumPortAllocatorFactory>(), 376 base::MakeUnique<protocol::ChromiumPortAllocatorFactory>(),
402 base::MakeUnique<ChromiumUrlRequestFactory>( 377 base::MakeUnique<ChromiumUrlRequestFactory>(
403 runtime_->url_requester()), 378 runtime_->url_requester()),
404 protocol::NetworkSettings( 379 protocol::NetworkSettings(
405 protocol::NetworkSettings::NAT_TRAVERSAL_FULL), 380 protocol::NetworkSettings::NAT_TRAVERSAL_FULL),
406 protocol::TransportRole::CLIENT); 381 protocol::TransportRole::CLIENT);
407 382
408 #if defined(ENABLE_WEBRTC_REMOTING_CLIENT) 383 #if defined(ENABLE_WEBRTC_REMOTING_CLIENT)
409 if (connection_info_.flags.find("useWebrtc") != std::string::npos) { 384 if (connection_info_.flags.find("useWebrtc") != std::string::npos) {
410 VLOG(0) << "Attempting to connect using WebRTC."; 385 VLOG(0) << "Attempting to connect using WebRTC.";
411 std::unique_ptr<protocol::CandidateSessionConfig> protocol_config = 386 std::unique_ptr<protocol::CandidateSessionConfig> protocol_config =
412 protocol::CandidateSessionConfig::CreateEmpty(); 387 protocol::CandidateSessionConfig::CreateEmpty();
413 protocol_config->set_webrtc_supported(true); 388 protocol_config->set_webrtc_supported(true);
414 protocol_config->set_ice_supported(false); 389 protocol_config->set_ice_supported(false);
415 client_->set_protocol_config(std::move(protocol_config)); 390 client_->set_protocol_config(std::move(protocol_config));
416 } 391 }
417 #endif // defined(ENABLE_WEBRTC_REMOTING_CLIENT) 392 #endif // defined(ENABLE_WEBRTC_REMOTING_CLIENT)
418 client_->Start(signaling_.get(), client_auth_config_, transport_context, 393 client_->Start(signaling_.get(), client_auth_config_, transport_context,
419 connection_info_.host_jid, capabilities_); 394 connection_info_.host_jid, capabilities_);
420 } 395 }
421 396
422 void ChromotingJniInstance::SetDeviceName(const std::string& device_name) { 397 void ChromotingSession::SetDeviceName(const std::string& device_name) {
423 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) { 398 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) {
424 runtime_->network_task_runner()->PostTask( 399 runtime_->network_task_runner()->PostTask(
425 FROM_HERE, base::Bind(&ChromotingJniInstance::SetDeviceName, 400 FROM_HERE, base::Bind(&ChromotingSession::SetDeviceName, GetWeakPtr(),
426 GetWeakPtr(), device_name)); 401 device_name));
427 return; 402 return;
428 } 403 }
429 404
430 device_name_ = device_name; 405 device_name_ = device_name;
431 } 406 }
432 407
433 void ChromotingJniInstance::SendKeyEventInternal(int usb_key_code, 408 void ChromotingSession::SendKeyEventInternal(int usb_key_code, bool key_down) {
434 bool key_down) {
435 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) { 409 if (!runtime_->network_task_runner()->BelongsToCurrentThread()) {
436 runtime_->network_task_runner()->PostTask( 410 runtime_->network_task_runner()->PostTask(
437 FROM_HERE, base::Bind(&ChromotingJniInstance::SendKeyEventInternal, 411 FROM_HERE, base::Bind(&ChromotingSession::SendKeyEventInternal,
438 GetWeakPtr(), usb_key_code, key_down)); 412 GetWeakPtr(), usb_key_code, key_down));
439 return; 413 return;
440 } 414 }
441 415
442 protocol::KeyEvent event; 416 protocol::KeyEvent event;
443 event.set_usb_keycode(usb_key_code); 417 event.set_usb_keycode(usb_key_code);
444 event.set_pressed(key_down); 418 event.set_pressed(key_down);
445 client_->input_stub()->InjectKeyEvent(event); 419 client_->input_stub()->InjectKeyEvent(event);
446 } 420 }
447 421
448 void ChromotingJniInstance::EnableStatsLogging(bool enabled) { 422 void ChromotingSession::EnableStatsLogging(bool enabled) {
449 DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread()); 423 DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread());
450 424
451 if (enabled && !stats_logging_enabled_) { 425 if (enabled && !stats_logging_enabled_) {
452 runtime_->network_task_runner()->PostDelayedTask( 426 runtime_->network_task_runner()->PostDelayedTask(
453 FROM_HERE, 427 FROM_HERE, base::Bind(&ChromotingSession::LogPerfStats, GetWeakPtr()),
454 base::Bind(&ChromotingJniInstance::LogPerfStats, GetWeakPtr()),
455 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); 428 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs));
456 } 429 }
457 stats_logging_enabled_ = enabled; 430 stats_logging_enabled_ = enabled;
458 } 431 }
459 432
460 void ChromotingJniInstance::LogPerfStats() { 433 void ChromotingSession::LogPerfStats() {
461 DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread()); 434 DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread());
462 435
463 if (!stats_logging_enabled_) 436 if (!stats_logging_enabled_)
464 return; 437 return;
465 438
466 __android_log_print( 439 // TODO(nicholss): When this was JNI only logging to android was possible.
467 ANDROID_LOG_INFO, "stats", 440 // But now the component is shared, we could IFDEF for android here if this
468 "Bandwidth:%.0f FrameRate:%.1f;" 441 // log is useful to be logged to a users device.
469 " (Avg, Max) Capture:%.1f, %" PRId64 " Encode:%.1f, %" PRId64 442 // __android_log_print(
470 " Decode:%.1f, %" PRId64 " Render:%.1f, %" PRId64 " RTL:%.0f, %" PRId64, 443 // ANDROID_LOG_INFO, "stats",
471 perf_tracker_->video_bandwidth(), perf_tracker_->video_frame_rate(), 444 // "Bandwidth:%.0f FrameRate:%.1f;"
472 perf_tracker_->video_capture_ms().Average(), 445 // " (Avg, Max) Capture:%.1f, %" PRId64 " Encode:%.1f, %" PRId64
473 perf_tracker_->video_capture_ms().Max(), 446 // " Decode:%.1f, %" PRId64 " Render:%.1f, %" PRId64 " RTL:%.0f, %"
474 perf_tracker_->video_encode_ms().Average(), 447 // PRId64, perf_tracker_->video_bandwidth(),
475 perf_tracker_->video_encode_ms().Max(), 448 // perf_tracker_->video_frame_rate(),
476 perf_tracker_->video_decode_ms().Average(), 449 // perf_tracker_->video_capture_ms().Average(),
477 perf_tracker_->video_decode_ms().Max(), 450 // perf_tracker_->video_capture_ms().Max(),
478 perf_tracker_->video_paint_ms().Average(), 451 // perf_tracker_->video_encode_ms().Average(),
479 perf_tracker_->video_paint_ms().Max(), 452 // perf_tracker_->video_encode_ms().Max(),
480 perf_tracker_->round_trip_ms().Average(), 453 // perf_tracker_->video_decode_ms().Average(),
481 perf_tracker_->round_trip_ms().Max()); 454 // perf_tracker_->video_decode_ms().Max(),
455 // perf_tracker_->video_paint_ms().Average(),
456 // perf_tracker_->video_paint_ms().Max(),
457 // perf_tracker_->round_trip_ms().Average(),
458 // perf_tracker_->round_trip_ms().Max());
482 459
483 logger_->LogStatistics(perf_tracker_.get()); 460 logger_->LogStatistics(perf_tracker_.get());
484 461
485 runtime_->network_task_runner()->PostDelayedTask( 462 runtime_->network_task_runner()->PostDelayedTask(
486 FROM_HERE, base::Bind(&ChromotingJniInstance::LogPerfStats, GetWeakPtr()), 463 FROM_HERE, base::Bind(&ChromotingSession::LogPerfStats, GetWeakPtr()),
487 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); 464 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs));
488 } 465 }
489 466
490 void ChromotingJniInstance::ReleaseResources() { 467 void ChromotingSession::ReleaseResources() {
491 logger_.reset(); 468 logger_.reset();
492 469
493 // |client_| must be torn down before |signaling_|. 470 // |client_| must be torn down before |signaling_|.
494 client_.reset(); 471 client_.reset();
472 delegate_.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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698