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::ConfirmAndConnect, 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::ConfirmAndConnect() { | |
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 if (!confirmation_dialog) { | |
143 ReadPolicyAndConnect(); | |
144 return; | |
145 } | |
146 | |
147 confirmation_dialog_proxy_.reset( | |
148 new It2MeConfirmationDialogProxy(host_context_->ui_task_runner(), | |
149 host_context_->network_task_runner(), | |
150 confirmation_dialog.Pass())); | |
151 | |
152 // Unretained because we own |confirmation_dialog_|. | |
153 confirmation_dialog_proxy_->Show( | |
154 base::Bind(&It2MeHost::OnConfirmationResult, base::Unretained(this))); | |
155 } | |
156 | |
157 void It2MeHost::OnConfirmationResult(It2MeConfirmationDialog::Result result) { | |
158 switch (result) { | |
159 case It2MeConfirmationDialog::Result::OK: | |
Sergey Ulanov
2014/12/19 03:16:19
I think you don't need ::Result here
dcaiafa
2014/12/20 00:22:00
It's needed because it's an "enum class" instead o
Sergey Ulanov
2014/12/22 19:29:08
oh, yay for C++11!
| |
160 ReadPolicyAndConnect(); | |
161 break; | |
162 | |
163 case It2MeConfirmationDialog::Result::CANCEL: | |
164 Disconnect(); | |
165 break; | |
166 | |
167 default: | |
168 NOTREACHED(); | |
169 return; | |
170 } | |
171 } | |
172 | |
131 void It2MeHost::ReadPolicyAndConnect() { | 173 void It2MeHost::ReadPolicyAndConnect() { |
132 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 174 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
133 | 175 DCHECK(state_ == kStarting); |
134 SetState(kStarting); | |
135 | 176 |
136 // Only proceed to FinishConnect() if at least one policy update has been | 177 // Only proceed to FinishConnect() if at least one policy update has been |
137 // received. | 178 // received. |
138 if (policy_received_) { | 179 if (policy_received_) { |
139 FinishConnect(); | 180 FinishConnect(); |
140 } else { | 181 } else { |
141 // Otherwise, create the policy watcher, and thunk the connect. | 182 // Otherwise, create the policy watcher, and thunk the connect. |
142 pending_connect_ = | 183 pending_connect_ = |
143 base::Bind(&It2MeHost::FinishConnect, this); | 184 base::Bind(&It2MeHost::FinishConnect, this); |
144 } | 185 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 host_->Start(xmpp_server_config_.username); | 267 host_->Start(xmpp_server_config_.username); |
227 | 268 |
228 SetState(kRequestedAccessCode); | 269 SetState(kRequestedAccessCode); |
229 return; | 270 return; |
230 } | 271 } |
231 | 272 |
232 void It2MeHost::ShutdownOnNetworkThread() { | 273 void It2MeHost::ShutdownOnNetworkThread() { |
233 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 274 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
234 DCHECK(state_ == kDisconnecting || state_ == kDisconnected); | 275 DCHECK(state_ == kDisconnecting || state_ == kDisconnected); |
235 | 276 |
277 confirmation_dialog_proxy_.reset(); | |
278 | |
236 if (state_ == kDisconnecting) { | 279 if (state_ == kDisconnecting) { |
237 host_event_logger_.reset(); | 280 host_event_logger_.reset(); |
238 host_->RemoveStatusObserver(this); | 281 host_->RemoveStatusObserver(this); |
239 host_.reset(); | 282 host_.reset(); |
240 | 283 |
241 register_request_.reset(); | 284 register_request_.reset(); |
242 host_status_logger_.reset(); | 285 host_status_logger_.reset(); |
243 signal_strategy_.reset(); | 286 signal_strategy_.reset(); |
244 SetState(kDisconnected); | 287 SetState(kDisconnected); |
245 } | 288 } |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 DCHECK(policy_service); | 526 DCHECK(policy_service); |
484 DCHECK(!policy_service_) << "|policy_service| can only be set once."; | 527 DCHECK(!policy_service_) << "|policy_service| can only be set once."; |
485 policy_service_ = policy_service; | 528 policy_service_ = policy_service; |
486 } | 529 } |
487 | 530 |
488 scoped_refptr<It2MeHost> It2MeHostFactory::CreateIt2MeHost( | 531 scoped_refptr<It2MeHost> It2MeHostFactory::CreateIt2MeHost( |
489 scoped_ptr<ChromotingHostContext> context, | 532 scoped_ptr<ChromotingHostContext> context, |
490 base::WeakPtr<It2MeHost::Observer> observer, | 533 base::WeakPtr<It2MeHost::Observer> observer, |
491 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, | 534 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, |
492 const std::string& directory_bot_jid) { | 535 const std::string& directory_bot_jid) { |
536 scoped_ptr<It2MeConfirmationDialogFactory> confirmation_dialog_factory( | |
537 new It2MeConfirmationDialogFactory()); | |
493 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher = | 538 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher = |
494 policy_hack::PolicyWatcher::Create(policy_service_, | 539 policy_hack::PolicyWatcher::Create(policy_service_, |
495 context->network_task_runner()); | 540 context->network_task_runner()); |
496 return new It2MeHost(context.Pass(), policy_watcher.Pass(), observer, | 541 return new It2MeHost(context.Pass(), policy_watcher.Pass(), |
497 xmpp_server_config, directory_bot_jid); | 542 confirmation_dialog_factory.Pass(), |
543 observer, xmpp_server_config, directory_bot_jid); | |
498 } | 544 } |
499 | 545 |
500 } // namespace remoting | 546 } // namespace remoting |
OLD | NEW |