Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef REMOTING_HOST_HOST_SIGNALING_MANAGER_H_ | 5 #ifndef REMOTING_HOST_HOST_SIGNALING_MANAGER_H_ |
| 6 #define REMOTING_HOST_HOST_SIGNALING_MANAGER_H_ | 6 #define REMOTING_HOST_HOST_SIGNALING_MANAGER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/threading/thread_checker.h" |
| 13 #include "remoting/base/auto_thread_task_runner.h" | |
| 14 #include "remoting/base/rsa_key_pair.h" | 13 #include "remoting/base/rsa_key_pair.h" |
| 15 #include "remoting/host/oauth_token_getter.h" | 14 #include "remoting/host/oauth_token_getter.h" |
| 16 #include "remoting/signaling/xmpp_signal_strategy.h" | 15 #include "remoting/signaling/xmpp_signal_strategy.h" |
| 17 | 16 |
| 18 namespace base { | 17 namespace base { |
| 19 class TimeDelta; | 18 class TimeDelta; |
| 20 } | 19 } |
| 21 | 20 |
| 22 namespace net { | |
| 23 class NetworkChangeNotifier; | |
| 24 } | |
| 25 | |
| 26 namespace remoting { | 21 namespace remoting { |
| 27 | 22 |
| 28 class ChromotingHostContext; | |
| 29 class DnsBlackholeChecker; | |
| 30 class HeartbeatSender; | 23 class HeartbeatSender; |
| 31 class OAuthTokenGetter; | 24 class OAuthTokenGetter; |
| 32 class SignalStrategy; | 25 class SignalStrategy; |
| 33 class SignalingConnector; | 26 class SignalingConnector; |
| 34 | 27 |
| 35 // HostSignalingManager has 2 functions: | 28 // HostSignalingManager manages objects needed for sending regular heartbeats to |
| 36 // 1. Keep sending regular heartbeats to the Chromoting Directory. | 29 // the Chromoting Directory. |
| 37 // 2. Keep the host process alive while sending host-offline-reason heartbeat. | |
| 38 class HostSignalingManager { | 30 class HostSignalingManager { |
| 39 public: | 31 public: |
| 40 class Listener { | 32 class Listener { |
| 41 public: | 33 public: |
| 42 virtual ~Listener() {} | 34 virtual ~Listener() {} |
| 43 | 35 |
| 44 // Invoked after the first successful heartbeat. | 36 // Invoked after the first successful heartbeat. |
| 45 virtual void OnHeartbeatSuccessful() = 0; | 37 virtual void OnHeartbeatSuccessful() = 0; |
| 46 | 38 |
| 47 // Invoked when the host ID is permanently not recognized by the server. | 39 // Invoked when the host ID is permanently not recognized by the server. |
| 48 virtual void OnUnknownHostIdError() = 0; | 40 virtual void OnUnknownHostIdError() = 0; |
| 49 | 41 |
| 50 // Invoked when authentication fails. | 42 // Invoked when authentication fails. |
| 51 virtual void OnAuthFailed() = 0; | 43 virtual void OnAuthFailed() = 0; |
| 52 }; | 44 }; |
| 53 | 45 |
| 54 // TODO(lukasza): Refactor to limit the number of parameters below. | 46 // TODO(lukasza): Refactor to limit the number of parameters below. |
| 55 // Probably necessitates refactoring HostProcess to extract a new | 47 // Probably necessitates refactoring HostProcess to extract a new |
| 56 // class to read and store config/policy/cmdline values. | 48 // class to read and store config/policy/cmdline values. |
| 57 // | 49 // |
| 58 // |listener| has to be valid until either | 50 // |listener| has to be valid until the returned HostSignalingManager is |
| 59 // 1) the returned HostSignalingManager is destroyed | 51 // destroyed |
|
Wez
2015/02/12 02:51:25
nit: Missing punctuation at end of line.
Łukasz Anforowicz
2015/02/12 18:08:01
Done.
| |
| 60 // or 2) SendHostOfflineReasonAndDelete is called. | |
| 61 static scoped_ptr<HostSignalingManager> Create( | 52 static scoped_ptr<HostSignalingManager> Create( |
| 62 Listener* listener, | 53 Listener* listener, |
| 63 const scoped_refptr<AutoThreadTaskRunner>& network_task_runner, | |
| 64 const scoped_refptr<net::URLRequestContextGetter>& | 54 const scoped_refptr<net::URLRequestContextGetter>& |
| 65 url_request_context_getter, | 55 url_request_context_getter, |
| 66 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, | 56 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, |
| 67 const std::string& talkgadget_prefix_policy, | 57 const std::string& talkgadget_prefix_policy, |
| 68 const std::string& host_id, | 58 const std::string& host_id, |
| 69 const scoped_refptr<const RsaKeyPair>& host_key_pair, | 59 const scoped_refptr<const RsaKeyPair>& host_key_pair, |
| 70 const std::string& directory_bot_jid, | 60 const std::string& directory_bot_jid, |
| 71 scoped_ptr<OAuthTokenGetter::OAuthCredentials> oauth_credentials); | 61 scoped_ptr<OAuthTokenGetter::OAuthCredentials> oauth_credentials); |
| 72 | 62 |
| 73 ~HostSignalingManager(); | 63 ~HostSignalingManager(); |
| 74 | 64 |
| 75 // Get the SignalStrategy to use for talking to the Chromoting bot. | 65 // Get the SignalStrategy to use for talking to the Chromoting bot. |
| 76 // Returned SignalStrategy remains owned by the HostSignalingManager. | 66 // Returned SignalStrategy remains owned by the HostSignalingManager. |
| 77 SignalStrategy* signal_strategy() { return signal_strategy_.get(); } | 67 SignalStrategy* signal_strategy() { return signal_strategy_.get(); } |
| 78 | 68 |
| 79 // Kicks off sending a heartbeat containing a host-offline-reason attribute. | 69 // Kicks off sending a heartbeat containing a host-offline-reason attribute. |
| 80 // Prevents future calls to the |listener| provided to the Create method. | 70 // Will call |ack_callback| once either the bot acks receiving the |
| 81 // | 71 // |host_offline_reason|, or the |timeout| is reached. |
| 82 // Will delete |this| once either the bot acks receiving the | 72 void SendHostOfflineReason( |
| 83 // |host_offline_reason|, or the |timeout| is reached. Deleting | 73 const std::string& host_offline_reason, |
| 84 // |this| will release |network_task_runner_| and allow the host | 74 const base::TimeDelta& timeout, |
| 85 // process to exit. | 75 const base::Callback<void(bool success)>& ack_callback); |
| 86 void SendHostOfflineReasonAndDelete(const std::string& host_offline_reason, | |
| 87 const base::TimeDelta& timeout); | |
| 88 | 76 |
| 89 private: | 77 private: |
| 90 HostSignalingManager( | 78 HostSignalingManager( |
| 91 scoped_ptr<base::WeakPtrFactory<Listener>> weak_factory_for_listener, | |
| 92 const scoped_refptr<AutoThreadTaskRunner>& network_task_runner, | |
| 93 scoped_ptr<SignalStrategy> signal_strategy, | 79 scoped_ptr<SignalStrategy> signal_strategy, |
| 94 scoped_ptr<SignalingConnector> signaling_connector, | 80 scoped_ptr<SignalingConnector> signaling_connector, |
| 95 scoped_ptr<HeartbeatSender> heartbeat_sender); | 81 scoped_ptr<HeartbeatSender> heartbeat_sender); |
| 96 | 82 |
| 97 void OnHostOfflineReasonAck(bool success); | 83 void OnHostOfflineReasonAck(bool success); |
|
Wez
2015/02/12 02:51:25
You've removed this method, haven't you?
Łukasz Anforowicz
2015/02/12 18:08:01
Yes, thanks for catching this.
| |
| 98 | 84 |
| 99 // Used to bind HeartbeatSender and SignalingConnector callbacks to |listener| | |
| 100 // in a way that allows "detaching" the |listener| when either |this| is | |
| 101 // destroyed or when SendHostOfflineReasonAndDelete method is called. | |
| 102 scoped_ptr<base::WeakPtrFactory<Listener>> weak_factory_for_listener_; | |
| 103 | |
| 104 // By holding a reference to |network_task_runner_|, HostSignalingManager is | |
| 105 // extending the lifetime of the host process. This is needed for the case | |
| 106 // where an instance of HostProcess has already been destroyed, but we want | |
| 107 // to keep the process running while we try to establish a connection and send | |
| 108 // host-offline-reason. | |
| 109 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; | |
| 110 | |
| 111 // |heartbeat_sender_| and |signaling_connector_| have to be destroyed before | 85 // |heartbeat_sender_| and |signaling_connector_| have to be destroyed before |
| 112 // |signal_strategy_| because their destructors need to call | 86 // |signal_strategy_| because their destructors need to call |
| 113 // signal_strategy_->RemoveListener(this) | 87 // signal_strategy_->RemoveListener(this) |
| 114 scoped_ptr<SignalStrategy> signal_strategy_; | 88 scoped_ptr<SignalStrategy> signal_strategy_; |
| 115 scoped_ptr<SignalingConnector> signaling_connector_; | 89 scoped_ptr<SignalingConnector> signaling_connector_; |
| 116 scoped_ptr<HeartbeatSender> heartbeat_sender_; | 90 scoped_ptr<HeartbeatSender> heartbeat_sender_; |
| 117 | 91 |
| 92 // Used to verify thread-safe usage. | |
| 93 base::ThreadChecker thread_checker_; | |
|
Wez
2015/02/12 02:51:25
Do you need an explicit thread-checker, or could y
Łukasz Anforowicz
2015/02/12 18:08:01
Either option would work. I picked the "member op
Wez
2015/02/12 21:07:07
Acknowledged! Didn't realise that was the new appr
| |
| 94 | |
| 118 DISALLOW_COPY_AND_ASSIGN(HostSignalingManager); | 95 DISALLOW_COPY_AND_ASSIGN(HostSignalingManager); |
| 119 }; | 96 }; |
| 120 | 97 |
| 121 } // namespace remoting | 98 } // namespace remoting |
| 122 | 99 |
| 123 #endif // REMOTING_HOST_HOST_SIGNALING_MANAGER_H_ | 100 #endif // REMOTING_HOST_HOST_SIGNALING_MANAGER_H_ |
| OLD | NEW |