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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 GURL token_url_; | 275 GURL token_url_; |
276 GURL token_validation_url_; | 276 GURL token_validation_url_; |
277 | 277 |
278 scoped_ptr<XmppSignalStrategy> signal_strategy_; | 278 scoped_ptr<XmppSignalStrategy> signal_strategy_; |
279 scoped_ptr<SignalingConnector> signaling_connector_; | 279 scoped_ptr<SignalingConnector> signaling_connector_; |
280 scoped_ptr<HeartbeatSender> heartbeat_sender_; | 280 scoped_ptr<HeartbeatSender> heartbeat_sender_; |
281 scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_; | 281 scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_; |
282 scoped_ptr<LogToServer> log_to_server_; | 282 scoped_ptr<LogToServer> log_to_server_; |
283 scoped_ptr<HostEventLogger> host_event_logger_; | 283 scoped_ptr<HostEventLogger> host_event_logger_; |
284 | 284 |
285 scoped_refptr<ChromotingHost> host_; | 285 scoped_ptr<ChromotingHost> host_; |
286 | 286 |
287 // Used to keep this HostProcess alive until it is shutdown. | 287 // Used to keep this HostProcess alive until it is shutdown. |
288 scoped_refptr<HostProcess> self_; | 288 scoped_refptr<HostProcess> self_; |
289 | 289 |
290 #if defined(REMOTING_MULTI_PROCESS) | 290 #if defined(REMOTING_MULTI_PROCESS) |
291 DesktopSessionConnector* desktop_session_connector_; | 291 DesktopSessionConnector* desktop_session_connector_; |
292 #endif // defined(REMOTING_MULTI_PROCESS) | 292 #endif // defined(REMOTING_MULTI_PROCESS) |
293 | 293 |
294 int* exit_code_out_; | 294 int* exit_code_out_; |
295 }; | 295 }; |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
943 | 943 |
944 NetworkSettings network_settings( | 944 NetworkSettings network_settings( |
945 allow_nat_traversal_ ? | 945 allow_nat_traversal_ ? |
946 NetworkSettings::NAT_TRAVERSAL_ENABLED : | 946 NetworkSettings::NAT_TRAVERSAL_ENABLED : |
947 NetworkSettings::NAT_TRAVERSAL_DISABLED); | 947 NetworkSettings::NAT_TRAVERSAL_DISABLED); |
948 if (!allow_nat_traversal_) { | 948 if (!allow_nat_traversal_) { |
949 network_settings.min_port = NetworkSettings::kDefaultMinPort; | 949 network_settings.min_port = NetworkSettings::kDefaultMinPort; |
950 network_settings.max_port = NetworkSettings::kDefaultMaxPort; | 950 network_settings.max_port = NetworkSettings::kDefaultMaxPort; |
951 } | 951 } |
952 | 952 |
953 host_ = new ChromotingHost( | 953 host_.reset(new ChromotingHost( |
954 signal_strategy_.get(), | 954 signal_strategy_.get(), |
955 desktop_environment_factory_.get(), | 955 desktop_environment_factory_.get(), |
956 CreateHostSessionManager(network_settings, | 956 CreateHostSessionManager(network_settings, |
957 context_->url_request_context_getter()), | 957 context_->url_request_context_getter()), |
958 context_->audio_task_runner(), | 958 context_->audio_task_runner(), |
959 context_->input_task_runner(), | 959 context_->input_task_runner(), |
960 context_->video_capture_task_runner(), | 960 context_->video_capture_task_runner(), |
961 context_->video_encode_task_runner(), | 961 context_->video_encode_task_runner(), |
962 context_->network_task_runner(), | 962 context_->network_task_runner(), |
963 context_->ui_task_runner()); | 963 context_->ui_task_runner())); |
964 | 964 |
965 // TODO(simonmorris): Get the maximum session duration from a policy. | 965 // TODO(simonmorris): Get the maximum session duration from a policy. |
966 #if defined(OS_LINUX) | 966 #if defined(OS_LINUX) |
967 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); | 967 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); |
968 #endif | 968 #endif |
969 | 969 |
970 heartbeat_sender_.reset(new HeartbeatSender( | 970 heartbeat_sender_.reset(new HeartbeatSender( |
971 this, host_id_, signal_strategy_.get(), key_pair_, | 971 this, host_id_, signal_strategy_.get(), key_pair_, |
972 directory_bot_jid_)); | 972 directory_bot_jid_)); |
973 | 973 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 if (host_) { | 1034 if (host_) { |
1035 host_->DisconnectAllClients(); | 1035 host_->DisconnectAllClients(); |
1036 } | 1036 } |
1037 } | 1037 } |
1038 | 1038 |
1039 void HostProcess::RestartHost() { | 1039 void HostProcess::RestartHost() { |
1040 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1040 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
1041 DCHECK_EQ(state_, HOST_STARTED); | 1041 DCHECK_EQ(state_, HOST_STARTED); |
1042 | 1042 |
1043 state_ = HOST_STOPPING_TO_RESTART; | 1043 state_ = HOST_STOPPING_TO_RESTART; |
1044 host_->Shutdown(base::Bind(&HostProcess::ShutdownOnNetworkThread, this)); | 1044 ShutdownOnNetworkThread(); |
1045 } | 1045 } |
1046 | 1046 |
1047 void HostProcess::ShutdownHost(int exit_code) { | 1047 void HostProcess::ShutdownHost(int exit_code) { |
1048 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1048 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
1049 | 1049 |
1050 *exit_code_out_ = exit_code; | 1050 *exit_code_out_ = exit_code; |
1051 | 1051 |
1052 switch (state_) { | 1052 switch (state_) { |
1053 case HOST_INITIALIZING: | 1053 case HOST_INITIALIZING: |
| 1054 case HOST_STARTED: |
1054 state_ = HOST_STOPPING; | 1055 state_ = HOST_STOPPING; |
1055 ShutdownOnNetworkThread(); | 1056 ShutdownOnNetworkThread(); |
1056 break; | 1057 break; |
1057 | 1058 |
1058 case HOST_STARTED: | |
1059 state_ = HOST_STOPPING; | |
1060 host_->Shutdown(base::Bind(&HostProcess::ShutdownOnNetworkThread, this)); | |
1061 break; | |
1062 | |
1063 case HOST_STOPPING_TO_RESTART: | 1059 case HOST_STOPPING_TO_RESTART: |
1064 state_ = HOST_STOPPING; | 1060 state_ = HOST_STOPPING; |
1065 break; | 1061 break; |
1066 | 1062 |
1067 case HOST_STOPPING: | 1063 case HOST_STOPPING: |
1068 case HOST_STOPPED: | 1064 case HOST_STOPPED: |
1069 // Host is already stopped or being stopped. No action is required. | 1065 // Host is already stopped or being stopped. No action is required. |
1070 break; | 1066 break; |
1071 } | 1067 } |
1072 } | 1068 } |
1073 | 1069 |
1074 void HostProcess::ShutdownOnNetworkThread() { | 1070 void HostProcess::ShutdownOnNetworkThread() { |
1075 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1071 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
1076 | 1072 |
1077 host_ = NULL; | 1073 host_.reset(); |
1078 curtaining_host_observer_.reset(); | 1074 curtaining_host_observer_.reset(); |
1079 host_event_logger_.reset(); | 1075 host_event_logger_.reset(); |
1080 log_to_server_.reset(); | 1076 log_to_server_.reset(); |
1081 heartbeat_sender_.reset(); | 1077 heartbeat_sender_.reset(); |
1082 host_change_notification_listener_.reset(); | 1078 host_change_notification_listener_.reset(); |
1083 signaling_connector_.reset(); | 1079 signaling_connector_.reset(); |
1084 signal_strategy_.reset(); | 1080 signal_strategy_.reset(); |
1085 network_change_notifier_.reset(); | 1081 network_change_notifier_.reset(); |
1086 | 1082 |
1087 if (state_ == HOST_STOPPING_TO_RESTART) { | 1083 if (state_ == HOST_STOPPING_TO_RESTART) { |
1088 StartHost(); | 1084 StartHost(); |
1089 } else if (state_ == HOST_STOPPING) { | 1085 } else if (state_ == HOST_STOPPING) { |
1090 state_ = HOST_STOPPED; | 1086 state_ = HOST_STOPPED; |
1091 | 1087 |
1092 if (policy_watcher_.get()) { | 1088 if (policy_watcher_.get()) { |
1093 base::WaitableEvent done_event(true, false); | 1089 base::WaitableEvent done_event(true, false); |
1094 policy_watcher_->StopWatching(&done_event); | 1090 policy_watcher_->StopWatching(&done_event); |
1095 done_event.Wait(); | 1091 done_event.Wait(); |
1096 policy_watcher_.reset(); | 1092 policy_watcher_.reset(); |
1097 } | 1093 } |
1098 | 1094 |
1099 config_watcher_.reset(); | 1095 config_watcher_.reset(); |
1100 | 1096 |
1101 // Complete the rest of shutdown on the main thread. | 1097 // Complete the rest of shutdown on the main thread. |
1102 context_->ui_task_runner()->PostTask( | 1098 context_->ui_task_runner()->PostTask( |
1103 FROM_HERE, | 1099 FROM_HERE, |
1104 base::Bind(&HostProcess::ShutdownOnUiThread, this)); | 1100 base::Bind(&HostProcess::ShutdownOnUiThread, this)); |
1105 } else { | 1101 } else { |
1106 // This method is used as a callback for ChromotingHost::Shutdown() which is | 1102 // This method is only called in STOPPING_TO_RESTART and STOPPING states. |
1107 // called only in STOPPING_TO_RESTART and STOPPING states. | |
1108 NOTREACHED(); | 1103 NOTREACHED(); |
1109 } | 1104 } |
1110 } | 1105 } |
1111 | 1106 |
1112 void HostProcess::OnCrash(const std::string& function_name, | 1107 void HostProcess::OnCrash(const std::string& function_name, |
1113 const std::string& file_name, | 1108 const std::string& file_name, |
1114 const int& line_number) { | 1109 const int& line_number) { |
1115 char message[1024]; | 1110 char message[1024]; |
1116 base::snprintf(message, sizeof(message), | 1111 base::snprintf(message, sizeof(message), |
1117 "Requested by %s at %s, line %d.", | 1112 "Requested by %s at %s, line %d.", |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1155 return exit_code; | 1150 return exit_code; |
1156 } | 1151 } |
1157 | 1152 |
1158 } // namespace remoting | 1153 } // namespace remoting |
1159 | 1154 |
1160 #if !defined(OS_WIN) | 1155 #if !defined(OS_WIN) |
1161 int main(int argc, char** argv) { | 1156 int main(int argc, char** argv) { |
1162 return remoting::HostMain(argc, argv); | 1157 return remoting::HostMain(argc, argv); |
1163 } | 1158 } |
1164 #endif // !defined(OS_WIN) | 1159 #endif // !defined(OS_WIN) |
OLD | NEW |