OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/timer.h" | 13 #include "base/timer.h" |
14 #include "remoting/host/host_key_pair.h" | 14 #include "remoting/host/host_key_pair.h" |
15 #include "remoting/host/host_status_observer.h" | 15 #include "remoting/host/host_status_observer.h" |
16 #include "remoting/jingle_glue/iq_request.h" | 16 #include "remoting/jingle_glue/iq_request.h" |
17 #include "testing/gtest/include/gtest/gtest_prod.h" | 17 #include "testing/gtest/include/gtest/gtest_prod.h" |
18 | 18 |
| 19 namespace base { |
| 20 class MessageLoopProxy; |
| 21 } // namespace base |
| 22 |
19 namespace remoting { | 23 namespace remoting { |
20 | 24 |
21 class IqRequest; | 25 class IqRequest; |
22 class HostKeyPair; | 26 class HostKeyPair; |
23 class MutableHostConfig; | 27 class MutableHostConfig; |
24 | 28 |
25 // HeartbeatSender periodically sends heartbeat stanzas to the Chromoting Bot. | 29 // HeartbeatSender periodically sends heartbeat stanzas to the Chromoting Bot. |
26 // Each heartbeat stanza looks as follows: | 30 // Each heartbeat stanza looks as follows: |
27 // | 31 // |
28 // <iq type="set" to="remoting@bot.talk.google.com" | 32 // <iq type="set" to="remoting@bot.talk.google.com" |
(...skipping 22 matching lines...) Expand all Loading... |
51 // | 55 // |
52 // The set-interval tag is used to specify desired heartbeat interval | 56 // The set-interval tag is used to specify desired heartbeat interval |
53 // in seconds. The heartbeat-result and the set-interval tags are | 57 // in seconds. The heartbeat-result and the set-interval tags are |
54 // optional. Host uses default heartbeat interval if it doesn't find | 58 // optional. Host uses default heartbeat interval if it doesn't find |
55 // set-interval tag in the result Iq stanza it receives from the | 59 // set-interval tag in the result Iq stanza it receives from the |
56 // server. | 60 // server. |
57 // | 61 // |
58 // TODO(sergeyu): Is it enough to sign JID and nothing else? | 62 // TODO(sergeyu): Is it enough to sign JID and nothing else? |
59 class HeartbeatSender : public HostStatusObserver { | 63 class HeartbeatSender : public HostStatusObserver { |
60 public: | 64 public: |
61 HeartbeatSender(MessageLoop* main_loop, | 65 HeartbeatSender(base::MessageLoopProxy* main_loop, |
62 MutableHostConfig* config); | 66 MutableHostConfig* config); |
63 virtual ~HeartbeatSender(); | 67 virtual ~HeartbeatSender(); |
64 | 68 |
65 // Initializes heart-beating for |jingle_client_| with |config_|. Returns | 69 // Initializes heart-beating for |jingle_client_| with |config_|. Returns |
66 // false if the config is invalid (e.g. private key cannot be parsed). | 70 // false if the config is invalid (e.g. private key cannot be parsed). |
67 bool Init(); | 71 bool Init(); |
68 | 72 |
69 // HostStatusObserver implementation. | 73 // HostStatusObserver implementation. |
70 virtual void OnSignallingConnected(SignalStrategy* signal_strategy, | 74 virtual void OnSignallingConnected(SignalStrategy* signal_strategy, |
71 const std::string& full_jid) OVERRIDE; | 75 const std::string& full_jid) OVERRIDE; |
(...skipping 20 matching lines...) Expand all Loading... |
92 void DoSendStanza(); | 96 void DoSendStanza(); |
93 void ProcessResponse(const buzz::XmlElement* response); | 97 void ProcessResponse(const buzz::XmlElement* response); |
94 void SetInterval(int interval); | 98 void SetInterval(int interval); |
95 | 99 |
96 // Helper methods used by DoSendStanza() to generate heartbeat stanzas. | 100 // Helper methods used by DoSendStanza() to generate heartbeat stanzas. |
97 // Caller owns the result. | 101 // Caller owns the result. |
98 buzz::XmlElement* CreateHeartbeatMessage(); | 102 buzz::XmlElement* CreateHeartbeatMessage(); |
99 buzz::XmlElement* CreateSignature(); | 103 buzz::XmlElement* CreateSignature(); |
100 | 104 |
101 State state_; | 105 State state_; |
102 MessageLoop* message_loop_; | 106 scoped_refptr<base::MessageLoopProxy> message_loop_; |
103 scoped_refptr<MutableHostConfig> config_; | 107 scoped_refptr<MutableHostConfig> config_; |
104 std::string host_id_; | 108 std::string host_id_; |
105 HostKeyPair key_pair_; | 109 HostKeyPair key_pair_; |
106 std::string full_jid_; | 110 std::string full_jid_; |
107 scoped_ptr<IqRequest> request_; | 111 scoped_ptr<IqRequest> request_; |
108 int interval_ms_; | 112 int interval_ms_; |
109 base::RepeatingTimer<HeartbeatSender> timer_; | 113 base::RepeatingTimer<HeartbeatSender> timer_; |
110 | 114 |
111 DISALLOW_COPY_AND_ASSIGN(HeartbeatSender); | 115 DISALLOW_COPY_AND_ASSIGN(HeartbeatSender); |
112 }; | 116 }; |
113 | 117 |
114 } // namespace remoting | 118 } // namespace remoting |
115 | 119 |
116 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_ | 120 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_ |
OLD | NEW |