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 HeartbeatSender( |
| 95 const base::Closure& on_unknown_host_id_error, | 96 // Invoked after the first successful heartbeat. |
| 96 const std::string& host_id, | 97 const base::Closure& on_heartbeat_successful_callback, |
| 97 SignalStrategy* signal_strategy, | 98 |
| 98 scoped_refptr<RsaKeyPair> key_pair, | 99 // Invoked when the host ID is permanently not recognized by the server. |
|
Wez
2014/12/19 22:05:37
These comments should be in the HeartbeatSender()
Łukasz Anforowicz
2015/01/07 01:24:04
Done.
| |
| 99 const std::string& directory_bot_jid); | 100 const base::Closure& on_unknown_host_id_error, |
| 101 | |
| 102 const std::string& host_id, | |
| 103 SignalStrategy* signal_strategy, | |
| 104 const scoped_refptr<const RsaKeyPair>& host_key_pair, | |
| 105 const std::string& directory_bot_jid); | |
| 100 ~HeartbeatSender() override; | 106 ~HeartbeatSender() override; |
| 101 | 107 |
| 102 // Sets host offline reason for future heartbeat stanzas, | 108 // Sets host offline reason for future heartbeat stanzas, and initiates |
| 103 // as well as intiates sending a stanza right away. | 109 // sending a stanza right away. |
| 104 // | 110 // |
| 105 // See rem:host-offline-reason class-level comments for discussion | 111 // For discussion of allowed values for |host_offline_reason| argument, |
| 106 // of allowed values for |host_offline_reason| string. | 112 // please see the description of rem:host-offline-reason xml attribute in |
| 113 // the class-level comments above. | |
| 107 // | 114 // |
| 108 // |ack_callback| will be called once, when the bot acks | 115 // |ack_callback| will be called once, when the bot acks receiving the |
| 109 // receiving the |host_offline_reason|. | 116 // |host_offline_reason| or when |timeout| is reached. |
| 110 void SetHostOfflineReason( | 117 void SetHostOfflineReason( |
| 111 const std::string& host_offline_reason, | 118 const std::string& host_offline_reason, |
| 112 const base::Closure& ack_callback); | 119 const base::TimeDelta& timeout, |
| 120 const base::Callback<void(bool success)>& ack_callback); | |
| 113 | 121 |
| 114 // SignalStrategy::Listener interface. | 122 // SignalStrategy::Listener interface. |
| 115 void OnSignalStrategyStateChange(SignalStrategy::State state) override; | 123 void OnSignalStrategyStateChange(SignalStrategy::State state) override; |
| 116 bool OnSignalStrategyIncomingStanza(const buzz::XmlElement* stanza) override; | 124 bool OnSignalStrategyIncomingStanza(const buzz::XmlElement* stanza) override; |
| 117 | 125 |
| 118 private: | 126 private: |
| 119 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, | 127 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, |
| 120 DoSendStanzaWithExpectedSequenceId); | 128 DoSendStanzaWithExpectedSequenceId); |
| 121 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, ProcessResponseSetInterval); | 129 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, ProcessResponseSetInterval); |
| 122 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, | 130 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, |
| 123 ProcessResponseExpectedSequenceId); | 131 ProcessResponseExpectedSequenceId); |
| 124 friend class HeartbeatSenderTest; | 132 friend class HeartbeatSenderTest; |
| 125 | 133 |
| 126 void SendStanza(); | 134 void SendStanza(); |
| 127 void ResendStanza(); | 135 void ResendStanza(); |
| 128 void DoSendStanza(); | 136 void DoSendStanza(); |
| 129 void ProcessResponse(bool is_offline_heartbeat_response, | 137 void ProcessResponse(bool is_offline_heartbeat_response, |
| 130 IqRequest* request, | 138 IqRequest* request, |
| 131 const buzz::XmlElement* response); | 139 const buzz::XmlElement* response); |
| 132 void SetInterval(int interval); | 140 void SetInterval(int interval); |
| 133 void SetSequenceId(int sequence_id); | 141 void SetSequenceId(int sequence_id); |
| 134 | 142 |
| 143 void PostHostOfflineReasonAckCallback(bool success); | |
| 144 void OnHostOfflineReasonTimeout(); | |
| 145 void OnHostOfflineReasonAck(); | |
|
Wez
2014/12/19 22:05:37
nit: A single-line comment on this block to explai
Łukasz Anforowicz
2015/01/07 01:24:04
Done.
| |
| 146 | |
| 135 // Helper methods used by DoSendStanza() to generate heartbeat stanzas. | 147 // Helper methods used by DoSendStanza() to generate heartbeat stanzas. |
| 136 scoped_ptr<buzz::XmlElement> CreateHeartbeatMessage(); | 148 scoped_ptr<buzz::XmlElement> CreateHeartbeatMessage(); |
| 137 scoped_ptr<buzz::XmlElement> CreateSignature(); | 149 scoped_ptr<buzz::XmlElement> CreateSignature(); |
| 138 | 150 |
| 139 base::Closure on_heartbeat_successful_callback_; | 151 base::Closure on_heartbeat_successful_callback_; |
| 140 base::Closure on_unknown_host_id_error_; | 152 base::Closure on_unknown_host_id_error_; |
| 141 std::string host_id_; | 153 std::string host_id_; |
| 142 SignalStrategy* signal_strategy_; | 154 SignalStrategy* signal_strategy_; |
| 143 scoped_refptr<RsaKeyPair> key_pair_; | 155 scoped_refptr<const RsaKeyPair> host_key_pair_; |
| 144 std::string directory_bot_jid_; | 156 std::string directory_bot_jid_; |
| 145 scoped_ptr<IqSender> iq_sender_; | 157 scoped_ptr<IqSender> iq_sender_; |
| 146 scoped_ptr<IqRequest> request_; | 158 scoped_ptr<IqRequest> request_; |
| 147 int interval_ms_; | 159 int interval_ms_; |
| 148 base::RepeatingTimer<HeartbeatSender> timer_; | 160 base::RepeatingTimer<HeartbeatSender> timer_; |
| 149 base::OneShotTimer<HeartbeatSender> timer_resend_; | 161 base::OneShotTimer<HeartbeatSender> timer_resend_; |
| 150 int sequence_id_; | 162 int sequence_id_; |
| 151 bool sequence_id_was_set_; | 163 bool sequence_id_was_set_; |
| 152 int sequence_id_recent_set_num_; | 164 int sequence_id_recent_set_num_; |
| 153 bool heartbeat_succeeded_; | 165 bool heartbeat_succeeded_; |
| 154 int failed_startup_heartbeat_count_; | 166 int failed_startup_heartbeat_count_; |
| 155 std::string host_offline_reason_; | 167 std::string host_offline_reason_; |
| 156 base::Closure host_offline_reason_ack_callback_; | 168 base::Callback<void(bool success)> host_offline_reason_ack_callback_; |
| 169 base::OneShotTimer<HeartbeatSender> host_offline_reason_timeout_timer_; | |
|
Wez
2014/12/19 22:05:37
Similarly here, it'd be good to separate the offli
Łukasz Anforowicz
2015/01/07 01:24:04
Done.
| |
| 157 | 170 |
| 158 base::ThreadChecker thread_checker_; | 171 base::ThreadChecker thread_checker_; |
| 159 | 172 |
| 160 DISALLOW_COPY_AND_ASSIGN(HeartbeatSender); | 173 DISALLOW_COPY_AND_ASSIGN(HeartbeatSender); |
| 161 }; | 174 }; |
| 162 | 175 |
| 163 } // namespace remoting | 176 } // namespace remoting |
| 164 | 177 |
| 165 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_ | 178 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_ |
| OLD | NEW |