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

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

Issue 9004050: Move signaling connection creation out of ChromotingHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 8 years, 11 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" 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 29 matching lines...) Expand all
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 //
66 // TODO(sergeyu): Is it enough to sign JID and nothing else? 66 // TODO(sergeyu): Is it enough to sign JID and nothing else?
Wez 2012/01/03 16:25:04 nit: Consider creating a bug for this, or removing
Sergey Ulanov 2012/01/03 21:51:02 Just removed it.
67 class HeartbeatSender : public HostStatusObserver { 67 class HeartbeatSender : public SignalStrategy::Listener {
68 public: 68 public:
69 HeartbeatSender(base::MessageLoopProxy* main_loop, 69 HeartbeatSender();
70 MutableHostConfig* config);
71 virtual ~HeartbeatSender(); 70 virtual ~HeartbeatSender();
72 71
73 // Initializes heart-beating for |jingle_client_| with |config_|. Returns 72 // Initializes heartbeating. Returns false if the |config| is
Wez 2012/01/03 16:25:04 nit: Initializes the HeartbeatSender. Heartbeats
Sergey Ulanov 2012/01/03 21:51:02 Done.
74 // false if the config is invalid (e.g. private key cannot be parsed). 73 // invalid (e.g. private key cannot be parsed). SignalStrategy must
75 bool Init(); 74 // outlive this object.
Wez 2012/01/03 16:25:04 HeartbeatSender must now be initialized and delete
Sergey Ulanov 2012/01/03 21:51:02 Not yet in this CL - they are still initialized on
75 bool Init(SignalStrategy* signal_strategy, MutableHostConfig* config);
76 76
77 // HostStatusObserver implementation. 77 // SignalStrategy::Listener interface.
78 virtual void OnSignallingConnected(SignalStrategy* signal_strategy) OVERRIDE; 78 virtual void OnSignalStrategyStateChange(
79 virtual void OnSignallingDisconnected() OVERRIDE; 79 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 80
85 private: 81 private:
86 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, DoSendStanza); 82 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, DoSendStanza);
87 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, CreateHeartbeatMessage); 83 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, CreateHeartbeatMessage);
88 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, ProcessResponse); 84 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, ProcessResponse);
89 85
90 enum State { 86 enum State {
91 CREATED, 87 CREATED,
92 INITIALIZED, 88 INITIALIZED,
93 STARTED, 89 STARTED,
94 STOPPED, 90 STOPPED,
95 }; 91 };
96 92
97 void DoSendStanza(); 93 void DoSendStanza();
98 void ProcessResponse(const buzz::XmlElement* response); 94 void ProcessResponse(const buzz::XmlElement* response);
99 void SetInterval(int interval); 95 void SetInterval(int interval);
100 96
101 // Helper methods used by DoSendStanza() to generate heartbeat stanzas. 97 // Helper methods used by DoSendStanza() to generate heartbeat stanzas.
102 // Caller owns the result. 98 // Caller owns the result.
103 buzz::XmlElement* CreateHeartbeatMessage(); 99 buzz::XmlElement* CreateHeartbeatMessage();
104 buzz::XmlElement* CreateSignature(); 100 buzz::XmlElement* CreateSignature();
105 101
106 State state_; 102 State state_;
107 scoped_refptr<base::MessageLoopProxy> message_loop_; 103 SignalStrategy* signal_strategy_;
108 scoped_refptr<MutableHostConfig> config_;
109 std::string host_id_; 104 std::string host_id_;
110 HostKeyPair key_pair_; 105 HostKeyPair key_pair_;
111 std::string full_jid_;
112 scoped_ptr<IqSender> iq_sender_; 106 scoped_ptr<IqSender> iq_sender_;
113 scoped_ptr<IqRequest> request_; 107 scoped_ptr<IqRequest> request_;
114 int interval_ms_; 108 int interval_ms_;
115 base::RepeatingTimer<HeartbeatSender> timer_; 109 base::RepeatingTimer<HeartbeatSender> timer_;
116 110
117 DISALLOW_COPY_AND_ASSIGN(HeartbeatSender); 111 DISALLOW_COPY_AND_ASSIGN(HeartbeatSender);
118 }; 112 };
119 113
120 } // namespace remoting 114 } // namespace remoting
121 115
122 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_ 116 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698