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

Side by Side Diff: remoting/client/jni/chromoting_jni_instance.cc

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

Powered by Google App Engine
This is Rietveld 408576698