| 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 // This file implements a standalone host process for Me2Me. | 5 // This file implements a standalone host process for Me2Me. |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "net/base/network_change_notifier.h" | 29 #include "net/base/network_change_notifier.h" |
| 30 #include "net/socket/ssl_server_socket.h" | 30 #include "net/socket/ssl_server_socket.h" |
| 31 #include "remoting/base/breakpad.h" | 31 #include "remoting/base/breakpad.h" |
| 32 #include "remoting/base/constants.h" | 32 #include "remoting/base/constants.h" |
| 33 #include "remoting/host/branding.h" | 33 #include "remoting/host/branding.h" |
| 34 #include "remoting/host/chromoting_host.h" | 34 #include "remoting/host/chromoting_host.h" |
| 35 #include "remoting/host/chromoting_host_context.h" | 35 #include "remoting/host/chromoting_host_context.h" |
| 36 #include "remoting/host/composite_host_config.h" | 36 #include "remoting/host/composite_host_config.h" |
| 37 #include "remoting/host/constants.h" | 37 #include "remoting/host/constants.h" |
| 38 #include "remoting/host/desktop_environment.h" | 38 #include "remoting/host/desktop_environment.h" |
| 39 #include "remoting/host/dns_blackhole_checker.h" |
| 39 #include "remoting/host/event_executor.h" | 40 #include "remoting/host/event_executor.h" |
| 40 #include "remoting/host/heartbeat_sender.h" | 41 #include "remoting/host/heartbeat_sender.h" |
| 41 #include "remoting/host/host_config.h" | 42 #include "remoting/host/host_config.h" |
| 42 #include "remoting/host/host_event_logger.h" | 43 #include "remoting/host/host_event_logger.h" |
| 43 #include "remoting/host/host_user_interface.h" | 44 #include "remoting/host/host_user_interface.h" |
| 44 #include "remoting/host/log_to_server.h" | 45 #include "remoting/host/log_to_server.h" |
| 45 #include "remoting/host/network_settings.h" | 46 #include "remoting/host/network_settings.h" |
| 46 #include "remoting/host/policy_hack/policy_watcher.h" | 47 #include "remoting/host/policy_hack/policy_watcher.h" |
| 47 #include "remoting/host/session_manager_factory.h" | 48 #include "remoting/host/session_manager_factory.h" |
| 48 #include "remoting/host/signaling_connector.h" | 49 #include "remoting/host/signaling_connector.h" |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 } | 386 } |
| 386 if (policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName, | 387 if (policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName, |
| 387 &bool_value)) { | 388 &bool_value)) { |
| 388 OnNatPolicyUpdate(bool_value); | 389 OnNatPolicyUpdate(bool_value); |
| 389 } | 390 } |
| 390 if (policies->GetBoolean( | 391 if (policies->GetBoolean( |
| 391 policy_hack::PolicyWatcher::kHostRequireCurtainPolicyName, | 392 policy_hack::PolicyWatcher::kHostRequireCurtainPolicyName, |
| 392 &bool_value)) { | 393 &bool_value)) { |
| 393 OnCurtainPolicyUpdate(bool_value); | 394 OnCurtainPolicyUpdate(bool_value); |
| 394 } | 395 } |
| 396 if (policies->GetString( |
| 397 policy_hack::PolicyWatcher::kHostTalkGadgetPrefixPolicyName, |
| 398 &string_value)) { |
| 399 OnHostTalkGadgetPrefixPolicyUpdate(string_value); |
| 400 } |
| 395 } | 401 } |
| 396 | 402 |
| 397 void OnHostDomainPolicyUpdate(const std::string& host_domain) { | 403 void OnHostDomainPolicyUpdate(const std::string& host_domain) { |
| 398 if (!context_->network_task_runner()->BelongsToCurrentThread()) { | 404 if (!context_->network_task_runner()->BelongsToCurrentThread()) { |
| 399 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( | 405 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( |
| 400 &HostProcess::OnHostDomainPolicyUpdate, base::Unretained(this), | 406 &HostProcess::OnHostDomainPolicyUpdate, base::Unretained(this), |
| 401 host_domain)); | 407 host_domain)); |
| 402 return; | 408 return; |
| 403 } | 409 } |
| 404 | 410 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 | 458 |
| 453 host_->AddStatusObserver(&curtain_); | 459 host_->AddStatusObserver(&curtain_); |
| 454 curtain_.SetEnabled(true); | 460 curtain_.SetEnabled(true); |
| 455 } else { | 461 } else { |
| 456 curtain_.SetEnabled(false); | 462 curtain_.SetEnabled(false); |
| 457 host_->RemoveStatusObserver(&curtain_); | 463 host_->RemoveStatusObserver(&curtain_); |
| 458 } | 464 } |
| 459 #endif | 465 #endif |
| 460 } | 466 } |
| 461 | 467 |
| 468 void OnHostTalkGadgetPrefixPolicyUpdate( |
| 469 const std::string& talkgadget_prefix) { |
| 470 if (!context_->network_task_runner()->BelongsToCurrentThread()) { |
| 471 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( |
| 472 &HostProcess::OnHostTalkGadgetPrefixPolicyUpdate, |
| 473 base::Unretained(this), talkgadget_prefix)); |
| 474 return; |
| 475 } |
| 476 |
| 477 if (talkgadget_prefix != talkgadget_prefix_) { |
| 478 LOG(INFO) << "Restarting host due to updated talkgadget policy:"; |
| 479 talkgadget_prefix_ = talkgadget_prefix; |
| 480 RestartHost(); |
| 481 } |
| 482 } |
| 483 |
| 462 void StartHost() { | 484 void StartHost() { |
| 463 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 485 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 464 DCHECK(!host_); | 486 DCHECK(!host_); |
| 487 DCHECK(!signal_strategy_.get()); |
| 465 | 488 |
| 466 if (shutting_down_) | 489 if (shutting_down_) |
| 467 return; | 490 return; |
| 468 | 491 |
| 469 if (!signal_strategy_.get()) { | 492 signal_strategy_.reset( |
| 470 signal_strategy_.reset( | 493 new XmppSignalStrategy(context_->url_request_context_getter(), |
| 471 new XmppSignalStrategy(context_->url_request_context_getter(), | 494 xmpp_login_, xmpp_auth_token_, |
| 472 xmpp_login_, xmpp_auth_token_, | 495 xmpp_auth_service_)); |
| 473 xmpp_auth_service_)); | |
| 474 | 496 |
| 475 signaling_connector_.reset(new SignalingConnector( | 497 scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker( |
| 476 signal_strategy_.get(), | 498 new DnsBlackholeChecker(context_.get(), talkgadget_prefix_)); |
| 477 base::Bind(&HostProcess::OnAuthFailed, base::Unretained(this)))); | |
| 478 | 499 |
| 479 if (!oauth_refresh_token_.empty()) { | 500 signaling_connector_.reset(new SignalingConnector( |
| 480 OAuthClientInfo client_info = { | 501 signal_strategy_.get(), context_.get(), dns_blackhole_checker.Pass(), |
| 481 kUnofficialOAuth2ClientId, | 502 base::Bind(&HostProcess::OnAuthFailed, base::Unretained(this)))); |
| 482 kUnofficialOAuth2ClientSecret | 503 |
| 504 if (!oauth_refresh_token_.empty()) { |
| 505 OAuthClientInfo client_info = { |
| 506 kUnofficialOAuth2ClientId, |
| 507 kUnofficialOAuth2ClientSecret |
| 508 }; |
| 509 |
| 510 #ifdef OFFICIAL_BUILD |
| 511 if (oauth_use_official_client_id_) { |
| 512 OAuthClientInfo official_client_info = { |
| 513 kOfficialOAuth2ClientId, |
| 514 kOfficialOAuth2ClientSecret |
| 483 }; | 515 }; |
| 484 | 516 |
| 485 #ifdef OFFICIAL_BUILD | 517 client_info = official_client_info; |
| 486 if (oauth_use_official_client_id_) { | 518 } |
| 487 OAuthClientInfo official_client_info = { | |
| 488 kOfficialOAuth2ClientId, | |
| 489 kOfficialOAuth2ClientSecret | |
| 490 }; | |
| 491 | |
| 492 client_info = official_client_info; | |
| 493 } | |
| 494 #endif // OFFICIAL_BUILD | 519 #endif // OFFICIAL_BUILD |
| 495 | 520 |
| 496 scoped_ptr<SignalingConnector::OAuthCredentials> oauth_credentials( | 521 scoped_ptr<SignalingConnector::OAuthCredentials> oauth_credentials( |
| 497 new SignalingConnector::OAuthCredentials( | 522 new SignalingConnector::OAuthCredentials( |
| 498 xmpp_login_, oauth_refresh_token_, client_info)); | 523 xmpp_login_, oauth_refresh_token_, client_info)); |
| 499 signaling_connector_->EnableOAuth( | 524 signaling_connector_->EnableOAuth(oauth_credentials.Pass()); |
| 500 oauth_credentials.Pass(), | |
| 501 context_->url_request_context_getter()); | |
| 502 } | |
| 503 } | 525 } |
| 504 | 526 |
| 505 if (!desktop_environment_.get()) { | 527 if (!desktop_environment_.get()) { |
| 506 desktop_environment_ = | 528 desktop_environment_ = |
| 507 DesktopEnvironment::CreateForService(context_.get()); | 529 DesktopEnvironment::CreateForService(context_.get()); |
| 508 } | 530 } |
| 509 | 531 |
| 510 NetworkSettings network_settings( | 532 NetworkSettings network_settings( |
| 511 allow_nat_traversal_ ? | 533 allow_nat_traversal_ ? |
| 512 NetworkSettings::NAT_TRAVERSAL_ENABLED : | 534 NetworkSettings::NAT_TRAVERSAL_ENABLED : |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 } | 592 } |
| 571 | 593 |
| 572 void RestartOnHostShutdown() { | 594 void RestartOnHostShutdown() { |
| 573 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 595 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 574 | 596 |
| 575 if (shutting_down_) | 597 if (shutting_down_) |
| 576 return; | 598 return; |
| 577 | 599 |
| 578 restarting_ = false; | 600 restarting_ = false; |
| 579 host_ = NULL; | 601 host_ = NULL; |
| 580 log_to_server_.reset(); | 602 ResetHost(); |
| 581 host_event_logger_.reset(); | |
| 582 heartbeat_sender_.reset(); | |
| 583 | 603 |
| 584 StartHost(); | 604 StartHost(); |
| 585 } | 605 } |
| 586 | 606 |
| 587 void Shutdown(int exit_code) { | 607 void Shutdown(int exit_code) { |
| 588 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 608 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 589 | 609 |
| 590 if (shutting_down_) | 610 if (shutting_down_) |
| 591 return; | 611 return; |
| 592 | 612 |
| 593 shutting_down_ = true; | 613 shutting_down_ = true; |
| 594 exit_code_ = exit_code; | 614 exit_code_ = exit_code; |
| 595 if (host_) { | 615 if (host_) { |
| 596 host_->Shutdown(base::Bind( | 616 host_->Shutdown(base::Bind( |
| 597 &HostProcess::OnShutdownFinished, base::Unretained(this))); | 617 &HostProcess::OnShutdownFinished, base::Unretained(this))); |
| 598 } else { | 618 } else { |
| 599 OnShutdownFinished(); | 619 OnShutdownFinished(); |
| 600 } | 620 } |
| 601 } | 621 } |
| 602 | 622 |
| 603 void OnShutdownFinished() { | 623 void OnShutdownFinished() { |
| 604 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 624 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 605 | 625 |
| 606 // Destroy networking objects while we are on the network thread. | 626 // Destroy networking objects while we are on the network thread. |
| 607 host_ = NULL; | 627 host_ = NULL; |
| 628 ResetHost(); |
| 629 |
| 630 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 631 } |
| 632 |
| 633 void ResetHost() { |
| 634 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 635 |
| 608 host_event_logger_.reset(); | 636 host_event_logger_.reset(); |
| 609 log_to_server_.reset(); | 637 log_to_server_.reset(); |
| 610 heartbeat_sender_.reset(); | 638 heartbeat_sender_.reset(); |
| 611 signaling_connector_.reset(); | 639 signaling_connector_.reset(); |
| 612 signal_strategy_.reset(); | 640 signal_strategy_.reset(); |
| 613 | |
| 614 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); | |
| 615 } | 641 } |
| 616 | 642 |
| 617 MessageLoop message_loop_; | 643 MessageLoop message_loop_; |
| 618 scoped_ptr<ChromotingHostContext> context_; | 644 scoped_ptr<ChromotingHostContext> context_; |
| 619 scoped_ptr<IPC::ChannelProxy> daemon_channel_; | 645 scoped_ptr<IPC::ChannelProxy> daemon_channel_; |
| 620 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 646 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
| 621 | 647 |
| 622 FilePath host_config_path_; | 648 FilePath host_config_path_; |
| 623 CompositeHostConfig config_; | 649 CompositeHostConfig config_; |
| 624 | 650 |
| 625 std::string host_id_; | 651 std::string host_id_; |
| 626 HostKeyPair key_pair_; | 652 HostKeyPair key_pair_; |
| 627 protocol::SharedSecretHash host_secret_hash_; | 653 protocol::SharedSecretHash host_secret_hash_; |
| 628 std::string xmpp_login_; | 654 std::string xmpp_login_; |
| 629 std::string xmpp_auth_token_; | 655 std::string xmpp_auth_token_; |
| 630 std::string xmpp_auth_service_; | 656 std::string xmpp_auth_service_; |
| 631 | 657 |
| 632 std::string oauth_refresh_token_; | 658 std::string oauth_refresh_token_; |
| 633 bool oauth_use_official_client_id_; | 659 bool oauth_use_official_client_id_; |
| 634 | 660 |
| 635 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; | 661 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; |
| 636 bool allow_nat_traversal_; | 662 bool allow_nat_traversal_; |
| 663 std::string talkgadget_prefix_; |
| 664 |
| 637 scoped_ptr<base::files::FilePathWatcher> config_watcher_; | 665 scoped_ptr<base::files::FilePathWatcher> config_watcher_; |
| 638 scoped_ptr<base::DelayTimer<HostProcess> > config_updated_timer_; | 666 scoped_ptr<base::DelayTimer<HostProcess> > config_updated_timer_; |
| 639 | 667 |
| 640 bool restarting_; | 668 bool restarting_; |
| 641 bool shutting_down_; | 669 bool shutting_down_; |
| 642 | 670 |
| 643 scoped_ptr<XmppSignalStrategy> signal_strategy_; | 671 scoped_ptr<XmppSignalStrategy> signal_strategy_; |
| 644 scoped_ptr<SignalingConnector> signaling_connector_; | 672 scoped_ptr<SignalingConnector> signaling_connector_; |
| 645 scoped_ptr<DesktopEnvironment> desktop_environment_; | 673 scoped_ptr<DesktopEnvironment> desktop_environment_; |
| 646 scoped_ptr<HeartbeatSender> heartbeat_sender_; | 674 scoped_ptr<HeartbeatSender> heartbeat_sender_; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 user32.GetFunctionPointer("SetProcessDPIAware")); | 775 user32.GetFunctionPointer("SetProcessDPIAware")); |
| 748 set_process_dpi_aware(); | 776 set_process_dpi_aware(); |
| 749 } | 777 } |
| 750 | 778 |
| 751 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting | 779 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
| 752 // the command line from GetCommandLineW(), so we can safely pass NULL here. | 780 // the command line from GetCommandLineW(), so we can safely pass NULL here. |
| 753 return main(0, NULL); | 781 return main(0, NULL); |
| 754 } | 782 } |
| 755 | 783 |
| 756 #endif // defined(OS_WIN) | 784 #endif // defined(OS_WIN) |
| OLD | NEW |