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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 } | 68 } |
69 | 69 |
70 return true; | 70 return true; |
71 } | 71 } |
72 | 72 |
73 } // namespace | 73 } // namespace |
74 | 74 |
75 It2MeHost::It2MeHost( | 75 It2MeHost::It2MeHost( |
76 std::unique_ptr<ChromotingHostContext> host_context, | 76 std::unique_ptr<ChromotingHostContext> host_context, |
77 std::unique_ptr<PolicyWatcher> policy_watcher, | 77 std::unique_ptr<PolicyWatcher> policy_watcher, |
78 std::unique_ptr<It2MeConfirmationDialog> confirmation_dialog, | 78 std::unique_ptr<It2MeConfirmationDialogFactory> dialog_factory, |
79 base::WeakPtr<It2MeHost::Observer> observer, | 79 base::WeakPtr<It2MeHost::Observer> observer, |
80 std::unique_ptr<SignalStrategy> signal_strategy, | 80 std::unique_ptr<SignalStrategy> signal_strategy, |
81 const std::string& username, | 81 const std::string& username, |
82 const std::string& directory_bot_jid) | 82 const std::string& directory_bot_jid) |
83 : host_context_(std::move(host_context)), | 83 : host_context_(std::move(host_context)), |
84 observer_(observer), | 84 observer_(observer), |
85 signal_strategy_(std::move(signal_strategy)), | 85 signal_strategy_(std::move(signal_strategy)), |
86 username_(username), | 86 username_(username), |
87 directory_bot_jid_(directory_bot_jid), | 87 directory_bot_jid_(directory_bot_jid), |
88 policy_watcher_(std::move(policy_watcher)), | 88 policy_watcher_(std::move(policy_watcher)), |
89 confirmation_dialog_(std::move(confirmation_dialog)) { | 89 confirmation_dialog_factory_(std::move(dialog_factory)) { |
90 DCHECK(host_context_->ui_task_runner()->BelongsToCurrentThread()); | 90 DCHECK(host_context_->ui_task_runner()->BelongsToCurrentThread()); |
91 } | 91 } |
92 | 92 |
93 It2MeHost::~It2MeHost() { | 93 It2MeHost::~It2MeHost() { |
94 // Check that resources that need to be torn down on the UI thread are gone. | 94 // Check that resources that need to be torn down on the UI thread are gone. |
95 DCHECK(!desktop_environment_factory_.get()); | 95 DCHECK(!desktop_environment_factory_.get()); |
96 DCHECK(!policy_watcher_.get()); | 96 DCHECK(!policy_watcher_.get()); |
97 } | 97 } |
98 | 98 |
99 void It2MeHost::Connect() { | 99 void It2MeHost::Connect() { |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 SetState(kRequestedAccessCode, ""); | 266 SetState(kRequestedAccessCode, ""); |
267 return; | 267 return; |
268 } | 268 } |
269 | 269 |
270 void It2MeHost::OnAccessDenied(const std::string& jid) { | 270 void It2MeHost::OnAccessDenied(const std::string& jid) { |
271 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 271 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
272 | 272 |
273 ++failed_login_attempts_; | 273 ++failed_login_attempts_; |
274 if (failed_login_attempts_ == kMaxLoginAttempts) { | 274 if (failed_login_attempts_ == kMaxLoginAttempts) { |
275 DisconnectOnNetworkThread(); | 275 DisconnectOnNetworkThread(); |
| 276 } else if (connecting_jid_ == jid) { |
| 277 DCHECK_EQ(state_, kConnecting); |
| 278 confirmation_dialog_proxy_.reset(); |
| 279 SetState(kReceivedAccessCode, std::string()); |
276 } | 280 } |
277 } | 281 } |
278 | 282 |
279 void It2MeHost::OnClientConnected(const std::string& jid) { | 283 void It2MeHost::OnClientConnected(const std::string& jid) { |
280 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 284 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
281 | 285 |
282 // ChromotingHost doesn't allow multiple concurrent connection and the | 286 // ChromotingHost doesn't allow multiple concurrent connection and the |
283 // host is destroyed in OnClientDisconnected() after the first connection. | 287 // host is destroyed in OnClientDisconnected() after the first connection. |
284 CHECK_NE(state_, kConnected); | 288 CHECK_NE(state_, kConnected); |
285 | 289 |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 // If we receive valid connection details multiple times, then we don't know | 549 // If we receive valid connection details multiple times, then we don't know |
546 // which remote user (if either) is valid so disconnect everyone. | 550 // which remote user (if either) is valid so disconnect everyone. |
547 if (state_ != kReceivedAccessCode) { | 551 if (state_ != kReceivedAccessCode) { |
548 LOG(ERROR) << "Received too many connection requests."; | 552 LOG(ERROR) << "Received too many connection requests."; |
549 result_callback.Run(ValidationResult::ERROR_TOO_MANY_CONNECTIONS); | 553 result_callback.Run(ValidationResult::ERROR_TOO_MANY_CONNECTIONS); |
550 DisconnectOnNetworkThread(); | 554 DisconnectOnNetworkThread(); |
551 return; | 555 return; |
552 } | 556 } |
553 | 557 |
554 HOST_LOG << "Client " << client_username << " connecting."; | 558 HOST_LOG << "Client " << client_username << " connecting."; |
| 559 connecting_jid_ = remote_jid; |
555 SetState(kConnecting, std::string()); | 560 SetState(kConnecting, std::string()); |
556 | 561 |
557 // Show a confirmation dialog to the user to allow them to confirm/reject it. | 562 // Show a confirmation dialog to the user to allow them to confirm/reject it. |
558 confirmation_dialog_proxy_.reset(new It2MeConfirmationDialogProxy( | 563 confirmation_dialog_proxy_.reset(new It2MeConfirmationDialogProxy( |
559 host_context_->ui_task_runner(), std::move(confirmation_dialog_))); | 564 host_context_->ui_task_runner(), confirmation_dialog_factory_->Create())); |
560 | 565 |
561 confirmation_dialog_proxy_->Show( | 566 confirmation_dialog_proxy_->Show( |
562 client_username, base::Bind(&It2MeHost::OnConfirmationResult, | 567 client_username, base::Bind(&It2MeHost::OnConfirmationResult, |
563 base::Unretained(this), result_callback)); | 568 base::Unretained(this), result_callback)); |
564 } | 569 } |
565 | 570 |
566 void It2MeHost::OnConfirmationResult( | 571 void It2MeHost::OnConfirmationResult( |
567 const ValidationResultCallback& result_callback, | 572 const ValidationResultCallback& result_callback, |
568 It2MeConfirmationDialog::Result result) { | 573 It2MeConfirmationDialog::Result result) { |
569 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 574 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
570 | 575 |
| 576 connecting_jid_.clear(); |
571 switch (result) { | 577 switch (result) { |
572 case It2MeConfirmationDialog::Result::OK: | 578 case It2MeConfirmationDialog::Result::OK: |
573 result_callback.Run(ValidationResult::SUCCESS); | 579 result_callback.Run(ValidationResult::SUCCESS); |
574 break; | 580 break; |
575 | 581 |
576 case It2MeConfirmationDialog::Result::CANCEL: | 582 case It2MeConfirmationDialog::Result::CANCEL: |
577 result_callback.Run(ValidationResult::ERROR_REJECTED_BY_USER); | 583 result_callback.Run(ValidationResult::ERROR_REJECTED_BY_USER); |
578 DisconnectOnNetworkThread(); | 584 DisconnectOnNetworkThread(); |
579 break; | 585 break; |
580 } | 586 } |
581 } | 587 } |
582 | 588 |
583 It2MeHostFactory::It2MeHostFactory() {} | 589 It2MeHostFactory::It2MeHostFactory() {} |
584 | 590 |
585 It2MeHostFactory::~It2MeHostFactory() {} | 591 It2MeHostFactory::~It2MeHostFactory() {} |
586 | 592 |
587 scoped_refptr<It2MeHost> It2MeHostFactory::CreateIt2MeHost( | 593 scoped_refptr<It2MeHost> It2MeHostFactory::CreateIt2MeHost( |
588 std::unique_ptr<ChromotingHostContext> context, | 594 std::unique_ptr<ChromotingHostContext> context, |
589 policy::PolicyService* policy_service, | 595 policy::PolicyService* policy_service, |
590 base::WeakPtr<It2MeHost::Observer> observer, | 596 base::WeakPtr<It2MeHost::Observer> observer, |
591 std::unique_ptr<SignalStrategy> signal_strategy, | 597 std::unique_ptr<SignalStrategy> signal_strategy, |
592 const std::string& username, | 598 const std::string& username, |
593 const std::string& directory_bot_jid) { | 599 const std::string& directory_bot_jid) { |
594 DCHECK(context->ui_task_runner()->BelongsToCurrentThread()); | 600 DCHECK(context->ui_task_runner()->BelongsToCurrentThread()); |
595 | 601 |
596 std::unique_ptr<PolicyWatcher> policy_watcher = | 602 std::unique_ptr<PolicyWatcher> policy_watcher = |
597 PolicyWatcher::Create(policy_service, context->file_task_runner()); | 603 PolicyWatcher::Create(policy_service, context->file_task_runner()); |
598 return new It2MeHost(std::move(context), std::move(policy_watcher), | 604 return new It2MeHost(std::move(context), std::move(policy_watcher), |
599 It2MeConfirmationDialog::Create(), observer, | 605 base::MakeUnique<It2MeConfirmationDialogFactory>(), |
600 std::move(signal_strategy), username, directory_bot_jid); | 606 observer, std::move(signal_strategy), username, |
| 607 directory_bot_jid); |
601 } | 608 } |
602 | 609 |
603 } // namespace remoting | 610 } // namespace remoting |
OLD | NEW |