Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: remoting/host/heartbeat_sender.h

Issue 6911024: Add HostObserverInterface and decouple HeartbeatSender and ChromotingHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
Wez 2011/05/03 05:21:50 Is this for OVERRIDE?
Sergey Ulanov 2011/05/03 17:24:18 Yes.
10 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/timer.h"
12 #include "remoting/host/host_key_pair.h" 14 #include "remoting/host/host_key_pair.h"
15 #include "remoting/host/host_status_observer.h"
13 #include "remoting/jingle_glue/iq_request.h" 16 #include "remoting/jingle_glue/iq_request.h"
14 #include "testing/gtest/include/gtest/gtest_prod.h" 17 #include "testing/gtest/include/gtest/gtest_prod.h"
15 18
16 namespace remoting { 19 namespace remoting {
17 20
18 class IqRequest; 21 class IqRequest;
19 class HostKeyPair; 22 class HostKeyPair;
20 class JingleClient;
21 class JingleThread;
22 class MutableHostConfig; 23 class MutableHostConfig;
23 24
24 // HeartbeatSender periodically sends heartbeat stanzas to the Chromoting Bot. 25 // HeartbeatSender periodically sends heartbeat stanzas to the Chromoting Bot.
25 // Each heartbeat stanza looks as follows: 26 // Each heartbeat stanza looks as follows:
26 // 27 //
27 // <iq type="set" to="remoting@bot.talk.google.com" 28 // <iq type="set" to="remoting@bot.talk.google.com"
28 // from="user@gmail.com/chromoting123123" id="5" xmlns="jabber:client"> 29 // from="user@gmail.com/chromoting123123" id="5" xmlns="jabber:client">
29 // <rem:heartbeat rem:hostid="a1ddb11e-8aef-11df-bccf-18a905b9cb5a" 30 // <rem:heartbeat rem:hostid="a1ddb11e-8aef-11df-bccf-18a905b9cb5a"
30 // xmlns:rem="google:remoting"> 31 // xmlns:rem="google:remoting">
31 // <rem:signature rem:time="1279061748">.signature.</rem:signature> 32 // <rem:signature rem:time="1279061748">.signature.</rem:signature>
(...skipping 16 matching lines...) Expand all
48 // </rem:heartbeat> 49 // </rem:heartbeat>
49 // </iq> 50 // </iq>
50 // 51 //
51 // The set-interval tag is used to specify desired heartbeat interval 52 // The set-interval tag is used to specify desired heartbeat interval
52 // in seconds. The heartbeat-result and the set-interval tags are 53 // in seconds. The heartbeat-result and the set-interval tags are
53 // optional. Host uses default heartbeat interval if it doesn't find 54 // optional. Host uses default heartbeat interval if it doesn't find
54 // set-interval tag in the result Iq stanza it receives from the 55 // set-interval tag in the result Iq stanza it receives from the
55 // server. 56 // server.
56 // 57 //
57 // TODO(sergeyu): Is it enough to sign JID and nothing else? 58 // TODO(sergeyu): Is it enough to sign JID and nothing else?
58 class HeartbeatSender : public base::RefCountedThreadSafe<HeartbeatSender> { 59 class HeartbeatSender : public HostStatusObserver {
59 public: 60 public:
60 HeartbeatSender(MessageLoop* main_loop, 61 HeartbeatSender(MessageLoop* main_loop,
61 JingleClient* jingle_client,
62 MutableHostConfig* config); 62 MutableHostConfig* config);
63 virtual ~HeartbeatSender(); 63 virtual ~HeartbeatSender();
64 64
65 // Initializes heart-beating for |jingle_client_| with |config_|. Returns 65 // Initializes heart-beating for |jingle_client_| with |config_|. Returns
66 // false if the config is invalid (e.g. private key cannot be parsed). 66 // false if the config is invalid (e.g. private key cannot be parsed).
67 bool Init(); 67 bool Init();
68 68
69 // Starts heart-beating. Must be called after init. 69 // HostStatusObserver implementation.
70 void Start(); 70 virtual void OnSignallingConnected(SignalStrategy* signal_strategy,
71 71 const std::string& full_jid) OVERRIDE;
72 // Stops heart-beating. Must be called before corresponding JingleClient 72 virtual void OnSignallingDisconnected() OVERRIDE;
73 // is destroyed. This object will not be deleted until Stop() is called, 73 virtual void OnShutdown() OVERRIDE;
74 // and it may (and will) crash after JingleClient is destroyed. Heartbeating
75 // cannot be restarted after it has been stopped, A new sender must be created
76 // instead.
77 void Stop();
78 74
79 private: 75 private:
80 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, DoSendStanza); 76 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, DoSendStanza);
81 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, CreateHeartbeatMessage); 77 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, CreateHeartbeatMessage);
82 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, ProcessResponse); 78 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, ProcessResponse);
83 79
84 enum State { 80 enum State {
85 CREATED, 81 CREATED,
86 INITIALIZED, 82 INITIALIZED,
87 STARTED, 83 STARTED,
88 STOPPED, 84 STOPPED,
89 }; 85 };
90 86
91 void DoSendStanza(); 87 void DoSendStanza();
88 void ProcessResponse(const buzz::XmlElement* response);
89 void SetInterval(int interval);
92 90
93 // Helper methods used by DoSendStanza() to generate heartbeat stanzas. 91 // Helper methods used by DoSendStanza() to generate heartbeat stanzas.
94 // Caller owns the result. 92 // Caller owns the result.
95 buzz::XmlElement* CreateHeartbeatMessage(); 93 buzz::XmlElement* CreateHeartbeatMessage();
96 buzz::XmlElement* CreateSignature(); 94 buzz::XmlElement* CreateSignature();
97 95
98 void ProcessResponse(const buzz::XmlElement* response);
99
100 State state_; 96 State state_;
101 MessageLoop* message_loop_; 97 MessageLoop* message_loop_;
102 JingleClient* jingle_client_;
103 scoped_refptr<MutableHostConfig> config_; 98 scoped_refptr<MutableHostConfig> config_;
104 scoped_ptr<IqRequest> request_;
105 std::string host_id_; 99 std::string host_id_;
106 HostKeyPair key_pair_; 100 HostKeyPair key_pair_;
101 std::string full_jid_;
102 scoped_ptr<IqRequest> request_;
107 int interval_ms_; 103 int interval_ms_;
104 base::RepeatingTimer<HeartbeatSender> timer_;
108 105
109 DISALLOW_COPY_AND_ASSIGN(HeartbeatSender); 106 DISALLOW_COPY_AND_ASSIGN(HeartbeatSender);
110 }; 107 };
111 108
112 } // namespace remoting 109 } // namespace remoting
113 110
114 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_ 111 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698