Chromium Code Reviews| 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 // Both |signal_strategy| and |desktop_environment_factory| should outlive |
| 68 // |desktop_environment_factory| remain valid at least until the | 69 // this object. |
| 69 // |shutdown_task| supplied to Shutdown() has been notified. | |
| 70 ChromotingHost( | 70 ChromotingHost( |
| 71 SignalStrategy* signal_strategy, | 71 SignalStrategy* signal_strategy, |
| 72 DesktopEnvironmentFactory* desktop_environment_factory, | 72 DesktopEnvironmentFactory* desktop_environment_factory, |
| 73 scoped_ptr<protocol::SessionManager> session_manager, | 73 scoped_ptr<protocol::SessionManager> session_manager, |
| 74 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, | 74 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, |
| 75 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, | 75 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, |
| 76 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner, | 76 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner, |
| 77 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner, | 77 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner, |
| 78 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, | 78 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, |
| 79 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); | 79 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); |
| 80 virtual ~ChromotingHost(); | |
| 80 | 81 |
| 81 // Asynchronously start the host process. | 82 // Asynchronously starts the host. |
| 82 // | 83 // |
| 83 // After this is invoked, the host process will connect to the talk | 84 // After this is invoked, the host process will connect to the talk |
| 84 // network and start listening for incoming connections. | 85 // network and start listening for incoming connections. |
| 85 // | 86 // |
| 86 // This method can only be called once during the lifetime of this object. | 87 // This method can only be called once during the lifetime of this object. |
| 87 void Start(const std::string& xmpp_login); | 88 void Start(const std::string& xmpp_login); |
| 88 | 89 |
| 89 // Asynchronously shutdown the host process. |shutdown_task| is | |
| 90 // called after shutdown is completed. | |
| 91 void Shutdown(const base::Closure& shutdown_task); | |
| 92 | |
| 93 // HostStatusMonitor interface. | 90 // HostStatusMonitor interface. |
| 94 virtual void AddStatusObserver(HostStatusObserver* observer) OVERRIDE; | 91 virtual void AddStatusObserver(HostStatusObserver* observer) OVERRIDE; |
| 95 virtual void RemoveStatusObserver(HostStatusObserver* observer) OVERRIDE; | 92 virtual void RemoveStatusObserver(HostStatusObserver* observer) OVERRIDE; |
| 96 | 93 |
| 97 // This method may be called only from | 94 // This method may be called only from |
| 98 // HostStatusObserver::OnClientAuthenticated() to reject the new | 95 // HostStatusObserver::OnClientAuthenticated() to reject the new |
| 99 // client. | 96 // client. |
| 100 void RejectAuthenticatingClient(); | 97 void RejectAuthenticatingClient(); |
| 101 | 98 |
| 102 // Sets the authenticator factory to use for incoming | 99 // Sets the authenticator factory to use for incoming |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 127 | 124 |
| 128 // SessionManager::Listener implementation. | 125 // SessionManager::Listener implementation. |
| 129 virtual void OnSessionManagerReady() OVERRIDE; | 126 virtual void OnSessionManagerReady() OVERRIDE; |
| 130 virtual void OnIncomingSession( | 127 virtual void OnIncomingSession( |
| 131 protocol::Session* session, | 128 protocol::Session* session, |
| 132 protocol::SessionManager::IncomingSessionResponse* response) OVERRIDE; | 129 protocol::SessionManager::IncomingSessionResponse* response) OVERRIDE; |
| 133 | 130 |
| 134 // Sets desired configuration for the protocol. Must be called before Start(). | 131 // Sets desired configuration for the protocol. Must be called before Start(). |
| 135 void set_protocol_config(scoped_ptr<protocol::CandidateSessionConfig> config); | 132 void set_protocol_config(scoped_ptr<protocol::CandidateSessionConfig> config); |
| 136 | 133 |
| 137 // Disconnects all active clients. Clients are disconnected | 134 // Disconnects all active clients synchronously. Sub-components might shutdown |
|
Wez
2013/04/15 19:50:04
nit: synchronously implies blocking. Suggest:
"I
alexeypa (please no reviews)
2013/04/15 20:04:42
Done.
| |
| 138 // asynchronously when this method is called on a thread other than | 135 // asynchronously (when they are running on different threads). No callbacks |
| 139 // the network thread. Potentically this may cause disconnection of | 136 // will be posted to the host in any case. |
| 140 // clients that were not connected when this method is called. | |
| 141 void DisconnectAllClients(); | 137 void DisconnectAllClients(); |
| 142 | 138 |
| 143 base::WeakPtr<ChromotingHost> AsWeakPtr() { | 139 base::WeakPtr<ChromotingHost> AsWeakPtr() { |
| 144 return weak_factory_.GetWeakPtr(); | 140 return weak_factory_.GetWeakPtr(); |
| 145 } | 141 } |
| 146 | 142 |
| 147 private: | 143 private: |
| 148 friend class base::RefCountedThreadSafe<ChromotingHost>; | |
| 149 friend class ChromotingHostTest; | 144 friend class ChromotingHostTest; |
| 150 | 145 |
| 151 typedef std::list<ClientSession*> ClientList; | 146 typedef std::list<ClientSession*> ClientList; |
| 152 | 147 |
| 153 enum State { | |
| 154 kInitial, | |
| 155 kStarted, | |
| 156 kStopping, | |
| 157 kStopped, | |
| 158 }; | |
| 159 | |
| 160 virtual ~ChromotingHost(); | |
| 161 | |
| 162 // Called from Shutdown() to finish shutdown. | |
| 163 void ShutdownFinish(); | |
| 164 | |
| 165 // Unless specified otherwise all members of this class must be | 148 // Unless specified otherwise all members of this class must be |
| 166 // used on the network thread only. | 149 // used on the network thread only. |
| 167 | 150 |
| 168 // Parameters specified when the host was created. | 151 // Parameters specified when the host was created. |
| 169 DesktopEnvironmentFactory* desktop_environment_factory_; | 152 DesktopEnvironmentFactory* desktop_environment_factory_; |
| 170 scoped_ptr<protocol::SessionManager> session_manager_; | 153 scoped_ptr<protocol::SessionManager> session_manager_; |
| 171 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_; | 154 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_; |
| 172 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner_; | 155 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner_; |
| 173 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner_; | 156 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner_; |
| 174 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner_; | 157 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner_; |
| 175 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | 158 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
| 176 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 159 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
| 177 | 160 |
| 178 // Connection objects. | 161 // Connection objects. |
| 179 SignalStrategy* signal_strategy_; | 162 SignalStrategy* signal_strategy_; |
| 180 | 163 |
| 181 // Must be used on the network thread only. | 164 // Must be used on the network thread only. |
| 182 ObserverList<HostStatusObserver> status_observers_; | 165 ObserverList<HostStatusObserver> status_observers_; |
| 183 | 166 |
| 184 // The connections to remote clients. | 167 // The connections to remote clients. |
| 185 ClientList clients_; | 168 ClientList clients_; |
| 186 | 169 |
| 187 // Tracks the internal state of the host. | 170 // True if the host has been started. |
| 188 State state_; | 171 bool started_; |
| 189 | 172 |
| 190 // Configuration of the protocol. | 173 // Configuration of the protocol. |
| 191 scoped_ptr<protocol::CandidateSessionConfig> protocol_config_; | 174 scoped_ptr<protocol::CandidateSessionConfig> protocol_config_; |
| 192 | 175 |
| 193 // Login backoff state. | 176 // Login backoff state. |
| 194 net::BackoffEntry login_backoff_; | 177 net::BackoffEntry login_backoff_; |
| 195 | 178 |
| 196 // Flags used for RejectAuthenticatingClient(). | 179 // Flags used for RejectAuthenticatingClient(). |
| 197 bool authenticating_client_; | 180 bool authenticating_client_; |
| 198 bool reject_authenticating_client_; | 181 bool reject_authenticating_client_; |
| 199 | 182 |
| 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. | 183 // The maximum duration of any session. |
| 205 base::TimeDelta max_session_duration_; | 184 base::TimeDelta max_session_duration_; |
| 206 | 185 |
| 207 base::WeakPtrFactory<ChromotingHost> weak_factory_; | 186 base::WeakPtrFactory<ChromotingHost> weak_factory_; |
| 208 | 187 |
| 209 DISALLOW_COPY_AND_ASSIGN(ChromotingHost); | 188 DISALLOW_COPY_AND_ASSIGN(ChromotingHost); |
| 210 }; | 189 }; |
| 211 | 190 |
| 212 } // namespace remoting | 191 } // namespace remoting |
| 213 | 192 |
| 214 #endif // REMOTING_HOST_CHROMOTING_HOST_H_ | 193 #endif // REMOTING_HOST_CHROMOTING_HOST_H_ |
| OLD | NEW |