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

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

Issue 1788943002: Revert of Move NegotiatingClientAuthentication creation to ChromotingClient. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 <utility> 10 #include <utility>
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 const std::string& username, 50 const std::string& username,
51 const std::string& auth_token, 51 const std::string& auth_token,
52 const std::string& host_jid, 52 const std::string& host_jid,
53 const std::string& host_id, 53 const std::string& host_id,
54 const std::string& host_pubkey, 54 const std::string& host_pubkey,
55 const std::string& pairing_id, 55 const std::string& pairing_id,
56 const std::string& pairing_secret, 56 const std::string& pairing_secret,
57 const std::string& capabilities, 57 const std::string& capabilities,
58 const std::string& flags) 58 const std::string& flags)
59 : jni_runtime_(jni_runtime), 59 : jni_runtime_(jni_runtime),
60 host_id_(host_id),
60 host_jid_(host_jid), 61 host_jid_(host_jid),
61 flags_(flags), 62 flags_(flags),
63 create_pairing_(false),
64 stats_logging_enabled_(false),
62 capabilities_(capabilities), 65 capabilities_(capabilities),
63 weak_factory_(this) { 66 weak_factory_(this) {
64 DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread()); 67 DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread());
65 68
66 // Initialize XMPP config. 69 // Initialize XMPP config.
67 xmpp_config_.host = kXmppServer; 70 xmpp_config_.host = kXmppServer;
68 xmpp_config_.port = kXmppPort; 71 xmpp_config_.port = kXmppPort;
69 xmpp_config_.use_tls = kXmppUseTls; 72 xmpp_config_.use_tls = kXmppUseTls;
70 xmpp_config_.username = username; 73 xmpp_config_.username = username;
71 xmpp_config_.auth_token = auth_token; 74 xmpp_config_.auth_token = auth_token;
72 75
73 client_auth_config_.host_id = host_id; 76 // Initialize |authenticator_|.
74 client_auth_config_.pairing_client_id = pairing_id; 77 authenticator_.reset(new protocol::NegotiatingClientAuthenticator(
75 client_auth_config_.pairing_secret = pairing_secret; 78 pairing_id, pairing_secret, host_id_,
76 client_auth_config_.fetch_secret_callback = base::Bind( 79 base::Bind(&ChromotingJniInstance::FetchSecret,
77 &ChromotingJniInstance::FetchSecret, weak_factory_.GetWeakPtr()); 80 weak_factory_.GetWeakPtr()),
78 client_auth_config_.fetch_third_party_token_callback =
79 base::Bind(&ChromotingJniInstance::FetchThirdPartyToken, 81 base::Bind(&ChromotingJniInstance::FetchThirdPartyToken,
80 weak_factory_.GetWeakPtr(), host_pubkey); 82 weak_factory_.GetWeakPtr(), host_pubkey)));
81 83
82 // Post a task to start connection 84 // Post a task to start connection
83 jni_runtime_->network_task_runner()->PostTask( 85 jni_runtime_->network_task_runner()->PostTask(
84 FROM_HERE, 86 FROM_HERE,
85 base::Bind(&ChromotingJniInstance::ConnectToHostOnNetworkThread, this)); 87 base::Bind(&ChromotingJniInstance::ConnectToHostOnNetworkThread, this));
86 } 88 }
87 89
88 ChromotingJniInstance::~ChromotingJniInstance() { 90 ChromotingJniInstance::~ChromotingJniInstance() {
89 // This object is ref-counted, so this dtor can execute on any thread. 91 // This object is ref-counted, so this dtor can execute on any thread.
90 // Ensure that all these objects have been freed already, so they are not 92 // Ensure that all these objects have been freed already, so they are not
91 // destroyed on some random thread. 93 // destroyed on some random thread.
92 DCHECK(!view_); 94 DCHECK(!view_);
93 DCHECK(!client_context_); 95 DCHECK(!client_context_);
94 DCHECK(!video_renderer_); 96 DCHECK(!video_renderer_);
97 DCHECK(!authenticator_);
95 DCHECK(!client_); 98 DCHECK(!client_);
96 DCHECK(!signaling_); 99 DCHECK(!signaling_);
97 DCHECK(!client_status_logger_); 100 DCHECK(!client_status_logger_);
98 } 101 }
99 102
100 void ChromotingJniInstance::Disconnect() { 103 void ChromotingJniInstance::Disconnect() {
101 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { 104 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) {
102 jni_runtime_->network_task_runner()->PostTask( 105 jni_runtime_->network_task_runner()->PostTask(
103 FROM_HERE, 106 FROM_HERE,
104 base::Bind(&ChromotingJniInstance::Disconnect, this)); 107 base::Bind(&ChromotingJniInstance::Disconnect, this));
105 return; 108 return;
106 } 109 }
107 110
111 host_id_.clear();
112
108 stats_logging_enabled_ = false; 113 stats_logging_enabled_ = false;
109 114
110 // |client_| must be torn down before |signaling_|. 115 // |client_| must be torn down before |signaling_|.
111 client_.reset(); 116 client_.reset();
112 client_status_logger_.reset(); 117 client_status_logger_.reset();
113 video_renderer_.reset(); 118 video_renderer_.reset();
114 view_.reset(); 119 view_.reset();
120 authenticator_.reset();
115 signaling_.reset(); 121 signaling_.reset();
116 perf_tracker_.reset(); 122 perf_tracker_.reset();
117 client_context_.reset(); 123 client_context_.reset();
118 } 124 }
119 125
120 void ChromotingJniInstance::FetchThirdPartyToken( 126 void ChromotingJniInstance::FetchThirdPartyToken(
121 const std::string& host_public_key, 127 const std::string& host_public_key,
122 const std::string& token_url, 128 const std::string& token_url,
123 const std::string& scope, 129 const std::string& scope,
124 const protocol::ThirdPartyTokenFetchedCallback& token_fetched_callback) { 130 const protocol::ThirdPartyTokenFetchedCallback& token_fetched_callback) {
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 void ChromotingJniInstance::OnRouteChanged( 326 void ChromotingJniInstance::OnRouteChanged(
321 const std::string& channel_name, 327 const std::string& channel_name,
322 const protocol::TransportRoute& route) { 328 const protocol::TransportRoute& route) {
323 std::string message = "Channel " + channel_name + " using " + 329 std::string message = "Channel " + channel_name + " using " +
324 protocol::TransportRoute::GetTypeString(route.type) + " connection."; 330 protocol::TransportRoute::GetTypeString(route.type) + " connection.";
325 __android_log_print(ANDROID_LOG_INFO, "route", "%s", message.c_str()); 331 __android_log_print(ANDROID_LOG_INFO, "route", "%s", message.c_str());
326 } 332 }
327 333
328 void ChromotingJniInstance::SetCapabilities(const std::string& capabilities) { 334 void ChromotingJniInstance::SetCapabilities(const std::string& capabilities) {
329 jni_runtime_->ui_task_runner()->PostTask( 335 jni_runtime_->ui_task_runner()->PostTask(
330 FROM_HERE, base::Bind(&ChromotingJniRuntime::SetCapabilities, 336 FROM_HERE,
331 base::Unretained(jni_runtime_), capabilities)); 337 base::Bind(&ChromotingJniRuntime::SetCapabilities,
338 base::Unretained(jni_runtime_),
339 capabilities));
332 } 340 }
333 341
334 void ChromotingJniInstance::SetPairingResponse( 342 void ChromotingJniInstance::SetPairingResponse(
335 const protocol::PairingResponse& response) { 343 const protocol::PairingResponse& response) {
344
336 jni_runtime_->ui_task_runner()->PostTask( 345 jni_runtime_->ui_task_runner()->PostTask(
337 FROM_HERE, 346 FROM_HERE,
338 base::Bind(&ChromotingJniRuntime::CommitPairingCredentials, 347 base::Bind(&ChromotingJniRuntime::CommitPairingCredentials,
339 base::Unretained(jni_runtime_), client_auth_config_.host_id, 348 base::Unretained(jni_runtime_),
340 response.client_id(), response.shared_secret())); 349 host_id_, response.client_id(), response.shared_secret()));
341 } 350 }
342 351
343 void ChromotingJniInstance::DeliverHostMessage( 352 void ChromotingJniInstance::DeliverHostMessage(
344 const protocol::ExtensionMessage& message) { 353 const protocol::ExtensionMessage& message) {
345 jni_runtime_->ui_task_runner()->PostTask( 354 jni_runtime_->ui_task_runner()->PostTask(
346 FROM_HERE, base::Bind(&ChromotingJniRuntime::HandleExtensionMessage, 355 FROM_HERE,
347 base::Unretained(jni_runtime_), message.type(), 356 base::Bind(&ChromotingJniRuntime::HandleExtensionMessage,
348 message.data())); 357 base::Unretained(jni_runtime_),
358 message.type(),
359 message.data()));
349 } 360 }
350 361
351 protocol::ClipboardStub* ChromotingJniInstance::GetClipboardStub() { 362 protocol::ClipboardStub* ChromotingJniInstance::GetClipboardStub() {
352 return this; 363 return this;
353 } 364 }
354 365
355 protocol::CursorShapeStub* ChromotingJniInstance::GetCursorShapeStub() { 366 protocol::CursorShapeStub* ChromotingJniInstance::GetCursorShapeStub() {
356 return this; 367 return this;
357 } 368 }
358 369
(...skipping 21 matching lines...) Expand all
380 391
381 client_context_.reset(new ClientContext(jni_runtime_->network_task_runner())); 392 client_context_.reset(new ClientContext(jni_runtime_->network_task_runner()));
382 client_context_->Start(); 393 client_context_->Start();
383 394
384 perf_tracker_.reset(new protocol::PerformanceTracker()); 395 perf_tracker_.reset(new protocol::PerformanceTracker());
385 396
386 view_.reset(new JniFrameConsumer(jni_runtime_)); 397 view_.reset(new JniFrameConsumer(jni_runtime_));
387 video_renderer_.reset(new SoftwareVideoRenderer( 398 video_renderer_.reset(new SoftwareVideoRenderer(
388 client_context_->decode_task_runner(), view_.get(), perf_tracker_.get())); 399 client_context_->decode_task_runner(), view_.get(), perf_tracker_.get()));
389 400
390 client_.reset(new ChromotingClient(client_context_.get(), this, 401 client_.reset(new ChromotingClient(
391 video_renderer_.get(), nullptr)); 402 client_context_.get(), this, video_renderer_.get(), nullptr));
392 403
393 signaling_.reset( 404 signaling_.reset(new XmppSignalStrategy(
394 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), 405 net::ClientSocketFactory::GetDefaultFactory(),
395 jni_runtime_->url_requester(), xmpp_config_)); 406 jni_runtime_->url_requester(), xmpp_config_));
396 407
397 client_status_logger_.reset( 408 client_status_logger_.reset(
398 new ClientStatusLogger(ServerLogEntry::ME2ME, signaling_.get(), 409 new ClientStatusLogger(ServerLogEntry::ME2ME,
410 signaling_.get(),
399 ServiceUrls::GetInstance()->directory_bot_jid())); 411 ServiceUrls::GetInstance()->directory_bot_jid()));
400 412
401 scoped_refptr<protocol::TransportContext> transport_context = 413 scoped_refptr<protocol::TransportContext> transport_context =
402 new protocol::TransportContext( 414 new protocol::TransportContext(
403 signaling_.get(), 415 signaling_.get(),
404 make_scoped_ptr(new protocol::ChromiumPortAllocatorFactory()), 416 make_scoped_ptr(new protocol::ChromiumPortAllocatorFactory()),
405 make_scoped_ptr( 417 make_scoped_ptr(
406 new ChromiumUrlRequestFactory(jni_runtime_->url_requester())), 418 new ChromiumUrlRequestFactory(jni_runtime_->url_requester())),
407 protocol::NetworkSettings( 419 protocol::NetworkSettings(
408 protocol::NetworkSettings::NAT_TRAVERSAL_FULL), 420 protocol::NetworkSettings::NAT_TRAVERSAL_FULL),
409 protocol::TransportRole::CLIENT); 421 protocol::TransportRole::CLIENT);
410 422
411 if (flags_.find("useWebrtc") != std::string::npos) { 423 if (flags_.find("useWebrtc") != std::string::npos) {
412 VLOG(0) << "Attempting to connect using WebRTC."; 424 VLOG(0) << "Attempting to connect using WebRTC.";
413 scoped_ptr<protocol::CandidateSessionConfig> protocol_config = 425 scoped_ptr<protocol::CandidateSessionConfig> protocol_config =
414 protocol::CandidateSessionConfig::CreateEmpty(); 426 protocol::CandidateSessionConfig::CreateEmpty();
415 protocol_config->set_webrtc_supported(true); 427 protocol_config->set_webrtc_supported(true);
416 protocol_config->set_ice_supported(false); 428 protocol_config->set_ice_supported(false);
417 client_->set_protocol_config(std::move(protocol_config)); 429 client_->set_protocol_config(std::move(protocol_config));
418 } 430 }
419 431
420 client_->Start(signaling_.get(), client_auth_config_, transport_context, 432 client_->Start(signaling_.get(), std::move(authenticator_), transport_context,
421 host_jid_, capabilities_); 433 host_jid_, capabilities_);
422 } 434 }
423 435
424 void ChromotingJniInstance::FetchSecret( 436 void ChromotingJniInstance::FetchSecret(
425 bool pairable, 437 bool pairable,
426 const protocol::SecretFetchedCallback& callback) { 438 const protocol::SecretFetchedCallback& callback) {
427 if (!jni_runtime_->ui_task_runner()->BelongsToCurrentThread()) { 439 if (!jni_runtime_->ui_task_runner()->BelongsToCurrentThread()) {
428 jni_runtime_->ui_task_runner()->PostTask( 440 jni_runtime_->ui_task_runner()->PostTask(
429 FROM_HERE, base::Bind(&ChromotingJniInstance::FetchSecret, 441 FROM_HERE, base::Bind(&ChromotingJniInstance::FetchSecret,
430 this, pairable, callback)); 442 this, pairable, callback));
431 return; 443 return;
432 } 444 }
433 445
434 // Delete pairing credentials if they exist. 446 // Delete pairing credentials if they exist.
435 jni_runtime_->CommitPairingCredentials(client_auth_config_.host_id, "", ""); 447 jni_runtime_->CommitPairingCredentials(host_id_, "", "");
436 448
437 pin_callback_ = callback; 449 pin_callback_ = callback;
438 jni_runtime_->DisplayAuthenticationPrompt(pairable); 450 jni_runtime_->DisplayAuthenticationPrompt(pairable);
439 } 451 }
440 452
441 void ChromotingJniInstance::SetDeviceName(const std::string& device_name) { 453 void ChromotingJniInstance::SetDeviceName(const std::string& device_name) {
442 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { 454 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) {
443 jni_runtime_->network_task_runner()->PostTask( 455 jni_runtime_->network_task_runner()->PostTask(
444 FROM_HERE, base::Bind(&ChromotingJniInstance::SetDeviceName, this, 456 FROM_HERE, base::Bind(&ChromotingJniInstance::SetDeviceName, this,
445 device_name)); 457 device_name));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 perf_tracker_->round_trip_ms()); 503 perf_tracker_->round_trip_ms());
492 504
493 client_status_logger_->LogStatistics(perf_tracker_.get()); 505 client_status_logger_->LogStatistics(perf_tracker_.get());
494 506
495 jni_runtime_->network_task_runner()->PostDelayedTask( 507 jni_runtime_->network_task_runner()->PostDelayedTask(
496 FROM_HERE, base::Bind(&ChromotingJniInstance::LogPerfStats, this), 508 FROM_HERE, base::Bind(&ChromotingJniInstance::LogPerfStats, this),
497 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); 509 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs));
498 } 510 }
499 511
500 } // namespace remoting 512 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/jni/chromoting_jni_instance.h ('k') | remoting/client/plugin/chromoting_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698