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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/threading/platform_thread.h" | 9 #include "base/threading/platform_thread.h" |
10 #include "net/socket/client_socket_factory.h" | 10 #include "net/socket/client_socket_factory.h" |
11 #include "remoting/base/auto_thread.h" | 11 #include "remoting/base/auto_thread.h" |
12 #include "remoting/base/logging.h" | 12 #include "remoting/base/logging.h" |
13 #include "remoting/base/rsa_key_pair.h" | 13 #include "remoting/base/rsa_key_pair.h" |
14 #include "remoting/host/chromoting_host.h" | 14 #include "remoting/host/chromoting_host.h" |
15 #include "remoting/host/chromoting_host_context.h" | 15 #include "remoting/host/chromoting_host_context.h" |
16 #include "remoting/host/host_event_logger.h" | 16 #include "remoting/host/host_event_logger.h" |
17 #include "remoting/host/host_secret.h" | 17 #include "remoting/host/host_secret.h" |
18 #include "remoting/host/host_status_logger.h" | 18 #include "remoting/host/host_status_logger.h" |
| 19 #include "remoting/host/it2me/it2me_confirmation_dialog.h" |
19 #include "remoting/host/it2me_desktop_environment.h" | 20 #include "remoting/host/it2me_desktop_environment.h" |
20 #include "remoting/host/policy_hack/policy_watcher.h" | 21 #include "remoting/host/policy_hack/policy_watcher.h" |
21 #include "remoting/host/register_support_host_request.h" | 22 #include "remoting/host/register_support_host_request.h" |
22 #include "remoting/host/session_manager_factory.h" | 23 #include "remoting/host/session_manager_factory.h" |
23 #include "remoting/protocol/it2me_host_authenticator_factory.h" | 24 #include "remoting/protocol/it2me_host_authenticator_factory.h" |
24 #include "remoting/protocol/network_settings.h" | 25 #include "remoting/protocol/network_settings.h" |
25 #include "remoting/signaling/server_log_entry.h" | 26 #include "remoting/signaling/server_log_entry.h" |
26 | 27 |
27 namespace remoting { | 28 namespace remoting { |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 // This is used for tagging system event logs. | 32 // This is used for tagging system event logs. |
32 const char kApplicationName[] = "chromoting"; | 33 const char kApplicationName[] = "chromoting"; |
33 const int kMaxLoginAttempts = 5; | 34 const int kMaxLoginAttempts = 5; |
34 | 35 |
35 } // namespace | 36 } // namespace |
36 | 37 |
37 It2MeHost::It2MeHost( | 38 It2MeHost::It2MeHost( |
38 scoped_ptr<ChromotingHostContext> host_context, | 39 scoped_ptr<ChromotingHostContext> host_context, |
39 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher, | 40 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher, |
| 41 scoped_ptr<It2MeConfirmationDialogFactory> confirmation_dialog_factory, |
40 base::WeakPtr<It2MeHost::Observer> observer, | 42 base::WeakPtr<It2MeHost::Observer> observer, |
41 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, | 43 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, |
42 const std::string& directory_bot_jid) | 44 const std::string& directory_bot_jid) |
43 : host_context_(host_context.Pass()), | 45 : host_context_(host_context.Pass()), |
44 task_runner_(host_context_->ui_task_runner()), | 46 task_runner_(host_context_->ui_task_runner()), |
45 observer_(observer), | 47 observer_(observer), |
46 xmpp_server_config_(xmpp_server_config), | 48 xmpp_server_config_(xmpp_server_config), |
47 directory_bot_jid_(directory_bot_jid), | 49 directory_bot_jid_(directory_bot_jid), |
48 state_(kDisconnected), | 50 state_(kDisconnected), |
49 failed_login_attempts_(0), | 51 failed_login_attempts_(0), |
50 policy_watcher_(policy_watcher.Pass()), | 52 policy_watcher_(policy_watcher.Pass()), |
| 53 confirmation_dialog_factory_(confirmation_dialog_factory.Pass()), |
51 nat_traversal_enabled_(false), | 54 nat_traversal_enabled_(false), |
52 policy_received_(false) { | 55 policy_received_(false) { |
53 DCHECK(task_runner_->BelongsToCurrentThread()); | 56 DCHECK(task_runner_->BelongsToCurrentThread()); |
54 } | 57 } |
55 | 58 |
56 void It2MeHost::Connect() { | 59 void It2MeHost::Connect() { |
57 if (!host_context_->ui_task_runner()->BelongsToCurrentThread()) { | 60 if (!host_context_->ui_task_runner()->BelongsToCurrentThread()) { |
58 DCHECK(task_runner_->BelongsToCurrentThread()); | 61 DCHECK(task_runner_->BelongsToCurrentThread()); |
59 host_context_->ui_task_runner()->PostTask( | 62 host_context_->ui_task_runner()->PostTask( |
60 FROM_HERE, base::Bind(&It2MeHost::Connect, this)); | 63 FROM_HERE, base::Bind(&It2MeHost::Connect, this)); |
61 return; | 64 return; |
62 } | 65 } |
63 | 66 |
64 desktop_environment_factory_.reset(new It2MeDesktopEnvironmentFactory( | 67 desktop_environment_factory_.reset(new It2MeDesktopEnvironmentFactory( |
65 host_context_->network_task_runner(), | 68 host_context_->network_task_runner(), |
66 host_context_->input_task_runner(), | 69 host_context_->input_task_runner(), |
67 host_context_->ui_task_runner())); | 70 host_context_->ui_task_runner())); |
68 | 71 |
69 // Start monitoring configured policies. | 72 // Start monitoring configured policies. |
70 policy_watcher_->StartWatching( | 73 policy_watcher_->StartWatching( |
71 base::Bind(&It2MeHost::OnPolicyUpdate, this), | 74 base::Bind(&It2MeHost::OnPolicyUpdate, this), |
72 base::Bind(&It2MeHost::OnPolicyError, this)); | 75 base::Bind(&It2MeHost::OnPolicyError, this)); |
73 | 76 |
74 // Switch to the network thread to start the actual connection. | 77 // Switch to the network thread to start the actual connection. |
75 host_context_->network_task_runner()->PostTask( | 78 host_context_->network_task_runner()->PostTask( |
76 FROM_HERE, base::Bind(&It2MeHost::ReadPolicyAndConnect, this)); | 79 FROM_HERE, base::Bind(&It2MeHost::ShowConfirmationPrompt, this)); |
77 } | 80 } |
78 | 81 |
79 void It2MeHost::Disconnect() { | 82 void It2MeHost::Disconnect() { |
80 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { | 83 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { |
81 DCHECK(task_runner_->BelongsToCurrentThread()); | 84 DCHECK(task_runner_->BelongsToCurrentThread()); |
82 host_context_->network_task_runner()->PostTask( | 85 host_context_->network_task_runner()->PostTask( |
83 FROM_HERE, base::Bind(&It2MeHost::Disconnect, this)); | 86 FROM_HERE, base::Bind(&It2MeHost::Disconnect, this)); |
84 return; | 87 return; |
85 } | 88 } |
86 | 89 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 DCHECK(task_runner_->BelongsToCurrentThread()); | 124 DCHECK(task_runner_->BelongsToCurrentThread()); |
122 host_context_->network_task_runner()->PostTask( | 125 host_context_->network_task_runner()->PostTask( |
123 FROM_HERE, base::Bind(&It2MeHost::RequestNatPolicy, this)); | 126 FROM_HERE, base::Bind(&It2MeHost::RequestNatPolicy, this)); |
124 return; | 127 return; |
125 } | 128 } |
126 | 129 |
127 if (policy_received_) | 130 if (policy_received_) |
128 UpdateNatPolicy(nat_traversal_enabled_); | 131 UpdateNatPolicy(nat_traversal_enabled_); |
129 } | 132 } |
130 | 133 |
| 134 void It2MeHost::ShowConfirmationPrompt() { |
| 135 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
| 136 |
| 137 SetState(kStarting); |
| 138 |
| 139 scoped_ptr<It2MeConfirmationDialog> confirmation_dialog = |
| 140 confirmation_dialog_factory_->Create(); |
| 141 |
| 142 // TODO(dcaiafa): Remove after dialog implementations for all platforms exist. |
| 143 if (!confirmation_dialog) { |
| 144 ReadPolicyAndConnect(); |
| 145 return; |
| 146 } |
| 147 |
| 148 confirmation_dialog_proxy_.reset( |
| 149 new It2MeConfirmationDialogProxy(host_context_->ui_task_runner(), |
| 150 confirmation_dialog.Pass())); |
| 151 |
| 152 confirmation_dialog_proxy_->Show( |
| 153 base::Bind(&It2MeHost::OnConfirmationResult, base::Unretained(this))); |
| 154 } |
| 155 |
| 156 void It2MeHost::OnConfirmationResult(It2MeConfirmationDialog::Result result) { |
| 157 switch (result) { |
| 158 case It2MeConfirmationDialog::Result::OK: |
| 159 ReadPolicyAndConnect(); |
| 160 break; |
| 161 |
| 162 case It2MeConfirmationDialog::Result::CANCEL: |
| 163 Disconnect(); |
| 164 break; |
| 165 |
| 166 default: |
| 167 NOTREACHED(); |
| 168 return; |
| 169 } |
| 170 } |
| 171 |
131 void It2MeHost::ReadPolicyAndConnect() { | 172 void It2MeHost::ReadPolicyAndConnect() { |
132 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 173 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
133 | 174 DCHECK_EQ(kStarting, state_); |
134 SetState(kStarting); | |
135 | 175 |
136 // Only proceed to FinishConnect() if at least one policy update has been | 176 // Only proceed to FinishConnect() if at least one policy update has been |
137 // received. | 177 // received. |
138 if (policy_received_) { | 178 if (policy_received_) { |
139 FinishConnect(); | 179 FinishConnect(); |
140 } else { | 180 } else { |
141 // Otherwise, create the policy watcher, and thunk the connect. | 181 // Otherwise, create the policy watcher, and thunk the connect. |
142 pending_connect_ = | 182 pending_connect_ = |
143 base::Bind(&It2MeHost::FinishConnect, this); | 183 base::Bind(&It2MeHost::FinishConnect, this); |
144 } | 184 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 host_->Start(xmpp_server_config_.username); | 266 host_->Start(xmpp_server_config_.username); |
227 | 267 |
228 SetState(kRequestedAccessCode); | 268 SetState(kRequestedAccessCode); |
229 return; | 269 return; |
230 } | 270 } |
231 | 271 |
232 void It2MeHost::ShutdownOnNetworkThread() { | 272 void It2MeHost::ShutdownOnNetworkThread() { |
233 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 273 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
234 DCHECK(state_ == kDisconnecting || state_ == kDisconnected); | 274 DCHECK(state_ == kDisconnecting || state_ == kDisconnected); |
235 | 275 |
| 276 confirmation_dialog_proxy_.reset(); |
| 277 |
236 if (state_ == kDisconnecting) { | 278 if (state_ == kDisconnecting) { |
237 host_event_logger_.reset(); | 279 host_event_logger_.reset(); |
238 host_->RemoveStatusObserver(this); | 280 host_->RemoveStatusObserver(this); |
239 host_.reset(); | 281 host_.reset(); |
240 | 282 |
241 register_request_.reset(); | 283 register_request_.reset(); |
242 host_status_logger_.reset(); | 284 host_status_logger_.reset(); |
243 signal_strategy_.reset(); | 285 signal_strategy_.reset(); |
244 SetState(kDisconnected); | 286 SetState(kDisconnected); |
245 } | 287 } |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 DCHECK(policy_service); | 525 DCHECK(policy_service); |
484 DCHECK(!policy_service_) << "|policy_service| can only be set once."; | 526 DCHECK(!policy_service_) << "|policy_service| can only be set once."; |
485 policy_service_ = policy_service; | 527 policy_service_ = policy_service; |
486 } | 528 } |
487 | 529 |
488 scoped_refptr<It2MeHost> It2MeHostFactory::CreateIt2MeHost( | 530 scoped_refptr<It2MeHost> It2MeHostFactory::CreateIt2MeHost( |
489 scoped_ptr<ChromotingHostContext> context, | 531 scoped_ptr<ChromotingHostContext> context, |
490 base::WeakPtr<It2MeHost::Observer> observer, | 532 base::WeakPtr<It2MeHost::Observer> observer, |
491 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, | 533 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, |
492 const std::string& directory_bot_jid) { | 534 const std::string& directory_bot_jid) { |
| 535 scoped_ptr<It2MeConfirmationDialogFactory> confirmation_dialog_factory( |
| 536 new It2MeConfirmationDialogFactory()); |
493 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher = | 537 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher = |
494 policy_hack::PolicyWatcher::Create(policy_service_, | 538 policy_hack::PolicyWatcher::Create(policy_service_, |
495 context->network_task_runner()); | 539 context->network_task_runner()); |
496 return new It2MeHost(context.Pass(), policy_watcher.Pass(), observer, | 540 return new It2MeHost(context.Pass(), policy_watcher.Pass(), |
497 xmpp_server_config, directory_bot_jid); | 541 confirmation_dialog_factory.Pass(), |
| 542 observer, xmpp_server_config, directory_bot_jid); |
498 } | 543 } |
499 | 544 |
500 } // namespace remoting | 545 } // namespace remoting |
OLD | NEW |