Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| 11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
| 12 #include "remoting/jingle_glue/iq_request.h" | 12 #include "remoting/jingle_glue/iq_request.h" |
| 13 #include "testing/gtest/include/gtest/gtest_prod.h" | |
| 13 | 14 |
| 14 namespace remoting { | 15 namespace remoting { |
| 15 | 16 |
| 16 class IqRequest; | 17 class IqRequest; |
| 18 class HostKeyPair; | |
| 17 class JingleClient; | 19 class JingleClient; |
| 18 class MutableHostConfig; | 20 class MutableHostConfig; |
| 19 | 21 |
| 20 // HeartbeatSender periodically sends hertbeats to the chromoting bot. | 22 // HeartbeatSender periodically sends hertbeats to the chromoting bot. |
| 21 // TODO(sergeyu): Write unittest for this class. | 23 // TODO(sergeyu): Write unittest for this class. |
| 22 class HeartbeatSender : public base::RefCountedThreadSafe<HeartbeatSender> { | 24 class HeartbeatSender : public base::RefCountedThreadSafe<HeartbeatSender> { |
| 23 public: | 25 public: |
| 24 HeartbeatSender(); | 26 HeartbeatSender(); |
| 27 ~HeartbeatSender(); | |
| 25 | 28 |
| 26 // Starts heart-beating for |jingle_client|. | 29 // Initializes heart-beating for |jingle_client| with the specified |
| 27 void Start(MutableHostConfig* config, JingleClient* jingle_client); | 30 // config. Returns false if the config is invalid (e.g. private key |
| 31 // cannot be parsed), true otherwise. | |
|
awong
2010/08/02 19:53:49
Drop the ", true otherwise." It's implied.
Sergey Ulanov
2010/08/03 02:10:39
Done.
| |
| 32 bool Init(MutableHostConfig* config, JingleClient* jingle_client); | |
| 33 | |
| 34 // Starts heart-beating. Must be called after init | |
|
awong
2010/08/02 19:53:49
Period at end of sentence.
Sergey Ulanov
2010/08/03 02:10:39
Done.
| |
| 35 void Start(); | |
| 36 | |
| 37 // Stops heart-beating. Must be called before corresponding JingleClient | |
| 38 // is destroyed otherwise heartbeating would continue indefinitely and | |
| 39 // this object would never be destroyed. Heartbeating cannot be started | |
| 40 // After it has been stopped, new sender must be created instead. | |
|
awong
2010/08/02 19:53:49
What happens if you neglec to call Stop() before d
Sergey Ulanov
2010/08/03 02:10:39
Done.
| |
| 41 void Stop(); | |
| 28 | 42 |
| 29 private: | 43 private: |
| 44 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, DoSendStanza); | |
| 45 | |
| 46 enum State { | |
| 47 CREATED, | |
| 48 INITIALIZED, | |
| 49 STARTED, | |
| 50 STOPPED, | |
| 51 }; | |
| 52 | |
| 30 void DoStart(); | 53 void DoStart(); |
| 54 void DoStop(); | |
|
awong
2010/08/02 19:53:49
Been trying to switch us over to a different style
Sergey Ulanov
2010/08/03 02:10:39
Done.
| |
| 31 void DoSendStanza(); | 55 void DoSendStanza(); |
| 32 | 56 |
| 57 // Helper method used by DoSendStanza() to sign heartbeat stanzas. | |
| 58 buzz::XmlElement* CreateSignature(const std::string& jid); | |
|
awong
2010/08/02 19:53:49
Who owns the returned XmlElement?
Sergey Ulanov
2010/08/03 02:10:39
Caller. Added comments about it.
| |
| 59 | |
| 33 void ProcessResponse(const buzz::XmlElement* response); | 60 void ProcessResponse(const buzz::XmlElement* response); |
| 34 | 61 |
| 35 bool started_; | 62 State state_; |
| 36 scoped_refptr<MutableHostConfig> config_; | 63 scoped_refptr<MutableHostConfig> config_; |
| 37 JingleClient* jingle_client_; | 64 JingleClient* jingle_client_; |
| 38 scoped_ptr<IqRequest> request_; | 65 scoped_ptr<IqRequest> request_; |
| 39 std::string host_id_; | 66 std::string host_id_; |
| 67 scoped_refptr<HostKeyPair> key_pair_; | |
| 40 }; | 68 }; |
| 41 | 69 |
| 42 } // namespace remoting | 70 } // namespace remoting |
| 43 | 71 |
| 44 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_ | 72 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_ |
| OLD | NEW |