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 |
Łukasz Anforowicz
2015/02/12 22:51:13
Wez said:
| |
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. |
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 |
71 // |host_offline_reason|, or the |timeout| is reached. | |
81 // | 72 // |
82 // Will delete |this| once either the bot acks receiving the | 73 // For discussion of allowed values for |host_offline_reason| argument, |
83 // |host_offline_reason|, or the |timeout| is reached. Deleting | 74 // please see the description of rem:host-offline-reason xml attribute in |
84 // |this| will release |network_task_runner_| and allow the host | 75 // the class-level comments for HeartbeatReasonSender. |
85 // process to exit. | 76 void SendHostOfflineReason( |
86 void SendHostOfflineReasonAndDelete(const std::string& host_offline_reason, | 77 const std::string& host_offline_reason, |
87 const base::TimeDelta& timeout); | 78 const base::TimeDelta& timeout, |
79 const base::Callback<void(bool success)>& ack_callback); | |
88 | 80 |
89 private: | 81 private: |
90 HostSignalingManager( | 82 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, | 83 scoped_ptr<SignalStrategy> signal_strategy, |
94 scoped_ptr<SignalingConnector> signaling_connector, | 84 scoped_ptr<SignalingConnector> signaling_connector, |
95 scoped_ptr<HeartbeatSender> heartbeat_sender); | 85 scoped_ptr<HeartbeatSender> heartbeat_sender); |
96 | 86 |
97 void OnHostOfflineReasonAck(bool success); | |
98 | |
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 | 87 // |heartbeat_sender_| and |signaling_connector_| have to be destroyed before |
112 // |signal_strategy_| because their destructors need to call | 88 // |signal_strategy_| because their destructors need to call |
113 // signal_strategy_->RemoveListener(this) | 89 // signal_strategy_->RemoveListener(this) |
114 scoped_ptr<SignalStrategy> signal_strategy_; | 90 scoped_ptr<SignalStrategy> signal_strategy_; |
115 scoped_ptr<SignalingConnector> signaling_connector_; | 91 scoped_ptr<SignalingConnector> signaling_connector_; |
116 scoped_ptr<HeartbeatSender> heartbeat_sender_; | 92 scoped_ptr<HeartbeatSender> heartbeat_sender_; |
117 | 93 |
94 // Used to verify thread-safe usage. | |
95 base::ThreadChecker thread_checker_; | |
96 | |
118 DISALLOW_COPY_AND_ASSIGN(HostSignalingManager); | 97 DISALLOW_COPY_AND_ASSIGN(HostSignalingManager); |
119 }; | 98 }; |
120 | 99 |
121 } // namespace remoting | 100 } // namespace remoting |
122 | 101 |
123 #endif // REMOTING_HOST_HOST_SIGNALING_MANAGER_H_ | 102 #endif // REMOTING_HOST_HOST_SIGNALING_MANAGER_H_ |
OLD | NEW |