Chromium Code Reviews| Index: remoting/host/host_signaling_manager.h |
| diff --git a/remoting/host/host_signaling_manager.h b/remoting/host/host_signaling_manager.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..42160880654004b0c84636fb467902a88d4f9594 |
| --- /dev/null |
| +++ b/remoting/host/host_signaling_manager.h |
| @@ -0,0 +1,104 @@ |
| +// 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_HOST_SIGNALING_MANAGER_H_ |
| +#define REMOTING_HOST_HOST_SIGNALING_MANAGER_H_ |
| + |
| +#include <string> |
| + |
| +#include "base/callback.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "remoting/base/auto_thread_task_runner.h" |
| +#include "remoting/base/rsa_key_pair.h" |
| +#include "remoting/host/heartbeat_sender.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; |
| + |
| +// HostSignalingManager has 2 functions: |
| +// 1. Keep sending regular heartbeats to the service. |
| +// 2. Keep the host process alive while sending host-offline-reason heartbeat. |
| +class HostSignalingManager { |
|
Lambros
2014/12/16 02:14:05
Please update the CL description with the new clas
Łukasz Anforowicz
2014/12/17 18:02:04
Ooops. Done.
|
| + public: |
| + // TODO(lukasza): Refactor to limit the number of parameters below. |
| + // Probably necessitates refactoring HostProcess to extract a new |
| + // class to read and store config/policy/cmdline values. |
| + static scoped_ptr<HostSignalingManager> 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<const RsaKeyPair>& key_pair, |
| + const std::string& directory_bot_jid, |
| + const std::string& oauth_refresh_token, |
| + bool use_service_account); |
| + |
| + ~HostSignalingManager(); |
| + |
| + // Gets signal strategy used for talking to the Chromoting bot. |
| + // Return value is valid until |this| gets deleted. |
| + SignalStrategy* signal_strategy() { return signal_strategy_.get(); } |
| + |
| + // Kicks off sending a heartbeat containing a host-offline-reason attribute. |
| + // |
| + // Will delete |this| once either the bot acks receiving the |
| + // |host_offline_reason|, or the |timeout| is reached. Deleting |
| + // |this| will release |network_task_runner_| and allow the host |
| + // process to exit. |
| + void SendHostOfflineReasonAndDelete(const std::string& host_offline_reason, |
|
Lambros
2014/12/16 02:14:05
Won't you get double-deletion when the scoped_ptr
Łukasz Anforowicz
2014/12/17 18:02:04
The caller of Create takes ownership of the return
Lambros
2014/12/17 23:44:34
So the caller owns the object until it calls SendH
Łukasz Anforowicz
2014/12/18 00:03:41
I don't have a strong opinion here (with no recent
|
| + const base::TimeDelta& timeout); |
| + |
| + private: |
| + HostSignalingManager( |
| + scoped_refptr<AutoThreadTaskRunner> network_task_runner, |
| + scoped_ptr<net::NetworkChangeNotifier> network_change_notifier, |
| + scoped_ptr<SignalStrategy> signal_strategy, |
| + scoped_ptr<SignalingConnector> signaling_connector, |
| + scoped_ptr<HeartbeatSender> heartbeat_sender); |
| + |
| + void OnAckOrTimeout(HeartbeatSender::AckOrTimeout ack_or_timeout); |
| + |
| + // Order of fields below is important for destructing them in the right order. |
| + // - |heartbeat_sender_| and |signaling_connector_| have to be destructed |
| + // before |signal_strategy_| because their destructors need to call |
| + // signal_strategy_->RemoveListener(this) |
| + // - |signaling_connector_| has to be destructed before |
| + // |network_change_notifier_| because its destructor needs to deregister |
| + // network change notifications |
| + // - |network_task_runner_| is used by all the other fields and has to be |
| + // destructed last. |
| + scoped_refptr<AutoThreadTaskRunner> network_task_runner_; |
| + scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
| + scoped_ptr<SignalStrategy> signal_strategy_; |
| + scoped_ptr<SignalingConnector> signaling_connector_; |
| + scoped_ptr<HeartbeatSender> heartbeat_sender_; |
| + |
| + // HostSignalingManager object owns itself via |self_| field while |
| + // SendHostOfflineReasonAndDelete is waiting for an ack or timeout. |
| + HostSignalingManager* self_; |
|
Lambros
2014/12/16 02:14:05
There's no ref-counting, so you don't need this.
Łukasz Anforowicz
2014/12/17 18:02:04
I do. I am calling "delete self_" in OnAckOrTimeo
Lambros
2014/12/17 23:44:34
Couldn't you do "delete this;" instead?
Łukasz Anforowicz
2014/12/18 00:03:41
Done.
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(HostSignalingManager); |
| +}; |
| + |
| +} // namespace remoting |
| + |
| +#endif // REMOTING_HOST_HOST_SIGNALING_MANAGER_H_ |