OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #ifndef REMOTING_HOST_HOST_SIGNALING_MANAGER_H_ | |
6 #define REMOTING_HOST_HOST_SIGNALING_MANAGER_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "remoting/base/auto_thread_task_runner.h" | |
13 #include "remoting/base/rsa_key_pair.h" | |
14 #include "remoting/host/heartbeat_sender.h" | |
15 #include "remoting/signaling/xmpp_signal_strategy.h" | |
16 | |
17 namespace base { | |
18 class TimeDelta; | |
19 } | |
20 | |
21 namespace net { | |
22 class NetworkChangeNotifier; | |
23 } | |
24 | |
25 namespace remoting { | |
26 | |
27 class ChromotingHostContext; | |
28 class DnsBlackholeChecker; | |
29 class HeartbeatSender; | |
30 class OAuthTokenGetter; | |
31 class SignalStrategy; | |
32 class SignalingConnector; | |
33 | |
34 // HostSignalingManager has 2 functions: | |
35 // 1. Keep sending regular heartbeats to the service. | |
36 // 2. Keep the host process alive while sending host-offline-reason heartbeat. | |
37 class HostSignalingManager { | |
38 public: | |
39 // TODO(lukasza): Refactor to limit the number of parameters below. | |
40 // Probably necessitates refactoring HostProcess to extract a new | |
41 // class to read and store config/policy/cmdline values. | |
42 static scoped_ptr<HostSignalingManager> Create( | |
43 // Invoked after the first successful heartbeat. | |
44 const base::Closure& on_heartbeat_successful_callback, | |
45 | |
46 // Invoked when the host ID is permanently not recognized by the server. | |
47 const base::Closure& on_unknown_host_id_error_callback, | |
48 | |
49 // Invoked when authentication fails. | |
50 const base::Closure& on_auth_failed_callback, | |
51 | |
52 const ChromotingHostContext& host_context, | |
53 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, | |
54 const std::string& talkgadget_prefix_policy, | |
55 const std::string& host_id, | |
56 const scoped_refptr<const RsaKeyPair>& host_key_pair, | |
57 | |
58 // Directory Bot's JID - i.e. "remoting@bot.talk.google.com". | |
59 const std::string& directory_bot_jid, | |
60 | |
61 const std::string& oauth_refresh_token, | |
62 | |
63 // Controls which API key gets used. | |
64 bool use_service_account); | |
65 | |
66 ~HostSignalingManager(); | |
Wez
2014/12/19 22:05:37
What is the behaviour of this class wrt the offlin
Łukasz Anforowicz
2015/01/07 01:24:04
The HostSignalingManager gets deleted (without a c
| |
67 | |
68 // Get the SignalStrategy to use for talking to the Chromoting bot. | |
69 // Returned SignalStrategy remains owned by the HostSignalingManager. | |
70 SignalStrategy* signal_strategy() { return signal_strategy_.get(); } | |
71 | |
72 // Kicks off sending a heartbeat containing a host-offline-reason attribute. | |
73 // | |
74 // Will delete |this| once either the bot acks receiving the | |
75 // |host_offline_reason|, or the |timeout| is reached. Deleting | |
76 // |this| will release |network_task_runner_| and allow the host | |
77 // process to exit. | |
78 void SendHostOfflineReasonAndDelete(const std::string& host_offline_reason, | |
79 const base::TimeDelta& timeout); | |
80 | |
81 private: | |
82 HostSignalingManager( | |
83 scoped_refptr<AutoThreadTaskRunner> network_task_runner, | |
84 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier, | |
85 scoped_ptr<SignalStrategy> signal_strategy, | |
86 scoped_ptr<SignalingConnector> signaling_connector, | |
87 scoped_ptr<HeartbeatSender> heartbeat_sender); | |
88 | |
89 void OnHostOfflineReasonAck(bool success); | |
90 | |
91 // Order of fields below is important for destroying them in the right order. | |
92 // - |heartbeat_sender_| and |signaling_connector_| have to be destroyed | |
93 // before |signal_strategy_| because their destructors need to call | |
94 // signal_strategy_->RemoveListener(this) | |
95 // - |signaling_connector_| has to be destroyed before | |
96 // |network_change_notifier_| because its destructor needs to deregister | |
97 // network change notifications | |
98 // - |network_task_runner_| keeps the process alive and is therefore | |
99 // used by all the other fields and has to be destroyed last. | |
100 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; | |
101 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | |
102 scoped_ptr<SignalStrategy> signal_strategy_; | |
103 scoped_ptr<SignalingConnector> signaling_connector_; | |
104 scoped_ptr<HeartbeatSender> heartbeat_sender_; | |
105 | |
106 DISALLOW_COPY_AND_ASSIGN(HostSignalingManager); | |
107 }; | |
108 | |
109 } // namespace remoting | |
110 | |
111 #endif // REMOTING_HOST_HOST_SIGNALING_MANAGER_H_ | |
OLD | NEW |