Index: remoting/host/minimum_heartbeat_supporter.h |
diff --git a/remoting/host/minimum_heartbeat_supporter.h b/remoting/host/minimum_heartbeat_supporter.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..99cb241de7fc10ab8b0136d38eacc4fd0bcbe3bb |
--- /dev/null |
+++ b/remoting/host/minimum_heartbeat_supporter.h |
@@ -0,0 +1,113 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef REMOTING_HOST_MINIMUM_HEARTBEAT_SUPPORTER_H_ |
+#define REMOTING_HOST_MINIMUM_HEARTBEAT_SUPPORTER_H_ |
+ |
+#include <string> |
+ |
+#include "base/callback.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/time/time.h" |
+#include "remoting/base/auto_thread_task_runner.h" |
+#include "remoting/base/rsa_key_pair.h" |
+#include "remoting/host/ack_or_timeout_reporter.h" |
+#include "remoting/signaling/xmpp_signal_strategy.h" |
+ |
+namespace base { |
+ class TimeDelta; |
+} |
+ |
+namespace net { |
+ class NetworkChangeNotifier; |
+} |
+ |
+namespace remoting { |
+ |
+class ChromotingHostContext; |
+class DnsBlackholeChecker; |
+class HeartbeatSender; |
+class OAuthTokenGetter; |
+class SignalStrategy; |
+class SignalingConnector; |
+ |
+// Keeping an instance of MinimumHeartbeatSupporter alive |
+// ensures that we keep trying to send heartbeats (which among other |
+// things means that it ensures that we don't exit the host process). |
+// |
+// Primary scenario where this class is useful is extending host process |
+// lifetime after |SendHostOfflineReason| is called. |
+// |
+// Secondary benefit of this class is hiding/encapsulating heartbeat |
+// and xmpp related things inside. |
+class MinimumHeartbeatSupporter |
+ : public base::RefCounted<MinimumHeartbeatSupporter> { |
+ public: |
+ // TODO(lukasza): Refactor to limit the number of parameters below. |
+ // Probably necessitates refactoring HostProcess to extract a new |
+ // class to read and store config/policy/cmdline values. |
+ static scoped_refptr<MinimumHeartbeatSupporter> Create( |
+ const base::Closure& on_heartbeat_successful_callback, |
+ const base::Closure& on_unknown_host_id_error_callback, |
+ const base::Closure& on_auth_failed_callback, |
+ const ChromotingHostContext& host_context, |
+ const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, |
+ const std::string& talkgadget_prefix, |
+ const std::string& host_id, |
+ const scoped_refptr<const RsaKeyPair>& key_pair, |
+ const std::string& directory_bot_jid, |
+ const std::string& oauth_refresh_token, |
+ bool use_service_account); |
+ |
+ // Gets signal strategy used for talking to the Chromoting bot. |
+ // Return value is valid until |this| gets deleted. |
+ SignalStrategy* signal_strategy() { |
+ return signal_strategy_.get(); |
+ } |
+ |
+ |
+ // Kicks off sending a heartbeat containing a host-offline-reason attribute. |
+ // |
+ // Ensures that |this| (and transitively the whole process) is kept alive |
+ // while waiting for an ack from the bot (this is subject to |timeout|). |
+ void SendHostOfflineReason( |
+ const std::string& host_offline_reason, |
+ const base::TimeDelta& timeout); |
+ |
+ private: |
+ // Ref-counting helpers. |
+ friend class base::RefCounted<MinimumHeartbeatSupporter>; |
+ ~MinimumHeartbeatSupporter(); |
+ |
+ MinimumHeartbeatSupporter( |
+ scoped_refptr<AutoThreadTaskRunner> network_task_runner, |
+ scoped_ptr<net::NetworkChangeNotifier> network_change_notifier, |
+ scoped_ptr<XmppSignalStrategy> signal_strategy, |
+ scoped_ptr<SignalingConnector> signaling_connector, |
+ scoped_ptr<HeartbeatSender> heartbeat_sender); |
+ |
+ void OnAckOrTimeout(AckOrTimeout ack_or_timeout); |
+ |
+ // Order fields below is important for destructing them in the right oder. |
+ // - |heartbeat_sender_| and |signaling_connector_| have to be destructed |
+ // before |signal_strategy_| because their destructors need to call |
+ // signal_strategy_->RemoveListener(this) |
+ // - |signaling_connector_| has to be destructed before |
+ // |network_change_notifier_| because its destructor needs to deregister |
+ // network change notifications |
+ // - |network_task_runner_| is used by all the other fields and has to be |
+ // destructed last. |
+ scoped_refptr<AutoThreadTaskRunner> network_task_runner_; |
+ scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
+ scoped_ptr<XmppSignalStrategy> signal_strategy_; |
+ scoped_ptr<SignalingConnector> signaling_connector_; |
+ scoped_ptr<HeartbeatSender> heartbeat_sender_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(MinimumHeartbeatSupporter); |
+}; |
+ |
+} // namespace remoting |
+ |
+#endif // REMOTING_HOST_MINIMUM_HEARTBEAT_SUPPORTER_H_ |