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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 // to="user@gmail.com/chromoting123123" id="5" xmlns="jabber:client"> | 85 // to="user@gmail.com/chromoting123123" id="5" xmlns="jabber:client"> |
| 85 // <rem:heartbeat-result xmlns:rem="google:remoting"> | 86 // <rem:heartbeat-result xmlns:rem="google:remoting"> |
| 86 // <rem:expected-sequence-id>654</rem:expected-sequence-id> | 87 // <rem:expected-sequence-id>654</rem:expected-sequence-id> |
| 87 // </rem:heartbeat-result> | 88 // </rem:heartbeat-result> |
| 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 // |
| 95 const base::Closure& on_unknown_host_id_error, | 96 // |on_heartbeat_successful_callback| is invoked after the first successful |
| 96 const std::string& host_id, | 97 // heartbeat. |
| 97 SignalStrategy* signal_strategy, | 98 // |
| 98 scoped_refptr<RsaKeyPair> key_pair, | 99 // |on_unknown_host_id_error| is invoked when the host ID is permanently not |
| 99 const std::string& directory_bot_jid); | 100 // recognized by the server. |
| 101 HeartbeatSender( | |
| 102 const base::Closure& on_heartbeat_successful_callback, | |
| 103 | |
|
Wez
2015/01/09 02:55:45
Why are there blank lines between these parameters
Łukasz Anforowicz
2015/01/09 19:00:13
Fixed.
| |
| 104 const base::Closure& on_unknown_host_id_error, | |
| 105 | |
| 106 const std::string& host_id, | |
| 107 SignalStrategy* signal_strategy, | |
| 108 const scoped_refptr<const RsaKeyPair>& host_key_pair, | |
| 109 const std::string& directory_bot_jid); | |
| 100 ~HeartbeatSender() override; | 110 ~HeartbeatSender() override; |
| 101 | 111 |
| 102 // Sets host offline reason for future heartbeat stanzas, | 112 // Sets host offline reason for future heartbeat stanzas, and initiates |
| 103 // as well as intiates sending a stanza right away. | 113 // sending a stanza right away. |
| 104 // | 114 // |
| 105 // See rem:host-offline-reason class-level comments for discussion | 115 // For discussion of allowed values for |host_offline_reason| argument, |
| 106 // of allowed values for |host_offline_reason| string. | 116 // please see the description of rem:host-offline-reason xml attribute in |
| 117 // the class-level comments above. | |
| 107 // | 118 // |
| 108 // |ack_callback| will be called once, when the bot acks | 119 // |ack_callback| will be called once, when the bot acks receiving the |
| 109 // receiving the |host_offline_reason|. | 120 // |host_offline_reason| or when |timeout| is reached. |
| 110 void SetHostOfflineReason( | 121 void SetHostOfflineReason( |
| 111 const std::string& host_offline_reason, | 122 const std::string& host_offline_reason, |
| 112 const base::Closure& ack_callback); | 123 const base::TimeDelta& timeout, |
| 124 const base::Callback<void(bool success)>& ack_callback); | |
| 113 | 125 |
| 114 // SignalStrategy::Listener interface. | 126 // SignalStrategy::Listener interface. |
| 115 void OnSignalStrategyStateChange(SignalStrategy::State state) override; | 127 void OnSignalStrategyStateChange(SignalStrategy::State state) override; |
| 116 bool OnSignalStrategyIncomingStanza(const buzz::XmlElement* stanza) override; | 128 bool OnSignalStrategyIncomingStanza(const buzz::XmlElement* stanza) override; |
| 117 | 129 |
| 118 private: | 130 private: |
| 119 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, | 131 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, |
| 120 DoSendStanzaWithExpectedSequenceId); | 132 DoSendStanzaWithExpectedSequenceId); |
| 121 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, ProcessResponseSetInterval); | 133 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, ProcessResponseSetInterval); |
| 122 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, | 134 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, |
| 123 ProcessResponseExpectedSequenceId); | 135 ProcessResponseExpectedSequenceId); |
| 124 friend class HeartbeatSenderTest; | 136 friend class HeartbeatSenderTest; |
| 125 | 137 |
| 126 void SendStanza(); | 138 void SendStanza(); |
| 127 void ResendStanza(); | 139 void ResendStanza(); |
| 128 void DoSendStanza(); | 140 void DoSendStanza(); |
| 129 void ProcessResponse(bool is_offline_heartbeat_response, | 141 void ProcessResponse(bool is_offline_heartbeat_response, |
| 130 IqRequest* request, | 142 IqRequest* request, |
| 131 const buzz::XmlElement* response); | 143 const buzz::XmlElement* response); |
| 132 void SetInterval(int interval); | 144 void SetInterval(int interval); |
| 133 void SetSequenceId(int sequence_id); | 145 void SetSequenceId(int sequence_id); |
| 134 | 146 |
| 147 // Handlers for host-offline-reason completion and timeout. | |
| 148 void OnHostOfflineReasonTimeout(); | |
| 149 void OnHostOfflineReasonAck(); | |
| 150 | |
| 135 // Helper methods used by DoSendStanza() to generate heartbeat stanzas. | 151 // Helper methods used by DoSendStanza() to generate heartbeat stanzas. |
| 136 scoped_ptr<buzz::XmlElement> CreateHeartbeatMessage(); | 152 scoped_ptr<buzz::XmlElement> CreateHeartbeatMessage(); |
| 137 scoped_ptr<buzz::XmlElement> CreateSignature(); | 153 scoped_ptr<buzz::XmlElement> CreateSignature(); |
| 138 | 154 |
| 139 base::Closure on_heartbeat_successful_callback_; | 155 base::Closure on_heartbeat_successful_callback_; |
| 140 base::Closure on_unknown_host_id_error_; | 156 base::Closure on_unknown_host_id_error_; |
| 141 std::string host_id_; | 157 std::string host_id_; |
| 142 SignalStrategy* signal_strategy_; | 158 SignalStrategy* signal_strategy_; |
| 143 scoped_refptr<RsaKeyPair> key_pair_; | 159 scoped_refptr<const RsaKeyPair> host_key_pair_; |
| 144 std::string directory_bot_jid_; | 160 std::string directory_bot_jid_; |
| 145 scoped_ptr<IqSender> iq_sender_; | 161 scoped_ptr<IqSender> iq_sender_; |
| 146 scoped_ptr<IqRequest> request_; | 162 scoped_ptr<IqRequest> request_; |
| 147 int interval_ms_; | 163 int interval_ms_; |
| 148 base::RepeatingTimer<HeartbeatSender> timer_; | 164 base::RepeatingTimer<HeartbeatSender> timer_; |
| 149 base::OneShotTimer<HeartbeatSender> timer_resend_; | 165 base::OneShotTimer<HeartbeatSender> timer_resend_; |
| 150 int sequence_id_; | 166 int sequence_id_; |
| 151 bool sequence_id_was_set_; | 167 bool sequence_id_was_set_; |
| 152 int sequence_id_recent_set_num_; | 168 int sequence_id_recent_set_num_; |
| 153 bool heartbeat_succeeded_; | 169 bool heartbeat_succeeded_; |
| 154 int failed_startup_heartbeat_count_; | 170 int failed_startup_heartbeat_count_; |
| 171 | |
| 172 // Fields to send and indicate completion of sending host-offline-reason. | |
| 155 std::string host_offline_reason_; | 173 std::string host_offline_reason_; |
| 156 base::Closure host_offline_reason_ack_callback_; | 174 base::Callback<void(bool success)> host_offline_reason_ack_callback_; |
| 175 base::OneShotTimer<HeartbeatSender> host_offline_reason_timeout_timer_; | |
| 157 | 176 |
| 158 base::ThreadChecker thread_checker_; | 177 base::ThreadChecker thread_checker_; |
| 159 | 178 |
| 160 DISALLOW_COPY_AND_ASSIGN(HeartbeatSender); | 179 DISALLOW_COPY_AND_ASSIGN(HeartbeatSender); |
| 161 }; | 180 }; |
| 162 | 181 |
| 163 } // namespace remoting | 182 } // namespace remoting |
| 164 | 183 |
| 165 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_ | 184 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_ |
| OLD | NEW |