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

Side by Side Diff: remoting/host/it2me/it2me_host.cc

Issue 2380463005: It2Me Host cleanup - Remove task_runner_ (Closed)
Patch Set: Removing unused header file Created 4 years, 2 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/host/it2me/it2me_host.h" 5 #include "remoting/host/it2me/it2me_host.h"
6 6
7 #include <cstdint> 7 #include <cstdint>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 } // namespace 57 } // namespace
58 58
59 It2MeHost::It2MeHost( 59 It2MeHost::It2MeHost(
60 std::unique_ptr<ChromotingHostContext> host_context, 60 std::unique_ptr<ChromotingHostContext> host_context,
61 std::unique_ptr<PolicyWatcher> policy_watcher, 61 std::unique_ptr<PolicyWatcher> policy_watcher,
62 std::unique_ptr<It2MeConfirmationDialog> confirmation_dialog, 62 std::unique_ptr<It2MeConfirmationDialog> confirmation_dialog,
63 base::WeakPtr<It2MeHost::Observer> observer, 63 base::WeakPtr<It2MeHost::Observer> observer,
64 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, 64 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config,
65 const std::string& directory_bot_jid) 65 const std::string& directory_bot_jid)
66 : host_context_(std::move(host_context)), 66 : host_context_(std::move(host_context)),
67 task_runner_(host_context_->ui_task_runner()),
68 observer_(observer), 67 observer_(observer),
69 xmpp_server_config_(xmpp_server_config), 68 xmpp_server_config_(xmpp_server_config),
70 directory_bot_jid_(directory_bot_jid), 69 directory_bot_jid_(directory_bot_jid),
71 policy_watcher_(std::move(policy_watcher)), 70 policy_watcher_(std::move(policy_watcher)),
72 confirmation_dialog_(std::move(confirmation_dialog)) { 71 confirmation_dialog_(std::move(confirmation_dialog)) {
73 DCHECK(task_runner_->BelongsToCurrentThread()); 72 DCHECK(host_context_->ui_task_runner()->BelongsToCurrentThread());
74 } 73 }
75 74
76 It2MeHost::~It2MeHost() { 75 It2MeHost::~It2MeHost() {
77 // Check that resources that need to be torn down on the UI thread are gone. 76 // Check that resources that need to be torn down on the UI thread are gone.
78 DCHECK(!desktop_environment_factory_.get()); 77 DCHECK(!desktop_environment_factory_.get());
79 DCHECK(!policy_watcher_.get()); 78 DCHECK(!policy_watcher_.get());
80 } 79 }
81 80
82 void It2MeHost::Connect() { 81 void It2MeHost::Connect() {
83 if (!host_context_->ui_task_runner()->BelongsToCurrentThread()) { 82 if (!host_context_->ui_task_runner()->BelongsToCurrentThread()) {
84 DCHECK(task_runner_->BelongsToCurrentThread());
85 host_context_->ui_task_runner()->PostTask( 83 host_context_->ui_task_runner()->PostTask(
86 FROM_HERE, base::Bind(&It2MeHost::Connect, this)); 84 FROM_HERE, base::Bind(&It2MeHost::Connect, this));
87 return; 85 return;
88 } 86 }
89 87
90 desktop_environment_factory_.reset(new It2MeDesktopEnvironmentFactory( 88 desktop_environment_factory_.reset(new It2MeDesktopEnvironmentFactory(
91 host_context_->network_task_runner(), 89 host_context_->network_task_runner(),
92 host_context_->video_capture_task_runner(), 90 host_context_->video_capture_task_runner(),
93 host_context_->input_task_runner(), host_context_->ui_task_runner())); 91 host_context_->input_task_runner(), host_context_->ui_task_runner()));
94 92
95 // Start monitoring configured policies. 93 // Start monitoring configured policies.
96 policy_watcher_->StartWatching( 94 policy_watcher_->StartWatching(
97 base::Bind(&It2MeHost::OnPolicyUpdate, this), 95 base::Bind(&It2MeHost::OnPolicyUpdate, this),
98 base::Bind(&It2MeHost::OnPolicyError, this)); 96 base::Bind(&It2MeHost::OnPolicyError, this));
99 97
100 // Switch to the network thread to start the actual connection. 98 // Switch to the network thread to start the actual connection.
101 host_context_->network_task_runner()->PostTask( 99 host_context_->network_task_runner()->PostTask(
102 FROM_HERE, base::Bind(&It2MeHost::ReadPolicyAndConnect, this)); 100 FROM_HERE, base::Bind(&It2MeHost::ReadPolicyAndConnect, this));
103 } 101 }
104 102
105 void It2MeHost::Disconnect() { 103 void It2MeHost::Disconnect() {
106 DCHECK(task_runner_->BelongsToCurrentThread()); 104 DCHECK(host_context_->ui_task_runner()->BelongsToCurrentThread());
107 host_context_->network_task_runner()->PostTask( 105 host_context_->network_task_runner()->PostTask(
108 FROM_HERE, base::Bind(&It2MeHost::DisconnectOnNetworkThread, this)); 106 FROM_HERE, base::Bind(&It2MeHost::DisconnectOnNetworkThread, this));
109 } 107 }
110 108
111 void It2MeHost::DisconnectOnNetworkThread() { 109 void It2MeHost::DisconnectOnNetworkThread() {
112 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); 110 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
113 111
114 // Disconnect() may be called even when after the host been already stopped. 112 // Disconnect() may be called even when after the host been already stopped.
115 // Ignore repeated calls. 113 // Ignore repeated calls.
116 if (state_ == kDisconnected) { 114 if (state_ == kDisconnected) {
(...skipping 16 matching lines...) Expand all
133 host_context_->ui_task_runner()->DeleteSoon( 131 host_context_->ui_task_runner()->DeleteSoon(
134 FROM_HERE, desktop_environment_factory_.release()); 132 FROM_HERE, desktop_environment_factory_.release());
135 host_context_->ui_task_runner()->DeleteSoon(FROM_HERE, 133 host_context_->ui_task_runner()->DeleteSoon(FROM_HERE,
136 policy_watcher_.release()); 134 policy_watcher_.release());
137 135
138 SetState(kDisconnected, ""); 136 SetState(kDisconnected, "");
139 } 137 }
140 138
141 void It2MeHost::RequestNatPolicy() { 139 void It2MeHost::RequestNatPolicy() {
142 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { 140 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) {
143 DCHECK(task_runner_->BelongsToCurrentThread()); 141 DCHECK(host_context_->ui_task_runner()->BelongsToCurrentThread());
144 host_context_->network_task_runner()->PostTask( 142 host_context_->network_task_runner()->PostTask(
145 FROM_HERE, base::Bind(&It2MeHost::RequestNatPolicy, this)); 143 FROM_HERE, base::Bind(&It2MeHost::RequestNatPolicy, this));
146 return; 144 return;
147 } 145 }
148 146
149 if (policy_received_) 147 if (policy_received_)
150 UpdateNatPolicy(nat_traversal_enabled_); 148 UpdateNatPolicy(nat_traversal_enabled_);
151 } 149 }
152 150
153 void It2MeHost::ReadPolicyAndConnect() { 151 void It2MeHost::ReadPolicyAndConnect() {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 273
276 std::string client_username; 274 std::string client_username;
277 if (!SplitJidResource(jid, &client_username, /*resource=*/nullptr)) { 275 if (!SplitJidResource(jid, &client_username, /*resource=*/nullptr)) {
278 LOG(WARNING) << "Incorrectly formatted JID received: " << jid; 276 LOG(WARNING) << "Incorrectly formatted JID received: " << jid;
279 client_username = jid; 277 client_username = jid;
280 } 278 }
281 279
282 HOST_LOG << "Client " << client_username << " connected."; 280 HOST_LOG << "Client " << client_username << " connected.";
283 281
284 // Pass the client user name to the script object before changing state. 282 // Pass the client user name to the script object before changing state.
285 task_runner_->PostTask( 283 host_context_->ui_task_runner()->PostTask(
286 FROM_HERE, base::Bind(&It2MeHost::Observer::OnClientAuthenticated, 284 FROM_HERE, base::Bind(&It2MeHost::Observer::OnClientAuthenticated,
287 observer_, client_username)); 285 observer_, client_username));
288 286
289 SetState(kConnected, ""); 287 SetState(kConnected, "");
290 } 288 }
291 289
292 void It2MeHost::OnClientDisconnected(const std::string& jid) { 290 void It2MeHost::OnClientDisconnected(const std::string& jid) {
293 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); 291 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
294 292
295 DisconnectOnNetworkThread(); 293 DisconnectOnNetworkThread();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 351
354 // When transitioning from enabled to disabled, force disconnect any 352 // When transitioning from enabled to disabled, force disconnect any
355 // existing session. 353 // existing session.
356 if (nat_traversal_enabled_ && !nat_traversal_enabled && IsConnected()) { 354 if (nat_traversal_enabled_ && !nat_traversal_enabled && IsConnected()) {
357 DisconnectOnNetworkThread(); 355 DisconnectOnNetworkThread();
358 } 356 }
359 357
360 nat_traversal_enabled_ = nat_traversal_enabled; 358 nat_traversal_enabled_ = nat_traversal_enabled;
361 359
362 // Notify the web-app of the policy setting. 360 // Notify the web-app of the policy setting.
363 task_runner_->PostTask( 361 host_context_->ui_task_runner()->PostTask(
364 FROM_HERE, base::Bind(&It2MeHost::Observer::OnNatPolicyChanged, 362 FROM_HERE, base::Bind(&It2MeHost::Observer::OnNatPolicyChanged, observer_,
365 observer_, nat_traversal_enabled_)); 363 nat_traversal_enabled_));
366 } 364 }
367 365
368 void It2MeHost::UpdateHostDomainPolicy(const std::string& host_domain) { 366 void It2MeHost::UpdateHostDomainPolicy(const std::string& host_domain) {
369 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); 367 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
370 368
371 VLOG(2) << "UpdateHostDomainPolicy: " << host_domain; 369 VLOG(2) << "UpdateHostDomainPolicy: " << host_domain;
372 370
373 // When setting a host domain policy, force disconnect any existing session. 371 // When setting a host domain policy, force disconnect any existing session.
374 if (!host_domain.empty() && IsConnected()) { 372 if (!host_domain.empty() && IsConnected()) {
375 DisconnectOnNetworkThread(); 373 DisconnectOnNetworkThread();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 DCHECK(state == kDisconnected) << state; 422 DCHECK(state == kDisconnected) << state;
425 break; 423 break;
426 case kInvalidDomainError: 424 case kInvalidDomainError:
427 DCHECK(state == kDisconnected) << state; 425 DCHECK(state == kDisconnected) << state;
428 break; 426 break;
429 }; 427 };
430 428
431 state_ = state; 429 state_ = state;
432 430
433 // Post a state-change notification to the web-app. 431 // Post a state-change notification to the web-app.
434 task_runner_->PostTask( 432 host_context_->ui_task_runner()->PostTask(
435 FROM_HERE, base::Bind(&It2MeHost::Observer::OnStateChanged, 433 FROM_HERE, base::Bind(&It2MeHost::Observer::OnStateChanged, observer_,
436 observer_, state, error_message)); 434 state, error_message));
437 } 435 }
438 436
439 bool It2MeHost::IsConnected() const { 437 bool It2MeHost::IsConnected() const {
440 return state_ == kRequestedAccessCode || state_ == kReceivedAccessCode || 438 return state_ == kRequestedAccessCode || state_ == kReceivedAccessCode ||
441 state_ == kConnected; 439 state_ == kConnected;
442 } 440 }
443 441
444 void It2MeHost::OnReceivedSupportID( 442 void It2MeHost::OnReceivedSupportID(
445 const std::string& support_id, 443 const std::string& support_id,
446 const base::TimeDelta& lifetime, 444 const base::TimeDelta& lifetime,
(...skipping 21 matching lines...) Expand all
468 } 466 }
469 467
470 std::unique_ptr<protocol::AuthenticatorFactory> factory( 468 std::unique_ptr<protocol::AuthenticatorFactory> factory(
471 new protocol::It2MeHostAuthenticatorFactory( 469 new protocol::It2MeHostAuthenticatorFactory(
472 local_certificate, host_key_pair_, access_code_hash, 470 local_certificate, host_key_pair_, access_code_hash,
473 base::Bind(&It2MeHost::ValidateConnectionDetails, 471 base::Bind(&It2MeHost::ValidateConnectionDetails,
474 base::Unretained(this)))); 472 base::Unretained(this))));
475 host_->SetAuthenticatorFactory(std::move(factory)); 473 host_->SetAuthenticatorFactory(std::move(factory));
476 474
477 // Pass the Access Code to the script object before changing state. 475 // Pass the Access Code to the script object before changing state.
478 task_runner_->PostTask( 476 host_context_->ui_task_runner()->PostTask(
479 FROM_HERE, base::Bind(&It2MeHost::Observer::OnStoreAccessCode, 477 FROM_HERE, base::Bind(&It2MeHost::Observer::OnStoreAccessCode, observer_,
480 observer_, access_code, lifetime)); 478 access_code, lifetime));
481 479
482 SetState(kReceivedAccessCode, ""); 480 SetState(kReceivedAccessCode, "");
483 } 481 }
484 482
485 void It2MeHost::ValidateConnectionDetails( 483 void It2MeHost::ValidateConnectionDetails(
486 const std::string& remote_jid, 484 const std::string& remote_jid,
487 const protocol::ValidatingAuthenticator::ResultCallback& result_callback) { 485 const protocol::ValidatingAuthenticator::ResultCallback& result_callback) {
488 // First ensure the JID we received is valid. 486 // First ensure the JID we received is valid.
489 std::string client_username; 487 std::string client_username;
490 if (!SplitJidResource(remote_jid, &client_username, /*resource=*/nullptr)) { 488 if (!SplitJidResource(remote_jid, &client_username, /*resource=*/nullptr)) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 DCHECK(context->ui_task_runner()->BelongsToCurrentThread()); 548 DCHECK(context->ui_task_runner()->BelongsToCurrentThread());
551 549
552 std::unique_ptr<PolicyWatcher> policy_watcher = 550 std::unique_ptr<PolicyWatcher> policy_watcher =
553 PolicyWatcher::Create(policy_service, context->file_task_runner()); 551 PolicyWatcher::Create(policy_service, context->file_task_runner());
554 return new It2MeHost(std::move(context), std::move(policy_watcher), 552 return new It2MeHost(std::move(context), std::move(policy_watcher),
555 It2MeConfirmationDialog::Create(), observer, 553 It2MeConfirmationDialog::Create(), observer,
556 xmpp_server_config, directory_bot_jid); 554 xmpp_server_config, directory_bot_jid);
557 } 555 }
558 556
559 } // namespace remoting 557 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/it2me/it2me_host.h ('k') | remoting/host/it2me/it2me_native_messaging_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698