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" | |
Lambros
2014/11/18 02:33:52
callback_forward.h :)
Łukasz Anforowicz
2014/11/18 17:30:45
What about the base::Closure by-value / not-a-poin
Lambros
2014/11/18 18:47:21
Yes you're right, didn't see those. I only scanned
| |
10 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
11 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
15 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
16 #include "remoting/base/rsa_key_pair.h" | 17 #include "remoting/base/rsa_key_pair.h" |
17 #include "remoting/signaling/signal_strategy.h" | 18 #include "remoting/signaling/signal_strategy.h" |
18 | 19 |
19 namespace base { | 20 namespace base { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 // stanza of this form: | 81 // stanza of this form: |
81 // | 82 // |
82 // <iq type="set" from="remoting@bot.talk.google.com" | 83 // <iq type="set" from="remoting@bot.talk.google.com" |
83 // to="user@gmail.com/chromoting123123" id="5" xmlns="jabber:client"> | 84 // to="user@gmail.com/chromoting123123" id="5" xmlns="jabber:client"> |
84 // <rem:heartbeat-result xmlns:rem="google:remoting"> | 85 // <rem:heartbeat-result xmlns:rem="google:remoting"> |
85 // <rem:expected-sequence-id>654</rem:expected-sequence-id> | 86 // <rem:expected-sequence-id>654</rem:expected-sequence-id> |
86 // </rem:heartbeat-result> | 87 // </rem:heartbeat-result> |
87 // </iq> | 88 // </iq> |
88 class HeartbeatSender : public SignalStrategy::Listener { | 89 class HeartbeatSender : public SignalStrategy::Listener { |
89 public: | 90 public: |
90 class Listener { | |
91 public: | |
92 virtual ~Listener() { } | |
93 | |
94 // Invoked after the first successful heartbeat. | |
95 virtual void OnHeartbeatSuccessful() = 0; | |
96 | |
97 // Invoked when the host ID is permanently not recognized by the server. | |
98 virtual void OnUnknownHostIdError() = 0; | |
99 }; | |
100 | |
101 // |signal_strategy| and |delegate| must outlive this | 91 // |signal_strategy| and |delegate| must outlive this |
102 // object. Heartbeats will start when the supplied SignalStrategy | 92 // object. Heartbeats will start when the supplied SignalStrategy |
103 // enters the CONNECTED state. | 93 // enters the CONNECTED state. |
104 HeartbeatSender(Listener* listener, | 94 HeartbeatSender(const base::Closure& on_heartbeat_successful_callback, |
95 const base::Closure& on_unknown_host_id_error, | |
105 const std::string& host_id, | 96 const std::string& host_id, |
106 SignalStrategy* signal_strategy, | 97 SignalStrategy* signal_strategy, |
107 scoped_refptr<RsaKeyPair> key_pair, | 98 scoped_refptr<RsaKeyPair> key_pair, |
108 const std::string& directory_bot_jid); | 99 const std::string& directory_bot_jid); |
109 virtual ~HeartbeatSender(); | 100 virtual ~HeartbeatSender(); |
110 | 101 |
111 // Sets host offline reason for future heartbeat stanzas, | 102 // Sets host offline reason for future heartbeat stanzas, |
112 // as well as intiates sending a stanza right away. | 103 // as well as intiates sending a stanza right away. |
113 // | 104 // |
114 // See rem:host-offline-reason class-level comments for discussion | 105 // See rem:host-offline-reason class-level comments for discussion |
(...skipping 25 matching lines...) Expand all Loading... | |
140 void ProcessResponse(bool is_offline_heartbeat_response, | 131 void ProcessResponse(bool is_offline_heartbeat_response, |
141 IqRequest* request, | 132 IqRequest* request, |
142 const buzz::XmlElement* response); | 133 const buzz::XmlElement* response); |
143 void SetInterval(int interval); | 134 void SetInterval(int interval); |
144 void SetSequenceId(int sequence_id); | 135 void SetSequenceId(int sequence_id); |
145 | 136 |
146 // Helper methods used by DoSendStanza() to generate heartbeat stanzas. | 137 // Helper methods used by DoSendStanza() to generate heartbeat stanzas. |
147 scoped_ptr<buzz::XmlElement> CreateHeartbeatMessage(); | 138 scoped_ptr<buzz::XmlElement> CreateHeartbeatMessage(); |
148 scoped_ptr<buzz::XmlElement> CreateSignature(); | 139 scoped_ptr<buzz::XmlElement> CreateSignature(); |
149 | 140 |
150 Listener* listener_; | 141 base::Closure on_heartbeat_successful_callback_; |
142 base::Closure on_unknown_host_id_error_; | |
151 std::string host_id_; | 143 std::string host_id_; |
152 SignalStrategy* signal_strategy_; | 144 SignalStrategy* signal_strategy_; |
153 scoped_refptr<RsaKeyPair> key_pair_; | 145 scoped_refptr<RsaKeyPair> key_pair_; |
154 std::string directory_bot_jid_; | 146 std::string directory_bot_jid_; |
155 scoped_ptr<IqSender> iq_sender_; | 147 scoped_ptr<IqSender> iq_sender_; |
156 scoped_ptr<IqRequest> request_; | 148 scoped_ptr<IqRequest> request_; |
157 int interval_ms_; | 149 int interval_ms_; |
158 base::RepeatingTimer<HeartbeatSender> timer_; | 150 base::RepeatingTimer<HeartbeatSender> timer_; |
159 base::OneShotTimer<HeartbeatSender> timer_resend_; | 151 base::OneShotTimer<HeartbeatSender> timer_resend_; |
160 int sequence_id_; | 152 int sequence_id_; |
161 bool sequence_id_was_set_; | 153 bool sequence_id_was_set_; |
162 int sequence_id_recent_set_num_; | 154 int sequence_id_recent_set_num_; |
163 bool heartbeat_succeeded_; | 155 bool heartbeat_succeeded_; |
164 int failed_startup_heartbeat_count_; | 156 int failed_startup_heartbeat_count_; |
165 std::string host_offline_reason_; | 157 std::string host_offline_reason_; |
166 base::Closure host_offline_reason_ack_callback_; | 158 base::Closure host_offline_reason_ack_callback_; |
167 // TODO(lukasza): Consistent usage of listener-vs-callback. This is | |
168 // inconsistent today, because 1) host-offline-reason changes really | |
169 // needed to use callbacks (for ability to wrap them in | |
170 // CancellableCallback and for ability to hold a ref-count to | |
171 // MinimumHeartbeatSupporter throughout the lifetime of a callback) | |
172 // and 2) refactoring for consistently using callbacks everywhere | |
173 // spans multiple files and would obscure the core changes for | |
174 // host-offline-reason code. | |
175 | 159 |
176 base::ThreadChecker thread_checker_; | 160 base::ThreadChecker thread_checker_; |
177 | 161 |
178 DISALLOW_COPY_AND_ASSIGN(HeartbeatSender); | 162 DISALLOW_COPY_AND_ASSIGN(HeartbeatSender); |
179 }; | 163 }; |
180 | 164 |
181 } // namespace remoting | 165 } // namespace remoting |
182 | 166 |
183 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_ | 167 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_ |
OLD | NEW |