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/gtest_prod_util.h" |
11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/timer.h" | 14 #include "base/timer.h" |
14 #include "remoting/host/host_key_pair.h" | 15 #include "remoting/host/host_key_pair.h" |
15 #include "remoting/host/host_status_observer.h" | 16 #include "remoting/jingle_glue/signal_strategy.h" |
16 #include "base/gtest_prod_util.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 { |
(...skipping 28 matching lines...) Expand all Loading... |
55 // <rem:heartbeat-result xmlns:rem="google:remoting"> | 55 // <rem:heartbeat-result xmlns:rem="google:remoting"> |
56 // <rem:set-interval>300</rem:set-interval> | 56 // <rem:set-interval>300</rem:set-interval> |
57 // </rem:heartbeat> | 57 // </rem:heartbeat> |
58 // </iq> | 58 // </iq> |
59 // | 59 // |
60 // The set-interval tag is used to specify desired heartbeat interval | 60 // The set-interval tag is used to specify desired heartbeat interval |
61 // in seconds. The heartbeat-result and the set-interval tags are | 61 // in seconds. The heartbeat-result and the set-interval tags are |
62 // optional. Host uses default heartbeat interval if it doesn't find | 62 // optional. Host uses default heartbeat interval if it doesn't find |
63 // set-interval tag in the result Iq stanza it receives from the | 63 // set-interval tag in the result Iq stanza it receives from the |
64 // server. | 64 // server. |
65 // | 65 class HeartbeatSender : public SignalStrategy::Listener { |
66 // TODO(sergeyu): Is it enough to sign JID and nothing else? | |
67 class HeartbeatSender : public HostStatusObserver { | |
68 public: | 66 public: |
69 HeartbeatSender(base::MessageLoopProxy* main_loop, | 67 HeartbeatSender(); |
70 MutableHostConfig* config); | |
71 virtual ~HeartbeatSender(); | 68 virtual ~HeartbeatSender(); |
72 | 69 |
73 // Initializes heart-beating for |jingle_client_| with |config_|. Returns | 70 // Initializes the HeartbeatSender. Returns false if the |config| is |
74 // false if the config is invalid (e.g. private key cannot be parsed). | 71 // invalid (e.g. private key cannot be parsed). SignalStrategy must |
75 bool Init(); | 72 // outlive this object. Heartbeats will start when the supplied |
| 73 // SignalStrategy enters the CONNECTED state. |
| 74 bool Init(SignalStrategy* signal_strategy, MutableHostConfig* config); |
76 | 75 |
77 // HostStatusObserver implementation. | 76 // SignalStrategy::Listener interface. |
78 virtual void OnSignallingConnected(SignalStrategy* signal_strategy) OVERRIDE; | 77 virtual void OnSignalStrategyStateChange( |
79 virtual void OnSignallingDisconnected() OVERRIDE; | 78 SignalStrategy::State state) OVERRIDE; |
80 virtual void OnClientAuthenticated(const std::string& jid) OVERRIDE; | |
81 virtual void OnClientDisconnected(const std::string& jid) OVERRIDE; | |
82 virtual void OnAccessDenied() OVERRIDE; | |
83 virtual void OnShutdown() OVERRIDE; | |
84 | 79 |
85 private: | 80 private: |
86 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, DoSendStanza); | 81 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, DoSendStanza); |
87 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, CreateHeartbeatMessage); | 82 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, CreateHeartbeatMessage); |
88 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, ProcessResponse); | 83 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, ProcessResponse); |
89 | 84 |
90 enum State { | 85 enum State { |
91 CREATED, | 86 CREATED, |
92 INITIALIZED, | 87 INITIALIZED, |
93 STARTED, | 88 STARTED, |
94 STOPPED, | 89 STOPPED, |
95 }; | 90 }; |
96 | 91 |
97 void DoSendStanza(); | 92 void DoSendStanza(); |
98 void ProcessResponse(const buzz::XmlElement* response); | 93 void ProcessResponse(const buzz::XmlElement* response); |
99 void SetInterval(int interval); | 94 void SetInterval(int interval); |
100 | 95 |
101 // Helper methods used by DoSendStanza() to generate heartbeat stanzas. | 96 // Helper methods used by DoSendStanza() to generate heartbeat stanzas. |
102 // Caller owns the result. | 97 // Caller owns the result. |
103 buzz::XmlElement* CreateHeartbeatMessage(); | 98 buzz::XmlElement* CreateHeartbeatMessage(); |
104 buzz::XmlElement* CreateSignature(); | 99 buzz::XmlElement* CreateSignature(); |
105 | 100 |
106 State state_; | 101 State state_; |
107 scoped_refptr<base::MessageLoopProxy> message_loop_; | 102 SignalStrategy* signal_strategy_; |
108 scoped_refptr<MutableHostConfig> config_; | |
109 std::string host_id_; | 103 std::string host_id_; |
110 HostKeyPair key_pair_; | 104 HostKeyPair key_pair_; |
111 std::string full_jid_; | |
112 scoped_ptr<IqSender> iq_sender_; | 105 scoped_ptr<IqSender> iq_sender_; |
113 scoped_ptr<IqRequest> request_; | 106 scoped_ptr<IqRequest> request_; |
114 int interval_ms_; | 107 int interval_ms_; |
115 base::RepeatingTimer<HeartbeatSender> timer_; | 108 base::RepeatingTimer<HeartbeatSender> timer_; |
116 | 109 |
117 DISALLOW_COPY_AND_ASSIGN(HeartbeatSender); | 110 DISALLOW_COPY_AND_ASSIGN(HeartbeatSender); |
118 }; | 111 }; |
119 | 112 |
120 } // namespace remoting | 113 } // namespace remoting |
121 | 114 |
122 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_ | 115 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_ |
OLD | NEW |