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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 scoped_ptr<CurtainingHostObserver> curtaining_host_observer_; | 268 scoped_ptr<CurtainingHostObserver> curtaining_host_observer_; |
269 bool curtain_required_; | 269 bool curtain_required_; |
270 | 270 |
271 scoped_ptr<XmppSignalStrategy> signal_strategy_; | 271 scoped_ptr<XmppSignalStrategy> signal_strategy_; |
272 scoped_ptr<SignalingConnector> signaling_connector_; | 272 scoped_ptr<SignalingConnector> signaling_connector_; |
273 scoped_ptr<HeartbeatSender> heartbeat_sender_; | 273 scoped_ptr<HeartbeatSender> heartbeat_sender_; |
274 scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_; | 274 scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_; |
275 scoped_ptr<LogToServer> log_to_server_; | 275 scoped_ptr<LogToServer> log_to_server_; |
276 scoped_ptr<HostEventLogger> host_event_logger_; | 276 scoped_ptr<HostEventLogger> host_event_logger_; |
277 | 277 |
278 scoped_refptr<ChromotingHost> host_; | 278 scoped_ptr<ChromotingHost> host_; |
279 | 279 |
280 // Used to keep this HostProcess alive until it is shutdown. | 280 // Used to keep this HostProcess alive until it is shutdown. |
281 scoped_refptr<HostProcess> self_; | 281 scoped_refptr<HostProcess> self_; |
282 | 282 |
283 #if defined(REMOTING_MULTI_PROCESS) | 283 #if defined(REMOTING_MULTI_PROCESS) |
284 DesktopSessionConnector* desktop_session_connector_; | 284 DesktopSessionConnector* desktop_session_connector_; |
285 #endif // defined(REMOTING_MULTI_PROCESS) | 285 #endif // defined(REMOTING_MULTI_PROCESS) |
286 | 286 |
287 int* exit_code_out_; | 287 int* exit_code_out_; |
288 }; | 288 }; |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
876 | 876 |
877 NetworkSettings network_settings( | 877 NetworkSettings network_settings( |
878 allow_nat_traversal_ ? | 878 allow_nat_traversal_ ? |
879 NetworkSettings::NAT_TRAVERSAL_ENABLED : | 879 NetworkSettings::NAT_TRAVERSAL_ENABLED : |
880 NetworkSettings::NAT_TRAVERSAL_DISABLED); | 880 NetworkSettings::NAT_TRAVERSAL_DISABLED); |
881 if (!allow_nat_traversal_) { | 881 if (!allow_nat_traversal_) { |
882 network_settings.min_port = NetworkSettings::kDefaultMinPort; | 882 network_settings.min_port = NetworkSettings::kDefaultMinPort; |
883 network_settings.max_port = NetworkSettings::kDefaultMaxPort; | 883 network_settings.max_port = NetworkSettings::kDefaultMaxPort; |
884 } | 884 } |
885 | 885 |
886 host_ = new ChromotingHost( | 886 host_.reset(new ChromotingHost( |
887 signal_strategy_.get(), | 887 signal_strategy_.get(), |
888 desktop_environment_factory_.get(), | 888 desktop_environment_factory_.get(), |
889 CreateHostSessionManager(network_settings, | 889 CreateHostSessionManager(network_settings, |
890 context_->url_request_context_getter()), | 890 context_->url_request_context_getter()), |
891 context_->audio_task_runner(), | 891 context_->audio_task_runner(), |
892 context_->input_task_runner(), | 892 context_->input_task_runner(), |
893 context_->video_capture_task_runner(), | 893 context_->video_capture_task_runner(), |
894 context_->video_encode_task_runner(), | 894 context_->video_encode_task_runner(), |
895 context_->network_task_runner(), | 895 context_->network_task_runner(), |
896 context_->ui_task_runner()); | 896 context_->ui_task_runner())); |
897 | 897 |
898 // TODO(simonmorris): Get the maximum session duration from a policy. | 898 // TODO(simonmorris): Get the maximum session duration from a policy. |
899 #if defined(OS_LINUX) | 899 #if defined(OS_LINUX) |
900 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); | 900 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); |
901 #endif | 901 #endif |
902 | 902 |
903 heartbeat_sender_.reset(new HeartbeatSender( | 903 heartbeat_sender_.reset(new HeartbeatSender( |
904 this, host_id_, signal_strategy_.get(), key_pair_, | 904 this, host_id_, signal_strategy_.get(), key_pair_, |
905 directory_bot_jid_)); | 905 directory_bot_jid_)); |
906 | 906 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 if (host_) { | 967 if (host_) { |
968 host_->DisconnectAllClients(); | 968 host_->DisconnectAllClients(); |
969 } | 969 } |
970 } | 970 } |
971 | 971 |
972 void HostProcess::RestartHost() { | 972 void HostProcess::RestartHost() { |
973 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 973 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
974 DCHECK_EQ(state_, HOST_STARTED); | 974 DCHECK_EQ(state_, HOST_STARTED); |
975 | 975 |
976 state_ = HOST_STOPPING_TO_RESTART; | 976 state_ = HOST_STOPPING_TO_RESTART; |
977 host_->Shutdown(base::Bind(&HostProcess::ShutdownOnNetworkThread, this)); | 977 ShutdownOnNetworkThread(); |
978 } | 978 } |
979 | 979 |
980 void HostProcess::ShutdownHost(int exit_code) { | 980 void HostProcess::ShutdownHost(int exit_code) { |
981 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 981 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
982 | 982 |
983 *exit_code_out_ = exit_code; | 983 *exit_code_out_ = exit_code; |
984 | 984 |
985 switch (state_) { | 985 switch (state_) { |
986 case HOST_INITIALIZING: | 986 case HOST_INITIALIZING: |
| 987 case HOST_STARTED: |
987 state_ = HOST_STOPPING; | 988 state_ = HOST_STOPPING; |
988 ShutdownOnNetworkThread(); | 989 ShutdownOnNetworkThread(); |
989 break; | 990 break; |
990 | 991 |
991 case HOST_STARTED: | |
992 state_ = HOST_STOPPING; | |
993 host_->Shutdown(base::Bind(&HostProcess::ShutdownOnNetworkThread, this)); | |
994 break; | |
995 | |
996 case HOST_STOPPING_TO_RESTART: | 992 case HOST_STOPPING_TO_RESTART: |
997 state_ = HOST_STOPPING; | 993 state_ = HOST_STOPPING; |
998 break; | 994 break; |
999 | 995 |
1000 case HOST_STOPPING: | 996 case HOST_STOPPING: |
1001 case HOST_STOPPED: | 997 case HOST_STOPPED: |
1002 // Host is already stopped or being stopped. No action is required. | 998 // Host is already stopped or being stopped. No action is required. |
1003 break; | 999 break; |
1004 } | 1000 } |
1005 } | 1001 } |
1006 | 1002 |
1007 void HostProcess::ShutdownOnNetworkThread() { | 1003 void HostProcess::ShutdownOnNetworkThread() { |
1008 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1004 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
1009 | 1005 |
1010 host_ = NULL; | 1006 host_.reset(); |
1011 curtaining_host_observer_.reset(); | 1007 curtaining_host_observer_.reset(); |
1012 host_event_logger_.reset(); | 1008 host_event_logger_.reset(); |
1013 log_to_server_.reset(); | 1009 log_to_server_.reset(); |
1014 heartbeat_sender_.reset(); | 1010 heartbeat_sender_.reset(); |
1015 host_change_notification_listener_.reset(); | 1011 host_change_notification_listener_.reset(); |
1016 signaling_connector_.reset(); | 1012 signaling_connector_.reset(); |
1017 signal_strategy_.reset(); | 1013 signal_strategy_.reset(); |
1018 network_change_notifier_.reset(); | 1014 network_change_notifier_.reset(); |
1019 | 1015 |
1020 if (state_ == HOST_STOPPING_TO_RESTART) { | 1016 if (state_ == HOST_STOPPING_TO_RESTART) { |
1021 StartHost(); | 1017 StartHost(); |
1022 } else if (state_ == HOST_STOPPING) { | 1018 } else if (state_ == HOST_STOPPING) { |
1023 state_ = HOST_STOPPED; | 1019 state_ = HOST_STOPPED; |
1024 | 1020 |
1025 if (policy_watcher_.get()) { | 1021 if (policy_watcher_.get()) { |
1026 base::WaitableEvent done_event(true, false); | 1022 base::WaitableEvent done_event(true, false); |
1027 policy_watcher_->StopWatching(&done_event); | 1023 policy_watcher_->StopWatching(&done_event); |
1028 done_event.Wait(); | 1024 done_event.Wait(); |
1029 policy_watcher_.reset(); | 1025 policy_watcher_.reset(); |
1030 } | 1026 } |
1031 | 1027 |
1032 config_watcher_.reset(); | 1028 config_watcher_.reset(); |
1033 | 1029 |
1034 // Complete the rest of shutdown on the main thread. | 1030 // Complete the rest of shutdown on the main thread. |
1035 context_->ui_task_runner()->PostTask( | 1031 context_->ui_task_runner()->PostTask( |
1036 FROM_HERE, | 1032 FROM_HERE, |
1037 base::Bind(&HostProcess::ShutdownOnUiThread, this)); | 1033 base::Bind(&HostProcess::ShutdownOnUiThread, this)); |
1038 } else { | 1034 } else { |
1039 // This method is used as a callback for ChromotingHost::Shutdown() which is | 1035 // This method is only called in STOPPING_TO_RESTART and STOPPING states. |
1040 // called only in STOPPING_TO_RESTART and STOPPING states. | |
1041 NOTREACHED(); | 1036 NOTREACHED(); |
1042 } | 1037 } |
1043 } | 1038 } |
1044 | 1039 |
1045 void HostProcess::OnCrash(const std::string& function_name, | 1040 void HostProcess::OnCrash(const std::string& function_name, |
1046 const std::string& file_name, | 1041 const std::string& file_name, |
1047 const int& line_number) { | 1042 const int& line_number) { |
1048 char message[1024]; | 1043 char message[1024]; |
1049 base::snprintf(message, sizeof(message), | 1044 base::snprintf(message, sizeof(message), |
1050 "Requested by %s at %s, line %d.", | 1045 "Requested by %s at %s, line %d.", |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1088 return exit_code; | 1083 return exit_code; |
1089 } | 1084 } |
1090 | 1085 |
1091 } // namespace remoting | 1086 } // namespace remoting |
1092 | 1087 |
1093 #if !defined(OS_WIN) | 1088 #if !defined(OS_WIN) |
1094 int main(int argc, char** argv) { | 1089 int main(int argc, char** argv) { |
1095 return remoting::HostMain(argc, argv); | 1090 return remoting::HostMain(argc, argv); |
1096 } | 1091 } |
1097 #endif // !defined(OS_WIN) | 1092 #endif // !defined(OS_WIN) |
OLD | NEW |