1 // Copyright 2014 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_HOST_SIGNALING_MANAGER_H_
6 #define REMOTING_HOST_HOST_SIGNALING_MANAGER_H_
10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/threading/thread_checker.h"
13 #include "remoting/base/rsa_key_pair.h"
14 #include "remoting/host/oauth_token_getter.h"
15 #include "remoting/signaling/xmpp_signal_strategy.h"
23 class HeartbeatSender
;
24 class OAuthTokenGetter
;
26 class SignalingConnector
;
28 // HostSignalingManager manages objects needed for sending regular heartbeats to
29 // the Chromoting Directory.
30 class HostSignalingManager
{
34 virtual ~Listener() {}
36 // Invoked after the first successful heartbeat.
37 virtual void OnHeartbeatSuccessful() = 0;
39 // Invoked when the host ID is permanently not recognized by the server.
40 virtual void OnUnknownHostIdError() = 0;
42 // Invoked when authentication fails.
43 virtual void OnAuthFailed() = 0;
46 // TODO(lukasza): Refactor to limit the number of parameters below.
47 // Probably necessitates refactoring HostProcess to extract a new
48 // class to read and store config/policy/cmdline values.
50 // |listener| has to be valid until the returned HostSignalingManager is
52 static scoped_ptr
<HostSignalingManager
> Create(
54 const scoped_refptr
<net::URLRequestContextGetter
>&
55 url_request_context_getter
,
56 const XmppSignalStrategy::XmppServerConfig
& xmpp_server_config
,
57 const std::string
& talkgadget_prefix_policy
,
58 const std::string
& host_id
,
59 const scoped_refptr
<const RsaKeyPair
>& host_key_pair
,
60 const std::string
& directory_bot_jid
,
61 scoped_ptr
<OAuthTokenGetter::OAuthCredentials
> oauth_credentials
);
63 ~HostSignalingManager();
65 // Get the SignalStrategy to use for talking to the Chromoting bot.
66 // Returned SignalStrategy remains owned by the HostSignalingManager.
67 SignalStrategy
* signal_strategy() { return signal_strategy_
.get(); }
69 // Kicks off sending a heartbeat containing a host-offline-reason attribute.
70 // Will call |ack_callback| once either the bot acks receiving the
71 // |host_offline_reason|, or the |timeout| is reached.
73 // For discussion of allowed values for |host_offline_reason| argument,
74 // please see the description of rem:host-offline-reason xml attribute in
75 // the class-level comments for HeartbeatReasonSender.
76 void SendHostOfflineReason(
77 const std::string
& host_offline_reason
,
78 const base::TimeDelta
& timeout
,
79 const base::Callback
<void(bool success
)>& ack_callback
);
83 scoped_ptr
<SignalStrategy
> signal_strategy
,
84 scoped_ptr
<SignalingConnector
> signaling_connector
,
85 scoped_ptr
<HeartbeatSender
> heartbeat_sender
);
87 // |heartbeat_sender_| and |signaling_connector_| have to be destroyed before
88 // |signal_strategy_| because their destructors need to call
89 // signal_strategy_->RemoveListener(this)
90 scoped_ptr
<SignalStrategy
> signal_strategy_
;
91 scoped_ptr
<SignalingConnector
> signaling_connector_
;
92 scoped_ptr
<HeartbeatSender
> heartbeat_sender_
;
94 // Used to verify thread-safe usage.
95 base::ThreadChecker thread_checker_
;
97 DISALLOW_COPY_AND_ASSIGN(HostSignalingManager
);
100 } // namespace remoting
102 #endif // REMOTING_HOST_HOST_SIGNALING_MANAGER_H_