Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_CHROMOTING_HOST_H_ | 5 #ifndef REMOTING_CHROMOTING_HOST_H_ |
| 6 #define REMOTING_CHROMOTING_HOST_H_ | 6 #define REMOTING_CHROMOTING_HOST_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| 11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
| 12 #include "remoting/base/encoder.h" | 12 #include "remoting/base/encoder.h" |
| 13 #include "remoting/host/access_verifier.h" | 13 #include "remoting/host/access_verifier.h" |
| 14 #include "remoting/host/capturer.h" | 14 #include "remoting/host/capturer.h" |
| 15 #include "remoting/host/client_session.h" | |
| 15 #include "remoting/host/desktop_environment.h" | 16 #include "remoting/host/desktop_environment.h" |
| 16 #include "remoting/host/heartbeat_sender.h" | 17 #include "remoting/host/heartbeat_sender.h" |
| 17 #include "remoting/jingle_glue/jingle_client.h" | 18 #include "remoting/jingle_glue/jingle_client.h" |
| 18 #include "remoting/jingle_glue/jingle_thread.h" | 19 #include "remoting/jingle_glue/jingle_thread.h" |
| 19 #include "remoting/protocol/session_manager.h" | 20 #include "remoting/protocol/session_manager.h" |
| 20 #include "remoting/protocol/connection_to_client.h" | 21 #include "remoting/protocol/connection_to_client.h" |
| 21 | 22 |
| 22 class Task; | 23 class Task; |
| 23 | 24 |
| 24 namespace remoting { | 25 namespace remoting { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 // After we have done all the initialization we'll start the ScreenRecorder. | 57 // After we have done all the initialization we'll start the ScreenRecorder. |
| 57 // We'll then enter the running state of the host process. | 58 // We'll then enter the running state of the host process. |
| 58 // | 59 // |
| 59 // 3. When the user is disconnected, we will pause the ScreenRecorder | 60 // 3. When the user is disconnected, we will pause the ScreenRecorder |
| 60 // and try to terminate the threads we have created. This will allow | 61 // and try to terminate the threads we have created. This will allow |
| 61 // all pending tasks to complete. After all of that completed we | 62 // all pending tasks to complete. After all of that completed we |
| 62 // return to the idle state. We then go to step (2) if there a new | 63 // return to the idle state. We then go to step (2) if there a new |
| 63 // incoming connection. | 64 // incoming connection. |
| 64 class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>, | 65 class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>, |
| 65 public protocol::ConnectionToClient::EventHandler, | 66 public protocol::ConnectionToClient::EventHandler, |
| 66 public DesktopEnvironment::EventHandler, | 67 public ClientSession::EventHandler, |
| 67 public JingleClient::Callback { | 68 public JingleClient::Callback { |
| 68 public: | 69 public: |
| 69 // Factory methods that must be used to create ChromotingHost instances. | 70 // Factory methods that must be used to create ChromotingHost instances. |
| 70 // Default capturer and input stub are used if it is not specified. | 71 // Default capturer and input stub are used if it is not specified. |
| 71 static ChromotingHost* Create(ChromotingHostContext* context, | 72 static ChromotingHost* Create(ChromotingHostContext* context, |
| 72 MutableHostConfig* config); | 73 MutableHostConfig* config); |
| 73 static ChromotingHost* Create(ChromotingHostContext* context, | 74 static ChromotingHost* Create(ChromotingHostContext* context, |
| 74 MutableHostConfig* config, | 75 MutableHostConfig* config, |
| 75 DesktopEnvironment* environment); | 76 DesktopEnvironment* environment); |
| 76 | 77 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 98 // protocol::ConnectionToClient::EventHandler implementations | 99 // protocol::ConnectionToClient::EventHandler implementations |
| 99 virtual void OnConnectionOpened(protocol::ConnectionToClient* client); | 100 virtual void OnConnectionOpened(protocol::ConnectionToClient* client); |
| 100 virtual void OnConnectionClosed(protocol::ConnectionToClient* client); | 101 virtual void OnConnectionClosed(protocol::ConnectionToClient* client); |
| 101 virtual void OnConnectionFailed(protocol::ConnectionToClient* client); | 102 virtual void OnConnectionFailed(protocol::ConnectionToClient* client); |
| 102 | 103 |
| 103 //////////////////////////////////////////////////////////////////////////// | 104 //////////////////////////////////////////////////////////////////////////// |
| 104 // JingleClient::Callback implementations | 105 // JingleClient::Callback implementations |
| 105 virtual void OnStateChange(JingleClient* client, JingleClient::State state); | 106 virtual void OnStateChange(JingleClient* client, JingleClient::State state); |
| 106 | 107 |
| 107 //////////////////////////////////////////////////////////////////////////// | 108 //////////////////////////////////////////////////////////////////////////// |
| 108 // DesktopEnvironment::EventHandler implementations | 109 // ClientSession::EventHandler implementations |
| 109 virtual void LocalLoginSucceeded(); | 110 virtual void LocalLoginSucceeded( |
| 110 virtual void LocalLoginFailed(); | 111 scoped_refptr<protocol::ConnectionToClient> client); |
| 112 virtual void LocalLoginFailed( | |
| 113 scoped_refptr<protocol::ConnectionToClient> client); | |
| 111 | 114 |
| 112 // Callback for ChromotingServer. | 115 // Callback for ChromotingServer. |
| 113 void OnNewClientSession( | 116 void OnNewClientSession( |
| 114 protocol::Session* session, | 117 protocol::Session* session, |
| 115 protocol::SessionManager::IncomingSessionResponse* response); | 118 protocol::SessionManager::IncomingSessionResponse* response); |
| 116 | 119 |
| 117 // Sets desired configuration for the protocol. Ownership of the | 120 // Sets desired configuration for the protocol. Ownership of the |
| 118 // |config| is transferred to the object. Must be called before Start(). | 121 // |config| is transferred to the object. Must be called before Start(). |
| 119 void set_protocol_config(protocol::CandidateSessionConfig* config); | 122 void set_protocol_config(protocol::CandidateSessionConfig* config); |
| 120 | 123 |
| 121 // This getter is only used in unit test. | |
| 122 protocol::HostStub* host_stub() const; | |
| 123 | |
| 124 // This setter is only used in unit test to simulate client connection. | 124 // This setter is only used in unit test to simulate client connection. |
| 125 void set_connection(protocol::ConnectionToClient* conn) { | 125 void add_client(ClientSession* client) { |
|
awong
2011/03/22 15:11:56
Chromium style says, add_client() shoudl only be u
simonmorris
2011/03/23 10:35:20
Done.
| |
| 126 connection_ = conn; | 126 clients_.push_back(client); |
| 127 } | 127 } |
| 128 | 128 |
| 129 private: | 129 private: |
| 130 friend class base::RefCountedThreadSafe<ChromotingHost>; | 130 friend class base::RefCountedThreadSafe<ChromotingHost>; |
| 131 | 131 |
| 132 ChromotingHost(ChromotingHostContext* context, MutableHostConfig* config, | 132 ChromotingHost(ChromotingHostContext* context, MutableHostConfig* config, |
| 133 DesktopEnvironment* environment); | 133 DesktopEnvironment* environment); |
| 134 virtual ~ChromotingHost(); | 134 virtual ~ChromotingHost(); |
| 135 | 135 |
| 136 enum State { | 136 enum State { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 160 // receive connection requests from chromoting client. | 160 // receive connection requests from chromoting client. |
| 161 scoped_refptr<JingleClient> jingle_client_; | 161 scoped_refptr<JingleClient> jingle_client_; |
| 162 | 162 |
| 163 scoped_refptr<protocol::SessionManager> session_manager_; | 163 scoped_refptr<protocol::SessionManager> session_manager_; |
| 164 | 164 |
| 165 // Objects that takes care of sending heartbeats to the chromoting bot. | 165 // Objects that takes care of sending heartbeats to the chromoting bot. |
| 166 scoped_refptr<HeartbeatSender> heartbeat_sender_; | 166 scoped_refptr<HeartbeatSender> heartbeat_sender_; |
| 167 | 167 |
| 168 AccessVerifier access_verifier_; | 168 AccessVerifier access_verifier_; |
| 169 | 169 |
| 170 // A ConnectionToClient manages the connectino to a remote client. | 170 // The connections to remote clients. |
| 171 // TODO(hclam): Expand this to a list of clients. | 171 std::vector<scoped_refptr<ClientSession> > clients_; |
| 172 scoped_refptr<protocol::ConnectionToClient> connection_; | |
| 173 | 172 |
| 174 // Session manager for the host process. | 173 // Session manager for the host process. |
| 175 scoped_refptr<ScreenRecorder> recorder_; | 174 scoped_refptr<ScreenRecorder> recorder_; |
| 176 | 175 |
| 177 // This task gets executed when this object fails to connect to the | 176 // This task gets executed when this object fails to connect to the |
| 178 // talk network or Shutdown() is called. | 177 // talk network or Shutdown() is called. |
| 179 scoped_ptr<Task> shutdown_task_; | 178 scoped_ptr<Task> shutdown_task_; |
| 180 | 179 |
| 181 // Tracks the internal state of the host. | 180 // Tracks the internal state of the host. |
| 182 // This variable is written on the main thread of ChromotingHostContext | 181 // This variable is written on the main thread of ChromotingHostContext |
| 183 // and read by jingle thread. | 182 // and read by jingle thread. |
| 184 State state_; | 183 State state_; |
| 185 | 184 |
| 186 // Lock is to lock the access to |state_|. | 185 // Lock is to lock the access to |state_|. |
| 187 base::Lock lock_; | 186 base::Lock lock_; |
| 188 | 187 |
| 189 // Configuration of the protocol. | 188 // Configuration of the protocol. |
| 190 scoped_ptr<protocol::CandidateSessionConfig> protocol_config_; | 189 scoped_ptr<protocol::CandidateSessionConfig> protocol_config_; |
| 191 | 190 |
| 192 DISALLOW_COPY_AND_ASSIGN(ChromotingHost); | 191 DISALLOW_COPY_AND_ASSIGN(ChromotingHost); |
| 193 }; | 192 }; |
| 194 | 193 |
| 195 } // namespace remoting | 194 } // namespace remoting |
| 196 | 195 |
| 197 #endif // REMOTING_HOST_CHROMOTING_HOST_H_ | 196 #endif // REMOTING_HOST_CHROMOTING_HOST_H_ |
| OLD | NEW |