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

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

Issue 2007403002: [Android Client] Move session-scoped native interface into JniClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DisconnectFromHost when destroy Created 4 years, 7 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 <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback_helpers.h" 13 #include "base/callback_helpers.h"
14 #include "base/format_macros.h" 14 #include "base/format_macros.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "jingle/glue/thread_wrapper.h" 17 #include "jingle/glue/thread_wrapper.h"
18 #include "net/socket/client_socket_factory.h" 18 #include "net/socket/client_socket_factory.h"
19 #include "remoting/base/chromium_url_request.h" 19 #include "remoting/base/chromium_url_request.h"
20 #include "remoting/client/audio_player_android.h" 20 #include "remoting/client/audio_player_android.h"
21 #include "remoting/client/client_telemetry_logger.h" 21 #include "remoting/client/client_telemetry_logger.h"
22 #include "remoting/client/jni/android_keymap.h" 22 #include "remoting/client/jni/android_keymap.h"
23 #include "remoting/client/jni/chromoting_jni_runtime.h" 23 #include "remoting/client/jni/chromoting_jni_runtime.h"
24 #include "remoting/client/jni/jni_client.h"
24 #include "remoting/client/jni/jni_frame_consumer.h" 25 #include "remoting/client/jni/jni_frame_consumer.h"
25 #include "remoting/client/software_video_renderer.h" 26 #include "remoting/client/software_video_renderer.h"
26 #include "remoting/protocol/chromium_port_allocator_factory.h" 27 #include "remoting/protocol/chromium_port_allocator_factory.h"
27 #include "remoting/protocol/chromium_socket_factory.h" 28 #include "remoting/protocol/chromium_socket_factory.h"
28 #include "remoting/protocol/client_authentication_config.h" 29 #include "remoting/protocol/client_authentication_config.h"
29 #include "remoting/protocol/host_stub.h" 30 #include "remoting/protocol/host_stub.h"
30 #include "remoting/protocol/network_settings.h" 31 #include "remoting/protocol/network_settings.h"
31 #include "remoting/protocol/performance_tracker.h" 32 #include "remoting/protocol/performance_tracker.h"
32 #include "remoting/protocol/transport_context.h" 33 #include "remoting/protocol/transport_context.h"
33 #include "remoting/signaling/server_log_entry.h" 34 #include "remoting/signaling/server_log_entry.h"
34 #include "ui/events/keycodes/dom/keycode_converter.h" 35 #include "ui/events/keycodes/dom/keycode_converter.h"
35 36
36 namespace remoting { 37 namespace remoting {
37 38
38 namespace { 39 namespace {
39 40
40 // TODO(solb) Move into location shared with client plugin. 41 // TODO(solb) Move into location shared with client plugin.
41 const char* const kXmppServer = "talk.google.com"; 42 const char* const kXmppServer = "talk.google.com";
42 const int kXmppPort = 5222; 43 const int kXmppPort = 5222;
43 const bool kXmppUseTls = true; 44 const bool kXmppUseTls = true;
44 45
45 // Interval at which to log performance statistics, if enabled. 46 // Interval at which to log performance statistics, if enabled.
46 const int kPerfStatsIntervalMs = 60000; 47 const int kPerfStatsIntervalMs = 60000;
47 48
48 } 49 }
49 50
50 ChromotingJniInstance::ChromotingJniInstance(ChromotingJniRuntime* jni_runtime, 51 ChromotingJniInstance::ChromotingJniInstance(ChromotingJniRuntime* jni_runtime,
52 JniClient* jni_client,
51 const std::string& username, 53 const std::string& username,
52 const std::string& auth_token, 54 const std::string& auth_token,
53 const std::string& host_jid, 55 const std::string& host_jid,
54 const std::string& host_id, 56 const std::string& host_id,
55 const std::string& host_pubkey, 57 const std::string& host_pubkey,
56 const std::string& pairing_id, 58 const std::string& pairing_id,
57 const std::string& pairing_secret, 59 const std::string& pairing_secret,
58 const std::string& capabilities, 60 const std::string& capabilities,
59 const std::string& flags) 61 const std::string& flags)
60 : jni_runtime_(jni_runtime), 62 : jni_runtime_(jni_runtime),
63 jni_client_(jni_client),
61 host_jid_(host_jid), 64 host_jid_(host_jid),
62 flags_(flags), 65 flags_(flags),
63 capabilities_(capabilities), 66 capabilities_(capabilities),
64 weak_factory_(this) { 67 weak_factory_(this) {
65 DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread()); 68 DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread());
66 69
67 // Initialize XMPP config. 70 // Initialize XMPP config.
68 xmpp_config_.host = kXmppServer; 71 xmpp_config_.host = kXmppServer;
69 xmpp_config_.port = kXmppPort; 72 xmpp_config_.port = kXmppPort;
70 xmpp_config_.use_tls = kXmppUseTls; 73 xmpp_config_.use_tls = kXmppUseTls;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 const protocol::ThirdPartyTokenFetchedCallback& token_fetched_callback) { 138 const protocol::ThirdPartyTokenFetchedCallback& token_fetched_callback) {
136 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); 139 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread());
137 DCHECK(third_party_token_fetched_callback_.is_null()); 140 DCHECK(third_party_token_fetched_callback_.is_null());
138 141
139 __android_log_print(ANDROID_LOG_INFO, 142 __android_log_print(ANDROID_LOG_INFO,
140 "ThirdPartyAuth", 143 "ThirdPartyAuth",
141 "Fetching Third Party Token from user."); 144 "Fetching Third Party Token from user.");
142 145
143 third_party_token_fetched_callback_ = token_fetched_callback; 146 third_party_token_fetched_callback_ = token_fetched_callback;
144 jni_runtime_->ui_task_runner()->PostTask( 147 jni_runtime_->ui_task_runner()->PostTask(
145 FROM_HERE, base::Bind(&ChromotingJniRuntime::FetchThirdPartyToken, 148 FROM_HERE, base::Bind(&JniClient::FetchThirdPartyToken,
146 base::Unretained(jni_runtime_), token_url, 149 jni_client_->GetWeakPtr(), token_url,
147 host_public_key, scope)); 150 host_public_key, scope));
148 } 151 }
149 152
150 void ChromotingJniInstance::HandleOnThirdPartyTokenFetched( 153 void ChromotingJniInstance::HandleOnThirdPartyTokenFetched(
151 const std::string& token, 154 const std::string& token,
152 const std::string& shared_secret) { 155 const std::string& shared_secret) {
153 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); 156 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread());
154 157
155 __android_log_print( 158 __android_log_print(
156 ANDROID_LOG_INFO, "ThirdPartyAuth", "Third Party Token Fetched."); 159 ANDROID_LOG_INFO, "ThirdPartyAuth", "Third Party Token Fetched.");
(...skipping 25 matching lines...) Expand all
182 } 185 }
183 186
184 void ChromotingJniInstance::RedrawDesktop() { 187 void ChromotingJniInstance::RedrawDesktop() {
185 if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) { 188 if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) {
186 jni_runtime_->display_task_runner()->PostTask( 189 jni_runtime_->display_task_runner()->PostTask(
187 FROM_HERE, 190 FROM_HERE,
188 base::Bind(&ChromotingJniInstance::RedrawDesktop, this)); 191 base::Bind(&ChromotingJniInstance::RedrawDesktop, this));
189 return; 192 return;
190 } 193 }
191 194
192 jni_runtime_->RedrawCanvas(); 195 jni_client_->RedrawCanvas();
193 } 196 }
194 197
195 void ChromotingJniInstance::SendMouseEvent( 198 void ChromotingJniInstance::SendMouseEvent(
196 int x, int y, 199 int x, int y,
197 protocol::MouseEvent_MouseButton button, 200 protocol::MouseEvent_MouseButton button,
198 bool button_down) { 201 bool button_down) {
199 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { 202 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) {
200 jni_runtime_->network_task_runner()->PostTask( 203 jni_runtime_->network_task_runner()->PostTask(
201 FROM_HERE, base::Bind(&ChromotingJniInstance::SendMouseEvent, 204 FROM_HERE, base::Bind(&ChromotingJniInstance::SendMouseEvent,
202 this, x, y, button, button_down)); 205 this, x, y, button, button_down));
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 319
317 if (create_pairing_ && state == protocol::ConnectionToHost::CONNECTED) { 320 if (create_pairing_ && state == protocol::ConnectionToHost::CONNECTED) {
318 protocol::PairingRequest request; 321 protocol::PairingRequest request;
319 DCHECK(!device_name_.empty()); 322 DCHECK(!device_name_.empty());
320 request.set_client_name(device_name_); 323 request.set_client_name(device_name_);
321 client_->host_stub()->RequestPairing(request); 324 client_->host_stub()->RequestPairing(request);
322 } 325 }
323 326
324 jni_runtime_->ui_task_runner()->PostTask( 327 jni_runtime_->ui_task_runner()->PostTask(
325 FROM_HERE, 328 FROM_HERE,
326 base::Bind(&ChromotingJniRuntime::OnConnectionState, 329 base::Bind(&JniClient::OnConnectionState,
327 base::Unretained(jni_runtime_), 330 jni_client_->GetWeakPtr(),
328 state, 331 state,
329 error)); 332 error));
330 } 333 }
331 334
332 void ChromotingJniInstance::OnConnectionReady(bool ready) { 335 void ChromotingJniInstance::OnConnectionReady(bool ready) {
333 // We ignore this message, since OnConnectionState tells us the same thing. 336 // We ignore this message, since OnConnectionState tells us the same thing.
334 } 337 }
335 338
336 void ChromotingJniInstance::OnRouteChanged( 339 void ChromotingJniInstance::OnRouteChanged(
337 const std::string& channel_name, 340 const std::string& channel_name,
338 const protocol::TransportRoute& route) { 341 const protocol::TransportRoute& route) {
339 std::string message = "Channel " + channel_name + " using " + 342 std::string message = "Channel " + channel_name + " using " +
340 protocol::TransportRoute::GetTypeString(route.type) + " connection."; 343 protocol::TransportRoute::GetTypeString(route.type) + " connection.";
341 __android_log_print(ANDROID_LOG_INFO, "route", "%s", message.c_str()); 344 __android_log_print(ANDROID_LOG_INFO, "route", "%s", message.c_str());
342 } 345 }
343 346
344 void ChromotingJniInstance::SetCapabilities(const std::string& capabilities) { 347 void ChromotingJniInstance::SetCapabilities(const std::string& capabilities) {
345 jni_runtime_->ui_task_runner()->PostTask( 348 jni_runtime_->ui_task_runner()->PostTask(
346 FROM_HERE, base::Bind(&ChromotingJniRuntime::SetCapabilities, 349 FROM_HERE, base::Bind(&JniClient::SetCapabilities,
347 base::Unretained(jni_runtime_), capabilities)); 350 jni_client_->GetWeakPtr(), capabilities));
348 } 351 }
349 352
350 void ChromotingJniInstance::SetPairingResponse( 353 void ChromotingJniInstance::SetPairingResponse(
351 const protocol::PairingResponse& response) { 354 const protocol::PairingResponse& response) {
352 jni_runtime_->ui_task_runner()->PostTask( 355 jni_runtime_->ui_task_runner()->PostTask(
353 FROM_HERE, 356 FROM_HERE,
354 base::Bind(&ChromotingJniRuntime::CommitPairingCredentials, 357 base::Bind(&JniClient::CommitPairingCredentials,
355 base::Unretained(jni_runtime_), client_auth_config_.host_id, 358 jni_client_->GetWeakPtr(), client_auth_config_.host_id,
356 response.client_id(), response.shared_secret())); 359 response.client_id(), response.shared_secret()));
357 } 360 }
358 361
359 void ChromotingJniInstance::DeliverHostMessage( 362 void ChromotingJniInstance::DeliverHostMessage(
360 const protocol::ExtensionMessage& message) { 363 const protocol::ExtensionMessage& message) {
361 jni_runtime_->ui_task_runner()->PostTask( 364 jni_runtime_->ui_task_runner()->PostTask(
362 FROM_HERE, base::Bind(&ChromotingJniRuntime::HandleExtensionMessage, 365 FROM_HERE, base::Bind(&JniClient::HandleExtensionMessage,
363 base::Unretained(jni_runtime_), message.type(), 366 jni_client_->GetWeakPtr(), message.type(),
364 message.data())); 367 message.data()));
365 } 368 }
366 369
367 void ChromotingJniInstance::SetDesktopSize(const webrtc::DesktopSize& size, 370 void ChromotingJniInstance::SetDesktopSize(const webrtc::DesktopSize& size,
368 const webrtc::DesktopVector& dpi) { 371 const webrtc::DesktopVector& dpi) {
369 // JniFrameConsumer get size from the frames and it doesn't use DPI, so this 372 // JniFrameConsumer get size from the frames and it doesn't use DPI, so this
370 // call can be ignored. 373 // call can be ignored.
371 } 374 }
372 375
373 protocol::ClipboardStub* ChromotingJniInstance::GetClipboardStub() { 376 protocol::ClipboardStub* ChromotingJniInstance::GetClipboardStub() {
(...skipping 11 matching lines...) Expand all
385 388
386 void ChromotingJniInstance::SetCursorShape( 389 void ChromotingJniInstance::SetCursorShape(
387 const protocol::CursorShapeInfo& shape) { 390 const protocol::CursorShapeInfo& shape) {
388 if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) { 391 if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) {
389 jni_runtime_->display_task_runner()->PostTask( 392 jni_runtime_->display_task_runner()->PostTask(
390 FROM_HERE, 393 FROM_HERE,
391 base::Bind(&ChromotingJniInstance::SetCursorShape, this, shape)); 394 base::Bind(&ChromotingJniInstance::SetCursorShape, this, shape));
392 return; 395 return;
393 } 396 }
394 397
395 jni_runtime_->UpdateCursorShape(shape); 398 jni_client_->UpdateCursorShape(shape);
396 } 399 }
397 400
398 void ChromotingJniInstance::ConnectToHostOnNetworkThread() { 401 void ChromotingJniInstance::ConnectToHostOnNetworkThread() {
399 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); 402 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread());
400 403
401 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); 404 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop();
402 405
403 client_context_.reset(new ClientContext(jni_runtime_->network_task_runner())); 406 client_context_.reset(new ClientContext(jni_runtime_->network_task_runner()));
404 client_context_->Start(); 407 client_context_->Start();
405 408
406 perf_tracker_.reset(new protocol::PerformanceTracker()); 409 perf_tracker_.reset(new protocol::PerformanceTracker());
407 410
408 view_.reset(new JniFrameConsumer(jni_runtime_)); 411 view_.reset(new JniFrameConsumer(jni_runtime_, jni_client_));
409 video_renderer_.reset(new SoftwareVideoRenderer( 412 video_renderer_.reset(new SoftwareVideoRenderer(
410 client_context_->decode_task_runner(), view_.get(), perf_tracker_.get())); 413 client_context_->decode_task_runner(), view_.get(), perf_tracker_.get()));
411 414
412 client_.reset( 415 client_.reset(
413 new ChromotingClient(client_context_.get(), this, video_renderer_.get(), 416 new ChromotingClient(client_context_.get(), this, video_renderer_.get(),
414 base::WrapUnique(new AudioPlayerAndroid()))); 417 base::WrapUnique(new AudioPlayerAndroid())));
415 418
416 signaling_.reset( 419 signaling_.reset(
417 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), 420 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(),
418 jni_runtime_->url_requester(), xmpp_config_)); 421 jni_runtime_->url_requester(), xmpp_config_));
(...skipping 26 matching lines...) Expand all
445 bool pairable, 448 bool pairable,
446 const protocol::SecretFetchedCallback& callback) { 449 const protocol::SecretFetchedCallback& callback) {
447 if (!jni_runtime_->ui_task_runner()->BelongsToCurrentThread()) { 450 if (!jni_runtime_->ui_task_runner()->BelongsToCurrentThread()) {
448 jni_runtime_->ui_task_runner()->PostTask( 451 jni_runtime_->ui_task_runner()->PostTask(
449 FROM_HERE, base::Bind(&ChromotingJniInstance::FetchSecret, 452 FROM_HERE, base::Bind(&ChromotingJniInstance::FetchSecret,
450 this, pairable, callback)); 453 this, pairable, callback));
451 return; 454 return;
452 } 455 }
453 456
454 // Delete pairing credentials if they exist. 457 // Delete pairing credentials if they exist.
455 jni_runtime_->CommitPairingCredentials(client_auth_config_.host_id, "", ""); 458 jni_client_->CommitPairingCredentials(client_auth_config_.host_id, "", "");
456 459
457 pin_callback_ = callback; 460 pin_callback_ = callback;
458 jni_runtime_->DisplayAuthenticationPrompt(pairable); 461 jni_client_->DisplayAuthenticationPrompt(pairable);
459 } 462 }
460 463
461 void ChromotingJniInstance::SetDeviceName(const std::string& device_name) { 464 void ChromotingJniInstance::SetDeviceName(const std::string& device_name) {
462 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { 465 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) {
463 jni_runtime_->network_task_runner()->PostTask( 466 jni_runtime_->network_task_runner()->PostTask(
464 FROM_HERE, base::Bind(&ChromotingJniInstance::SetDeviceName, this, 467 FROM_HERE, base::Bind(&ChromotingJniInstance::SetDeviceName, this,
465 device_name)); 468 device_name));
466 return; 469 return;
467 } 470 }
468 471
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 perf_tracker_->round_trip_ms().Max()); 522 perf_tracker_->round_trip_ms().Max());
520 523
521 jni_runtime_->logger()->LogStatistics(perf_tracker_.get()); 524 jni_runtime_->logger()->LogStatistics(perf_tracker_.get());
522 525
523 jni_runtime_->network_task_runner()->PostDelayedTask( 526 jni_runtime_->network_task_runner()->PostDelayedTask(
524 FROM_HERE, base::Bind(&ChromotingJniInstance::LogPerfStats, this), 527 FROM_HERE, base::Bind(&ChromotingJniInstance::LogPerfStats, this),
525 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); 528 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs));
526 } 529 }
527 530
528 } // namespace remoting 531 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698