Index: remoting/host/remoting_me2me_host.cc |
diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc |
index d684a8617283cf9c6651e3d91ced4e2c27199d0c..505fdb1ad70cbff46c985b7c465f5269ef15befe 100644 |
--- a/remoting/host/remoting_me2me_host.cc |
+++ b/remoting/host/remoting_me2me_host.cc |
@@ -22,6 +22,7 @@ |
#include "base/strings/utf_string_conversions.h" |
#include "base/synchronization/waitable_event.h" |
#include "base/threading/thread.h" |
+#include "base/timer.h" |
#include "build/build_config.h" |
#include "crypto/nss_util.h" |
#include "ipc/ipc_channel.h" |
@@ -57,6 +58,7 @@ |
#include "remoting/host/log_to_server.h" |
#include "remoting/host/logging.h" |
#include "remoting/host/me2me_desktop_environment.h" |
+#include "remoting/host/offline_status_sender.h" |
#include "remoting/host/pairing_registry_delegate.h" |
#include "remoting/host/policy_hack/policy_watcher.h" |
#include "remoting/host/service_urls.h" |
@@ -223,6 +225,8 @@ class HostProcess |
// Stops the host and shuts down the process with the specified |exit_code|. |
void ShutdownHost(int exit_code); |
+ void ScheduleHostShutdown(); |
+ |
void ShutdownOnNetworkThread(); |
// Crashes the process in response to a daemon's request. The daemon passes |
@@ -272,6 +276,7 @@ class HostProcess |
scoped_ptr<XmppSignalStrategy> signal_strategy_; |
scoped_ptr<SignalingConnector> signaling_connector_; |
scoped_ptr<HeartbeatSender> heartbeat_sender_; |
+ scoped_ptr<OfflineStatusSender> offline_status_sender_; |
scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_; |
scoped_ptr<LogToServer> log_to_server_; |
scoped_ptr<HostEventLogger> host_event_logger_; |
@@ -287,6 +292,8 @@ class HostProcess |
int* exit_code_out_; |
bool signal_parent_; |
+ |
+ base::OneShotTimer<HostProcess> timer_; |
}; |
HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, |
@@ -958,6 +965,9 @@ void HostProcess::StartHost() { |
this, host_id_, signal_strategy_.get(), key_pair_, |
directory_bot_jid_)); |
+ offline_status_sender_.reset(new OfflineStatusSender( |
+ host_id_, signal_strategy_.get(), key_pair_, directory_bot_jid_)); |
+ |
host_change_notification_listener_.reset(new HostChangeNotificationListener( |
this, host_id_, signal_strategy_.get(), directory_bot_jid_)); |
@@ -1001,7 +1011,8 @@ void HostProcess::ShutdownHost(int exit_code) { |
case HOST_INITIALIZING: |
case HOST_STARTED: |
state_ = HOST_STOPPING; |
- ShutdownOnNetworkThread(); |
+ offline_status_sender_->SendOfflineStatus(exit_code); |
+ ScheduleHostShutdown(); |
break; |
case HOST_STOPPING_TO_RESTART: |
@@ -1015,6 +1026,17 @@ void HostProcess::ShutdownHost(int exit_code) { |
} |
} |
+// TODO(weitaosu): shut down the host once we get an ACK. |
+void HostProcess::ScheduleHostShutdown() { |
+ // 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.
|
+ if (timer_.IsRunning()) |
+ return; |
+ |
+ // 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.
|
+ timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(2), |
+ this, &HostProcess::ShutdownOnNetworkThread); |
+} |
+ |
void HostProcess::ShutdownOnNetworkThread() { |
DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
@@ -1022,6 +1044,7 @@ void HostProcess::ShutdownOnNetworkThread() { |
host_event_logger_.reset(); |
log_to_server_.reset(); |
heartbeat_sender_.reset(); |
+ offline_status_sender_.reset(); |
host_change_notification_listener_.reset(); |
signaling_connector_.reset(); |
signal_strategy_.reset(); |