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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 #include "remoting/host/config_file_watcher.h" | 43 #include "remoting/host/config_file_watcher.h" |
44 #include "remoting/host/desktop_environment.h" | 44 #include "remoting/host/desktop_environment.h" |
45 #include "remoting/host/desktop_session_connector.h" | 45 #include "remoting/host/desktop_session_connector.h" |
46 #include "remoting/host/dns_blackhole_checker.h" | 46 #include "remoting/host/dns_blackhole_checker.h" |
47 #include "remoting/host/heartbeat_sender.h" | 47 #include "remoting/host/heartbeat_sender.h" |
48 #include "remoting/host/host_change_notification_listener.h" | 48 #include "remoting/host/host_change_notification_listener.h" |
49 #include "remoting/host/host_config.h" | 49 #include "remoting/host/host_config.h" |
50 #include "remoting/host/host_event_logger.h" | 50 #include "remoting/host/host_event_logger.h" |
51 #include "remoting/host/host_exit_codes.h" | 51 #include "remoting/host/host_exit_codes.h" |
52 #include "remoting/host/host_main.h" | 52 #include "remoting/host/host_main.h" |
| 53 #include "remoting/host/host_status_sender.h" |
53 #include "remoting/host/ipc_constants.h" | 54 #include "remoting/host/ipc_constants.h" |
54 #include "remoting/host/ipc_desktop_environment.h" | 55 #include "remoting/host/ipc_desktop_environment.h" |
55 #include "remoting/host/ipc_host_event_logger.h" | 56 #include "remoting/host/ipc_host_event_logger.h" |
56 #include "remoting/host/json_host_config.h" | 57 #include "remoting/host/json_host_config.h" |
57 #include "remoting/host/log_to_server.h" | 58 #include "remoting/host/log_to_server.h" |
58 #include "remoting/host/logging.h" | 59 #include "remoting/host/logging.h" |
59 #include "remoting/host/me2me_desktop_environment.h" | 60 #include "remoting/host/me2me_desktop_environment.h" |
60 #include "remoting/host/pairing_registry_delegate.h" | 61 #include "remoting/host/pairing_registry_delegate.h" |
61 #include "remoting/host/policy_hack/policy_watcher.h" | 62 #include "remoting/host/policy_hack/policy_watcher.h" |
62 #include "remoting/host/service_urls.h" | 63 #include "remoting/host/service_urls.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 bool OnHostTokenUrlPolicyUpdate(const GURL& token_url, | 215 bool OnHostTokenUrlPolicyUpdate(const GURL& token_url, |
215 const GURL& token_validation_url); | 216 const GURL& token_validation_url); |
216 | 217 |
217 void StartHost(); | 218 void StartHost(); |
218 | 219 |
219 void OnAuthFailed(); | 220 void OnAuthFailed(); |
220 | 221 |
221 void RestartHost(); | 222 void RestartHost(); |
222 | 223 |
223 // Stops the host and shuts down the process with the specified |exit_code|. | 224 // Stops the host and shuts down the process with the specified |exit_code|. |
224 void ShutdownHost(int exit_code); | 225 void ShutdownHost(HostExitCodes exit_code); |
| 226 |
| 227 void ScheduleHostShutdown(); |
225 | 228 |
226 void ShutdownOnNetworkThread(); | 229 void ShutdownOnNetworkThread(); |
227 | 230 |
228 // Crashes the process in response to a daemon's request. The daemon passes | 231 // Crashes the process in response to a daemon's request. The daemon passes |
229 // the location of the code that detected the fatal error resulted in this | 232 // the location of the code that detected the fatal error resulted in this |
230 // request. | 233 // request. |
231 void OnCrash(const std::string& function_name, | 234 void OnCrash(const std::string& function_name, |
232 const std::string& file_name, | 235 const std::string& file_name, |
233 const int& line_number); | 236 const int& line_number); |
234 | 237 |
(...skipping 30 matching lines...) Expand all Loading... |
265 bool allow_nat_traversal_; | 268 bool allow_nat_traversal_; |
266 std::string talkgadget_prefix_; | 269 std::string talkgadget_prefix_; |
267 | 270 |
268 bool curtain_required_; | 271 bool curtain_required_; |
269 GURL token_url_; | 272 GURL token_url_; |
270 GURL token_validation_url_; | 273 GURL token_validation_url_; |
271 | 274 |
272 scoped_ptr<XmppSignalStrategy> signal_strategy_; | 275 scoped_ptr<XmppSignalStrategy> signal_strategy_; |
273 scoped_ptr<SignalingConnector> signaling_connector_; | 276 scoped_ptr<SignalingConnector> signaling_connector_; |
274 scoped_ptr<HeartbeatSender> heartbeat_sender_; | 277 scoped_ptr<HeartbeatSender> heartbeat_sender_; |
| 278 scoped_ptr<HostStatusSender> host_status_sender_; |
275 scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_; | 279 scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_; |
276 scoped_ptr<LogToServer> log_to_server_; | 280 scoped_ptr<LogToServer> log_to_server_; |
277 scoped_ptr<HostEventLogger> host_event_logger_; | 281 scoped_ptr<HostEventLogger> host_event_logger_; |
278 | 282 |
279 scoped_ptr<ChromotingHost> host_; | 283 scoped_ptr<ChromotingHost> host_; |
280 | 284 |
281 // Used to keep this HostProcess alive until it is shutdown. | 285 // Used to keep this HostProcess alive until it is shutdown. |
282 scoped_refptr<HostProcess> self_; | 286 scoped_refptr<HostProcess> self_; |
283 | 287 |
284 #if defined(REMOTING_MULTI_PROCESS) | 288 #if defined(REMOTING_MULTI_PROCESS) |
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
949 | 953 |
950 // TODO(simonmorris): Get the maximum session duration from a policy. | 954 // TODO(simonmorris): Get the maximum session duration from a policy. |
951 #if defined(OS_LINUX) | 955 #if defined(OS_LINUX) |
952 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); | 956 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); |
953 #endif | 957 #endif |
954 | 958 |
955 heartbeat_sender_.reset(new HeartbeatSender( | 959 heartbeat_sender_.reset(new HeartbeatSender( |
956 this, host_id_, signal_strategy_.get(), key_pair_, | 960 this, host_id_, signal_strategy_.get(), key_pair_, |
957 directory_bot_jid_)); | 961 directory_bot_jid_)); |
958 | 962 |
| 963 host_status_sender_.reset(new HostStatusSender( |
| 964 host_id_, signal_strategy_.get(), key_pair_, directory_bot_jid_)); |
| 965 |
959 host_change_notification_listener_.reset(new HostChangeNotificationListener( | 966 host_change_notification_listener_.reset(new HostChangeNotificationListener( |
960 this, host_id_, signal_strategy_.get(), directory_bot_jid_)); | 967 this, host_id_, signal_strategy_.get(), directory_bot_jid_)); |
961 | 968 |
962 log_to_server_.reset( | 969 log_to_server_.reset( |
963 new LogToServer(host_->AsWeakPtr(), ServerLogEntry::ME2ME, | 970 new LogToServer(host_->AsWeakPtr(), ServerLogEntry::ME2ME, |
964 signal_strategy_.get(), directory_bot_jid_)); | 971 signal_strategy_.get(), directory_bot_jid_)); |
965 | 972 |
966 // Set up repoting the host status notifications. | 973 // Set up repoting the host status notifications. |
967 #if defined(REMOTING_MULTI_PROCESS) | 974 #if defined(REMOTING_MULTI_PROCESS) |
968 host_event_logger_.reset( | 975 host_event_logger_.reset( |
(...skipping 14 matching lines...) Expand all Loading... |
983 } | 990 } |
984 | 991 |
985 void HostProcess::RestartHost() { | 992 void HostProcess::RestartHost() { |
986 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 993 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
987 DCHECK_EQ(state_, HOST_STARTED); | 994 DCHECK_EQ(state_, HOST_STARTED); |
988 | 995 |
989 state_ = HOST_STOPPING_TO_RESTART; | 996 state_ = HOST_STOPPING_TO_RESTART; |
990 ShutdownOnNetworkThread(); | 997 ShutdownOnNetworkThread(); |
991 } | 998 } |
992 | 999 |
993 void HostProcess::ShutdownHost(int exit_code) { | 1000 void HostProcess::ShutdownHost(HostExitCodes exit_code) { |
994 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1001 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
995 | 1002 |
996 *exit_code_out_ = exit_code; | 1003 *exit_code_out_ = exit_code; |
997 | 1004 |
998 switch (state_) { | 1005 switch (state_) { |
999 case HOST_INITIALIZING: | 1006 case HOST_INITIALIZING: |
1000 case HOST_STARTED: | 1007 case HOST_STARTED: |
1001 state_ = HOST_STOPPING; | 1008 state_ = HOST_STOPPING; |
1002 ShutdownOnNetworkThread(); | 1009 host_status_sender_->SendOfflineStatus(exit_code); |
| 1010 ScheduleHostShutdown(); |
1003 break; | 1011 break; |
1004 | 1012 |
1005 case HOST_STOPPING_TO_RESTART: | 1013 case HOST_STOPPING_TO_RESTART: |
1006 state_ = HOST_STOPPING; | 1014 state_ = HOST_STOPPING; |
1007 break; | 1015 break; |
1008 | 1016 |
1009 case HOST_STOPPING: | 1017 case HOST_STOPPING: |
1010 case HOST_STOPPED: | 1018 case HOST_STOPPED: |
1011 // Host is already stopped or being stopped. No action is required. | 1019 // Host is already stopped or being stopped. No action is required. |
1012 break; | 1020 break; |
1013 } | 1021 } |
1014 } | 1022 } |
1015 | 1023 |
| 1024 // TODO(weitaosu): shut down the host once we get an ACK for the offline status |
| 1025 // XMPP message. |
| 1026 void HostProcess::ScheduleHostShutdown() { |
| 1027 // Delay the shutdown by 2 second to allow SendOfflineStatus to complete. |
| 1028 context_->network_task_runner()->PostDelayedTask( |
| 1029 FROM_HERE, |
| 1030 base::Bind(&HostProcess::ShutdownOnNetworkThread, base::Unretained(this)), |
| 1031 base::TimeDelta::FromSeconds(2)); |
| 1032 } |
| 1033 |
1016 void HostProcess::ShutdownOnNetworkThread() { | 1034 void HostProcess::ShutdownOnNetworkThread() { |
1017 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1035 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
1018 | 1036 |
1019 host_.reset(); | 1037 host_.reset(); |
1020 host_event_logger_.reset(); | 1038 host_event_logger_.reset(); |
1021 log_to_server_.reset(); | 1039 log_to_server_.reset(); |
1022 heartbeat_sender_.reset(); | 1040 heartbeat_sender_.reset(); |
| 1041 host_status_sender_.reset(); |
1023 host_change_notification_listener_.reset(); | 1042 host_change_notification_listener_.reset(); |
1024 signaling_connector_.reset(); | 1043 signaling_connector_.reset(); |
1025 signal_strategy_.reset(); | 1044 signal_strategy_.reset(); |
1026 network_change_notifier_.reset(); | 1045 network_change_notifier_.reset(); |
1027 | 1046 |
1028 if (state_ == HOST_STOPPING_TO_RESTART) { | 1047 if (state_ == HOST_STOPPING_TO_RESTART) { |
1029 StartHost(); | 1048 StartHost(); |
1030 } else if (state_ == HOST_STOPPING) { | 1049 } else if (state_ == HOST_STOPPING) { |
1031 state_ = HOST_STOPPED; | 1050 state_ = HOST_STOPPED; |
1032 | 1051 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1097 return exit_code; | 1116 return exit_code; |
1098 } | 1117 } |
1099 | 1118 |
1100 } // namespace remoting | 1119 } // namespace remoting |
1101 | 1120 |
1102 #if !defined(OS_WIN) | 1121 #if !defined(OS_WIN) |
1103 int main(int argc, char** argv) { | 1122 int main(int argc, char** argv) { |
1104 return remoting::HostMain(argc, argv); | 1123 return remoting::HostMain(argc, argv); |
1105 } | 1124 } |
1106 #endif // !defined(OS_WIN) | 1125 #endif // !defined(OS_WIN) |
OLD | NEW |