Chromium Code Reviews| 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> { |
| + public: |
| + 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
|
| + 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, |
|
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
|
| + 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(); |
|
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.
|
| + |
| + // 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_; |
|
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,
|
| + 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_ |