OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_GCD_STATE_UPDATER_H_ | 5 #ifndef REMOTING_HOST_GCD_STATE_UPDATER_H_ |
6 #define REMOTING_HOST_GCD_STATE_UPDATER_H_ | 6 #define REMOTING_HOST_GCD_STATE_UPDATER_H_ |
7 | 7 |
| 8 #include <memory> |
8 #include <string> | 9 #include <string> |
9 | 10 |
10 #include "base/callback.h" | 11 #include "base/callback.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
14 #include "remoting/host/backoff_timer.h" | 14 #include "remoting/host/backoff_timer.h" |
15 #include "remoting/host/gcd_rest_client.h" | 15 #include "remoting/host/gcd_rest_client.h" |
16 #include "remoting/signaling/signal_strategy.h" | 16 #include "remoting/signaling/signal_strategy.h" |
17 | 17 |
18 namespace base { | 18 namespace base { |
19 class TimeDelta; | 19 class TimeDelta; |
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 { |
27 | 27 |
28 // An object that uses GcdRestClient to send status updates to GCD | 28 // An object that uses GcdRestClient to send status updates to GCD |
29 // when the XMPP connection state changes. | 29 // when the XMPP connection state changes. |
30 class GcdStateUpdater : public SignalStrategy::Listener { | 30 class GcdStateUpdater : public SignalStrategy::Listener { |
31 public: | 31 public: |
32 // |signal_strategy| must outlive this object. Updates will start | 32 // |signal_strategy| must outlive this object. Updates will start |
33 // when the supplied SignalStrategy enters the CONNECTED state. | 33 // when the supplied SignalStrategy enters the CONNECTED state. |
34 // | 34 // |
35 // |on_update_successful_callback| is invoked after the first successful | 35 // |on_update_successful_callback| is invoked after the first successful |
36 // update. | 36 // update. |
37 GcdStateUpdater(const base::Closure& on_update_successful_callback, | 37 GcdStateUpdater(const base::Closure& on_update_successful_callback, |
38 const base::Closure& on_unknown_host_id_error, | 38 const base::Closure& on_unknown_host_id_error, |
39 SignalStrategy* signal_strategy, | 39 SignalStrategy* signal_strategy, |
40 scoped_ptr<GcdRestClient> gcd_client); | 40 std::unique_ptr<GcdRestClient> gcd_client); |
41 ~GcdStateUpdater() override; | 41 ~GcdStateUpdater() override; |
42 | 42 |
43 // See HeartbeatSender::SetHostOfflineReason. | 43 // See HeartbeatSender::SetHostOfflineReason. |
44 void SetHostOfflineReason( | 44 void SetHostOfflineReason( |
45 const std::string& host_offline_reason, | 45 const std::string& host_offline_reason, |
46 const base::TimeDelta& timeout, | 46 const base::TimeDelta& timeout, |
47 const base::Callback<void(bool success)>& ack_callback); | 47 const base::Callback<void(bool success)>& ack_callback); |
48 | 48 |
49 private: | 49 private: |
50 // SignalStrategy::Listener interface. | 50 // SignalStrategy::Listener interface. |
51 void OnSignalStrategyStateChange(SignalStrategy::State state) override; | 51 void OnSignalStrategyStateChange(SignalStrategy::State state) override; |
52 bool OnSignalStrategyIncomingStanza(const buzz::XmlElement* stanza) override; | 52 bool OnSignalStrategyIncomingStanza(const buzz::XmlElement* stanza) override; |
53 | 53 |
54 void OnPatchStateResult(GcdRestClient::Result result); | 54 void OnPatchStateResult(GcdRestClient::Result result); |
55 void MaybeSendStateUpdate(); | 55 void MaybeSendStateUpdate(); |
56 | 56 |
57 base::Closure on_update_successful_callback_; | 57 base::Closure on_update_successful_callback_; |
58 base::Closure on_unknown_host_id_error_; | 58 base::Closure on_unknown_host_id_error_; |
59 SignalStrategy* signal_strategy_; | 59 SignalStrategy* signal_strategy_; |
60 scoped_ptr<GcdRestClient> gcd_rest_client_; | 60 std::unique_ptr<GcdRestClient> gcd_rest_client_; |
61 BackoffTimer timer_; | 61 BackoffTimer timer_; |
62 base::ThreadChecker thread_checker_; | 62 base::ThreadChecker thread_checker_; |
63 std::string pending_request_jid_; | 63 std::string pending_request_jid_; |
64 | 64 |
65 DISALLOW_COPY_AND_ASSIGN(GcdStateUpdater); | 65 DISALLOW_COPY_AND_ASSIGN(GcdStateUpdater); |
66 }; | 66 }; |
67 | 67 |
68 } // namespace remoting | 68 } // namespace remoting |
69 | 69 |
70 #endif // REMOTING_HOST_GCD_STATE_UPDATER_H_ | 70 #endif // REMOTING_HOST_GCD_STATE_UPDATER_H_ |
OLD | NEW |