OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef REMOTING_HOST_MINIMUM_HEARTBEAT_SUPPORTER_H_ |
| 6 #define REMOTING_HOST_MINIMUM_HEARTBEAT_SUPPORTER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/time/time.h" |
| 14 #include "remoting/base/auto_thread_task_runner.h" |
| 15 #include "remoting/base/rsa_key_pair.h" |
| 16 #include "remoting/host/ack_or_timeout_reporter.h" |
| 17 #include "remoting/signaling/xmpp_signal_strategy.h" |
| 18 |
| 19 namespace base { |
| 20 class TimeDelta; |
| 21 } |
| 22 |
| 23 namespace net { |
| 24 class NetworkChangeNotifier; |
| 25 } |
| 26 |
| 27 namespace remoting { |
| 28 |
| 29 class ChromotingHostContext; |
| 30 class DnsBlackholeChecker; |
| 31 class HeartbeatSender; |
| 32 class OAuthTokenGetter; |
| 33 class SignalStrategy; |
| 34 class SignalingConnector; |
| 35 |
| 36 // Keeping an instance of MinimumHeartbeatSupporter alive |
| 37 // ensures that we keep trying to send heartbeats (which among other |
| 38 // things means that it ensures that we don't exit the host process). |
| 39 // |
| 40 // Primary scenario where this class is useful is extending host process |
| 41 // lifetime after |SendHostOfflineReason| is called. |
| 42 // |
| 43 // Secondary benefit of this class is hiding/encapsulating heartbeat |
| 44 // and xmpp related things inside. |
| 45 class MinimumHeartbeatSupporter |
| 46 : public base::RefCounted<MinimumHeartbeatSupporter> { |
| 47 public: |
| 48 // TODO(lukasza): Refactor to limit the number of parameters below. |
| 49 // Probably necessitates refactoring HostProcess to extract a new |
| 50 // class to read and store config/policy/cmdline values. |
| 51 static scoped_refptr<MinimumHeartbeatSupporter> Create( |
| 52 const base::Closure& on_heartbeat_successful_callback, |
| 53 const base::Closure& on_unknown_host_id_error_callback, |
| 54 const base::Closure& on_auth_failed_callback, |
| 55 const ChromotingHostContext& host_context, |
| 56 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, |
| 57 const std::string& talkgadget_prefix, |
| 58 const std::string& host_id, |
| 59 const scoped_refptr<const RsaKeyPair>& key_pair, |
| 60 const std::string& directory_bot_jid, |
| 61 const std::string& oauth_refresh_token, |
| 62 bool use_service_account); |
| 63 |
| 64 // Gets signal strategy used for talking to the Chromoting bot. |
| 65 // Return value is valid until |this| gets deleted. |
| 66 SignalStrategy* signal_strategy() { |
| 67 return signal_strategy_.get(); |
| 68 } |
| 69 |
| 70 |
| 71 // Kicks off sending a heartbeat containing a host-offline-reason attribute. |
| 72 // |
| 73 // Ensures that |this| (and transitively the whole process) is kept alive |
| 74 // while waiting for an ack from the bot (this is subject to |timeout|). |
| 75 void SendHostOfflineReason( |
| 76 const std::string& host_offline_reason, |
| 77 const base::TimeDelta& timeout); |
| 78 |
| 79 private: |
| 80 // Ref-counting helpers. |
| 81 friend class base::RefCounted<MinimumHeartbeatSupporter>; |
| 82 ~MinimumHeartbeatSupporter(); |
| 83 |
| 84 MinimumHeartbeatSupporter( |
| 85 scoped_refptr<AutoThreadTaskRunner> network_task_runner, |
| 86 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier, |
| 87 scoped_ptr<XmppSignalStrategy> signal_strategy, |
| 88 scoped_ptr<SignalingConnector> signaling_connector, |
| 89 scoped_ptr<HeartbeatSender> heartbeat_sender); |
| 90 |
| 91 void OnAckOrTimeout(AckOrTimeout ack_or_timeout); |
| 92 |
| 93 // Order fields below is important for destructing them in the right oder. |
| 94 // - |heartbeat_sender_| and |signaling_connector_| have to be destructed |
| 95 // before |signal_strategy_| because their destructors need to call |
| 96 // signal_strategy_->RemoveListener(this) |
| 97 // - |signaling_connector_| has to be destructed before |
| 98 // |network_change_notifier_| because its destructor needs to deregister |
| 99 // network change notifications |
| 100 // - |network_task_runner_| is used by all the other fields and has to be |
| 101 // destructed last. |
| 102 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; |
| 103 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
| 104 scoped_ptr<XmppSignalStrategy> signal_strategy_; |
| 105 scoped_ptr<SignalingConnector> signaling_connector_; |
| 106 scoped_ptr<HeartbeatSender> heartbeat_sender_; |
| 107 |
| 108 DISALLOW_COPY_AND_ASSIGN(MinimumHeartbeatSupporter); |
| 109 }; |
| 110 |
| 111 } // namespace remoting |
| 112 |
| 113 #endif // REMOTING_HOST_MINIMUM_HEARTBEAT_SUPPORTER_H_ |
OLD | NEW |