Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
|
Lambros
2014/11/14 01:24:58
2014, no '(c)'
Łukasz Anforowicz
2014/11/17 18:17:02
Done.
| |
| 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/cancelable_callback.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/memory/ref_counted_delete_on_message_loop.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "net/url_request/url_request_context_getter.h" | |
| 15 #include "remoting/base/auto_thread.h" | |
| 16 #include "remoting/base/rsa_key_pair.h" | |
| 17 #include "remoting/host/heartbeat_sender.h" | |
| 18 #include "remoting/signaling/xmpp_signal_strategy.h" | |
| 19 | |
| 20 namespace base { | |
| 21 class TimeDelta; | |
| 22 } | |
| 23 | |
| 24 namespace net { | |
| 25 class NetworkChangeNotifier; | |
| 26 } | |
| 27 | |
| 28 namespace remoting { | |
| 29 | |
| 30 class ChromotingHostContext; | |
| 31 class SignalStrategy; | |
| 32 class SignalingConnector; | |
| 33 class OAuthTokenGetter; | |
| 34 | |
| 35 /* Keeping an instance of MinimumHeartbeatSupporter alive | |
|
Lambros
2014/11/14 01:24:57
nit: C++ style '//'
Łukasz Anforowicz
2014/11/17 18:17:02
Done.
| |
| 36 * ensures that we keep trying to send heartbeats (which among other | |
| 37 * things means that it ensures that we don't exit the host process). | |
| 38 * | |
| 39 * Primary scenario where this class is useful is extending host process | |
| 40 * lifetime after |SendHostOfflineReason| is called. | |
| 41 * | |
| 42 * Secondary benefit of this class is hiding/encapsulating heartbeat | |
| 43 * and xmpp related things inside. | |
| 44 */ | |
| 45 class MinimumHeartbeatSupporter | |
| 46 : public base::RefCountedDeleteOnMessageLoop<MinimumHeartbeatSupporter>, | |
| 47 public HeartbeatSender::Listener { | |
| 48 public: | |
| 49 class Listener { | |
| 50 public: | |
| 51 virtual ~Listener() { } | |
| 52 | |
| 53 // Invoked after the first successful heartbeat. | |
| 54 virtual void OnHeartbeatSuccessful() = 0; | |
| 55 | |
| 56 // Invoked when the host ID is permanently not recognized by the server. | |
| 57 virtual void OnUnknownHostIdError() = 0; | |
| 58 | |
| 59 // Invoked when authentication fails. | |
| 60 virtual void OnAuthFailed() = 0; | |
| 61 }; | |
| 62 | |
| 63 MinimumHeartbeatSupporter( | |
| 64 const ChromotingHostContext* host_context, | |
| 65 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, | |
| 66 const std::string& talkgadget_prefix, | |
| 67 const std::string& host_id, | |
| 68 scoped_refptr<RsaKeyPair> key_pair, | |
| 69 const std::string& directory_bot_jid, | |
| 70 const std::string& oauth_refresh_token, | |
| 71 bool use_service_account); | |
| 72 | |
| 73 // gets signal strategy used for talking to the Chromoting bot | |
|
Lambros
2014/11/14 01:24:57
nit: Capital letter + period.
Łukasz Anforowicz
2014/11/17 18:17:02
Done.
| |
| 74 // return value is valid until |this| gets deleted | |
| 75 SignalStrategy* GetSignalStrategy(); | |
| 76 | |
| 77 // Registers a listener to forward various events to | |
| 78 // Caller has to make sure that |listener| is valid for the lifetime of |this| | |
| 79 // or until the next call to |SetListener| [whichever is shorter] | |
| 80 void SetListener(Listener* listener); | |
| 81 | |
| 82 // Kicks off sending a heartbeat containing a host-offline-reason attribute. | |
| 83 // | |
| 84 // Ensures that |this| (and transitively the whole process) is kept alive | |
| 85 // while waiting for an ack from the bot | |
| 86 // - this is subject to |timeout| | |
| 87 // - this is implemented by temporarily bumping-up ref-count to |this| | |
| 88 // | |
| 89 // Caller has to guarantee that |host_offline_reason| is valid | |
| 90 // for the lifetime of |this| (which in practice means that | |
| 91 // |host_offline_reason| has to point to a string literal. | |
| 92 void SendHostOfflineReason( | |
| 93 const char* host_offline_reason, | |
| 94 const base::TimeDelta& timeout); | |
| 95 | |
| 96 private: | |
| 97 friend class base::RefCountedDeleteOnMessageLoop<MinimumHeartbeatSupporter>; | |
| 98 friend class base::DeleteHelper<MinimumHeartbeatSupporter>; | |
| 99 virtual ~MinimumHeartbeatSupporter() override; | |
| 100 | |
| 101 // HeartbeatSender::Listener overrides. | |
| 102 virtual void OnHeartbeatSuccessful() override; | |
| 103 virtual void OnUnknownHostIdError() override; | |
| 104 | |
| 105 // Callback used by SignalingConnector | |
| 106 void OnAuthFailed(); | |
| 107 | |
| 108 // Fields that support sending of heartbeats | |
| 109 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; | |
| 110 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | |
| 111 scoped_ptr<XmppSignalStrategy> signal_strategy_; | |
|
Lambros
2014/11/14 01:24:57
I'm not sure about this being the class that owns
Łukasz Anforowicz
2014/11/17 18:17:02
RE: this class owning the fields
This class needs
| |
| 112 scoped_ptr<SignalingConnector> signaling_connector_; | |
| 113 scoped_ptr<OAuthTokenGetter> oauth_token_getter_; | |
| 114 scoped_ptr<HeartbeatSender> heartbeat_sender_; | |
| 115 | |
| 116 Listener* listener_; | |
| 117 | |
| 118 // Helper methods and fields for mechanics of SendHostOfflineReason | |
| 119 scoped_ptr<base::CancelableClosure> timeout_callback_; | |
| 120 scoped_ptr<base::CancelableClosure> ack_callback_; | |
| 121 void OnAck(); | |
| 122 void OnTimeout(); | |
| 123 void OnAckOrTimeout(); | |
| 124 | |
| 125 DISALLOW_COPY_AND_ASSIGN(MinimumHeartbeatSupporter); | |
| 126 }; | |
| 127 | |
| 128 } // namespace remoting | |
| 129 | |
| 130 #endif // REMOTING_HOST_MINIMUM_HEARTBEAT_SUPPORTER_H_ | |
| OLD | NEW |