| 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/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 ~HeartbeatSender() override; | 100 ~HeartbeatSender() override; |
| 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 23 matching lines...) Expand all Loading... |
| 138 void ProcessResponse(bool is_offline_heartbeat_response, | 129 void ProcessResponse(bool is_offline_heartbeat_response, |
| 139 IqRequest* request, | 130 IqRequest* request, |
| 140 const buzz::XmlElement* response); | 131 const buzz::XmlElement* response); |
| 141 void SetInterval(int interval); | 132 void SetInterval(int interval); |
| 142 void SetSequenceId(int sequence_id); | 133 void SetSequenceId(int sequence_id); |
| 143 | 134 |
| 144 // Helper methods used by DoSendStanza() to generate heartbeat stanzas. | 135 // Helper methods used by DoSendStanza() to generate heartbeat stanzas. |
| 145 scoped_ptr<buzz::XmlElement> CreateHeartbeatMessage(); | 136 scoped_ptr<buzz::XmlElement> CreateHeartbeatMessage(); |
| 146 scoped_ptr<buzz::XmlElement> CreateSignature(); | 137 scoped_ptr<buzz::XmlElement> CreateSignature(); |
| 147 | 138 |
| 148 Listener* listener_; | 139 base::Closure on_heartbeat_successful_callback_; |
| 140 base::Closure on_unknown_host_id_error_; |
| 149 std::string host_id_; | 141 std::string host_id_; |
| 150 SignalStrategy* signal_strategy_; | 142 SignalStrategy* signal_strategy_; |
| 151 scoped_refptr<RsaKeyPair> key_pair_; | 143 scoped_refptr<RsaKeyPair> key_pair_; |
| 152 std::string directory_bot_jid_; | 144 std::string directory_bot_jid_; |
| 153 scoped_ptr<IqSender> iq_sender_; | 145 scoped_ptr<IqSender> iq_sender_; |
| 154 scoped_ptr<IqRequest> request_; | 146 scoped_ptr<IqRequest> request_; |
| 155 int interval_ms_; | 147 int interval_ms_; |
| 156 base::RepeatingTimer<HeartbeatSender> timer_; | 148 base::RepeatingTimer<HeartbeatSender> timer_; |
| 157 base::OneShotTimer<HeartbeatSender> timer_resend_; | 149 base::OneShotTimer<HeartbeatSender> timer_resend_; |
| 158 int sequence_id_; | 150 int sequence_id_; |
| 159 bool sequence_id_was_set_; | 151 bool sequence_id_was_set_; |
| 160 int sequence_id_recent_set_num_; | 152 int sequence_id_recent_set_num_; |
| 161 bool heartbeat_succeeded_; | 153 bool heartbeat_succeeded_; |
| 162 int failed_startup_heartbeat_count_; | 154 int failed_startup_heartbeat_count_; |
| 163 std::string host_offline_reason_; | 155 std::string host_offline_reason_; |
| 164 base::Closure host_offline_reason_ack_callback_; | 156 base::Closure host_offline_reason_ack_callback_; |
| 165 // TODO(lukasza): Consistent usage of listener-vs-callback. This is | |
| 166 // inconsistent today, because 1) host-offline-reason changes really | |
| 167 // needed to use callbacks (for ability to wrap them in | |
| 168 // CancellableCallback and for ability to hold a ref-count to | |
| 169 // MinimumHeartbeatSupporter throughout the lifetime of a callback) | |
| 170 // and 2) refactoring for consistently using callbacks everywhere | |
| 171 // spans multiple files and would obscure the core changes for | |
| 172 // host-offline-reason code. | |
| 173 | 157 |
| 174 base::ThreadChecker thread_checker_; | 158 base::ThreadChecker thread_checker_; |
| 175 | 159 |
| 176 DISALLOW_COPY_AND_ASSIGN(HeartbeatSender); | 160 DISALLOW_COPY_AND_ASSIGN(HeartbeatSender); |
| 177 }; | 161 }; |
| 178 | 162 |
| 179 } // namespace remoting | 163 } // namespace remoting |
| 180 | 164 |
| 181 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_ | 165 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_ |
| OLD | NEW |