| 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/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/timer.h" | 14 #include "base/timer.h" |
| 15 #include "remoting/host/host_key_pair.h" | 15 #include "remoting/base/rsa_key_pair.h" |
| 16 #include "remoting/jingle_glue/signal_strategy.h" | 16 #include "remoting/jingle_glue/signal_strategy.h" |
| 17 | 17 |
| 18 namespace base { | 18 namespace base { |
| 19 class MessageLoopProxy; | 19 class MessageLoopProxy; |
| 20 } // namespace base | 20 } // namespace base |
| 21 | 21 |
| 22 namespace buzz { | 22 namespace buzz { |
| 23 class XmlElement; | 23 class XmlElement; |
| 24 } // namespace buzz | 24 } // namespace buzz |
| 25 | 25 |
| 26 namespace remoting { | 26 namespace remoting { |
| 27 | 27 |
| 28 class HostKeyPair; | 28 class RsaKeyPair; |
| 29 class IqRequest; | 29 class IqRequest; |
| 30 class IqSender; | 30 class IqSender; |
| 31 | 31 |
| 32 // HeartbeatSender periodically sends heartbeat stanzas to the Chromoting Bot. | 32 // HeartbeatSender periodically sends heartbeat stanzas to the Chromoting Bot. |
| 33 // Each heartbeat stanza looks as follows: | 33 // Each heartbeat stanza looks as follows: |
| 34 // | 34 // |
| 35 // <iq type="set" to="remoting@bot.talk.google.com" | 35 // <iq type="set" to="remoting@bot.talk.google.com" |
| 36 // from="user@gmail.com/chromoting123123" id="5" xmlns="jabber:client"> | 36 // from="user@gmail.com/chromoting123123" id="5" xmlns="jabber:client"> |
| 37 // <rem:heartbeat rem:hostid="a1ddb11e-8aef-11df-bccf-18a905b9cb5a" | 37 // <rem:heartbeat rem:hostid="a1ddb11e-8aef-11df-bccf-18a905b9cb5a" |
| 38 // rem:sequence-id="456" | 38 // rem:sequence-id="456" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 // </iq> | 79 // </iq> |
| 80 class HeartbeatSender : public SignalStrategy::Listener { | 80 class HeartbeatSender : public SignalStrategy::Listener { |
| 81 public: | 81 public: |
| 82 class Listener { | 82 class Listener { |
| 83 public: | 83 public: |
| 84 virtual ~Listener() { } | 84 virtual ~Listener() { } |
| 85 // Invoked when the host ID is permanently not recognized by the server. | 85 // Invoked when the host ID is permanently not recognized by the server. |
| 86 virtual void OnUnknownHostIdError() = 0; | 86 virtual void OnUnknownHostIdError() = 0; |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 // |signal_strategy|, |key_pair| and |delegate| must outlive this | 89 // |signal_strategy| and |delegate| must outlive this |
| 90 // object. Heartbeats will start when the supplied SignalStrategy | 90 // object. Heartbeats will start when the supplied SignalStrategy |
| 91 // enters the CONNECTED state. | 91 // enters the CONNECTED state. |
| 92 HeartbeatSender(Listener* listener, | 92 HeartbeatSender(Listener* listener, |
| 93 const std::string& host_id, | 93 const std::string& host_id, |
| 94 SignalStrategy* signal_strategy, | 94 SignalStrategy* signal_strategy, |
| 95 HostKeyPair* key_pair, | 95 scoped_refptr<RsaKeyPair> key_pair, |
| 96 const std::string& directory_bot_jid); | 96 const std::string& directory_bot_jid); |
| 97 virtual ~HeartbeatSender(); | 97 virtual ~HeartbeatSender(); |
| 98 | 98 |
| 99 // SignalStrategy::Listener interface. | 99 // SignalStrategy::Listener interface. |
| 100 virtual void OnSignalStrategyStateChange( | 100 virtual void OnSignalStrategyStateChange( |
| 101 SignalStrategy::State state) OVERRIDE; | 101 SignalStrategy::State state) OVERRIDE; |
| 102 virtual bool OnSignalStrategyIncomingStanza( | 102 virtual bool OnSignalStrategyIncomingStanza( |
| 103 const buzz::XmlElement* stanza) OVERRIDE; | 103 const buzz::XmlElement* stanza) OVERRIDE; |
| 104 | 104 |
| 105 private: | 105 private: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 118 void SetInterval(int interval); | 118 void SetInterval(int interval); |
| 119 void SetSequenceId(int sequence_id); | 119 void SetSequenceId(int sequence_id); |
| 120 | 120 |
| 121 // Helper methods used by DoSendStanza() to generate heartbeat stanzas. | 121 // Helper methods used by DoSendStanza() to generate heartbeat stanzas. |
| 122 scoped_ptr<buzz::XmlElement> CreateHeartbeatMessage(); | 122 scoped_ptr<buzz::XmlElement> CreateHeartbeatMessage(); |
| 123 scoped_ptr<buzz::XmlElement> CreateSignature(); | 123 scoped_ptr<buzz::XmlElement> CreateSignature(); |
| 124 | 124 |
| 125 Listener* listener_; | 125 Listener* listener_; |
| 126 std::string host_id_; | 126 std::string host_id_; |
| 127 SignalStrategy* signal_strategy_; | 127 SignalStrategy* signal_strategy_; |
| 128 HostKeyPair* key_pair_; | 128 scoped_refptr<RsaKeyPair> key_pair_; |
| 129 std::string directory_bot_jid_; | 129 std::string directory_bot_jid_; |
| 130 scoped_ptr<IqSender> iq_sender_; | 130 scoped_ptr<IqSender> iq_sender_; |
| 131 scoped_ptr<IqRequest> request_; | 131 scoped_ptr<IqRequest> request_; |
| 132 int interval_ms_; | 132 int interval_ms_; |
| 133 base::RepeatingTimer<HeartbeatSender> timer_; | 133 base::RepeatingTimer<HeartbeatSender> timer_; |
| 134 base::OneShotTimer<HeartbeatSender> timer_resend_; | 134 base::OneShotTimer<HeartbeatSender> timer_resend_; |
| 135 int sequence_id_; | 135 int sequence_id_; |
| 136 bool sequence_id_was_set_; | 136 bool sequence_id_was_set_; |
| 137 int sequence_id_recent_set_num_; | 137 int sequence_id_recent_set_num_; |
| 138 bool heartbeat_succeeded_; | 138 bool heartbeat_succeeded_; |
| 139 int failed_startup_heartbeat_count_; | 139 int failed_startup_heartbeat_count_; |
| 140 | 140 |
| 141 DISALLOW_COPY_AND_ASSIGN(HeartbeatSender); | 141 DISALLOW_COPY_AND_ASSIGN(HeartbeatSender); |
| 142 }; | 142 }; |
| 143 | 143 |
| 144 } // namespace remoting | 144 } // namespace remoting |
| 145 | 145 |
| 146 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_ | 146 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_ |
| OLD | NEW |