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 "base/time/time.h" | |
14 #include "remoting/base/auto_thread_task_runner.h" | |
15 #include "remoting/base/rsa_key_pair.h" | |
16 #include "remoting/host/ack_or_timeout_reporter.h" | |
17 #include "remoting/signaling/xmpp_signal_strategy.h" | |
18 | |
19 namespace base { | |
20 class TimeDelta; | |
21 } | |
22 | |
23 namespace net { | |
24 class NetworkChangeNotifier; | |
25 } | |
26 | |
27 namespace remoting { | |
28 | |
29 class ChromotingHostContext; | |
30 class DnsBlackholeChecker; | |
31 class HeartbeatSender; | |
32 class OAuthTokenGetter; | |
33 class SignalStrategy; | |
34 class SignalingConnector; | |
35 | |
36 // Keeping an instance of MinimumHeartbeatSupporter alive | |
37 // ensures that we keep trying to send heartbeats (which among other | |
38 // things means that it ensures that we don't exit the host process). | |
39 // | |
40 // Primary scenario where this class is useful is extending host process | |
41 // lifetime after |SendHostOfflineReason| is called. | |
42 // | |
43 // Secondary benefit of this class is hiding/encapsulating heartbeat | |
44 // and xmpp related things inside. | |
45 class MinimumHeartbeatSupporter | |
46 : public base::RefCounted<MinimumHeartbeatSupporter> { | |
47 public: | |
48 static scoped_refptr<MinimumHeartbeatSupporter> Create( | |
Lambros
2014/12/02 03:35:23
This feels like too many parameters to one method,
Łukasz Anforowicz
2014/12/02 20:08:01
Can you comment on the things below please?:
1. I
Lambros
2014/12/03 03:20:25
I think a TODO: is fine for now - I accept that re
| |
49 const base::Closure& on_heartbeat_successful_callback, | |
50 const base::Closure& on_unknown_host_id_error_callback, | |
51 const base::Closure& on_auth_failed_callback, | |
52 const ChromotingHostContext& host_context, | |
53 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, | |
54 const std::string& talkgadget_prefix, | |
55 const std::string& host_id, | |
56 const scoped_refptr<RsaKeyPair> key_pair, | |
Lambros
2014/12/02 03:35:23
It is strange to have 'const' with a pass-by-value
Łukasz Anforowicz
2014/12/02 20:08:01
Good catch - thanks. I blame it on:
1. My stupidi
Lambros
2014/12/03 03:20:24
Yes, I think scoped_refptr should be passed around
| |
57 const std::string& directory_bot_jid, | |
58 const std::string& oauth_refresh_token, | |
59 bool use_service_account); | |
60 | |
61 // Gets signal strategy used for talking to the Chromoting bot. | |
62 // Return value is valid until |this| gets deleted. | |
63 SignalStrategy* GetSignalStrategy(); | |
Lambros
2014/12/02 03:35:23
nit: This is a simple getter, so name it Unix-styl
Łukasz Anforowicz
2014/12/02 20:08:01
Done.
| |
64 | |
65 // Kicks off sending a heartbeat containing a host-offline-reason attribute. | |
66 // | |
67 // Ensures that |this| (and transitively the whole process) is kept alive | |
68 // while waiting for an ack from the bot (this is subject to |timeout|). | |
69 void SendHostOfflineReason( | |
70 const std::string& host_offline_reason, | |
71 const base::TimeDelta& timeout); | |
72 | |
73 private: | |
74 // Ref-counting helpers. | |
75 friend class base::RefCounted<MinimumHeartbeatSupporter>; | |
76 ~MinimumHeartbeatSupporter(); | |
77 | |
78 MinimumHeartbeatSupporter( | |
79 scoped_refptr<AutoThreadTaskRunner> network_task_runner, | |
80 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier, | |
81 scoped_ptr<XmppSignalStrategy> signal_strategy, | |
82 scoped_ptr<SignalingConnector> signaling_connector, | |
83 scoped_ptr<HeartbeatSender> heartbeat_sender); | |
84 | |
85 void OnAckOrTimeout(AckOrTimeout ack_or_timeout); | |
86 | |
87 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; | |
88 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | |
Lambros
2014/12/02 03:35:22
|network_change_notifier_| is never used in this c
Łukasz Anforowicz
2014/12/02 20:08:01
No - there is an implicit / magical / global depen
Lambros
2014/12/03 03:20:25
Fair enough :) I guess we had this problem before,
| |
89 scoped_ptr<XmppSignalStrategy> signal_strategy_; | |
90 scoped_ptr<SignalingConnector> signaling_connector_; | |
91 scoped_ptr<HeartbeatSender> heartbeat_sender_; | |
92 | |
93 DISALLOW_COPY_AND_ASSIGN(MinimumHeartbeatSupporter); | |
94 }; | |
95 | |
96 } // namespace remoting | |
97 | |
98 #endif // REMOTING_HOST_MINIMUM_HEARTBEAT_SUPPORTER_H_ | |
OLD | NEW |