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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: remoting/host/minimum_heartbeat_supporter.h
diff --git a/remoting/host/minimum_heartbeat_supporter.h b/remoting/host/minimum_heartbeat_supporter.h
new file mode 100644
index 0000000000000000000000000000000000000000..47d2a56571d4127ef933043c55abe2d3e9512f91
--- /dev/null
+++ b/remoting/host/minimum_heartbeat_supporter.h
@@ -0,0 +1,98 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef REMOTING_HOST_MINIMUM_HEARTBEAT_SUPPORTER_H_
+#define REMOTING_HOST_MINIMUM_HEARTBEAT_SUPPORTER_H_
+
+#include <string>
+
+#include "base/callback.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/time/time.h"
+#include "remoting/base/auto_thread_task_runner.h"
+#include "remoting/base/rsa_key_pair.h"
+#include "remoting/host/ack_or_timeout_reporter.h"
+#include "remoting/signaling/xmpp_signal_strategy.h"
+
+namespace base {
+ class TimeDelta;
+}
+
+namespace net {
+ class NetworkChangeNotifier;
+}
+
+namespace remoting {
+
+class ChromotingHostContext;
+class DnsBlackholeChecker;
+class HeartbeatSender;
+class OAuthTokenGetter;
+class SignalStrategy;
+class SignalingConnector;
+
+// Keeping an instance of MinimumHeartbeatSupporter alive
+// ensures that we keep trying to send heartbeats (which among other
+// things means that it ensures that we don't exit the host process).
+//
+// Primary scenario where this class is useful is extending host process
+// lifetime after |SendHostOfflineReason| is called.
+//
+// Secondary benefit of this class is hiding/encapsulating heartbeat
+// and xmpp related things inside.
+class MinimumHeartbeatSupporter
+ : 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
+ public:
+ static scoped_refptr<MinimumHeartbeatSupporter> Create(
+ const base::Closure& on_heartbeat_successful_callback,
+ const base::Closure& on_unknown_host_id_error_callback,
+ const base::Closure& on_auth_failed_callback,
+ const ChromotingHostContext& host_context,
+ const XmppSignalStrategy::XmppServerConfig& xmpp_server_config,
+ const std::string& talkgadget_prefix,
+ const std::string& host_id,
+ const scoped_refptr<RsaKeyPair> key_pair,
+ const std::string& directory_bot_jid,
+ const std::string& oauth_refresh_token,
+ bool use_service_account);
+
+ // Gets signal strategy used for talking to the Chromoting bot.
+ // Return value is valid until |this| gets deleted.
+ SignalStrategy* GetSignalStrategy();
+
+ // Kicks off sending a heartbeat containing a host-offline-reason attribute.
+ //
+ // Ensures that |this| (and transitively the whole process) is kept alive
+ // while waiting for an ack from the bot (this is subject to |timeout|).
+ void SendHostOfflineReason(
+ const std::string& host_offline_reason,
+ const base::TimeDelta& timeout);
+
+ private:
+ // Ref-counting helpers.
+ friend class base::RefCounted<MinimumHeartbeatSupporter>;
+ ~MinimumHeartbeatSupporter();
+
+ MinimumHeartbeatSupporter(
+ scoped_refptr<AutoThreadTaskRunner> network_task_runner,
+ scoped_ptr<net::NetworkChangeNotifier> network_change_notifier,
+ scoped_ptr<XmppSignalStrategy> signal_strategy,
+ scoped_ptr<SignalingConnector> signaling_connector,
+ scoped_ptr<HeartbeatSender> heartbeat_sender);
+
+ void OnAckOrTimeout(AckOrTimeout ack_or_timeout);
+
+ scoped_refptr<AutoThreadTaskRunner> network_task_runner_;
+ scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
+ scoped_ptr<XmppSignalStrategy> signal_strategy_;
+ scoped_ptr<SignalingConnector> signaling_connector_;
+ scoped_ptr<HeartbeatSender> heartbeat_sender_;
+
+ DISALLOW_COPY_AND_ASSIGN(MinimumHeartbeatSupporter);
+};
+
+} // namespace remoting
+
+#endif // REMOTING_HOST_MINIMUM_HEARTBEAT_SUPPORTER_H_

Powered by Google App Engine
This is Rietveld 408576698