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

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: Minor tweaks after end-to-end tests and self-review. Created 6 years, 1 month 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"
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> {
Lambros 2014/11/19 02:29:42 Do we need ref-counting here? Will this have multi
Łukasz Anforowicz 2014/11/19 21:44:24 There are 2 owners: 1) HostProcess 2) AckOrTimeout
47 public:
48 static scoped_refptr<MinimumHeartbeatSupporter> Create(
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,
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();
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_;
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698