OLD | NEW |
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 using protocol::ValidatingAuthenticator; | 52 using protocol::ValidatingAuthenticator; |
53 typedef ValidatingAuthenticator::Result ValidationResult; | 53 typedef ValidatingAuthenticator::Result ValidationResult; |
54 typedef ValidatingAuthenticator::ValidationCallback ValidationCallback; | 54 typedef ValidatingAuthenticator::ValidationCallback ValidationCallback; |
55 typedef ValidatingAuthenticator::ResultCallback ValidationResultCallback; | 55 typedef ValidatingAuthenticator::ResultCallback ValidationResultCallback; |
56 | 56 |
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<It2MeConfirmationDialogFactory> dialog_factory, |
63 base::WeakPtr<It2MeHost::Observer> observer, | 63 base::WeakPtr<It2MeHost::Observer> observer, |
64 std::unique_ptr<SignalStrategy> signal_strategy, | 64 std::unique_ptr<SignalStrategy> signal_strategy, |
65 const std::string& username, | 65 const std::string& username, |
66 const std::string& directory_bot_jid) | 66 const std::string& directory_bot_jid) |
67 : host_context_(std::move(host_context)), | 67 : host_context_(std::move(host_context)), |
68 observer_(observer), | 68 observer_(observer), |
69 signal_strategy_(std::move(signal_strategy)), | 69 signal_strategy_(std::move(signal_strategy)), |
70 username_(username), | 70 username_(username), |
71 directory_bot_jid_(directory_bot_jid), | 71 directory_bot_jid_(directory_bot_jid), |
72 policy_watcher_(std::move(policy_watcher)), | 72 policy_watcher_(std::move(policy_watcher)), |
73 confirmation_dialog_(std::move(confirmation_dialog)) { | 73 confirmation_dialog_factory_(std::move(dialog_factory)) { |
74 DCHECK(host_context_->ui_task_runner()->BelongsToCurrentThread()); | 74 DCHECK(host_context_->ui_task_runner()->BelongsToCurrentThread()); |
75 } | 75 } |
76 | 76 |
77 It2MeHost::~It2MeHost() { | 77 It2MeHost::~It2MeHost() { |
78 // Check that resources that need to be torn down on the UI thread are gone. | 78 // Check that resources that need to be torn down on the UI thread are gone. |
79 DCHECK(!desktop_environment_factory_.get()); | 79 DCHECK(!desktop_environment_factory_.get()); |
80 DCHECK(!policy_watcher_.get()); | 80 DCHECK(!policy_watcher_.get()); |
81 } | 81 } |
82 | 82 |
83 void It2MeHost::Connect() { | 83 void It2MeHost::Connect() { |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 SetState(kRequestedAccessCode, ""); | 250 SetState(kRequestedAccessCode, ""); |
251 return; | 251 return; |
252 } | 252 } |
253 | 253 |
254 void It2MeHost::OnAccessDenied(const std::string& jid) { | 254 void It2MeHost::OnAccessDenied(const std::string& jid) { |
255 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 255 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
256 | 256 |
257 ++failed_login_attempts_; | 257 ++failed_login_attempts_; |
258 if (failed_login_attempts_ == kMaxLoginAttempts) { | 258 if (failed_login_attempts_ == kMaxLoginAttempts) { |
259 DisconnectOnNetworkThread(); | 259 DisconnectOnNetworkThread(); |
| 260 } else if (connecting_jid_ == jid) { |
| 261 DCHECK_EQ(state_, kConnecting); |
| 262 connecting_jid_.clear(); |
| 263 confirmation_dialog_proxy_.reset(); |
| 264 SetState(kReceivedAccessCode, std::string()); |
260 } | 265 } |
261 } | 266 } |
262 | 267 |
263 void It2MeHost::OnClientConnected(const std::string& jid) { | 268 void It2MeHost::OnClientConnected(const std::string& jid) { |
264 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 269 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
265 | 270 |
266 // ChromotingHost doesn't allow multiple concurrent connection and the | 271 // ChromotingHost doesn't allow multiple concurrent connection and the |
267 // host is destroyed in OnClientDisconnected() after the first connection. | 272 // host is destroyed in OnClientDisconnected() after the first connection. |
268 CHECK_NE(state_, kConnected); | 273 CHECK_NE(state_, kConnected); |
269 | 274 |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 // which remote user (if either) is valid so disconnect everyone. | 527 // which remote user (if either) is valid so disconnect everyone. |
523 if (state_ != kReceivedAccessCode) { | 528 if (state_ != kReceivedAccessCode) { |
524 DCHECK_EQ(kConnecting, state_); | 529 DCHECK_EQ(kConnecting, state_); |
525 LOG(ERROR) << "Received too many connection requests."; | 530 LOG(ERROR) << "Received too many connection requests."; |
526 result_callback.Run(ValidationResult::ERROR_TOO_MANY_CONNECTIONS); | 531 result_callback.Run(ValidationResult::ERROR_TOO_MANY_CONNECTIONS); |
527 DisconnectOnNetworkThread(); | 532 DisconnectOnNetworkThread(); |
528 return; | 533 return; |
529 } | 534 } |
530 | 535 |
531 HOST_LOG << "Client " << client_username << " connecting."; | 536 HOST_LOG << "Client " << client_username << " connecting."; |
| 537 connecting_jid_ = remote_jid; |
532 SetState(kConnecting, std::string()); | 538 SetState(kConnecting, std::string()); |
533 | 539 |
534 // Show a confirmation dialog to the user to allow them to confirm/reject it. | 540 // Show a confirmation dialog to the user to allow them to confirm/reject it. |
535 confirmation_dialog_proxy_.reset(new It2MeConfirmationDialogProxy( | 541 confirmation_dialog_proxy_.reset(new It2MeConfirmationDialogProxy( |
536 host_context_->ui_task_runner(), std::move(confirmation_dialog_))); | 542 host_context_->ui_task_runner(), confirmation_dialog_factory_->Create())); |
537 | 543 |
538 confirmation_dialog_proxy_->Show( | 544 confirmation_dialog_proxy_->Show( |
539 client_username, base::Bind(&It2MeHost::OnConfirmationResult, | 545 client_username, base::Bind(&It2MeHost::OnConfirmationResult, |
540 base::Unretained(this), result_callback)); | 546 base::Unretained(this), result_callback)); |
541 } | 547 } |
542 | 548 |
543 void It2MeHost::OnConfirmationResult( | 549 void It2MeHost::OnConfirmationResult( |
544 const ValidationResultCallback& result_callback, | 550 const ValidationResultCallback& result_callback, |
545 It2MeConfirmationDialog::Result result) { | 551 It2MeConfirmationDialog::Result result) { |
546 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 552 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
547 | 553 |
| 554 connecting_jid_.clear(); |
548 switch (result) { | 555 switch (result) { |
549 case It2MeConfirmationDialog::Result::OK: | 556 case It2MeConfirmationDialog::Result::OK: |
550 result_callback.Run(ValidationResult::SUCCESS); | 557 result_callback.Run(ValidationResult::SUCCESS); |
551 break; | 558 break; |
552 | 559 |
553 case It2MeConfirmationDialog::Result::CANCEL: | 560 case It2MeConfirmationDialog::Result::CANCEL: |
554 result_callback.Run(ValidationResult::ERROR_REJECTED_BY_USER); | 561 result_callback.Run(ValidationResult::ERROR_REJECTED_BY_USER); |
555 DisconnectOnNetworkThread(); | 562 DisconnectOnNetworkThread(); |
556 break; | 563 break; |
557 } | 564 } |
558 } | 565 } |
559 | 566 |
560 It2MeHostFactory::It2MeHostFactory() {} | 567 It2MeHostFactory::It2MeHostFactory() {} |
561 | 568 |
562 It2MeHostFactory::~It2MeHostFactory() {} | 569 It2MeHostFactory::~It2MeHostFactory() {} |
563 | 570 |
564 scoped_refptr<It2MeHost> It2MeHostFactory::CreateIt2MeHost( | 571 scoped_refptr<It2MeHost> It2MeHostFactory::CreateIt2MeHost( |
565 std::unique_ptr<ChromotingHostContext> context, | 572 std::unique_ptr<ChromotingHostContext> context, |
566 policy::PolicyService* policy_service, | 573 policy::PolicyService* policy_service, |
567 base::WeakPtr<It2MeHost::Observer> observer, | 574 base::WeakPtr<It2MeHost::Observer> observer, |
568 std::unique_ptr<SignalStrategy> signal_strategy, | 575 std::unique_ptr<SignalStrategy> signal_strategy, |
569 const std::string& username, | 576 const std::string& username, |
570 const std::string& directory_bot_jid) { | 577 const std::string& directory_bot_jid) { |
571 DCHECK(context->ui_task_runner()->BelongsToCurrentThread()); | 578 DCHECK(context->ui_task_runner()->BelongsToCurrentThread()); |
572 | 579 |
573 std::unique_ptr<PolicyWatcher> policy_watcher = | 580 std::unique_ptr<PolicyWatcher> policy_watcher = |
574 PolicyWatcher::Create(policy_service, context->file_task_runner()); | 581 PolicyWatcher::Create(policy_service, context->file_task_runner()); |
575 return new It2MeHost(std::move(context), std::move(policy_watcher), | 582 return new It2MeHost(std::move(context), std::move(policy_watcher), |
576 It2MeConfirmationDialog::Create(), observer, | 583 base::MakeUnique<It2MeConfirmationDialogFactory>(), |
577 std::move(signal_strategy), username, directory_bot_jid); | 584 observer, std::move(signal_strategy), username, |
| 585 directory_bot_jid); |
578 } | 586 } |
579 | 587 |
580 } // namespace remoting | 588 } // namespace remoting |
OLD | NEW |