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_MINIMUM_HEARTBEAT_SUPPORTER_H_ | |
6 #define REMOTING_HOST_MINIMUM_HEARTBEAT_SUPPORTER_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "remoting/base/auto_thread_task_runner.h" | |
14 #include "remoting/base/rsa_key_pair.h" | |
15 #include "remoting/host/ack_or_timeout_reporter.h" | |
16 #include "remoting/signaling/xmpp_signal_strategy.h" | |
17 | |
18 namespace base { | |
19 class TimeDelta; | |
20 } | |
21 | |
22 namespace net { | |
23 class NetworkChangeNotifier; | |
24 } | |
25 | |
26 namespace remoting { | |
27 | |
28 class ChromotingHostContext; | |
29 class DnsBlackholeChecker; | |
30 class HeartbeatSender; | |
31 class OAuthTokenGetter; | |
32 class SignalStrategy; | |
33 class SignalingConnector; | |
34 | |
35 // MinimumHeartbeatSupporter has 2 functions: | |
36 // 1. Keep sending regulard heartbeats to the service. | |
Lambros
2014/12/06 01:25:05
nit: regular
Łukasz Anforowicz
2014/12/09 18:47:07
Done.
| |
37 // 2. Keep the host process alive while sending host-offline-reason heartbeat. | |
Wez
2014/12/09 00:51:58
Would it be cleaner to leave HostProcess in charge
Łukasz Anforowicz
2014/12/09 18:47:07
I like the fact that MinimumHeartbeatSupporter has
| |
38 class MinimumHeartbeatSupporter | |
Wez
2014/12/09 00:51:58
This seems a not-very-helpful name - it's not clea
Łukasz Anforowicz
2014/12/09 18:47:07
What name would you suggest?
RE: the difference f
| |
39 : public base::RefCounted<MinimumHeartbeatSupporter> { | |
Wez
2014/12/09 00:51:58
Noooo! Does this really need to be ref-counted?
Łukasz Anforowicz
2014/12/09 18:47:07
It is kept alive by 1) HostProcess (wants to keep
| |
40 public: | |
41 // TODO(lukasza): Refactor to limit the number of parameters below. | |
42 // Probably necessitates refactoring HostProcess to extract a new | |
43 // class to read and store config/policy/cmdline values. | |
Wez
2014/12/09 00:51:58
We store config in a dictionary; we specifically r
Łukasz Anforowicz
2014/12/09 18:47:07
Acknowledged. OTOH, I thought more about strongly
| |
44 static scoped_refptr<MinimumHeartbeatSupporter> Create( | |
45 const base::Closure& on_heartbeat_successful_callback, | |
46 const base::Closure& on_unknown_host_id_error_callback, | |
47 const base::Closure& on_auth_failed_callback, | |
48 const ChromotingHostContext& host_context, | |
49 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, | |
50 const std::string& talkgadget_prefix, | |
51 const std::string& host_id, | |
52 const scoped_refptr<const RsaKeyPair>& key_pair, | |
53 const std::string& directory_bot_jid, | |
54 const std::string& oauth_refresh_token, | |
55 bool use_service_account); | |
56 | |
57 // Gets signal strategy used for talking to the Chromoting bot. | |
58 // Return value is valid until |this| gets deleted. | |
59 SignalStrategy* signal_strategy() { return signal_strategy_.get(); } | |
60 | |
61 // Kicks off sending a heartbeat containing a host-offline-reason attribute. | |
62 // | |
63 // Ensures that |this| (and transitively the whole process) is kept alive | |
64 // while waiting for an ack from the bot (this is subject to |timeout|). | |
65 void SendHostOfflineReason(const std::string& host_offline_reason, | |
66 const base::TimeDelta& timeout); | |
67 | |
68 private: | |
69 // Ref-counting helpers. | |
70 friend class base::RefCounted<MinimumHeartbeatSupporter>; | |
71 ~MinimumHeartbeatSupporter(); | |
72 | |
73 MinimumHeartbeatSupporter( | |
74 scoped_refptr<AutoThreadTaskRunner> network_task_runner, | |
75 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier, | |
76 scoped_ptr<XmppSignalStrategy> signal_strategy, | |
77 scoped_ptr<SignalingConnector> signaling_connector, | |
78 scoped_ptr<HeartbeatSender> heartbeat_sender); | |
79 | |
80 void OnAckOrTimeout(AckOrTimeout ack_or_timeout); | |
81 | |
82 // Order of fields below is important for destructing them in the right order. | |
83 // - |heartbeat_sender_| and |signaling_connector_| have to be destructed | |
84 // before |signal_strategy_| because their destructors need to call | |
85 // signal_strategy_->RemoveListener(this) | |
86 // - |signaling_connector_| has to be destructed before | |
87 // |network_change_notifier_| because its destructor needs to deregister | |
88 // network change notifications | |
89 // - |network_task_runner_| is used by all the other fields and has to be | |
90 // destructed last. | |
91 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; | |
92 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | |
93 scoped_ptr<XmppSignalStrategy> signal_strategy_; | |
94 scoped_ptr<SignalingConnector> signaling_connector_; | |
95 scoped_ptr<HeartbeatSender> heartbeat_sender_; | |
96 | |
97 DISALLOW_COPY_AND_ASSIGN(MinimumHeartbeatSupporter); | |
98 }; | |
99 | |
100 } // namespace remoting | |
101 | |
102 #endif // REMOTING_HOST_MINIMUM_HEARTBEAT_SUPPORTER_H_ | |
OLD | NEW |