OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef REMOTING_SIMPLE_HOST_H_ |
| 6 #define REMOTING_SIMPLE_HOST_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/thread.h" |
| 11 #include "remoting/host/capturer.h" |
| 12 #include "remoting/host/client_connection.h" |
| 13 #include "remoting/host/encoder.h" |
| 14 #include "remoting/host/event_executor.h" |
| 15 #include "remoting/host/heartbeat_sender.h" |
| 16 #include "remoting/host/session_manager.h" |
| 17 #include "remoting/jingle_glue/jingle_client.h" |
| 18 |
| 19 namespace remoting { |
| 20 |
| 21 // A class to implement the functionality of a host process. |
| 22 // |
| 23 // Here's the work flow of this class: |
| 24 // 1. We should load the saved GAIA ID token or if this is the first |
| 25 // time the host process runs we should prompt user for the |
| 26 // credential. We will use this token or credentials to authenicate |
| 27 // and register the host. |
| 28 // |
| 29 // 2. We listen for incoming connection using libjingle. We will create |
| 30 // a ClientConnection object that wraps around linjingle for transport. Also |
| 31 // create a SessionManager with appropriate Encoder and Capturer and |
| 32 // add the ClientConnection to this SessionManager for transporting the |
| 33 // screen captures. A EventExecutor is created and registered with the |
| 34 // ClientConnection to receive mouse / keyboard events from the remote |
| 35 // client. |
| 36 // This is also the right time to create multiple threads to host |
| 37 // the above objects. After we have done all the initialization |
| 38 // we'll start the SessionManager. We'll then enter the running state |
| 39 // of the host process. |
| 40 // |
| 41 // 3. When the user is disconencted, we will pause the SessionManager |
| 42 // and try to terminate the threads we have created. This will allow |
| 43 // all pending tasks to complete. After all of that completed we |
| 44 // return to the idle state. We then go to step (2) if there a new |
| 45 // incoming connection. |
| 46 class SimpleHost : public base::RefCountedThreadSafe<SimpleHost>, |
| 47 public ClientConnection::EventHandler, |
| 48 public JingleClient::Callback { |
| 49 public: |
| 50 SimpleHost(const std::string& username, const std::string& password, |
| 51 Capturer* capturer, Encoder* encoder, EventExecutor* executor); |
| 52 |
| 53 // Run the host porcess. This method returns only after the message loop |
| 54 // of the host process exits. |
| 55 void Run(); |
| 56 |
| 57 // This method is called when we need to the host process. |
| 58 void DestroySession(); |
| 59 |
| 60 // This method talks to the cloud to register the host process. If |
| 61 // successful we will start listening to network requests. |
| 62 void RegisterHost(); |
| 63 |
| 64 // This method is called if a client is connected to this object. |
| 65 void OnClientConnected(ClientConnection* client); |
| 66 |
| 67 // This method is called if a client is disconnected from the host. |
| 68 void OnClientDisconnected(ClientConnection* client); |
| 69 |
| 70 //////////////////////////////////////////////////////////////////////////// |
| 71 // ClientConnection::EventHandler implementations |
| 72 virtual void HandleMessages(ClientConnection* client, |
| 73 ClientMessageList* messages); |
| 74 virtual void OnConnectionOpened(ClientConnection* client); |
| 75 virtual void OnConnectionClosed(ClientConnection* client); |
| 76 virtual void OnConnectionFailed(ClientConnection* client); |
| 77 |
| 78 //////////////////////////////////////////////////////////////////////////// |
| 79 // JingleClient::Callback implementations |
| 80 virtual void OnStateChange(JingleClient* client, JingleClient::State state); |
| 81 virtual bool OnAcceptConnection( |
| 82 JingleClient* jingle, const std::string& jid, |
| 83 JingleChannel::Callback** channel_callback); |
| 84 virtual void OnNewConnection( |
| 85 JingleClient* jingle, |
| 86 scoped_refptr<JingleChannel> channel); |
| 87 |
| 88 private: |
| 89 // The message loop that this class runs on. |
| 90 MessageLoop main_loop_; |
| 91 |
| 92 // A thread that hosts capture operations. |
| 93 base::Thread capture_thread_; |
| 94 |
| 95 // A thread that hosts encode operations. |
| 96 base::Thread encode_thread_; |
| 97 |
| 98 std::string username_; |
| 99 std::string password_; |
| 100 |
| 101 // Capturer to be used by SessionManager. Once the SessionManager is |
| 102 // constructed this is set to NULL. |
| 103 scoped_ptr<Capturer> capturer_; |
| 104 |
| 105 // Encoder to be used by the SessionManager. Once the SessionManager is |
| 106 // constructed this is set to NULL. |
| 107 scoped_ptr<Encoder> encoder_; |
| 108 |
| 109 // EventExecutor executes input events received from the client. |
| 110 scoped_ptr<EventExecutor> executor_; |
| 111 |
| 112 // The libjingle client. This is used to connect to the talk network to |
| 113 // receive connection requests from chromoting client. |
| 114 scoped_refptr<JingleClient> jingle_client_; |
| 115 |
| 116 // Objects that takes care of sending heartbeats to the chromoting bot. |
| 117 scoped_refptr<HeartbeatSender> heartbeat_sender_; |
| 118 |
| 119 // A ClientConnection manages the connectino to a remote client. |
| 120 // TODO(hclam): Expand this to a list of clients. |
| 121 scoped_refptr<ClientConnection> client_; |
| 122 |
| 123 // Session manager for the host process. |
| 124 scoped_refptr<SessionManager> session_; |
| 125 |
| 126 DISALLOW_COPY_AND_ASSIGN(SimpleHost); |
| 127 }; |
| 128 |
| 129 } // namespace remoting |
| 130 |
| 131 #endif // REMOTING_HOST_SIMPLE_HOST_H_ |
OLD | NEW |