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, as well as |
103 // as well as intiates sending a stanza right away. | 104 // intiates sending a stanza right away. |
Lambros
2014/12/16 02:14:05
typo: initiates (maybe "initiating"? Or better: ".
Łukasz Anforowicz
2014/12/17 18:02:04
Done.
| |
104 // | 105 // |
105 // See rem:host-offline-reason class-level comments for discussion | 106 // See rem:host-offline-reason class-level comments for discussion of |
Lambros
2014/12/16 02:14:05
nit: What is "rem:host-offline-reason"? If it's an
Łukasz Anforowicz
2014/12/17 18:02:04
This is an xml attribute referred to in the class-
| |
106 // of allowed values for |host_offline_reason| string. | 107 // allowed values for |host_offline_reason| string. |
107 // | 108 // |
108 // |ack_callback| will be called once, when the bot acks | 109 // |ack_callback| will be called once, when the bot acks receiving the |
109 // receiving the |host_offline_reason|. | 110 // |host_offline_reason| or when |timeout| is reached. |
111 enum AckOrTimeout { Ack, Timeout }; | |
Wez
2014/12/18 00:46:20
Elsewhere we just return a |bool success| paramete
Łukasz Anforowicz
2014/12/18 19:02:33
Seemed cleaner this way (i.e. Timeout is more read
| |
110 void SetHostOfflineReason( | 112 void SetHostOfflineReason( |
111 const std::string& host_offline_reason, | 113 const std::string& host_offline_reason, |
112 const base::Closure& ack_callback); | 114 const base::TimeDelta& timeout, |
115 const base::Callback<void(AckOrTimeout)>& ack_callback); | |
113 | 116 |
114 // SignalStrategy::Listener interface. | 117 // SignalStrategy::Listener interface. |
115 void OnSignalStrategyStateChange(SignalStrategy::State state) override; | 118 void OnSignalStrategyStateChange(SignalStrategy::State state) override; |
116 bool OnSignalStrategyIncomingStanza(const buzz::XmlElement* stanza) override; | 119 bool OnSignalStrategyIncomingStanza(const buzz::XmlElement* stanza) override; |
117 | 120 |
118 private: | 121 private: |
119 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, | 122 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, |
120 DoSendStanzaWithExpectedSequenceId); | 123 DoSendStanzaWithExpectedSequenceId); |
121 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, ProcessResponseSetInterval); | 124 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, ProcessResponseSetInterval); |
122 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, | 125 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, |
123 ProcessResponseExpectedSequenceId); | 126 ProcessResponseExpectedSequenceId); |
124 friend class HeartbeatSenderTest; | 127 friend class HeartbeatSenderTest; |
125 | 128 |
126 void SendStanza(); | 129 void SendStanza(); |
127 void ResendStanza(); | 130 void ResendStanza(); |
128 void DoSendStanza(); | 131 void DoSendStanza(); |
129 void ProcessResponse(bool is_offline_heartbeat_response, | 132 void ProcessResponse(bool is_offline_heartbeat_response, |
130 IqRequest* request, | 133 IqRequest* request, |
131 const buzz::XmlElement* response); | 134 const buzz::XmlElement* response); |
132 void SetInterval(int interval); | 135 void SetInterval(int interval); |
133 void SetSequenceId(int sequence_id); | 136 void SetSequenceId(int sequence_id); |
137 void CallHostOfflineReasonAckCallback(AckOrTimeout ack_or_timeout); | |
134 | 138 |
135 // Helper methods used by DoSendStanza() to generate heartbeat stanzas. | 139 // Helper methods used by DoSendStanza() to generate heartbeat stanzas. |
136 scoped_ptr<buzz::XmlElement> CreateHeartbeatMessage(); | 140 scoped_ptr<buzz::XmlElement> CreateHeartbeatMessage(); |
137 scoped_ptr<buzz::XmlElement> CreateSignature(); | 141 scoped_ptr<buzz::XmlElement> CreateSignature(); |
138 | 142 |
139 base::Closure on_heartbeat_successful_callback_; | 143 base::Closure on_heartbeat_successful_callback_; |
140 base::Closure on_unknown_host_id_error_; | 144 base::Closure on_unknown_host_id_error_; |
141 std::string host_id_; | 145 std::string host_id_; |
142 SignalStrategy* signal_strategy_; | 146 SignalStrategy* signal_strategy_; |
143 scoped_refptr<RsaKeyPair> key_pair_; | 147 scoped_refptr<const RsaKeyPair> key_pair_; |
144 std::string directory_bot_jid_; | 148 std::string directory_bot_jid_; |
145 scoped_ptr<IqSender> iq_sender_; | 149 scoped_ptr<IqSender> iq_sender_; |
146 scoped_ptr<IqRequest> request_; | 150 scoped_ptr<IqRequest> request_; |
147 int interval_ms_; | 151 int interval_ms_; |
148 base::RepeatingTimer<HeartbeatSender> timer_; | 152 base::RepeatingTimer<HeartbeatSender> timer_; |
149 base::OneShotTimer<HeartbeatSender> timer_resend_; | 153 base::OneShotTimer<HeartbeatSender> timer_resend_; |
150 int sequence_id_; | 154 int sequence_id_; |
151 bool sequence_id_was_set_; | 155 bool sequence_id_was_set_; |
152 int sequence_id_recent_set_num_; | 156 int sequence_id_recent_set_num_; |
153 bool heartbeat_succeeded_; | 157 bool heartbeat_succeeded_; |
154 int failed_startup_heartbeat_count_; | 158 int failed_startup_heartbeat_count_; |
155 std::string host_offline_reason_; | 159 std::string host_offline_reason_; |
156 base::Closure host_offline_reason_ack_callback_; | 160 base::Callback<void(AckOrTimeout)> host_offline_reason_ack_callback_; |
161 base::OneShotTimer<HeartbeatSender> host_offline_reason_timeout_timer_; | |
Lambros
2014/12/16 02:14:05
Maybe just host_offline_reason_timer_?
Łukasz Anforowicz
2014/12/17 18:02:04
I think I'll just leave the current name - more ac
| |
157 | 162 |
158 base::ThreadChecker thread_checker_; | 163 base::ThreadChecker thread_checker_; |
159 | 164 |
160 DISALLOW_COPY_AND_ASSIGN(HeartbeatSender); | 165 DISALLOW_COPY_AND_ASSIGN(HeartbeatSender); |
161 }; | 166 }; |
162 | 167 |
163 } // namespace remoting | 168 } // namespace remoting |
164 | 169 |
165 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_ | 170 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_ |
OLD | NEW |