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" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/debug/alias.h" | 13 #include "base/debug/alias.h" |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
19 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
20 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
21 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
23 #include "base/synchronization/waitable_event.h" | 23 #include "base/synchronization/waitable_event.h" |
24 #include "base/threading/thread.h" | 24 #include "base/threading/thread.h" |
25 #include "base/timer.h" | |
25 #include "build/build_config.h" | 26 #include "build/build_config.h" |
26 #include "crypto/nss_util.h" | 27 #include "crypto/nss_util.h" |
27 #include "ipc/ipc_channel.h" | 28 #include "ipc/ipc_channel.h" |
28 #include "ipc/ipc_channel_proxy.h" | 29 #include "ipc/ipc_channel_proxy.h" |
29 #include "ipc/ipc_listener.h" | 30 #include "ipc/ipc_listener.h" |
30 #include "media/base/media.h" | 31 #include "media/base/media.h" |
31 #include "net/base/network_change_notifier.h" | 32 #include "net/base/network_change_notifier.h" |
32 #include "net/socket/ssl_server_socket.h" | 33 #include "net/socket/ssl_server_socket.h" |
33 #include "net/url_request/url_fetcher.h" | 34 #include "net/url_request/url_fetcher.h" |
34 #include "remoting/base/auto_thread_task_runner.h" | 35 #include "remoting/base/auto_thread_task_runner.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
50 #include "remoting/host/host_event_logger.h" | 51 #include "remoting/host/host_event_logger.h" |
51 #include "remoting/host/host_exit_codes.h" | 52 #include "remoting/host/host_exit_codes.h" |
52 #include "remoting/host/host_main.h" | 53 #include "remoting/host/host_main.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" |
61 #include "remoting/host/offline_status_sender.h" | |
60 #include "remoting/host/pairing_registry_delegate.h" | 62 #include "remoting/host/pairing_registry_delegate.h" |
61 #include "remoting/host/policy_hack/policy_watcher.h" | 63 #include "remoting/host/policy_hack/policy_watcher.h" |
62 #include "remoting/host/service_urls.h" | 64 #include "remoting/host/service_urls.h" |
63 #include "remoting/host/session_manager_factory.h" | 65 #include "remoting/host/session_manager_factory.h" |
64 #include "remoting/host/signaling_connector.h" | 66 #include "remoting/host/signaling_connector.h" |
65 #include "remoting/host/token_validator_factory_impl.h" | 67 #include "remoting/host/token_validator_factory_impl.h" |
66 #include "remoting/host/ui_strings.h" | 68 #include "remoting/host/ui_strings.h" |
67 #include "remoting/host/usage_stats_consent.h" | 69 #include "remoting/host/usage_stats_consent.h" |
68 #include "remoting/jingle_glue/network_settings.h" | 70 #include "remoting/jingle_glue/network_settings.h" |
69 #include "remoting/jingle_glue/xmpp_signal_strategy.h" | 71 #include "remoting/jingle_glue/xmpp_signal_strategy.h" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 | 218 |
217 void StartHost(); | 219 void StartHost(); |
218 | 220 |
219 void OnAuthFailed(); | 221 void OnAuthFailed(); |
220 | 222 |
221 void RestartHost(); | 223 void RestartHost(); |
222 | 224 |
223 // Stops the host and shuts down the process with the specified |exit_code|. | 225 // Stops the host and shuts down the process with the specified |exit_code|. |
224 void ShutdownHost(int exit_code); | 226 void ShutdownHost(int exit_code); |
225 | 227 |
228 void ScheduleHostShutdown(); | |
229 | |
226 void ShutdownOnNetworkThread(); | 230 void ShutdownOnNetworkThread(); |
227 | 231 |
228 // Crashes the process in response to a daemon's request. The daemon passes | 232 // 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 | 233 // the location of the code that detected the fatal error resulted in this |
230 // request. | 234 // request. |
231 void OnCrash(const std::string& function_name, | 235 void OnCrash(const std::string& function_name, |
232 const std::string& file_name, | 236 const std::string& file_name, |
233 const int& line_number); | 237 const int& line_number); |
234 | 238 |
235 scoped_ptr<ChromotingHostContext> context_; | 239 scoped_ptr<ChromotingHostContext> context_; |
(...skipping 29 matching lines...) Expand all Loading... | |
265 bool allow_nat_traversal_; | 269 bool allow_nat_traversal_; |
266 std::string talkgadget_prefix_; | 270 std::string talkgadget_prefix_; |
267 | 271 |
268 bool curtain_required_; | 272 bool curtain_required_; |
269 GURL token_url_; | 273 GURL token_url_; |
270 GURL token_validation_url_; | 274 GURL token_validation_url_; |
271 | 275 |
272 scoped_ptr<XmppSignalStrategy> signal_strategy_; | 276 scoped_ptr<XmppSignalStrategy> signal_strategy_; |
273 scoped_ptr<SignalingConnector> signaling_connector_; | 277 scoped_ptr<SignalingConnector> signaling_connector_; |
274 scoped_ptr<HeartbeatSender> heartbeat_sender_; | 278 scoped_ptr<HeartbeatSender> heartbeat_sender_; |
279 scoped_ptr<OfflineStatusSender> offline_status_sender_; | |
275 scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_; | 280 scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_; |
276 scoped_ptr<LogToServer> log_to_server_; | 281 scoped_ptr<LogToServer> log_to_server_; |
277 scoped_ptr<HostEventLogger> host_event_logger_; | 282 scoped_ptr<HostEventLogger> host_event_logger_; |
278 | 283 |
279 scoped_ptr<ChromotingHost> host_; | 284 scoped_ptr<ChromotingHost> host_; |
280 | 285 |
281 // Used to keep this HostProcess alive until it is shutdown. | 286 // Used to keep this HostProcess alive until it is shutdown. |
282 scoped_refptr<HostProcess> self_; | 287 scoped_refptr<HostProcess> self_; |
283 | 288 |
284 #if defined(REMOTING_MULTI_PROCESS) | 289 #if defined(REMOTING_MULTI_PROCESS) |
285 DesktopSessionConnector* desktop_session_connector_; | 290 DesktopSessionConnector* desktop_session_connector_; |
286 #endif // defined(REMOTING_MULTI_PROCESS) | 291 #endif // defined(REMOTING_MULTI_PROCESS) |
287 | 292 |
288 int* exit_code_out_; | 293 int* exit_code_out_; |
289 bool signal_parent_; | 294 bool signal_parent_; |
295 | |
296 base::OneShotTimer<HostProcess> timer_; | |
290 }; | 297 }; |
291 | 298 |
292 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, | 299 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, |
293 int* exit_code_out) | 300 int* exit_code_out) |
294 : context_(context.Pass()), | 301 : context_(context.Pass()), |
295 state_(HOST_INITIALIZING), | 302 state_(HOST_INITIALIZING), |
296 allow_nat_traversal_(true), | 303 allow_nat_traversal_(true), |
297 curtain_required_(false), | 304 curtain_required_(false), |
298 #if defined(REMOTING_MULTI_PROCESS) | 305 #if defined(REMOTING_MULTI_PROCESS) |
299 desktop_session_connector_(NULL), | 306 desktop_session_connector_(NULL), |
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
951 | 958 |
952 // TODO(simonmorris): Get the maximum session duration from a policy. | 959 // TODO(simonmorris): Get the maximum session duration from a policy. |
953 #if defined(OS_LINUX) | 960 #if defined(OS_LINUX) |
954 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); | 961 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); |
955 #endif | 962 #endif |
956 | 963 |
957 heartbeat_sender_.reset(new HeartbeatSender( | 964 heartbeat_sender_.reset(new HeartbeatSender( |
958 this, host_id_, signal_strategy_.get(), key_pair_, | 965 this, host_id_, signal_strategy_.get(), key_pair_, |
959 directory_bot_jid_)); | 966 directory_bot_jid_)); |
960 | 967 |
968 offline_status_sender_.reset(new OfflineStatusSender( | |
969 host_id_, signal_strategy_.get(), key_pair_, directory_bot_jid_)); | |
970 | |
961 host_change_notification_listener_.reset(new HostChangeNotificationListener( | 971 host_change_notification_listener_.reset(new HostChangeNotificationListener( |
962 this, host_id_, signal_strategy_.get(), directory_bot_jid_)); | 972 this, host_id_, signal_strategy_.get(), directory_bot_jid_)); |
963 | 973 |
964 log_to_server_.reset( | 974 log_to_server_.reset( |
965 new LogToServer(host_->AsWeakPtr(), ServerLogEntry::ME2ME, | 975 new LogToServer(host_->AsWeakPtr(), ServerLogEntry::ME2ME, |
966 signal_strategy_.get(), directory_bot_jid_)); | 976 signal_strategy_.get(), directory_bot_jid_)); |
967 | 977 |
968 // Set up repoting the host status notifications. | 978 // Set up repoting the host status notifications. |
969 #if defined(REMOTING_MULTI_PROCESS) | 979 #if defined(REMOTING_MULTI_PROCESS) |
970 host_event_logger_.reset( | 980 host_event_logger_.reset( |
(...skipping 23 matching lines...) Expand all Loading... | |
994 | 1004 |
995 void HostProcess::ShutdownHost(int exit_code) { | 1005 void HostProcess::ShutdownHost(int exit_code) { |
996 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1006 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
997 | 1007 |
998 *exit_code_out_ = exit_code; | 1008 *exit_code_out_ = exit_code; |
999 | 1009 |
1000 switch (state_) { | 1010 switch (state_) { |
1001 case HOST_INITIALIZING: | 1011 case HOST_INITIALIZING: |
1002 case HOST_STARTED: | 1012 case HOST_STARTED: |
1003 state_ = HOST_STOPPING; | 1013 state_ = HOST_STOPPING; |
1004 ShutdownOnNetworkThread(); | 1014 offline_status_sender_->SendOfflineStatus(exit_code); |
1015 ScheduleHostShutdown(); | |
1005 break; | 1016 break; |
1006 | 1017 |
1007 case HOST_STOPPING_TO_RESTART: | 1018 case HOST_STOPPING_TO_RESTART: |
1008 state_ = HOST_STOPPING; | 1019 state_ = HOST_STOPPING; |
1009 break; | 1020 break; |
1010 | 1021 |
1011 case HOST_STOPPING: | 1022 case HOST_STOPPING: |
1012 case HOST_STOPPED: | 1023 case HOST_STOPPED: |
1013 // Host is already stopped or being stopped. No action is required. | 1024 // Host is already stopped or being stopped. No action is required. |
1014 break; | 1025 break; |
1015 } | 1026 } |
1016 } | 1027 } |
1017 | 1028 |
1029 // TODO(weitaosu): shut down the host once we get an ACK. | |
1030 void HostProcess::ScheduleHostShutdown() { | |
1031 // If the timer is running that means a shutdown is already in progress. | |
rmsousa
2013/07/02 02:09:24
Can this happen? This is only called on the HOST_I
weitao
2013/07/03 19:23:31
Done.
| |
1032 if (timer_.IsRunning()) | |
1033 return; | |
1034 | |
1035 // Delay the shutdown by 2 second to allow SendOfflineStatus to complete. | |
rmsousa
2013/07/02 02:09:24
Nit: For the simple "perform this action later" sc
weitao
2013/07/03 19:23:31
Done.
| |
1036 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(2), | |
1037 this, &HostProcess::ShutdownOnNetworkThread); | |
1038 } | |
1039 | |
1018 void HostProcess::ShutdownOnNetworkThread() { | 1040 void HostProcess::ShutdownOnNetworkThread() { |
1019 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1041 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
1020 | 1042 |
1021 host_.reset(); | 1043 host_.reset(); |
1022 host_event_logger_.reset(); | 1044 host_event_logger_.reset(); |
1023 log_to_server_.reset(); | 1045 log_to_server_.reset(); |
1024 heartbeat_sender_.reset(); | 1046 heartbeat_sender_.reset(); |
1047 offline_status_sender_.reset(); | |
1025 host_change_notification_listener_.reset(); | 1048 host_change_notification_listener_.reset(); |
1026 signaling_connector_.reset(); | 1049 signaling_connector_.reset(); |
1027 signal_strategy_.reset(); | 1050 signal_strategy_.reset(); |
1028 network_change_notifier_.reset(); | 1051 network_change_notifier_.reset(); |
1029 | 1052 |
1030 if (state_ == HOST_STOPPING_TO_RESTART) { | 1053 if (state_ == HOST_STOPPING_TO_RESTART) { |
1031 StartHost(); | 1054 StartHost(); |
1032 } else if (state_ == HOST_STOPPING) { | 1055 } else if (state_ == HOST_STOPPING) { |
1033 state_ = HOST_STOPPED; | 1056 state_ = HOST_STOPPED; |
1034 | 1057 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1099 return exit_code; | 1122 return exit_code; |
1100 } | 1123 } |
1101 | 1124 |
1102 } // namespace remoting | 1125 } // namespace remoting |
1103 | 1126 |
1104 #if !defined(OS_WIN) | 1127 #if !defined(OS_WIN) |
1105 int main(int argc, char** argv) { | 1128 int main(int argc, char** argv) { |
1106 return remoting::HostMain(argc, argv); | 1129 return remoting::HostMain(argc, argv); |
1107 } | 1130 } |
1108 #endif // !defined(OS_WIN) | 1131 #endif // !defined(OS_WIN) |
OLD | NEW |