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_impl.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/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
11 #include "net/socket/client_socket_factory.h" | 11 #include "net/socket/client_socket_factory.h" |
12 #include "remoting/base/auto_thread.h" | 12 #include "remoting/base/auto_thread.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/it2me_desktop_environment.h" | 18 #include "remoting/host/it2me_desktop_environment.h" |
19 #include "remoting/host/policy_hack/policy_watcher.h" | 19 #include "remoting/host/policy_hack/policy_watcher.h" |
20 #include "remoting/host/register_support_host_request.h" | 20 #include "remoting/host/register_support_host_request.h" |
21 #include "remoting/host/session_manager_factory.h" | 21 #include "remoting/host/session_manager_factory.h" |
22 #include "remoting/jingle_glue/network_settings.h" | 22 #include "remoting/jingle_glue/network_settings.h" |
23 #include "remoting/protocol/it2me_host_authenticator_factory.h" | 23 #include "remoting/protocol/it2me_host_authenticator_factory.h" |
24 | 24 |
25 namespace remoting { | 25 namespace remoting { |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 // This is used for tagging system event logs. | 29 // This is used for tagging system event logs. |
30 const char kApplicationName[] = "chromoting"; | 30 const char kApplicationName[] = "chromoting"; |
31 const int kMaxLoginAttempts = 5; | 31 const int kMaxLoginAttempts = 5; |
32 | 32 |
33 } // namespace | 33 } // namespace |
34 | 34 |
35 It2MeImpl::It2MeImpl( | 35 It2MeHost::It2MeHost( |
36 scoped_ptr<ChromotingHostContext> host_context, | 36 scoped_ptr<ChromotingHostContext> host_context, |
37 scoped_refptr<base::SingleThreadTaskRunner> plugin_task_runner, | 37 scoped_refptr<base::SingleThreadTaskRunner> plugin_task_runner, |
38 base::WeakPtr<It2MeImpl::Observer> observer, | 38 base::WeakPtr<It2MeHost::Observer> observer, |
39 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, | 39 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, |
40 const std::string& directory_bot_jid) | 40 const std::string& directory_bot_jid) |
41 : host_context_(host_context.Pass()), | 41 : host_context_(host_context.Pass()), |
42 plugin_task_runner_(plugin_task_runner), | 42 plugin_task_runner_(plugin_task_runner), |
43 observer_(observer), | 43 observer_(observer), |
44 xmpp_server_config_(xmpp_server_config), | 44 xmpp_server_config_(xmpp_server_config), |
45 directory_bot_jid_(directory_bot_jid), | 45 directory_bot_jid_(directory_bot_jid), |
46 state_(kDisconnected), | 46 state_(kDisconnected), |
47 failed_login_attempts_(0), | 47 failed_login_attempts_(0), |
48 nat_traversal_enabled_(false), | 48 nat_traversal_enabled_(false), |
49 policy_received_(false) { | 49 policy_received_(false) { |
50 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 50 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
51 } | 51 } |
52 | 52 |
53 void It2MeImpl::Connect() { | 53 void It2MeHost::Connect() { |
54 if (!host_context_->ui_task_runner()->BelongsToCurrentThread()) { | 54 if (!host_context_->ui_task_runner()->BelongsToCurrentThread()) { |
55 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 55 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
56 host_context_->ui_task_runner()->PostTask( | 56 host_context_->ui_task_runner()->PostTask( |
57 FROM_HERE, base::Bind(&It2MeImpl::Connect, this)); | 57 FROM_HERE, base::Bind(&It2MeHost::Connect, this)); |
58 return; | 58 return; |
59 } | 59 } |
60 | 60 |
61 desktop_environment_factory_.reset(new It2MeDesktopEnvironmentFactory( | 61 desktop_environment_factory_.reset(new It2MeDesktopEnvironmentFactory( |
62 host_context_->network_task_runner(), | 62 host_context_->network_task_runner(), |
63 host_context_->input_task_runner(), | 63 host_context_->input_task_runner(), |
64 host_context_->ui_task_runner())); | 64 host_context_->ui_task_runner())); |
65 | 65 |
66 // Start monitoring configured policies. | 66 // Start monitoring configured policies. |
67 policy_watcher_.reset( | 67 policy_watcher_.reset( |
68 policy_hack::PolicyWatcher::Create(host_context_->network_task_runner())); | 68 policy_hack::PolicyWatcher::Create(host_context_->network_task_runner())); |
69 policy_watcher_->StartWatching( | 69 policy_watcher_->StartWatching( |
70 base::Bind(&It2MeImpl::OnPolicyUpdate, this)); | 70 base::Bind(&It2MeHost::OnPolicyUpdate, this)); |
71 | 71 |
72 // Switch to the network thread to start the actual connection. | 72 // Switch to the network thread to start the actual connection. |
73 host_context_->network_task_runner()->PostTask( | 73 host_context_->network_task_runner()->PostTask( |
74 FROM_HERE, base::Bind(&It2MeImpl::ReadPolicyAndConnect, this)); | 74 FROM_HERE, base::Bind(&It2MeHost::ReadPolicyAndConnect, this)); |
75 } | 75 } |
76 | 76 |
77 void It2MeImpl::Disconnect() { | 77 void It2MeHost::Disconnect() { |
78 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { | 78 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { |
79 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 79 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
80 host_context_->network_task_runner()->PostTask( | 80 host_context_->network_task_runner()->PostTask( |
81 FROM_HERE, base::Bind(&It2MeImpl::Disconnect, this)); | 81 FROM_HERE, base::Bind(&It2MeHost::Disconnect, this)); |
82 return; | 82 return; |
83 } | 83 } |
84 | 84 |
85 switch (state_) { | 85 switch (state_) { |
86 case kDisconnected: | 86 case kDisconnected: |
87 ShutdownOnNetworkThread(); | 87 ShutdownOnNetworkThread(); |
88 return; | 88 return; |
89 | 89 |
90 case kStarting: | 90 case kStarting: |
91 SetState(kDisconnecting); | 91 SetState(kDisconnecting); |
(...skipping 10 matching lines...) Expand all Loading... |
102 if (!host_) { | 102 if (!host_) { |
103 SetState(kDisconnected); | 103 SetState(kDisconnected); |
104 ShutdownOnNetworkThread(); | 104 ShutdownOnNetworkThread(); |
105 return; | 105 return; |
106 } | 106 } |
107 | 107 |
108 // Deleting the host destroys SignalStrategy synchronously, but | 108 // Deleting the host destroys SignalStrategy synchronously, but |
109 // SignalStrategy::Listener handlers are not allowed to destroy | 109 // SignalStrategy::Listener handlers are not allowed to destroy |
110 // SignalStrategy, so post task to destroy the host later. | 110 // SignalStrategy, so post task to destroy the host later. |
111 host_context_->network_task_runner()->PostTask( | 111 host_context_->network_task_runner()->PostTask( |
112 FROM_HERE, base::Bind(&It2MeImpl::ShutdownOnNetworkThread, this)); | 112 FROM_HERE, base::Bind(&It2MeHost::ShutdownOnNetworkThread, this)); |
113 return; | 113 return; |
114 } | 114 } |
115 } | 115 } |
116 | 116 |
117 void It2MeImpl::RequestNatPolicy() { | 117 void It2MeHost::RequestNatPolicy() { |
118 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { | 118 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { |
119 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 119 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
120 host_context_->network_task_runner()->PostTask( | 120 host_context_->network_task_runner()->PostTask( |
121 FROM_HERE, base::Bind(&It2MeImpl::RequestNatPolicy, this)); | 121 FROM_HERE, base::Bind(&It2MeHost::RequestNatPolicy, this)); |
122 return; | 122 return; |
123 } | 123 } |
124 | 124 |
125 if (policy_received_) | 125 if (policy_received_) |
126 UpdateNatPolicy(nat_traversal_enabled_); | 126 UpdateNatPolicy(nat_traversal_enabled_); |
127 } | 127 } |
128 | 128 |
129 void It2MeImpl::ReadPolicyAndConnect() { | 129 void It2MeHost::ReadPolicyAndConnect() { |
130 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 130 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
131 | 131 |
132 SetState(kStarting); | 132 SetState(kStarting); |
133 | 133 |
134 // Only proceed to FinishConnect() if at least one policy update has been | 134 // Only proceed to FinishConnect() if at least one policy update has been |
135 // received. | 135 // received. |
136 if (policy_received_) { | 136 if (policy_received_) { |
137 FinishConnect(); | 137 FinishConnect(); |
138 } else { | 138 } else { |
139 // Otherwise, create the policy watcher, and thunk the connect. | 139 // Otherwise, create the policy watcher, and thunk the connect. |
140 pending_connect_ = | 140 pending_connect_ = |
141 base::Bind(&It2MeImpl::FinishConnect, this); | 141 base::Bind(&It2MeHost::FinishConnect, this); |
142 } | 142 } |
143 } | 143 } |
144 | 144 |
145 void It2MeImpl::FinishConnect() { | 145 void It2MeHost::FinishConnect() { |
146 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 146 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
147 | 147 |
148 if (state_ != kStarting) { | 148 if (state_ != kStarting) { |
149 // Host has been stopped while we were fetching policy. | 149 // Host has been stopped while we were fetching policy. |
150 return; | 150 return; |
151 } | 151 } |
152 | 152 |
153 // Check the host domain policy. | 153 // Check the host domain policy. |
154 if (!required_host_domain_.empty() && | 154 if (!required_host_domain_.empty() && |
155 !EndsWith(xmpp_server_config_.username, | 155 !EndsWith(xmpp_server_config_.username, |
156 std::string("@") + required_host_domain_, false)) { | 156 std::string("@") + required_host_domain_, false)) { |
157 SetState(kInvalidDomainError); | 157 SetState(kInvalidDomainError); |
158 return; | 158 return; |
159 } | 159 } |
160 | 160 |
161 // Generate a key pair for the Host to use. | 161 // Generate a key pair for the Host to use. |
162 // TODO(wez): Move this to the worker thread. | 162 // TODO(wez): Move this to the worker thread. |
163 host_key_pair_ = RsaKeyPair::Generate(); | 163 host_key_pair_ = RsaKeyPair::Generate(); |
164 | 164 |
165 // Create XMPP connection. | 165 // Create XMPP connection. |
166 scoped_ptr<SignalStrategy> signal_strategy( | 166 scoped_ptr<SignalStrategy> signal_strategy( |
167 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), | 167 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), |
168 host_context_->url_request_context_getter(), | 168 host_context_->url_request_context_getter(), |
169 xmpp_server_config_)); | 169 xmpp_server_config_)); |
170 | 170 |
171 // Request registration of the host for support. | 171 // Request registration of the host for support. |
172 scoped_ptr<RegisterSupportHostRequest> register_request( | 172 scoped_ptr<RegisterSupportHostRequest> register_request( |
173 new RegisterSupportHostRequest( | 173 new RegisterSupportHostRequest( |
174 signal_strategy.get(), host_key_pair_, directory_bot_jid_, | 174 signal_strategy.get(), host_key_pair_, directory_bot_jid_, |
175 base::Bind(&It2MeImpl::OnReceivedSupportID, | 175 base::Bind(&It2MeHost::OnReceivedSupportID, |
176 base::Unretained(this)))); | 176 base::Unretained(this)))); |
177 | 177 |
178 // Beyond this point nothing can fail, so save the config and request. | 178 // Beyond this point nothing can fail, so save the config and request. |
179 signal_strategy_ = signal_strategy.Pass(); | 179 signal_strategy_ = signal_strategy.Pass(); |
180 register_request_ = register_request.Pass(); | 180 register_request_ = register_request.Pass(); |
181 | 181 |
182 // If NAT traversal is off then limit port range to allow firewall pin-holing. | 182 // If NAT traversal is off then limit port range to allow firewall pin-holing. |
183 LOG(INFO) << "NAT state: " << nat_traversal_enabled_; | 183 LOG(INFO) << "NAT state: " << nat_traversal_enabled_; |
184 NetworkSettings network_settings( | 184 NetworkSettings network_settings( |
185 nat_traversal_enabled_ ? | 185 nat_traversal_enabled_ ? |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName); | 224 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName); |
225 | 225 |
226 // Connect signaling and start the host. | 226 // Connect signaling and start the host. |
227 signal_strategy_->Connect(); | 227 signal_strategy_->Connect(); |
228 host_->Start(xmpp_server_config_.username); | 228 host_->Start(xmpp_server_config_.username); |
229 | 229 |
230 SetState(kRequestedAccessCode); | 230 SetState(kRequestedAccessCode); |
231 return; | 231 return; |
232 } | 232 } |
233 | 233 |
234 void It2MeImpl::ShutdownOnNetworkThread() { | 234 void It2MeHost::ShutdownOnNetworkThread() { |
235 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 235 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
236 DCHECK(state_ == kDisconnecting || state_ == kDisconnected); | 236 DCHECK(state_ == kDisconnecting || state_ == kDisconnected); |
237 | 237 |
238 if (state_ == kDisconnecting) { | 238 if (state_ == kDisconnecting) { |
239 host_event_logger_.reset(); | 239 host_event_logger_.reset(); |
240 host_->RemoveStatusObserver(this); | 240 host_->RemoveStatusObserver(this); |
241 host_.reset(); | 241 host_.reset(); |
242 | 242 |
243 register_request_.reset(); | 243 register_request_.reset(); |
244 log_to_server_.reset(); | 244 log_to_server_.reset(); |
245 signal_strategy_.reset(); | 245 signal_strategy_.reset(); |
246 SetState(kDisconnected); | 246 SetState(kDisconnected); |
247 } | 247 } |
248 | 248 |
249 host_context_->ui_task_runner()->PostTask( | 249 host_context_->ui_task_runner()->PostTask( |
250 FROM_HERE, base::Bind(&It2MeImpl::ShutdownOnUiThread, this)); | 250 FROM_HERE, base::Bind(&It2MeHost::ShutdownOnUiThread, this)); |
251 } | 251 } |
252 | 252 |
253 void It2MeImpl::ShutdownOnUiThread() { | 253 void It2MeHost::ShutdownOnUiThread() { |
254 DCHECK(host_context_->ui_task_runner()->BelongsToCurrentThread()); | 254 DCHECK(host_context_->ui_task_runner()->BelongsToCurrentThread()); |
255 | 255 |
256 // Destroy the DesktopEnvironmentFactory, to free thread references. | 256 // Destroy the DesktopEnvironmentFactory, to free thread references. |
257 desktop_environment_factory_.reset(); | 257 desktop_environment_factory_.reset(); |
258 | 258 |
259 // Stop listening for policy updates. | 259 // Stop listening for policy updates. |
260 if (policy_watcher_.get()) { | 260 if (policy_watcher_.get()) { |
261 base::WaitableEvent policy_watcher_stopped_(true, false); | 261 base::WaitableEvent policy_watcher_stopped_(true, false); |
262 policy_watcher_->StopWatching(&policy_watcher_stopped_); | 262 policy_watcher_->StopWatching(&policy_watcher_stopped_); |
263 policy_watcher_stopped_.Wait(); | 263 policy_watcher_stopped_.Wait(); |
264 policy_watcher_.reset(); | 264 policy_watcher_.reset(); |
265 } | 265 } |
266 } | 266 } |
267 | 267 |
268 void It2MeImpl::OnAccessDenied(const std::string& jid) { | 268 void It2MeHost::OnAccessDenied(const std::string& jid) { |
269 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 269 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
270 | 270 |
271 ++failed_login_attempts_; | 271 ++failed_login_attempts_; |
272 if (failed_login_attempts_ == kMaxLoginAttempts) { | 272 if (failed_login_attempts_ == kMaxLoginAttempts) { |
273 Disconnect(); | 273 Disconnect(); |
274 } | 274 } |
275 } | 275 } |
276 | 276 |
277 void It2MeImpl::OnClientAuthenticated( | 277 void It2MeHost::OnClientAuthenticated(const std::string& jid) { |
278 const std::string& jid) { | |
279 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 278 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
280 | 279 |
281 if (state_ == kDisconnecting) { | 280 if (state_ == kDisconnecting) { |
282 // Ignore the new connection if we are disconnecting. | 281 // Ignore the new connection if we are disconnecting. |
283 return; | 282 return; |
284 } | 283 } |
285 if (state_ == kConnected) { | 284 if (state_ == kConnected) { |
286 // If we already connected another client then one of the connections may be | 285 // If we already connected another client then one of the connections may be |
287 // an attacker, so both are suspect and we have to reject the second | 286 // an attacker, so both are suspect and we have to reject the second |
288 // connection and shutdown the host. | 287 // connection and shutdown the host. |
289 host_->RejectAuthenticatingClient(); | 288 host_->RejectAuthenticatingClient(); |
290 Disconnect(); | 289 Disconnect(); |
291 return; | 290 return; |
292 } | 291 } |
293 | 292 |
294 std::string client_username = jid; | 293 std::string client_username = jid; |
295 size_t pos = client_username.find('/'); | 294 size_t pos = client_username.find('/'); |
296 if (pos != std::string::npos) | 295 if (pos != std::string::npos) |
297 client_username.replace(pos, std::string::npos, ""); | 296 client_username.replace(pos, std::string::npos, ""); |
298 | 297 |
299 LOG(INFO) << "Client " << client_username << " connected."; | 298 LOG(INFO) << "Client " << client_username << " connected."; |
300 | 299 |
301 // Pass the client user name to the script object before changing state. | 300 // Pass the client user name to the script object before changing state. |
302 plugin_task_runner_->PostTask( | 301 plugin_task_runner_->PostTask( |
303 FROM_HERE, base::Bind(&It2MeImpl::Observer::OnClientAuthenticated, | 302 FROM_HERE, base::Bind(&It2MeHost::Observer::OnClientAuthenticated, |
304 observer_, client_username)); | 303 observer_, client_username)); |
305 | 304 |
306 SetState(kConnected); | 305 SetState(kConnected); |
307 } | 306 } |
308 | 307 |
309 void It2MeImpl::OnClientDisconnected( | 308 void It2MeHost::OnClientDisconnected(const std::string& jid) { |
310 const std::string& jid) { | |
311 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 309 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
312 | 310 |
313 Disconnect(); | 311 Disconnect(); |
314 } | 312 } |
315 | 313 |
316 void It2MeImpl::OnPolicyUpdate( | 314 void It2MeHost::OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies) { |
317 scoped_ptr<base::DictionaryValue> policies) { | |
318 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 315 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
319 | 316 |
320 bool nat_policy; | 317 bool nat_policy; |
321 if (policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName, | 318 if (policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName, |
322 &nat_policy)) { | 319 &nat_policy)) { |
323 UpdateNatPolicy(nat_policy); | 320 UpdateNatPolicy(nat_policy); |
324 } | 321 } |
325 std::string host_domain; | 322 std::string host_domain; |
326 if (policies->GetString(policy_hack::PolicyWatcher::kHostDomainPolicyName, | 323 if (policies->GetString(policy_hack::PolicyWatcher::kHostDomainPolicyName, |
327 &host_domain)) { | 324 &host_domain)) { |
328 UpdateHostDomainPolicy(host_domain); | 325 UpdateHostDomainPolicy(host_domain); |
329 } | 326 } |
330 | 327 |
331 policy_received_ = true; | 328 policy_received_ = true; |
332 | 329 |
333 if (!pending_connect_.is_null()) { | 330 if (!pending_connect_.is_null()) { |
334 pending_connect_.Run(); | 331 pending_connect_.Run(); |
335 pending_connect_.Reset(); | 332 pending_connect_.Reset(); |
336 } | 333 } |
337 } | 334 } |
338 | 335 |
339 void It2MeImpl::UpdateNatPolicy( | 336 void It2MeHost::UpdateNatPolicy(bool nat_traversal_enabled) { |
340 bool nat_traversal_enabled) { | |
341 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 337 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
342 | 338 |
343 VLOG(2) << "UpdateNatPolicy: " << nat_traversal_enabled; | 339 VLOG(2) << "UpdateNatPolicy: " << nat_traversal_enabled; |
344 | 340 |
345 // When transitioning from enabled to disabled, force disconnect any | 341 // When transitioning from enabled to disabled, force disconnect any |
346 // existing session. | 342 // existing session. |
347 if (nat_traversal_enabled_ && !nat_traversal_enabled && IsConnected()) { | 343 if (nat_traversal_enabled_ && !nat_traversal_enabled && IsConnected()) { |
348 Disconnect(); | 344 Disconnect(); |
349 } | 345 } |
350 | 346 |
351 nat_traversal_enabled_ = nat_traversal_enabled; | 347 nat_traversal_enabled_ = nat_traversal_enabled; |
352 | 348 |
353 // Notify the web-app of the policy setting. | 349 // Notify the web-app of the policy setting. |
354 plugin_task_runner_->PostTask( | 350 plugin_task_runner_->PostTask( |
355 FROM_HERE, base::Bind(&It2MeImpl::Observer::OnNatPolicyChanged, | 351 FROM_HERE, base::Bind(&It2MeHost::Observer::OnNatPolicyChanged, |
356 observer_, nat_traversal_enabled_)); | 352 observer_, nat_traversal_enabled_)); |
357 } | 353 } |
358 | 354 |
359 void It2MeImpl::UpdateHostDomainPolicy( | 355 void It2MeHost::UpdateHostDomainPolicy(const std::string& host_domain) { |
360 const std::string& host_domain) { | |
361 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 356 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
362 | 357 |
363 VLOG(2) << "UpdateHostDomainPolicy: " << host_domain; | 358 VLOG(2) << "UpdateHostDomainPolicy: " << host_domain; |
364 | 359 |
365 // When setting a host domain policy, force disconnect any existing session. | 360 // When setting a host domain policy, force disconnect any existing session. |
366 if (!host_domain.empty() && IsConnected()) { | 361 if (!host_domain.empty() && IsConnected()) { |
367 Disconnect(); | 362 Disconnect(); |
368 } | 363 } |
369 | 364 |
370 required_host_domain_ = host_domain; | 365 required_host_domain_ = host_domain; |
371 } | 366 } |
372 | 367 |
373 It2MeImpl::~It2MeImpl() { | 368 It2MeHost::~It2MeHost() { |
374 // Check that resources that need to be torn down on the UI thread are gone. | 369 // Check that resources that need to be torn down on the UI thread are gone. |
375 DCHECK(!desktop_environment_factory_.get()); | 370 DCHECK(!desktop_environment_factory_.get()); |
376 DCHECK(!policy_watcher_.get()); | 371 DCHECK(!policy_watcher_.get()); |
377 } | 372 } |
378 | 373 |
379 void It2MeImpl::SetState(It2MeHostState state) { | 374 void It2MeHost::SetState(It2MeHostState state) { |
380 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 375 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
381 | 376 |
382 switch (state_) { | 377 switch (state_) { |
383 case kDisconnected: | 378 case kDisconnected: |
384 DCHECK(state == kStarting || | 379 DCHECK(state == kStarting || |
385 state == kError) << state; | 380 state == kError) << state; |
386 break; | 381 break; |
387 case kStarting: | 382 case kStarting: |
388 DCHECK(state == kRequestedAccessCode || | 383 DCHECK(state == kRequestedAccessCode || |
389 state == kDisconnecting || | 384 state == kDisconnecting || |
(...skipping 23 matching lines...) Expand all Loading... |
413 break; | 408 break; |
414 case kInvalidDomainError: | 409 case kInvalidDomainError: |
415 DCHECK(state == kDisconnecting) << state; | 410 DCHECK(state == kDisconnecting) << state; |
416 break; | 411 break; |
417 }; | 412 }; |
418 | 413 |
419 state_ = state; | 414 state_ = state; |
420 | 415 |
421 // Post a state-change notification to the web-app. | 416 // Post a state-change notification to the web-app. |
422 plugin_task_runner_->PostTask( | 417 plugin_task_runner_->PostTask( |
423 FROM_HERE, base::Bind(&It2MeImpl::Observer::OnStateChanged, | 418 FROM_HERE, base::Bind(&It2MeHost::Observer::OnStateChanged, |
424 observer_, state)); | 419 observer_, state)); |
425 } | 420 } |
426 | 421 |
427 bool It2MeImpl::IsConnected() const { | 422 bool It2MeHost::IsConnected() const { |
428 return state_ == kRequestedAccessCode || state_ == kReceivedAccessCode || | 423 return state_ == kRequestedAccessCode || state_ == kReceivedAccessCode || |
429 state_ == kConnected; | 424 state_ == kConnected; |
430 } | 425 } |
431 | 426 |
432 void It2MeImpl::OnReceivedSupportID( | 427 void It2MeHost::OnReceivedSupportID( |
433 bool success, | 428 bool success, |
434 const std::string& support_id, | 429 const std::string& support_id, |
435 const base::TimeDelta& lifetime) { | 430 const base::TimeDelta& lifetime) { |
436 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 431 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
437 | 432 |
438 if (!success) { | 433 if (!success) { |
439 SetState(kError); | 434 SetState(kError); |
440 Disconnect(); | 435 Disconnect(); |
441 return; | 436 return; |
442 } | 437 } |
443 | 438 |
444 std::string host_secret = GenerateSupportHostSecret(); | 439 std::string host_secret = GenerateSupportHostSecret(); |
445 std::string access_code = support_id + host_secret; | 440 std::string access_code = support_id + host_secret; |
446 | 441 |
447 std::string local_certificate = host_key_pair_->GenerateCertificate(); | 442 std::string local_certificate = host_key_pair_->GenerateCertificate(); |
448 if (local_certificate.empty()) { | 443 if (local_certificate.empty()) { |
449 LOG(ERROR) << "Failed to generate host certificate."; | 444 LOG(ERROR) << "Failed to generate host certificate."; |
450 SetState(kError); | 445 SetState(kError); |
451 Disconnect(); | 446 Disconnect(); |
452 return; | 447 return; |
453 } | 448 } |
454 | 449 |
455 scoped_ptr<protocol::AuthenticatorFactory> factory( | 450 scoped_ptr<protocol::AuthenticatorFactory> factory( |
456 new protocol::It2MeHostAuthenticatorFactory( | 451 new protocol::It2MeHostAuthenticatorFactory( |
457 local_certificate, host_key_pair_, access_code)); | 452 local_certificate, host_key_pair_, access_code)); |
458 host_->SetAuthenticatorFactory(factory.Pass()); | 453 host_->SetAuthenticatorFactory(factory.Pass()); |
459 | 454 |
460 // Pass the Access Code to the script object before changing state. | 455 // Pass the Access Code to the script object before changing state. |
461 plugin_task_runner_->PostTask( | 456 plugin_task_runner_->PostTask( |
462 FROM_HERE, base::Bind(&It2MeImpl::Observer::OnStoreAccessCode, | 457 FROM_HERE, base::Bind(&It2MeHost::Observer::OnStoreAccessCode, |
463 observer_, access_code, lifetime)); | 458 observer_, access_code, lifetime)); |
464 | 459 |
465 SetState(kReceivedAccessCode); | 460 SetState(kReceivedAccessCode); |
466 } | 461 } |
467 | 462 |
468 } // namespace remoting | 463 } // namespace remoting |
OLD | NEW |