| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/thread.h" | 10 #include "base/thread.h" |
| 11 #include "remoting/base/encoder.h" | 11 #include "remoting/base/encoder.h" |
| 12 #include "remoting/host/access_verifier.h" | 12 #include "remoting/host/access_verifier.h" |
| 13 #include "remoting/host/capturer.h" | 13 #include "remoting/host/capturer.h" |
| 14 #include "remoting/host/heartbeat_sender.h" | 14 #include "remoting/host/heartbeat_sender.h" |
| 15 #include "remoting/jingle_glue/jingle_client.h" | 15 #include "remoting/jingle_glue/jingle_client.h" |
| 16 #include "remoting/jingle_glue/jingle_thread.h" | 16 #include "remoting/jingle_glue/jingle_thread.h" |
| 17 #include "remoting/protocol/session_manager.h" | 17 #include "remoting/protocol/session_manager.h" |
| 18 #include "remoting/protocol/connection_to_client.h" | 18 #include "remoting/protocol/connection_to_client.h" |
| 19 | 19 |
| 20 class Task; | 20 class Task; |
| 21 | 21 |
| 22 namespace remoting { | 22 namespace remoting { |
| 23 | 23 |
| 24 namespace protocol { | 24 namespace protocol { |
| 25 class ConnectionToClient; | 25 class ConnectionToClient; |
| 26 class HostStub; | 26 class HostStub; |
| 27 class InputStub; | 27 class InputStub; |
| 28 class SessionConfig; | 28 class SessionConfig; |
| 29 class CandidateSessionConfig; |
| 29 } // namespace protocol | 30 } // namespace protocol |
| 30 | 31 |
| 31 class Capturer; | 32 class Capturer; |
| 32 class ChromotingHostContext; | 33 class ChromotingHostContext; |
| 33 class Encoder; | 34 class Encoder; |
| 34 class MutableHostConfig; | 35 class MutableHostConfig; |
| 35 class SessionManager; | 36 class SessionManager; |
| 36 | 37 |
| 37 // A class to implement the functionality of a host process. | 38 // A class to implement the functionality of a host process. |
| 38 // | 39 // |
| (...skipping 17 matching lines...) Expand all Loading... |
| 56 // | 57 // |
| 57 // 3. When the user is disconencted, we will pause the SessionManager | 58 // 3. When the user is disconencted, we will pause the SessionManager |
| 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::RefCountedThreadSafe<ChromotingHost>, |
| 63 public protocol::ConnectionToClient::EventHandler, | 64 public protocol::ConnectionToClient::EventHandler, |
| 64 public JingleClient::Callback { | 65 public JingleClient::Callback { |
| 65 public: | 66 public: |
| 66 ChromotingHost(ChromotingHostContext* context, MutableHostConfig* config); | 67 // Factory methods that must be used to create ChromotingHost |
| 67 ChromotingHost(ChromotingHostContext* context, MutableHostConfig* config, | 68 // instances. Default capturer is used if it is not specified. |
| 68 Capturer* capturer); | 69 static ChromotingHost* Create(ChromotingHostContext* context, |
| 69 virtual ~ChromotingHost(); | 70 MutableHostConfig* config); |
| 71 static ChromotingHost* Create(ChromotingHostContext* context, |
| 72 MutableHostConfig* config, |
| 73 Capturer* capturer); |
| 70 | 74 |
| 71 // Asynchronously start the host process. | 75 // Asynchronously start the host process. |
| 72 // | 76 // |
| 73 // After this is invoked, the host process will connect to the talk | 77 // After this is invoked, the host process will connect to the talk |
| 74 // network and start listening for incoming connections. | 78 // network and start listening for incoming connections. |
| 75 // | 79 // |
| 76 // |shutdown_task| is called if Start() has failed ot Shutdown() is called | 80 // |shutdown_task| is called if Start() has failed ot Shutdown() is called |
| 77 // and all related operations are completed. | 81 // and all related operations are completed. |
| 78 // | 82 // |
| 79 // This method can only be called once during the lifetime of this object. | 83 // This method can only be called once during the lifetime of this object. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 96 | 100 |
| 97 //////////////////////////////////////////////////////////////////////////// | 101 //////////////////////////////////////////////////////////////////////////// |
| 98 // JingleClient::Callback implementations | 102 // JingleClient::Callback implementations |
| 99 virtual void OnStateChange(JingleClient* client, JingleClient::State state); | 103 virtual void OnStateChange(JingleClient* client, JingleClient::State state); |
| 100 | 104 |
| 101 // Callback for ChromotingServer. | 105 // Callback for ChromotingServer. |
| 102 void OnNewClientSession( | 106 void OnNewClientSession( |
| 103 protocol::Session* session, | 107 protocol::Session* session, |
| 104 protocol::SessionManager::IncomingSessionResponse* response); | 108 protocol::SessionManager::IncomingSessionResponse* response); |
| 105 | 109 |
| 110 // Sets desired configuration for the protocol. Ownership of the |
| 111 // |config| is transferred to the object. Must be called before Start(). |
| 112 void set_protocol_config(protocol::CandidateSessionConfig* config); |
| 113 |
| 106 private: | 114 private: |
| 115 friend class base::RefCountedThreadSafe<ChromotingHost>; |
| 116 ChromotingHost(ChromotingHostContext* context, MutableHostConfig* config, |
| 117 Capturer* capturer); |
| 118 virtual ~ChromotingHost(); |
| 119 |
| 107 enum State { | 120 enum State { |
| 108 kInitial, | 121 kInitial, |
| 109 kStarted, | 122 kStarted, |
| 110 kStopped, | 123 kStopped, |
| 111 }; | 124 }; |
| 112 | 125 |
| 113 // This method connects to the talk network and start listening for incoming | |
| 114 // connections. | |
| 115 void DoStart(Task* shutdown_task); | |
| 116 | |
| 117 // Callback for protocol::SessionManager::Close(). | 126 // Callback for protocol::SessionManager::Close(). |
| 118 void OnServerClosed(); | 127 void OnServerClosed(); |
| 119 | 128 |
| 120 // Creates encoder for the specified configuration. | 129 // Creates encoder for the specified configuration. |
| 121 Encoder* CreateEncoder(const protocol::SessionConfig* config); | 130 Encoder* CreateEncoder(const protocol::SessionConfig* config); |
| 122 | 131 |
| 123 // The context that the chromoting host runs on. | 132 // The context that the chromoting host runs on. |
| 124 ChromotingHostContext* context_; | 133 ChromotingHostContext* context_; |
| 125 | 134 |
| 126 scoped_refptr<MutableHostConfig> config_; | 135 scoped_refptr<MutableHostConfig> config_; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 scoped_ptr<Task> shutdown_task_; | 170 scoped_ptr<Task> shutdown_task_; |
| 162 | 171 |
| 163 // Tracks the internal state of the host. | 172 // Tracks the internal state of the host. |
| 164 // This variable is written on the main thread of ChromotingHostContext | 173 // This variable is written on the main thread of ChromotingHostContext |
| 165 // and read by jingle thread. | 174 // and read by jingle thread. |
| 166 State state_; | 175 State state_; |
| 167 | 176 |
| 168 // Lock is to lock the access to |state_|. | 177 // Lock is to lock the access to |state_|. |
| 169 Lock lock_; | 178 Lock lock_; |
| 170 | 179 |
| 180 // Configuration of the protocol. |
| 181 scoped_ptr<protocol::CandidateSessionConfig> protocol_config_; |
| 182 |
| 171 DISALLOW_COPY_AND_ASSIGN(ChromotingHost); | 183 DISALLOW_COPY_AND_ASSIGN(ChromotingHost); |
| 172 }; | 184 }; |
| 173 | 185 |
| 174 } // namespace remoting | 186 } // namespace remoting |
| 175 | 187 |
| 176 #endif // REMOTING_HOST_CHROMOTING_HOST_H_ | 188 #endif // REMOTING_HOST_CHROMOTING_HOST_H_ |
| OLD | NEW |