| 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 <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
| 13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 14 #include "net/base/backoff_entry.h" | 14 #include "net/base/backoff_entry.h" |
| 15 #include "remoting/base/encoder.h" | 15 #include "remoting/base/encoder.h" |
| 16 #include "remoting/host/client_session.h" | 16 #include "remoting/host/client_session.h" |
| 17 #include "remoting/host/desktop_environment.h" | |
| 18 #include "remoting/host/host_key_pair.h" | 17 #include "remoting/host/host_key_pair.h" |
| 19 #include "remoting/host/host_status_observer.h" | 18 #include "remoting/host/host_status_observer.h" |
| 20 #include "remoting/host/mouse_move_observer.h" | 19 #include "remoting/host/mouse_move_observer.h" |
| 21 #include "remoting/host/ui_strings.h" | 20 #include "remoting/host/ui_strings.h" |
| 22 #include "remoting/protocol/authenticator.h" | 21 #include "remoting/protocol/authenticator.h" |
| 23 #include "remoting/protocol/session_manager.h" | 22 #include "remoting/protocol/session_manager.h" |
| 24 #include "remoting/protocol/connection_to_client.h" | 23 #include "remoting/protocol/connection_to_client.h" |
| 25 | 24 |
| 26 namespace remoting { | 25 namespace remoting { |
| 27 | 26 |
| 28 namespace protocol { | 27 namespace protocol { |
| 29 class InputStub; | 28 class InputStub; |
| 30 class SessionConfig; | 29 class SessionConfig; |
| 31 class CandidateSessionConfig; | 30 class CandidateSessionConfig; |
| 32 } // namespace protocol | 31 } // namespace protocol |
| 33 | 32 |
| 34 class AudioEncoder; | |
| 35 class AudioScheduler; | |
| 36 class ChromotingHostContext; | 33 class ChromotingHostContext; |
| 37 class DesktopEnvironment; | 34 class DesktopEnvironmentFactory; |
| 38 class Encoder; | |
| 39 class ScreenRecorder; | |
| 40 class VideoFrameCapturer; | |
| 41 | 35 |
| 42 // A class to implement the functionality of a host process. | 36 // A class to implement the functionality of a host process. |
| 43 // | 37 // |
| 44 // Here's the work flow of this class: | 38 // Here's the work flow of this class: |
| 45 // 1. We should load the saved GAIA ID token or if this is the first | 39 // 1. We should load the saved GAIA ID token or if this is the first |
| 46 // time the host process runs we should prompt user for the | 40 // time the host process runs we should prompt user for the |
| 47 // credential. We will use this token or credentials to authenicate | 41 // credential. We will use this token or credentials to authenicate |
| 48 // and register the host. | 42 // and register the host. |
| 49 // | 43 // |
| 50 // 2. We listen for incoming connection using libjingle. We will create | 44 // 2. We listen for incoming connection using libjingle. We will create |
| (...skipping 11 matching lines...) Expand all Loading... |
| 62 // all pending tasks to complete. After all of that completed we | 56 // all pending tasks to complete. After all of that completed we |
| 63 // return to the idle state. We then go to step (2) if there a new | 57 // return to the idle state. We then go to step (2) if there a new |
| 64 // incoming connection. | 58 // incoming connection. |
| 65 class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>, | 59 class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>, |
| 66 public ClientSession::EventHandler, | 60 public ClientSession::EventHandler, |
| 67 public protocol::SessionManager::Listener, | 61 public protocol::SessionManager::Listener, |
| 68 public MouseMoveObserver { | 62 public MouseMoveObserver { |
| 69 public: | 63 public: |
| 70 // The caller must ensure that |context|, |signal_strategy| and | 64 // The caller must ensure that |context|, |signal_strategy| and |
| 71 // |environment| out-live the host. | 65 // |environment| out-live the host. |
| 72 ChromotingHost(ChromotingHostContext* context, | 66 ChromotingHost( |
| 73 SignalStrategy* signal_strategy, | 67 ChromotingHostContext* context, |
| 74 DesktopEnvironment* environment, | 68 SignalStrategy* signal_strategy, |
| 75 scoped_ptr<protocol::SessionManager> session_manager); | 69 DesktopEnvironmentFactory* desktop_environment_factory, |
| 70 scoped_ptr<protocol::SessionManager> session_manager); |
| 76 | 71 |
| 77 // Asynchronously start the host process. | 72 // Asynchronously start the host process. |
| 78 // | 73 // |
| 79 // After this is invoked, the host process will connect to the talk | 74 // After this is invoked, the host process will connect to the talk |
| 80 // network and start listening for incoming connections. | 75 // network and start listening for incoming connections. |
| 81 // | 76 // |
| 82 // This method can only be called once during the lifetime of this object. | 77 // This method can only be called once during the lifetime of this object. |
| 83 void Start(); | 78 void Start(); |
| 84 | 79 |
| 85 // Asynchronously shutdown the host process. |shutdown_task| is | 80 // Asynchronously shutdown the host process. |shutdown_task| is |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 151 |
| 157 typedef std::vector<ClientSession*> ClientList; | 152 typedef std::vector<ClientSession*> ClientList; |
| 158 | 153 |
| 159 enum State { | 154 enum State { |
| 160 kInitial, | 155 kInitial, |
| 161 kStarted, | 156 kStarted, |
| 162 kStopping, | 157 kStopping, |
| 163 kStopped, | 158 kStopped, |
| 164 }; | 159 }; |
| 165 | 160 |
| 166 // Creates encoder for the specified configuration. | |
| 167 static Encoder* CreateEncoder(const protocol::SessionConfig& config); | |
| 168 | |
| 169 // Creates an audio encoder for the specified configuration. | |
| 170 static scoped_ptr<AudioEncoder> CreateAudioEncoder( | |
| 171 const protocol::SessionConfig& config); | |
| 172 | |
| 173 virtual ~ChromotingHost(); | 161 virtual ~ChromotingHost(); |
| 174 | 162 |
| 175 void StopScreenRecorder(); | 163 // Called from Shutdown() to finish shutdown. |
| 176 void StopAudioScheduler(); | |
| 177 void OnRecorderStopped(); | |
| 178 | |
| 179 // Called from Shutdown() or OnScreenRecorderStopped() to finish shutdown. | |
| 180 void ShutdownFinish(); | 164 void ShutdownFinish(); |
| 181 | 165 |
| 182 // Unless specified otherwise all members of this class must be | 166 // Unless specified otherwise all members of this class must be |
| 183 // used on the network thread only. | 167 // used on the network thread only. |
| 184 | 168 |
| 185 // Parameters specified when the host was created. | 169 // Parameters specified when the host was created. |
| 186 ChromotingHostContext* context_; | 170 ChromotingHostContext* context_; |
| 187 DesktopEnvironment* desktop_environment_; | 171 DesktopEnvironmentFactory* desktop_environment_factory_; |
| 188 scoped_ptr<protocol::SessionManager> session_manager_; | 172 scoped_ptr<protocol::SessionManager> session_manager_; |
| 189 | 173 |
| 190 // Connection objects. | 174 // Connection objects. |
| 191 SignalStrategy* signal_strategy_; | 175 SignalStrategy* signal_strategy_; |
| 192 | 176 |
| 193 // Must be used on the network thread only. | 177 // Must be used on the network thread only. |
| 194 ObserverList<HostStatusObserver> status_observers_; | 178 ObserverList<HostStatusObserver> status_observers_; |
| 195 | 179 |
| 196 // The connections to remote clients. | 180 // The connections to remote clients. |
| 197 ClientList clients_; | 181 ClientList clients_; |
| 198 | 182 |
| 199 // Schedulers for audio and video capture. | |
| 200 // TODO(sergeyu): Do we need to have one set of schedulers per client? | |
| 201 scoped_refptr<ScreenRecorder> recorder_; | |
| 202 scoped_refptr<AudioScheduler> audio_scheduler_; | |
| 203 | |
| 204 // Number of screen recorders and audio schedulers that are currently being | |
| 205 // stopped. Used to delay shutdown if one or more recorders/schedulers are | |
| 206 // asynchronously shutting down. | |
| 207 int stopping_recorders_; | |
| 208 | |
| 209 // Tracks the internal state of the host. | 183 // Tracks the internal state of the host. |
| 210 State state_; | 184 State state_; |
| 211 | 185 |
| 212 // Configuration of the protocol. | 186 // Configuration of the protocol. |
| 213 scoped_ptr<protocol::CandidateSessionConfig> protocol_config_; | 187 scoped_ptr<protocol::CandidateSessionConfig> protocol_config_; |
| 214 | 188 |
| 215 // Login backoff state. | 189 // Login backoff state. |
| 216 net::BackoffEntry login_backoff_; | 190 net::BackoffEntry login_backoff_; |
| 217 | 191 |
| 218 // Flags used for RejectAuthenticatingClient(). | 192 // Flags used for RejectAuthenticatingClient(). |
| (...skipping 10 matching lines...) Expand all Loading... |
| 229 | 203 |
| 230 // The maximum duration of any session. | 204 // The maximum duration of any session. |
| 231 base::TimeDelta max_session_duration_; | 205 base::TimeDelta max_session_duration_; |
| 232 | 206 |
| 233 DISALLOW_COPY_AND_ASSIGN(ChromotingHost); | 207 DISALLOW_COPY_AND_ASSIGN(ChromotingHost); |
| 234 }; | 208 }; |
| 235 | 209 |
| 236 } // namespace remoting | 210 } // namespace remoting |
| 237 | 211 |
| 238 #endif // REMOTING_HOST_CHROMOTING_HOST_H_ | 212 #endif // REMOTING_HOST_CHROMOTING_HOST_H_ |
| OLD | NEW |