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
3 // found in the LICENSE file.
5 #ifndef REMOTING_HOST_GCD_STATE_UPDATER_H_
6 #define REMOTING_HOST_GCD_STATE_UPDATER_H_
10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/threading/thread_checker.h"
13 #include "remoting/host/backoff_timer.h"
14 #include "remoting/host/gcd_rest_client.h"
15 #include "remoting/signaling/signal_strategy.h"
27 // An object that uses GcdRestClient to send status updates to GCD
28 // when the XMPP connection state changes.
29 class GcdStateUpdater
: public SignalStrategy::Listener
{
31 // |signal_strategy| must outlive this object. Updates will start
32 // when the supplied SignalStrategy enters the CONNECTED state.
34 // |on_update_successful_callback| is invoked after the first successful
36 GcdStateUpdater(const base::Closure
& on_update_successful_callback
,
37 const base::Closure
& on_unknown_host_id_error
,
38 SignalStrategy
* signal_strategy
,
39 scoped_ptr
<GcdRestClient
> gcd_client
);
40 ~GcdStateUpdater() override
;
42 // See HeartbeatSender::SetHostOfflineReason.
43 void SetHostOfflineReason(
44 const std::string
& host_offline_reason
,
45 const base::TimeDelta
& timeout
,
46 const base::Callback
<void(bool success
)>& ack_callback
);
49 // SignalStrategy::Listener interface.
50 void OnSignalStrategyStateChange(SignalStrategy::State state
) override
;
51 bool OnSignalStrategyIncomingStanza(const buzz::XmlElement
* stanza
) override
;
53 void OnPatchStateStatus(GcdRestClient::Status status
);
54 void MaybeSendStateUpdate();
56 base::Closure on_update_successful_callback_
;
57 base::Closure on_unknown_host_id_error_
;
58 SignalStrategy
* signal_strategy_
;
59 scoped_ptr
<GcdRestClient
> gcd_rest_client_
;
61 base::ThreadChecker thread_checker_
;
62 bool has_pending_state_request_
= false;
63 std::string pending_request_jid_
;
65 DISALLOW_COPY_AND_ASSIGN(GcdStateUpdater
);
68 } // namespace remoting
70 #endif // REMOTING_HOST_GCD_STATE_UPDATER_H_