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

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

Powered by Google App Engine
This is Rietveld 408576698