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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 DCHECK(signal_number == SIGTERM); | 373 DCHECK(signal_number == SIGTERM); |
374 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 374 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
375 LOG(INFO) << "Caught SIGTERM: Shutting down..."; | 375 LOG(INFO) << "Caught SIGTERM: Shutting down..."; |
376 Shutdown(kSuccessExitCode); | 376 Shutdown(kSuccessExitCode); |
377 } | 377 } |
378 #endif // OS_POSIX | 378 #endif // OS_POSIX |
379 | 379 |
380 void HostProcess::CreateAuthenticatorFactory() { | 380 void HostProcess::CreateAuthenticatorFactory() { |
381 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 381 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
382 | 382 |
383 if (!host_ || shutting_down_) | 383 if (!host_.get() || shutting_down_) |
384 return; | 384 return; |
385 | 385 |
386 std::string local_certificate = key_pair_.GenerateCertificate(); | 386 std::string local_certificate = key_pair_.GenerateCertificate(); |
387 if (local_certificate.empty()) { | 387 if (local_certificate.empty()) { |
388 LOG(ERROR) << "Failed to generate host certificate."; | 388 LOG(ERROR) << "Failed to generate host certificate."; |
389 Shutdown(kInitializationFailed); | 389 Shutdown(kInitializationFailed); |
390 return; | 390 return; |
391 } | 391 } |
392 | 392 |
393 scoped_ptr<protocol::AuthenticatorFactory> factory( | 393 scoped_ptr<protocol::AuthenticatorFactory> factory( |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 if (policies->GetString( | 593 if (policies->GetString( |
594 policy_hack::PolicyWatcher::kHostTalkGadgetPrefixPolicyName, | 594 policy_hack::PolicyWatcher::kHostTalkGadgetPrefixPolicyName, |
595 &string_value)) { | 595 &string_value)) { |
596 restart_required |= OnHostTalkGadgetPrefixPolicyUpdate(string_value); | 596 restart_required |= OnHostTalkGadgetPrefixPolicyUpdate(string_value); |
597 } | 597 } |
598 if (policies->GetBoolean( | 598 if (policies->GetBoolean( |
599 policy_hack::PolicyWatcher::kHostRequireCurtainPolicyName, | 599 policy_hack::PolicyWatcher::kHostRequireCurtainPolicyName, |
600 &bool_value)) { | 600 &bool_value)) { |
601 restart_required |= OnCurtainPolicyUpdate(bool_value); | 601 restart_required |= OnCurtainPolicyUpdate(bool_value); |
602 } | 602 } |
603 if (!host_) { | 603 if (!host_.get()) { |
604 StartHost(); | 604 StartHost(); |
605 } else if (restart_required) { | 605 } else if (restart_required) { |
606 RestartHost(); | 606 RestartHost(); |
607 } | 607 } |
608 } | 608 } |
609 | 609 |
610 bool HostProcess::OnHostDomainPolicyUpdate(const std::string& host_domain) { | 610 bool HostProcess::OnHostDomainPolicyUpdate(const std::string& host_domain) { |
611 // Returns true if the host has to be restarted after this policy update. | 611 // Returns true if the host has to be restarted after this policy update. |
612 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 612 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
613 | 613 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 if (talkgadget_prefix != talkgadget_prefix_) { | 665 if (talkgadget_prefix != talkgadget_prefix_) { |
666 LOG(INFO) << "Updated talkgadget policy."; | 666 LOG(INFO) << "Updated talkgadget policy."; |
667 talkgadget_prefix_ = talkgadget_prefix; | 667 talkgadget_prefix_ = talkgadget_prefix; |
668 return true; | 668 return true; |
669 } | 669 } |
670 return false; | 670 return false; |
671 } | 671 } |
672 | 672 |
673 void HostProcess::StartHost() { | 673 void HostProcess::StartHost() { |
674 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 674 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
675 DCHECK(!host_); | 675 DCHECK(!host_.get()); |
676 DCHECK(!signal_strategy_.get()); | 676 DCHECK(!signal_strategy_.get()); |
677 | 677 |
678 if (shutting_down_) | 678 if (shutting_down_) |
679 return; | 679 return; |
680 | 680 |
681 signal_strategy_.reset( | 681 signal_strategy_.reset( |
682 new XmppSignalStrategy(context_->url_request_context_getter(), | 682 new XmppSignalStrategy(context_->url_request_context_getter(), |
683 xmpp_login_, xmpp_auth_token_, | 683 xmpp_login_, xmpp_auth_token_, |
684 xmpp_auth_service_)); | 684 xmpp_auth_service_)); |
685 | 685 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 | 720 |
721 // TODO(simonmorris): Get the maximum session duration from a policy. | 721 // TODO(simonmorris): Get the maximum session duration from a policy. |
722 #if defined(OS_LINUX) | 722 #if defined(OS_LINUX) |
723 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); | 723 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); |
724 #endif | 724 #endif |
725 | 725 |
726 heartbeat_sender_.reset(new HeartbeatSender( | 726 heartbeat_sender_.reset(new HeartbeatSender( |
727 this, host_id_, signal_strategy_.get(), &key_pair_)); | 727 this, host_id_, signal_strategy_.get(), &key_pair_)); |
728 | 728 |
729 log_to_server_.reset( | 729 log_to_server_.reset( |
730 new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get())); | 730 new LogToServer( |
731 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName); | 731 host_.get(), ServerLogEntry::ME2ME, signal_strategy_.get())); |
| 732 host_event_logger_ = HostEventLogger::Create(host_.get(), kApplicationName); |
732 | 733 |
733 #if defined(OS_LINUX) | 734 #if defined(OS_LINUX) |
734 // Desktop resizing is implemented on all three platforms, but may not be | 735 // Desktop resizing is implemented on all three platforms, but may not be |
735 // the right thing to do for non-virtual desktops. Disable it until we can | 736 // the right thing to do for non-virtual desktops. Disable it until we can |
736 // implement a configuration UI. | 737 // implement a configuration UI. |
737 resizing_host_observer_.reset( | 738 resizing_host_observer_.reset( |
738 new ResizingHostObserver(desktop_resizer_.get(), host_)); | 739 new ResizingHostObserver(desktop_resizer_.get(), host_.get())); |
739 #endif | 740 #endif |
740 | 741 |
741 // Curtain mode is currently broken on Mac (the only supported platform), | 742 // Curtain mode is currently broken on Mac (the only supported platform), |
742 // so it's disabled until we've had time to fully investigate. | 743 // so it's disabled until we've had time to fully investigate. |
743 // curtaining_host_observer_.reset(new CurtainingHostObserver( | 744 // curtaining_host_observer_.reset(new CurtainingHostObserver( |
744 // curtain_.get(), host_)); | 745 // curtain_.get(), host_)); |
745 | 746 |
746 if (host_user_interface_.get()) { | 747 if (host_user_interface_.get()) { |
747 host_user_interface_->Start( | 748 host_user_interface_->Start( |
748 host_, base::Bind(&HostProcess::OnDisconnectRequested, | 749 host_.get(), base::Bind(&HostProcess::OnDisconnectRequested, |
749 base::Unretained(this))); | 750 base::Unretained(this))); |
750 } | 751 } |
751 | 752 |
752 host_->Start(xmpp_login_); | 753 host_->Start(xmpp_login_); |
753 | 754 |
754 CreateAuthenticatorFactory(); | 755 CreateAuthenticatorFactory(); |
755 } | 756 } |
756 | 757 |
757 void HostProcess::OnAuthFailed() { | 758 void HostProcess::OnAuthFailed() { |
758 Shutdown(kInvalidOauthCredentialsExitCode); | 759 Shutdown(kInvalidOauthCredentialsExitCode); |
759 } | 760 } |
760 | 761 |
761 void HostProcess::RejectAuthenticatingClient() { | 762 void HostProcess::RejectAuthenticatingClient() { |
762 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 763 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
763 DCHECK(host_); | 764 DCHECK(host_); |
764 host_->RejectAuthenticatingClient(); | 765 host_->RejectAuthenticatingClient(); |
765 } | 766 } |
766 | 767 |
767 // Invoked when the user uses the Disconnect windows to terminate | 768 // Invoked when the user uses the Disconnect windows to terminate |
768 // the sessions, or when the local session is activated in curtain mode. | 769 // the sessions, or when the local session is activated in curtain mode. |
769 void HostProcess::OnDisconnectRequested() { | 770 void HostProcess::OnDisconnectRequested() { |
770 if (!context_->network_task_runner()->BelongsToCurrentThread()) { | 771 if (!context_->network_task_runner()->BelongsToCurrentThread()) { |
771 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( | 772 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( |
772 &HostProcess::OnDisconnectRequested, base::Unretained(this))); | 773 &HostProcess::OnDisconnectRequested, base::Unretained(this))); |
773 return; | 774 return; |
774 } | 775 } |
775 if (host_) { | 776 if (host_.get()) { |
776 host_->DisconnectAllClients(); | 777 host_->DisconnectAllClients(); |
777 } | 778 } |
778 } | 779 } |
779 | 780 |
780 void HostProcess::RestartHost() { | 781 void HostProcess::RestartHost() { |
781 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 782 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
782 | 783 |
783 if (restarting_ || shutting_down_) | 784 if (restarting_ || shutting_down_) |
784 return; | 785 return; |
785 | 786 |
(...skipping 16 matching lines...) Expand all Loading... |
802 } | 803 } |
803 | 804 |
804 void HostProcess::Shutdown(int exit_code) { | 805 void HostProcess::Shutdown(int exit_code) { |
805 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 806 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
806 | 807 |
807 if (shutting_down_) | 808 if (shutting_down_) |
808 return; | 809 return; |
809 | 810 |
810 shutting_down_ = true; | 811 shutting_down_ = true; |
811 exit_code_ = exit_code; | 812 exit_code_ = exit_code; |
812 if (host_) { | 813 if (host_.get()) { |
813 host_->Shutdown(base::Bind( | 814 host_->Shutdown(base::Bind( |
814 &HostProcess::OnShutdownFinished, base::Unretained(this))); | 815 &HostProcess::OnShutdownFinished, base::Unretained(this))); |
815 } else { | 816 } else { |
816 OnShutdownFinished(); | 817 OnShutdownFinished(); |
817 } | 818 } |
818 } | 819 } |
819 | 820 |
820 void HostProcess::OnShutdownFinished() { | 821 void HostProcess::OnShutdownFinished() { |
821 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 822 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
822 | 823 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
949 user32.GetFunctionPointer("SetProcessDPIAware")); | 950 user32.GetFunctionPointer("SetProcessDPIAware")); |
950 set_process_dpi_aware(); | 951 set_process_dpi_aware(); |
951 } | 952 } |
952 | 953 |
953 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting | 954 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
954 // the command line from GetCommandLineW(), so we can safely pass NULL here. | 955 // the command line from GetCommandLineW(), so we can safely pass NULL here. |
955 return main(0, NULL); | 956 return main(0, NULL); |
956 } | 957 } |
957 | 958 |
958 #endif // defined(OS_WIN) | 959 #endif // defined(OS_WIN) |
OLD | NEW |