Chromium Code Reviews| 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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(int exit_code); |
| 225 | 226 |
| 227 void ScheduleHostShutdown(); | |
| 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 |
| 235 scoped_ptr<ChromotingHostContext> context_; | 238 scoped_ptr<ChromotingHostContext> context_; |
| (...skipping 29 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) |
| 285 DesktopSessionConnector* desktop_session_connector_; | 289 DesktopSessionConnector* desktop_session_connector_; |
| 286 #endif // defined(REMOTING_MULTI_PROCESS) | 290 #endif // defined(REMOTING_MULTI_PROCESS) |
| 287 | 291 |
| 288 int* exit_code_out_; | 292 int* exit_code_out_; |
| 289 bool signal_parent_; | 293 bool signal_parent_; |
| 294 | |
|
rmsousa
2013/07/04 01:20:14
Unused
weitao
2013/07/09 00:37:40
Done.
| |
| 295 base::OneShotTimer<HostProcess> timer_; | |
| 290 }; | 296 }; |
| 291 | 297 |
| 292 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, | 298 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, |
| 293 int* exit_code_out) | 299 int* exit_code_out) |
| 294 : context_(context.Pass()), | 300 : context_(context.Pass()), |
| 295 state_(HOST_INITIALIZING), | 301 state_(HOST_INITIALIZING), |
| 296 allow_nat_traversal_(true), | 302 allow_nat_traversal_(true), |
| 297 curtain_required_(false), | 303 curtain_required_(false), |
| 298 #if defined(REMOTING_MULTI_PROCESS) | 304 #if defined(REMOTING_MULTI_PROCESS) |
| 299 desktop_session_connector_(NULL), | 305 desktop_session_connector_(NULL), |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 949 | 955 |
| 950 // TODO(simonmorris): Get the maximum session duration from a policy. | 956 // TODO(simonmorris): Get the maximum session duration from a policy. |
| 951 #if defined(OS_LINUX) | 957 #if defined(OS_LINUX) |
| 952 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); | 958 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); |
| 953 #endif | 959 #endif |
| 954 | 960 |
| 955 heartbeat_sender_.reset(new HeartbeatSender( | 961 heartbeat_sender_.reset(new HeartbeatSender( |
| 956 this, host_id_, signal_strategy_.get(), key_pair_, | 962 this, host_id_, signal_strategy_.get(), key_pair_, |
| 957 directory_bot_jid_)); | 963 directory_bot_jid_)); |
| 958 | 964 |
| 965 host_status_sender_.reset(new HostStatusSender( | |
| 966 host_id_, signal_strategy_.get(), key_pair_, directory_bot_jid_)); | |
| 967 | |
| 959 host_change_notification_listener_.reset(new HostChangeNotificationListener( | 968 host_change_notification_listener_.reset(new HostChangeNotificationListener( |
| 960 this, host_id_, signal_strategy_.get(), directory_bot_jid_)); | 969 this, host_id_, signal_strategy_.get(), directory_bot_jid_)); |
| 961 | 970 |
| 962 log_to_server_.reset( | 971 log_to_server_.reset( |
| 963 new LogToServer(host_->AsWeakPtr(), ServerLogEntry::ME2ME, | 972 new LogToServer(host_->AsWeakPtr(), ServerLogEntry::ME2ME, |
| 964 signal_strategy_.get(), directory_bot_jid_)); | 973 signal_strategy_.get(), directory_bot_jid_)); |
| 965 | 974 |
| 966 // Set up repoting the host status notifications. | 975 // Set up repoting the host status notifications. |
| 967 #if defined(REMOTING_MULTI_PROCESS) | 976 #if defined(REMOTING_MULTI_PROCESS) |
| 968 host_event_logger_.reset( | 977 host_event_logger_.reset( |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 992 | 1001 |
| 993 void HostProcess::ShutdownHost(int exit_code) { | 1002 void HostProcess::ShutdownHost(int exit_code) { |
| 994 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1003 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 995 | 1004 |
| 996 *exit_code_out_ = exit_code; | 1005 *exit_code_out_ = exit_code; |
| 997 | 1006 |
| 998 switch (state_) { | 1007 switch (state_) { |
| 999 case HOST_INITIALIZING: | 1008 case HOST_INITIALIZING: |
| 1000 case HOST_STARTED: | 1009 case HOST_STARTED: |
| 1001 state_ = HOST_STOPPING; | 1010 state_ = HOST_STOPPING; |
| 1002 ShutdownOnNetworkThread(); | 1011 host_status_sender_->SendOfflineStatus(exit_code); |
| 1012 ScheduleHostShutdown(); | |
| 1003 break; | 1013 break; |
| 1004 | 1014 |
| 1005 case HOST_STOPPING_TO_RESTART: | 1015 case HOST_STOPPING_TO_RESTART: |
| 1006 state_ = HOST_STOPPING; | 1016 state_ = HOST_STOPPING; |
| 1007 break; | 1017 break; |
| 1008 | 1018 |
| 1009 case HOST_STOPPING: | 1019 case HOST_STOPPING: |
| 1010 case HOST_STOPPED: | 1020 case HOST_STOPPED: |
| 1011 // Host is already stopped or being stopped. No action is required. | 1021 // Host is already stopped or being stopped. No action is required. |
| 1012 break; | 1022 break; |
| 1013 } | 1023 } |
| 1014 } | 1024 } |
| 1015 | 1025 |
| 1026 // TODO(weitaosu): shut down the host once we get an ACK for the offline status | |
| 1027 // XMPP message. | |
| 1028 void HostProcess::ScheduleHostShutdown() { | |
| 1029 // Delay the shutdown by 2 second to allow SendOfflineStatus to complete. | |
| 1030 context_->network_task_runner()->PostDelayedTask( | |
| 1031 FROM_HERE, | |
| 1032 base::Bind(&HostProcess::ShutdownOnNetworkThread, base::Unretained(this)), | |
| 1033 base::TimeDelta::FromSeconds(2)); | |
| 1034 } | |
| 1035 | |
| 1016 void HostProcess::ShutdownOnNetworkThread() { | 1036 void HostProcess::ShutdownOnNetworkThread() { |
| 1017 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1037 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 1018 | 1038 |
| 1019 host_.reset(); | 1039 host_.reset(); |
| 1020 host_event_logger_.reset(); | 1040 host_event_logger_.reset(); |
| 1021 log_to_server_.reset(); | 1041 log_to_server_.reset(); |
| 1022 heartbeat_sender_.reset(); | 1042 heartbeat_sender_.reset(); |
| 1043 host_status_sender_.reset(); | |
| 1023 host_change_notification_listener_.reset(); | 1044 host_change_notification_listener_.reset(); |
| 1024 signaling_connector_.reset(); | 1045 signaling_connector_.reset(); |
| 1025 signal_strategy_.reset(); | 1046 signal_strategy_.reset(); |
| 1026 network_change_notifier_.reset(); | 1047 network_change_notifier_.reset(); |
| 1027 | 1048 |
| 1028 if (state_ == HOST_STOPPING_TO_RESTART) { | 1049 if (state_ == HOST_STOPPING_TO_RESTART) { |
| 1029 StartHost(); | 1050 StartHost(); |
| 1030 } else if (state_ == HOST_STOPPING) { | 1051 } else if (state_ == HOST_STOPPING) { |
| 1031 state_ = HOST_STOPPED; | 1052 state_ = HOST_STOPPED; |
| 1032 | 1053 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1097 return exit_code; | 1118 return exit_code; |
| 1098 } | 1119 } |
| 1099 | 1120 |
| 1100 } // namespace remoting | 1121 } // namespace remoting |
| 1101 | 1122 |
| 1102 #if !defined(OS_WIN) | 1123 #if !defined(OS_WIN) |
| 1103 int main(int argc, char** argv) { | 1124 int main(int argc, char** argv) { |
| 1104 return remoting::HostMain(argc, argv); | 1125 return remoting::HostMain(argc, argv); |
| 1105 } | 1126 } |
| 1106 #endif // !defined(OS_WIN) | 1127 #endif // !defined(OS_WIN) |
| OLD | NEW |