Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_HOST_SIGNALING_MANAGER_H_ | |
| 6 #define REMOTING_HOST_HOST_SIGNALING_MANAGER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/callback.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "remoting/base/auto_thread_task_runner.h" | |
| 14 #include "remoting/base/rsa_key_pair.h" | |
| 15 #include "remoting/host/oauth_token_getter.h" | |
| 16 #include "remoting/signaling/xmpp_signal_strategy.h" | |
| 17 | |
| 18 namespace base { | |
| 19 class TimeDelta; | |
| 20 } | |
| 21 | |
| 22 namespace net { | |
| 23 class NetworkChangeNotifier; | |
| 24 } | |
| 25 | |
| 26 namespace remoting { | |
| 27 | |
| 28 class ChromotingHostContext; | |
| 29 class DnsBlackholeChecker; | |
| 30 class HeartbeatSender; | |
| 31 class OAuthTokenGetter; | |
| 32 class SignalStrategy; | |
| 33 class SignalingConnector; | |
| 34 | |
| 35 // HostSignalingManager has 2 functions: | |
| 36 // 1. Keep sending regular heartbeats to the Chromoting Directory. | |
| 37 // 2. Keep the host process alive while sending host-offline-reason heartbeat. | |
| 38 class HostSignalingManager { | |
| 39 public: | |
| 40 class Listener { | |
| 41 public: | |
| 42 virtual ~Listener() {} | |
| 43 | |
| 44 // Invoked after the first successful heartbeat. | |
| 45 virtual void OnHeartbeatSuccessful() = 0; | |
| 46 | |
| 47 // Invoked when the host ID is permanently not recognized by the server. | |
| 48 virtual void OnUnknownHostIdError() = 0; | |
| 49 | |
| 50 // Invoked when authentication fails. | |
| 51 virtual void OnAuthFailed() = 0; | |
| 52 }; | |
| 53 | |
| 54 // TODO(lukasza): Refactor to limit the number of parameters below. | |
| 55 // Probably necessitates refactoring HostProcess to extract a new | |
| 56 // class to read and store config/policy/cmdline values. | |
| 57 // | |
| 58 // |listener| has to be valid until either | |
| 59 // 1) the returned HostSignalingManager is destroyed | |
| 60 // or 2) SendHostOfflineReasonAndDelete is called. | |
| 61 static scoped_ptr<HostSignalingManager> Create( | |
| 62 Listener* listener, | |
| 63 const scoped_refptr<AutoThreadTaskRunner>& network_task_runner, | |
| 64 const scoped_refptr<net::URLRequestContextGetter>& | |
| 65 url_request_context_getter, | |
| 66 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, | |
| 67 const std::string& talkgadget_prefix_policy, | |
| 68 const std::string& host_id, | |
| 69 const scoped_refptr<const RsaKeyPair>& host_key_pair, | |
| 70 const std::string& directory_bot_jid, | |
| 71 scoped_ptr<OAuthTokenGetter::OAuthCredentials> oauth_credentials); | |
| 72 | |
| 73 ~HostSignalingManager(); | |
| 74 | |
| 75 // Get the SignalStrategy to use for talking to the Chromoting bot. | |
| 76 // Returned SignalStrategy remains owned by the HostSignalingManager. | |
| 77 SignalStrategy* signal_strategy() { return signal_strategy_.get(); } | |
| 78 | |
| 79 // Kicks off sending a heartbeat containing a host-offline-reason attribute. | |
| 80 // Prevents future calls to the |listener| provided to the Create method. | |
| 81 // | |
| 82 // Will delete |this| once either the bot acks receiving the | |
| 83 // |host_offline_reason|, or the |timeout| is reached. Deleting | |
| 84 // |this| will release |network_task_runner_| and allow the host | |
| 85 // process to exit. | |
| 86 void SendHostOfflineReasonAndDelete(const std::string& host_offline_reason, | |
| 87 const base::TimeDelta& timeout); | |
| 88 | |
| 89 private: | |
| 90 HostSignalingManager( | |
| 91 scoped_ptr<base::WeakPtrFactory<Listener>> weak_factory_for_listener, | |
| 92 const scoped_refptr<AutoThreadTaskRunner>& network_task_runner, | |
| 93 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier, | |
| 94 scoped_ptr<SignalStrategy> signal_strategy, | |
| 95 scoped_ptr<SignalingConnector> signaling_connector, | |
| 96 scoped_ptr<HeartbeatSender> heartbeat_sender); | |
| 97 | |
| 98 void OnHostOfflineReasonAck(bool success); | |
| 99 | |
| 100 // Used to bind HeartbeatSender and SignalingConnector callbacks to |listener| | |
| 101 // in a way that allows "detaching" the |listener| when either |this| is | |
| 102 // destoyed or when SendHostOfflineReasonAndDelete method is called. | |
|
Wez
2015/01/10 01:43:32
typo: destroyed
| |
| 103 scoped_ptr<base::WeakPtrFactory<Listener>> weak_factory_for_listener_; | |
| 104 | |
| 105 // By holding a reference to |network_task_runner_|, HostSignalingManager is | |
| 106 // extending the lifetime of the host process. This is needed for the case | |
| 107 // where an instance of HostProcess has been already destroyed, but we want | |
|
Wez
2015/01/10 01:43:32
nit: already been
Łukasz Anforowicz
2015/01/12 18:05:14
Done. I actually had this written the other way a
| |
| 108 // to keep the process running while SendHostOfflineReasonAndDelete tries to | |
|
Wez
2015/01/10 01:43:32
nit: No need for the full method name; suggest "..
Łukasz Anforowicz
2015/01/12 18:05:14
Done.
| |
| 109 // establish a connection and send host-offline-reason. | |
| 110 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; | |
| 111 | |
| 112 // Order of fields below is important for destroying them in the right order. | |
| 113 // - |heartbeat_sender_| and |signaling_connector_| have to be destroyed | |
| 114 // before |signal_strategy_| because their destructors need to call | |
| 115 // signal_strategy_->RemoveListener(this) | |
| 116 // - |signaling_connector_| has to be destroyed before | |
| 117 // |network_change_notifier_| because its destructor needs to deregister | |
| 118 // network change notifications | |
| 119 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | |
| 120 scoped_ptr<SignalStrategy> signal_strategy_; | |
| 121 scoped_ptr<SignalingConnector> signaling_connector_; | |
| 122 scoped_ptr<HeartbeatSender> heartbeat_sender_; | |
| 123 | |
| 124 DISALLOW_COPY_AND_ASSIGN(HostSignalingManager); | |
| 125 }; | |
| 126 | |
| 127 } // namespace remoting | |
| 128 | |
| 129 #endif // REMOTING_HOST_HOST_SIGNALING_MANAGER_H_ | |
| OLD | NEW |