Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(385)

Side by Side Diff: remoting/host/minimum_heartbeat_supporter.h

Issue 719983002: Reporting of policy errors via host-offline-reason: part 3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hor-nohoststatussender
Patch Set: Trying to see how things look without mock_callback.h Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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"
Lambros 2014/12/05 22:19:48 Don't need time.h ?
Łukasz Anforowicz 2014/12/05 23:59:28 Done.
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
Lambros 2014/12/05 22:19:48 "among other things"? Remove this, or say what tho
Łukasz Anforowicz 2014/12/05 23:59:28 The comment was not trying to explain the purpose
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 // TODO(lukasza): Refactor to limit the number of parameters below.
49 // Probably necessitates refactoring HostProcess to extract a new
50 // class to read and store config/policy/cmdline values.
51 static scoped_refptr<MinimumHeartbeatSupporter> Create(
52 const base::Closure& on_heartbeat_successful_callback,
53 const base::Closure& on_unknown_host_id_error_callback,
54 const base::Closure& on_auth_failed_callback,
55 const ChromotingHostContext& host_context,
56 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config,
57 const std::string& talkgadget_prefix,
58 const std::string& host_id,
59 const scoped_refptr<const RsaKeyPair>& key_pair,
60 const std::string& directory_bot_jid,
61 const std::string& oauth_refresh_token,
62 bool use_service_account);
63
64 // Gets signal strategy used for talking to the Chromoting bot.
65 // Return value is valid until |this| gets deleted.
66 SignalStrategy* signal_strategy() { return signal_strategy_.get(); }
67
68 // Kicks off sending a heartbeat containing a host-offline-reason attribute.
69 //
70 // Ensures that |this| (and transitively the whole process) is kept alive
71 // while waiting for an ack from the bot (this is subject to |timeout|).
72 void SendHostOfflineReason(const std::string& host_offline_reason,
73 const base::TimeDelta& timeout);
74
75 private:
76 // Ref-counting helpers.
77 friend class base::RefCounted<MinimumHeartbeatSupporter>;
78 ~MinimumHeartbeatSupporter();
79
80 MinimumHeartbeatSupporter(
81 scoped_refptr<AutoThreadTaskRunner> network_task_runner,
82 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier,
83 scoped_ptr<XmppSignalStrategy> signal_strategy,
84 scoped_ptr<SignalingConnector> signaling_connector,
85 scoped_ptr<HeartbeatSender> heartbeat_sender);
86
87 void OnAckOrTimeout(AckOrTimeout ack_or_timeout);
88
89 // Order fields below is important for destructing them in the right oder.
Lambros 2014/12/05 22:19:48 nit: Order of the fields ...
Łukasz Anforowicz 2014/12/05 23:59:28 Done.
90 // - |heartbeat_sender_| and |signaling_connector_| have to be destructed
91 // before |signal_strategy_| because their destructors need to call
92 // signal_strategy_->RemoveListener(this)
93 // - |signaling_connector_| has to be destructed before
94 // |network_change_notifier_| because its destructor needs to deregister
95 // network change notifications
96 // - |network_task_runner_| is used by all the other fields and has to be
Lambros 2014/12/05 22:19:48 |network_task_runner_| is ref-counted, so it doesn
Łukasz Anforowicz 2014/12/05 23:59:28 The other objects don't hold a reference to networ
Lambros 2014/12/06 01:25:05 Hmm, that doesn't feel right, but I can see why yo
97 // destructed last.
98 scoped_refptr<AutoThreadTaskRunner> network_task_runner_;
99 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
100 scoped_ptr<XmppSignalStrategy> signal_strategy_;
101 scoped_ptr<SignalingConnector> signaling_connector_;
102 scoped_ptr<HeartbeatSender> heartbeat_sender_;
103
104 DISALLOW_COPY_AND_ASSIGN(MinimumHeartbeatSupporter);
105 };
106
107 } // namespace remoting
108
109 #endif // REMOTING_HOST_MINIMUM_HEARTBEAT_SUPPORTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698