OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/plugin/host_script_object.h" | 5 #include "remoting/host/plugin/host_script_object.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
14 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
15 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
19 #include "remoting/base/auth_token_util.h" | 19 #include "remoting/base/auth_token_util.h" |
20 #include "remoting/base/auto_thread.h" | 20 #include "remoting/base/auto_thread.h" |
21 #include "remoting/base/rsa_key_pair.h" | 21 #include "remoting/base/rsa_key_pair.h" |
22 #include "remoting/host/basic_desktop_environment.h" | |
23 #include "remoting/host/chromoting_host.h" | 22 #include "remoting/host/chromoting_host.h" |
24 #include "remoting/host/chromoting_host_context.h" | 23 #include "remoting/host/chromoting_host_context.h" |
25 #include "remoting/host/host_config.h" | 24 #include "remoting/host/host_config.h" |
26 #include "remoting/host/host_event_logger.h" | 25 #include "remoting/host/host_event_logger.h" |
27 #include "remoting/host/host_secret.h" | 26 #include "remoting/host/host_secret.h" |
28 #include "remoting/host/host_status_observer.h" | 27 #include "remoting/host/host_status_observer.h" |
29 #include "remoting/host/it2me_host_user_interface.h" | 28 #include "remoting/host/it2me_desktop_environment.h" |
30 #include "remoting/host/network_settings.h" | 29 #include "remoting/host/network_settings.h" |
31 #include "remoting/host/pin_hash.h" | 30 #include "remoting/host/pin_hash.h" |
32 #include "remoting/host/plugin/host_log_handler.h" | 31 #include "remoting/host/plugin/host_log_handler.h" |
33 #include "remoting/host/policy_hack/policy_watcher.h" | 32 #include "remoting/host/policy_hack/policy_watcher.h" |
34 #include "remoting/host/register_support_host_request.h" | 33 #include "remoting/host/register_support_host_request.h" |
35 #include "remoting/host/service_urls.h" | 34 #include "remoting/host/service_urls.h" |
36 #include "remoting/host/session_manager_factory.h" | 35 #include "remoting/host/session_manager_factory.h" |
37 #include "remoting/jingle_glue/xmpp_signal_strategy.h" | 36 #include "remoting/jingle_glue/xmpp_signal_strategy.h" |
38 #include "remoting/protocol/it2me_host_authenticator_factory.h" | 37 #include "remoting/protocol/it2me_host_authenticator_factory.h" |
39 #include "third_party/npapi/bindings/npruntime.h" | 38 #include "third_party/npapi/bindings/npruntime.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; | 159 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; |
161 std::string directory_bot_jid_; | 160 std::string directory_bot_jid_; |
162 | 161 |
163 State state_; | 162 State state_; |
164 | 163 |
165 scoped_refptr<RsaKeyPair> host_key_pair_; | 164 scoped_refptr<RsaKeyPair> host_key_pair_; |
166 scoped_ptr<SignalStrategy> signal_strategy_; | 165 scoped_ptr<SignalStrategy> signal_strategy_; |
167 scoped_ptr<RegisterSupportHostRequest> register_request_; | 166 scoped_ptr<RegisterSupportHostRequest> register_request_; |
168 scoped_ptr<LogToServer> log_to_server_; | 167 scoped_ptr<LogToServer> log_to_server_; |
169 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; | 168 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; |
170 scoped_ptr<It2MeHostUserInterface> it2me_host_user_interface_; | |
171 scoped_ptr<HostEventLogger> host_event_logger_; | 169 scoped_ptr<HostEventLogger> host_event_logger_; |
172 | 170 |
173 scoped_refptr<ChromotingHost> host_; | 171 scoped_refptr<ChromotingHost> host_; |
174 int failed_login_attempts_; | 172 int failed_login_attempts_; |
175 | 173 |
176 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; | 174 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; |
177 | 175 |
178 // Host the current nat traversal policy setting. | 176 // Host the current nat traversal policy setting. |
179 bool nat_traversal_enabled_; | 177 bool nat_traversal_enabled_; |
180 | 178 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 const UiStrings& ui_strings) { | 218 const UiStrings& ui_strings) { |
221 if (!host_context_->ui_task_runner()->BelongsToCurrentThread()) { | 219 if (!host_context_->ui_task_runner()->BelongsToCurrentThread()) { |
222 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 220 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
223 host_context_->ui_task_runner()->PostTask( | 221 host_context_->ui_task_runner()->PostTask( |
224 FROM_HERE, | 222 FROM_HERE, |
225 base::Bind(&It2MeImpl::Connect, this, uid, auth_token, auth_service, | 223 base::Bind(&It2MeImpl::Connect, this, uid, auth_token, auth_service, |
226 ui_strings)); | 224 ui_strings)); |
227 return; | 225 return; |
228 } | 226 } |
229 | 227 |
230 desktop_environment_factory_.reset(new BasicDesktopEnvironmentFactory( | 228 desktop_environment_factory_.reset(new It2MeDesktopEnvironmentFactory( |
231 host_context_->network_task_runner(), | 229 host_context_->network_task_runner(), |
232 host_context_->input_task_runner(), | 230 host_context_->input_task_runner(), |
233 host_context_->ui_task_runner(), | 231 host_context_->ui_task_runner(), |
234 ui_strings)); | 232 ui_strings)); |
235 | 233 |
236 // Start monitoring configured policies. | 234 // Start monitoring configured policies. |
237 policy_watcher_.reset( | 235 policy_watcher_.reset( |
238 policy_hack::PolicyWatcher::Create(host_context_->network_task_runner())); | 236 policy_hack::PolicyWatcher::Create(host_context_->network_task_runner())); |
239 policy_watcher_->StartWatching( | 237 policy_watcher_->StartWatching( |
240 base::Bind(&It2MeImpl::OnPolicyUpdate, this)); | 238 base::Bind(&It2MeImpl::OnPolicyUpdate, this)); |
241 | 239 |
242 // The UserInterface object needs to be created on the UI thread. | |
243 it2me_host_user_interface_.reset( | |
244 new It2MeHostUserInterface(host_context_->network_task_runner(), | |
245 host_context_->ui_task_runner(), ui_strings)); | |
246 it2me_host_user_interface_->Init(); | |
247 | |
248 // Switch to the network thread to start the actual connection. | 240 // Switch to the network thread to start the actual connection. |
249 host_context_->network_task_runner()->PostTask( | 241 host_context_->network_task_runner()->PostTask( |
250 FROM_HERE, base::Bind( | 242 FROM_HERE, base::Bind( |
251 &It2MeImpl::ReadPolicyAndConnect, this, | 243 &It2MeImpl::ReadPolicyAndConnect, this, |
252 uid, auth_token, auth_service)); | 244 uid, auth_token, auth_service)); |
253 } | 245 } |
254 | 246 |
255 void HostNPScriptObject::It2MeImpl::Disconnect() { | 247 void HostNPScriptObject::It2MeImpl::Disconnect() { |
256 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { | 248 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { |
257 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 249 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 new LogToServer(host_->AsWeakPtr(), ServerLogEntry::IT2ME, | 385 new LogToServer(host_->AsWeakPtr(), ServerLogEntry::IT2ME, |
394 signal_strategy_.get(), directory_bot_jid_)); | 386 signal_strategy_.get(), directory_bot_jid_)); |
395 | 387 |
396 // Disable audio by default. | 388 // Disable audio by default. |
397 // TODO(sergeyu): Add UI to enable it. | 389 // TODO(sergeyu): Add UI to enable it. |
398 scoped_ptr<protocol::CandidateSessionConfig> protocol_config = | 390 scoped_ptr<protocol::CandidateSessionConfig> protocol_config = |
399 protocol::CandidateSessionConfig::CreateDefault(); | 391 protocol::CandidateSessionConfig::CreateDefault(); |
400 protocol::CandidateSessionConfig::DisableAudioChannel(protocol_config.get()); | 392 protocol::CandidateSessionConfig::DisableAudioChannel(protocol_config.get()); |
401 host_->set_protocol_config(protocol_config.Pass()); | 393 host_->set_protocol_config(protocol_config.Pass()); |
402 | 394 |
403 // Create user interface. | |
404 it2me_host_user_interface_->Start(host_.get(), | |
405 base::Bind(&It2MeImpl::Disconnect, this)); | |
406 | |
407 // Create event logger. | 395 // Create event logger. |
408 host_event_logger_ = | 396 host_event_logger_ = |
409 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName); | 397 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName); |
410 | 398 |
411 // Connect signaling and start the host. | 399 // Connect signaling and start the host. |
412 signal_strategy_->Connect(); | 400 signal_strategy_->Connect(); |
413 host_->Start(uid); | 401 host_->Start(uid); |
414 | 402 |
415 SetState(kRequestedAccessCode); | 403 SetState(kRequestedAccessCode); |
416 return; | 404 return; |
417 } | 405 } |
418 | 406 |
419 void HostNPScriptObject::It2MeImpl::OnShutdownFinished() { | 407 void HostNPScriptObject::It2MeImpl::OnShutdownFinished() { |
420 if (!host_context_->ui_task_runner()->BelongsToCurrentThread()) { | 408 if (!host_context_->ui_task_runner()->BelongsToCurrentThread()) { |
421 host_context_->ui_task_runner()->PostTask( | 409 host_context_->ui_task_runner()->PostTask( |
422 FROM_HERE, base::Bind(&It2MeImpl::OnShutdownFinished, this)); | 410 FROM_HERE, base::Bind(&It2MeImpl::OnShutdownFinished, this)); |
423 return; | 411 return; |
424 } | 412 } |
425 | 413 |
426 // Note that OnShutdownFinished() may be called more than once. | 414 // Note that OnShutdownFinished() may be called more than once. |
427 | 415 |
428 // UI needs to be shut down on the UI thread before we destroy the | |
429 // host context (because it depends on the context object), but | |
430 // only after the host has been shut down (becase the UI object is | |
431 // registered as status observer for the host, and we can't | |
432 // unregister it from this thread). | |
433 it2me_host_user_interface_.reset(); | |
434 | |
435 // Destroy the DesktopEnvironmentFactory, to free thread references. | 416 // Destroy the DesktopEnvironmentFactory, to free thread references. |
436 desktop_environment_factory_.reset(); | 417 desktop_environment_factory_.reset(); |
437 | 418 |
438 // Stop listening for policy updates. | 419 // Stop listening for policy updates. |
439 if (policy_watcher_.get()) { | 420 if (policy_watcher_.get()) { |
440 base::WaitableEvent policy_watcher_stopped_(true, false); | 421 base::WaitableEvent policy_watcher_stopped_(true, false); |
441 policy_watcher_->StopWatching(&policy_watcher_stopped_); | 422 policy_watcher_->StopWatching(&policy_watcher_stopped_); |
442 policy_watcher_stopped_.Wait(); | 423 policy_watcher_stopped_.Wait(); |
443 policy_watcher_.reset(); | 424 policy_watcher_.reset(); |
444 } | 425 } |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 // When setting a host domain policy, force disconnect any existing session. | 545 // When setting a host domain policy, force disconnect any existing session. |
565 if (!host_domain.empty() && IsConnected()) { | 546 if (!host_domain.empty() && IsConnected()) { |
566 Disconnect(); | 547 Disconnect(); |
567 } | 548 } |
568 | 549 |
569 required_host_domain_ = host_domain; | 550 required_host_domain_ = host_domain; |
570 } | 551 } |
571 | 552 |
572 HostNPScriptObject::It2MeImpl::~It2MeImpl() { | 553 HostNPScriptObject::It2MeImpl::~It2MeImpl() { |
573 // Check that resources that need to be torn down on the UI thread are gone. | 554 // Check that resources that need to be torn down on the UI thread are gone. |
574 DCHECK(!it2me_host_user_interface_.get()); | |
575 DCHECK(!desktop_environment_factory_.get()); | 555 DCHECK(!desktop_environment_factory_.get()); |
576 DCHECK(!policy_watcher_.get()); | 556 DCHECK(!policy_watcher_.get()); |
577 } | 557 } |
578 | 558 |
579 void HostNPScriptObject::It2MeImpl::SetState(State state) { | 559 void HostNPScriptObject::It2MeImpl::SetState(State state) { |
580 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 560 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
581 | 561 |
582 switch (state_) { | 562 switch (state_) { |
583 case kDisconnected: | 563 case kDisconnected: |
584 DCHECK(state == kStarting || | 564 DCHECK(state == kStarting || |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 SetState(kReceivedAccessCode); | 645 SetState(kReceivedAccessCode); |
666 } | 646 } |
667 | 647 |
668 HostNPScriptObject::HostNPScriptObject( | 648 HostNPScriptObject::HostNPScriptObject( |
669 NPP plugin, | 649 NPP plugin, |
670 NPObject* parent, | 650 NPObject* parent, |
671 scoped_refptr<AutoThreadTaskRunner> plugin_task_runner) | 651 scoped_refptr<AutoThreadTaskRunner> plugin_task_runner) |
672 : plugin_(plugin), | 652 : plugin_(plugin), |
673 parent_(parent), | 653 parent_(parent), |
674 plugin_task_runner_(plugin_task_runner), | 654 plugin_task_runner_(plugin_task_runner), |
| 655 plugin_task_runner_handle_(plugin_task_runner_), |
675 am_currently_logging_(false), | 656 am_currently_logging_(false), |
676 state_(kDisconnected), | 657 state_(kDisconnected), |
677 daemon_controller_(DaemonController::Create()), | 658 daemon_controller_(DaemonController::Create()), |
678 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 659 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
679 weak_ptr_(weak_factory_.GetWeakPtr()) { | 660 weak_ptr_(weak_factory_.GetWeakPtr()) { |
680 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 661 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
681 ServiceUrls* service_urls = ServiceUrls::GetInstance(); | 662 ServiceUrls* service_urls = ServiceUrls::GetInstance(); |
682 bool xmpp_server_valid = net::ParseHostAndPort( | 663 bool xmpp_server_valid = net::ParseHostAndPort( |
683 service_urls->xmpp_server_address(), | 664 service_urls->xmpp_server_address(), |
684 &xmpp_server_config_.host, &xmpp_server_config_.port); | 665 &xmpp_server_config_.host, &xmpp_server_config_.port); |
(...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1584 } | 1565 } |
1585 | 1566 |
1586 void HostNPScriptObject::SetException(const std::string& exception_string) { | 1567 void HostNPScriptObject::SetException(const std::string& exception_string) { |
1587 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 1568 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
1588 | 1569 |
1589 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); | 1570 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); |
1590 LOG(INFO) << exception_string; | 1571 LOG(INFO) << exception_string; |
1591 } | 1572 } |
1592 | 1573 |
1593 } // namespace remoting | 1574 } // namespace remoting |
OLD | NEW |