OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_CHROMOTING_HOST_H_ | 5 #ifndef REMOTING_HOST_CHROMOTING_HOST_H_ |
6 #define REMOTING_HOST_CHROMOTING_HOST_H_ | 6 #define REMOTING_HOST_CHROMOTING_HOST_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
15 #include "base/threading/non_thread_safe.h" | |
15 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
16 #include "net/base/backoff_entry.h" | 17 #include "net/base/backoff_entry.h" |
17 #include "remoting/host/client_session.h" | 18 #include "remoting/host/client_session.h" |
18 #include "remoting/host/host_status_monitor.h" | 19 #include "remoting/host/host_status_monitor.h" |
19 #include "remoting/host/host_status_observer.h" | 20 #include "remoting/host/host_status_observer.h" |
20 #include "remoting/protocol/authenticator.h" | 21 #include "remoting/protocol/authenticator.h" |
21 #include "remoting/protocol/session_manager.h" | 22 #include "remoting/protocol/session_manager.h" |
22 #include "remoting/protocol/connection_to_client.h" | 23 #include "remoting/protocol/connection_to_client.h" |
23 #include "third_party/skia/include/core/SkSize.h" | 24 #include "third_party/skia/include/core/SkSize.h" |
24 | 25 |
(...skipping 27 matching lines...) Expand all Loading... | |
52 // ConnectionToClient to receive mouse / keyboard events from the remote | 53 // ConnectionToClient to receive mouse / keyboard events from the remote |
53 // client. | 54 // client. |
54 // After we have done all the initialization we'll start the ScreenRecorder. | 55 // After we have done all the initialization we'll start the ScreenRecorder. |
55 // We'll then enter the running state of the host process. | 56 // We'll then enter the running state of the host process. |
56 // | 57 // |
57 // 3. When the user is disconnected, we will pause the ScreenRecorder | 58 // 3. When the user is disconnected, we will pause the ScreenRecorder |
58 // and try to terminate the threads we have created. This will allow | 59 // and try to terminate the threads we have created. This will allow |
59 // all pending tasks to complete. After all of that completed we | 60 // all pending tasks to complete. After all of that completed we |
60 // return to the idle state. We then go to step (2) if there a new | 61 // return to the idle state. We then go to step (2) if there a new |
61 // incoming connection. | 62 // incoming connection. |
62 class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>, | 63 class ChromotingHost : public base::NonThreadSafe, |
63 public ClientSession::EventHandler, | 64 public ClientSession::EventHandler, |
64 public protocol::SessionManager::Listener, | 65 public protocol::SessionManager::Listener, |
65 public HostStatusMonitor { | 66 public HostStatusMonitor { |
66 public: | 67 public: |
67 // The caller must ensure that |signal_strategy| and | 68 // The caller must ensure that |signal_strategy| and |
68 // |desktop_environment_factory| remain valid at least until the | 69 // |desktop_environment_factory| remain valid at least until the |
69 // |shutdown_task| supplied to Shutdown() has been notified. | 70 // |shutdown_task| supplied to Shutdown() has been notified. |
70 ChromotingHost( | 71 ChromotingHost( |
71 SignalStrategy* signal_strategy, | 72 SignalStrategy* signal_strategy, |
72 DesktopEnvironmentFactory* desktop_environment_factory, | 73 DesktopEnvironmentFactory* desktop_environment_factory, |
73 scoped_ptr<protocol::SessionManager> session_manager, | 74 scoped_ptr<protocol::SessionManager> session_manager, |
74 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, | 75 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, |
75 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, | 76 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, |
76 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner, | 77 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner, |
77 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner, | 78 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner, |
78 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, | 79 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, |
79 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); | 80 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); |
81 virtual ~ChromotingHost(); | |
80 | 82 |
81 // Asynchronously start the host process. | 83 // Asynchronously start the host process. |
82 // | 84 // |
83 // After this is invoked, the host process will connect to the talk | 85 // After this is invoked, the host process will connect to the talk |
84 // network and start listening for incoming connections. | 86 // network and start listening for incoming connections. |
85 // | 87 // |
86 // This method can only be called once during the lifetime of this object. | 88 // This method can only be called once during the lifetime of this object. |
87 void Start(const std::string& xmpp_login); | 89 void Start(const std::string& xmpp_login); |
88 | 90 |
89 // Asynchronously shutdown the host process. |shutdown_task| is | 91 // Shuts down the host process. |
90 // called after shutdown is completed. | 92 void Shutdown(); |
Wez
2013/04/02 19:58:33
Rename this Stop() to match Start().
alexeypa (please no reviews)
2013/04/08 23:28:17
I moved the logic to the destructor.
| |
91 void Shutdown(const base::Closure& shutdown_task); | |
92 | 93 |
93 // HostStatusMonitor interface. | 94 // HostStatusMonitor interface. |
94 virtual void AddStatusObserver(HostStatusObserver* observer) OVERRIDE; | 95 virtual void AddStatusObserver(HostStatusObserver* observer) OVERRIDE; |
95 virtual void RemoveStatusObserver(HostStatusObserver* observer) OVERRIDE; | 96 virtual void RemoveStatusObserver(HostStatusObserver* observer) OVERRIDE; |
96 | 97 |
97 // This method may be called only from | 98 // This method may be called only from |
98 // HostStatusObserver::OnClientAuthenticated() to reject the new | 99 // HostStatusObserver::OnClientAuthenticated() to reject the new |
99 // client. | 100 // client. |
100 void RejectAuthenticatingClient(); | 101 void RejectAuthenticatingClient(); |
101 | 102 |
(...skipping 25 matching lines...) Expand all Loading... | |
127 | 128 |
128 // SessionManager::Listener implementation. | 129 // SessionManager::Listener implementation. |
129 virtual void OnSessionManagerReady() OVERRIDE; | 130 virtual void OnSessionManagerReady() OVERRIDE; |
130 virtual void OnIncomingSession( | 131 virtual void OnIncomingSession( |
131 protocol::Session* session, | 132 protocol::Session* session, |
132 protocol::SessionManager::IncomingSessionResponse* response) OVERRIDE; | 133 protocol::SessionManager::IncomingSessionResponse* response) OVERRIDE; |
133 | 134 |
134 // Sets desired configuration for the protocol. Must be called before Start(). | 135 // Sets desired configuration for the protocol. Must be called before Start(). |
135 void set_protocol_config(scoped_ptr<protocol::CandidateSessionConfig> config); | 136 void set_protocol_config(scoped_ptr<protocol::CandidateSessionConfig> config); |
136 | 137 |
137 // Disconnects all active clients. Clients are disconnected | 138 // Disconnects all active clients. |
Wez
2013/04/02 19:58:33
Clarify the semantics, e.g. might sub-components a
alexeypa (please no reviews)
2013/04/08 23:28:17
Done.
| |
138 // asynchronously when this method is called on a thread other than | |
139 // the network thread. Potentically this may cause disconnection of | |
140 // clients that were not connected when this method is called. | |
141 void DisconnectAllClients(); | 139 void DisconnectAllClients(); |
142 | 140 |
143 base::WeakPtr<ChromotingHost> AsWeakPtr() { | 141 base::WeakPtr<ChromotingHost> AsWeakPtr() { |
144 return weak_factory_.GetWeakPtr(); | 142 return weak_factory_.GetWeakPtr(); |
145 } | 143 } |
146 | 144 |
147 private: | 145 private: |
148 friend class base::RefCountedThreadSafe<ChromotingHost>; | |
149 friend class ChromotingHostTest; | 146 friend class ChromotingHostTest; |
150 | 147 |
151 typedef std::list<ClientSession*> ClientList; | 148 typedef std::list<ClientSession*> ClientList; |
152 | 149 |
153 enum State { | 150 enum State { |
154 kInitial, | 151 kInitial, |
155 kStarted, | 152 kStarted, |
156 kStopping, | 153 kStopping, |
157 kStopped, | 154 kStopped, |
158 }; | 155 }; |
159 | 156 |
160 virtual ~ChromotingHost(); | |
161 | |
162 // Called from Shutdown() to finish shutdown. | 157 // Called from Shutdown() to finish shutdown. |
163 void ShutdownFinish(); | 158 void ShutdownFinish(); |
164 | 159 |
165 // Unless specified otherwise all members of this class must be | 160 // Unless specified otherwise all members of this class must be |
166 // used on the network thread only. | 161 // used on the network thread only. |
167 | 162 |
168 // Parameters specified when the host was created. | 163 // Parameters specified when the host was created. |
169 DesktopEnvironmentFactory* desktop_environment_factory_; | 164 DesktopEnvironmentFactory* desktop_environment_factory_; |
170 scoped_ptr<protocol::SessionManager> session_manager_; | 165 scoped_ptr<protocol::SessionManager> session_manager_; |
171 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_; | 166 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_; |
(...skipping 18 matching lines...) Expand all Loading... | |
190 // Configuration of the protocol. | 185 // Configuration of the protocol. |
191 scoped_ptr<protocol::CandidateSessionConfig> protocol_config_; | 186 scoped_ptr<protocol::CandidateSessionConfig> protocol_config_; |
192 | 187 |
193 // Login backoff state. | 188 // Login backoff state. |
194 net::BackoffEntry login_backoff_; | 189 net::BackoffEntry login_backoff_; |
195 | 190 |
196 // Flags used for RejectAuthenticatingClient(). | 191 // Flags used for RejectAuthenticatingClient(). |
197 bool authenticating_client_; | 192 bool authenticating_client_; |
198 bool reject_authenticating_client_; | 193 bool reject_authenticating_client_; |
199 | 194 |
200 // Stores list of tasks that should be executed when we finish | |
201 // shutdown. Used only while |state_| is set to kStopping. | |
202 std::vector<base::Closure> shutdown_tasks_; | |
203 | |
204 // The maximum duration of any session. | 195 // The maximum duration of any session. |
205 base::TimeDelta max_session_duration_; | 196 base::TimeDelta max_session_duration_; |
206 | 197 |
207 base::WeakPtrFactory<ChromotingHost> weak_factory_; | 198 base::WeakPtrFactory<ChromotingHost> weak_factory_; |
208 | 199 |
209 DISALLOW_COPY_AND_ASSIGN(ChromotingHost); | 200 DISALLOW_COPY_AND_ASSIGN(ChromotingHost); |
210 }; | 201 }; |
211 | 202 |
212 } // namespace remoting | 203 } // namespace remoting |
213 | 204 |
214 #endif // REMOTING_HOST_CHROMOTING_HOST_H_ | 205 #endif // REMOTING_HOST_CHROMOTING_HOST_H_ |
OLD | NEW |