Chromium Code Reviews| 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 #ifndef REMOTING_HOST_HEARTBEAT_SENDER_H_ | 5 #ifndef REMOTING_HOST_HEARTBEAT_SENDER_H_ |
| 6 #define REMOTING_HOST_HEARTBEAT_SENDER_H_ | 6 #define REMOTING_HOST_HEARTBEAT_SENDER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
| 16 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
| 17 #include "remoting/base/rsa_key_pair.h" | 17 #include "remoting/base/rsa_key_pair.h" |
| 18 #include "remoting/signaling/signal_strategy.h" | 18 #include "remoting/signaling/signal_strategy.h" |
| 19 | 19 |
| 20 namespace base { | 20 namespace base { |
| 21 class MessageLoopProxy; | 21 class MessageLoopProxy; |
| 22 class TimeDelta; | |
| 22 } // namespace base | 23 } // namespace base |
| 23 | 24 |
| 24 namespace buzz { | 25 namespace buzz { |
| 25 class XmlElement; | 26 class XmlElement; |
| 26 } // namespace buzz | 27 } // namespace buzz |
| 27 | 28 |
| 28 namespace remoting { | 29 namespace remoting { |
| 29 | 30 |
| 30 class RsaKeyPair; | 31 class RsaKeyPair; |
| 31 class IqRequest; | 32 class IqRequest; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 // </iq> | 89 // </iq> |
| 89 class HeartbeatSender : public SignalStrategy::Listener { | 90 class HeartbeatSender : public SignalStrategy::Listener { |
| 90 public: | 91 public: |
| 91 // |signal_strategy| and |delegate| must outlive this | 92 // |signal_strategy| and |delegate| must outlive this |
| 92 // object. Heartbeats will start when the supplied SignalStrategy | 93 // object. Heartbeats will start when the supplied SignalStrategy |
| 93 // enters the CONNECTED state. | 94 // enters the CONNECTED state. |
| 94 HeartbeatSender(const base::Closure& on_heartbeat_successful_callback, | 95 HeartbeatSender(const base::Closure& on_heartbeat_successful_callback, |
| 95 const base::Closure& on_unknown_host_id_error, | 96 const base::Closure& on_unknown_host_id_error, |
| 96 const std::string& host_id, | 97 const std::string& host_id, |
| 97 SignalStrategy* signal_strategy, | 98 SignalStrategy* signal_strategy, |
| 98 scoped_refptr<RsaKeyPair> key_pair, | 99 const scoped_refptr<const RsaKeyPair>& key_pair, |
| 99 const std::string& directory_bot_jid); | 100 const std::string& directory_bot_jid); |
| 100 ~HeartbeatSender() override; | 101 ~HeartbeatSender() override; |
| 101 | 102 |
| 102 // Sets host offline reason for future heartbeat stanzas, | 103 // Sets host offline reason for future heartbeat stanzas, and initiates |
| 103 // as well as intiates sending a stanza right away. | 104 // sending a stanza right away. |
| 104 // | 105 // |
| 105 // See rem:host-offline-reason class-level comments for discussion | 106 // For discussion of allowed values for |host_offline_reason| argument, |
| 106 // of allowed values for |host_offline_reason| string. | 107 // please see the description of rem:host-offline-reason xml attribute in |
| 108 // the class-level comments above. | |
| 107 // | 109 // |
| 108 // |ack_callback| will be called once, when the bot acks | 110 // |ack_callback| will be called once, when the bot acks receiving the |
| 109 // receiving the |host_offline_reason|. | 111 // |host_offline_reason| or when |timeout| is reached. |
| 112 enum AckOrTimeout { Ack, Timeout }; | |
|
Wez
2014/12/18 00:46:20
Why do we need this rather than a success/failure
Łukasz Anforowicz
2014/12/18 19:02:33
Done - I switched to bool.
| |
| 110 void SetHostOfflineReason( | 113 void SetHostOfflineReason( |
| 111 const std::string& host_offline_reason, | 114 const std::string& host_offline_reason, |
| 112 const base::Closure& ack_callback); | 115 const base::TimeDelta& timeout, |
| 116 const base::Callback<void(AckOrTimeout)>& ack_callback); | |
| 113 | 117 |
| 114 // SignalStrategy::Listener interface. | 118 // SignalStrategy::Listener interface. |
| 115 void OnSignalStrategyStateChange(SignalStrategy::State state) override; | 119 void OnSignalStrategyStateChange(SignalStrategy::State state) override; |
| 116 bool OnSignalStrategyIncomingStanza(const buzz::XmlElement* stanza) override; | 120 bool OnSignalStrategyIncomingStanza(const buzz::XmlElement* stanza) override; |
| 117 | 121 |
| 118 private: | 122 private: |
| 119 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, | 123 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, |
| 120 DoSendStanzaWithExpectedSequenceId); | 124 DoSendStanzaWithExpectedSequenceId); |
| 121 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, ProcessResponseSetInterval); | 125 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, ProcessResponseSetInterval); |
| 122 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, | 126 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, |
| 123 ProcessResponseExpectedSequenceId); | 127 ProcessResponseExpectedSequenceId); |
| 124 friend class HeartbeatSenderTest; | 128 friend class HeartbeatSenderTest; |
| 125 | 129 |
| 126 void SendStanza(); | 130 void SendStanza(); |
| 127 void ResendStanza(); | 131 void ResendStanza(); |
| 128 void DoSendStanza(); | 132 void DoSendStanza(); |
| 129 void ProcessResponse(bool is_offline_heartbeat_response, | 133 void ProcessResponse(bool is_offline_heartbeat_response, |
| 130 IqRequest* request, | 134 IqRequest* request, |
| 131 const buzz::XmlElement* response); | 135 const buzz::XmlElement* response); |
| 132 void SetInterval(int interval); | 136 void SetInterval(int interval); |
| 133 void SetSequenceId(int sequence_id); | 137 void SetSequenceId(int sequence_id); |
| 138 void CallHostOfflineReasonAckCallback(AckOrTimeout ack_or_timeout); | |
| 134 | 139 |
| 135 // Helper methods used by DoSendStanza() to generate heartbeat stanzas. | 140 // Helper methods used by DoSendStanza() to generate heartbeat stanzas. |
| 136 scoped_ptr<buzz::XmlElement> CreateHeartbeatMessage(); | 141 scoped_ptr<buzz::XmlElement> CreateHeartbeatMessage(); |
| 137 scoped_ptr<buzz::XmlElement> CreateSignature(); | 142 scoped_ptr<buzz::XmlElement> CreateSignature(); |
| 138 | 143 |
| 139 base::Closure on_heartbeat_successful_callback_; | 144 base::Closure on_heartbeat_successful_callback_; |
| 140 base::Closure on_unknown_host_id_error_; | 145 base::Closure on_unknown_host_id_error_; |
| 141 std::string host_id_; | 146 std::string host_id_; |
| 142 SignalStrategy* signal_strategy_; | 147 SignalStrategy* signal_strategy_; |
| 143 scoped_refptr<RsaKeyPair> key_pair_; | 148 scoped_refptr<const RsaKeyPair> key_pair_; |
| 144 std::string directory_bot_jid_; | 149 std::string directory_bot_jid_; |
| 145 scoped_ptr<IqSender> iq_sender_; | 150 scoped_ptr<IqSender> iq_sender_; |
| 146 scoped_ptr<IqRequest> request_; | 151 scoped_ptr<IqRequest> request_; |
| 147 int interval_ms_; | 152 int interval_ms_; |
| 148 base::RepeatingTimer<HeartbeatSender> timer_; | 153 base::RepeatingTimer<HeartbeatSender> timer_; |
| 149 base::OneShotTimer<HeartbeatSender> timer_resend_; | 154 base::OneShotTimer<HeartbeatSender> timer_resend_; |
| 150 int sequence_id_; | 155 int sequence_id_; |
| 151 bool sequence_id_was_set_; | 156 bool sequence_id_was_set_; |
| 152 int sequence_id_recent_set_num_; | 157 int sequence_id_recent_set_num_; |
| 153 bool heartbeat_succeeded_; | 158 bool heartbeat_succeeded_; |
| 154 int failed_startup_heartbeat_count_; | 159 int failed_startup_heartbeat_count_; |
| 155 std::string host_offline_reason_; | 160 std::string host_offline_reason_; |
| 156 base::Closure host_offline_reason_ack_callback_; | 161 base::Callback<void(AckOrTimeout)> host_offline_reason_ack_callback_; |
| 162 base::OneShotTimer<HeartbeatSender> host_offline_reason_timeout_timer_; | |
| 157 | 163 |
| 158 base::ThreadChecker thread_checker_; | 164 base::ThreadChecker thread_checker_; |
| 159 | 165 |
| 160 DISALLOW_COPY_AND_ASSIGN(HeartbeatSender); | 166 DISALLOW_COPY_AND_ASSIGN(HeartbeatSender); |
| 161 }; | 167 }; |
| 162 | 168 |
| 163 } // namespace remoting | 169 } // namespace remoting |
| 164 | 170 |
| 165 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_ | 171 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_ |
| OLD | NEW |