| 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_HOST_CLIENT_CONNECTION_H_ | 5 #ifndef REMOTING_HOST_CLIENT_CONNECTION_H_ |
| 6 #define REMOTING_HOST_CLIENT_CONNECTION_H_ | 6 #define REMOTING_HOST_CLIENT_CONNECTION_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
| 13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
| 14 #include "remoting/proto/internal.pb.h" | 14 #include "remoting/proto/internal.pb.h" |
| 15 #include "remoting/protocol/chromotocol_connection.h" | |
| 16 #include "remoting/protocol/message_reader.h" | 15 #include "remoting/protocol/message_reader.h" |
| 16 #include "remoting/protocol/session.h" |
| 17 #include "remoting/protocol/stream_writer.h" | 17 #include "remoting/protocol/stream_writer.h" |
| 18 #include "remoting/protocol/video_writer.h" | 18 #include "remoting/protocol/video_writer.h" |
| 19 | 19 |
| 20 namespace remoting { | 20 namespace remoting { |
| 21 | 21 |
| 22 // This class represents a remote viewer connected to the chromoting host | 22 // This class represents a remote viewer connected to the chromoting host |
| 23 // through a libjingle connection. A viewer object is responsible for sending | 23 // through a libjingle connection. A viewer object is responsible for sending |
| 24 // screen updates and other messages to the remote viewer. It is also | 24 // screen updates and other messages to the remote viewer. It is also |
| 25 // responsible for receiving and parsing data from the remote viewer and | 25 // responsible for receiving and parsing data from the remote viewer and |
| 26 // delegating events to the event handler. | 26 // delegating events to the event handler. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 49 | 49 |
| 50 // Constructs a ClientConnection object. |message_loop| is the message loop | 50 // Constructs a ClientConnection object. |message_loop| is the message loop |
| 51 // that this object runs on. A viewer object receives events and messages from | 51 // that this object runs on. A viewer object receives events and messages from |
| 52 // a libjingle channel, these events are delegated to |handler|. | 52 // a libjingle channel, these events are delegated to |handler|. |
| 53 // It is guranteed that |handler| is called only on the |message_loop|. | 53 // It is guranteed that |handler| is called only on the |message_loop|. |
| 54 ClientConnection(MessageLoop* message_loop, | 54 ClientConnection(MessageLoop* message_loop, |
| 55 EventHandler* handler); | 55 EventHandler* handler); |
| 56 | 56 |
| 57 virtual ~ClientConnection(); | 57 virtual ~ClientConnection(); |
| 58 | 58 |
| 59 virtual void Init(ChromotocolConnection* connection); | 59 virtual void Init(protocol::Session* session); |
| 60 | 60 |
| 61 // Returns the connection in use. | 61 // Returns the connection in use. |
| 62 virtual ChromotocolConnection* connection(); | 62 virtual protocol::Session* session(); |
| 63 | 63 |
| 64 // Send information to the client for initialization. | 64 // Send information to the client for initialization. |
| 65 virtual void SendInitClientMessage(int width, int height); | 65 virtual void SendInitClientMessage(int width, int height); |
| 66 | 66 |
| 67 // Send encoded update stream data to the viewer. | 67 // Send encoded update stream data to the viewer. |
| 68 virtual void SendVideoPacket(const VideoPacket& packet); | 68 virtual void SendVideoPacket(const VideoPacket& packet); |
| 69 | 69 |
| 70 // Gets the number of update stream messages not yet transmitted. | 70 // Gets the number of update stream messages not yet transmitted. |
| 71 // Note that the value returned is an estimate using average size of the | 71 // Note that the value returned is an estimate using average size of the |
| 72 // most recent update streams. | 72 // most recent update streams. |
| 73 // TODO(hclam): Report this number accurately. | 73 // TODO(hclam): Report this number accurately. |
| 74 virtual int GetPendingUpdateStreamMessages(); | 74 virtual int GetPendingUpdateStreamMessages(); |
| 75 | 75 |
| 76 // Disconnect the client connection. This method is allowed to be called | 76 // Disconnect the client connection. This method is allowed to be called |
| 77 // more than once and calls after the first one will be ignored. | 77 // more than once and calls after the first one will be ignored. |
| 78 // | 78 // |
| 79 // After this method is called all the send method calls will be ignored. | 79 // After this method is called all the send method calls will be ignored. |
| 80 virtual void Disconnect(); | 80 virtual void Disconnect(); |
| 81 | 81 |
| 82 protected: | 82 protected: |
| 83 // Protected constructor used by unit test. | 83 // Protected constructor used by unit test. |
| 84 ClientConnection(); | 84 ClientConnection(); |
| 85 | 85 |
| 86 private: | 86 private: |
| 87 // Callback for ChromotocolConnection. | 87 // Callback for protocol Session. |
| 88 void OnConnectionStateChange(ChromotocolConnection::State state); | 88 void OnSessionStateChange(protocol::Session::State state); |
| 89 | 89 |
| 90 // Callback for MessageReader. | 90 // Callback for MessageReader. |
| 91 void OnMessageReceived(ChromotingClientMessage* message); | 91 void OnMessageReceived(ChromotingClientMessage* message); |
| 92 | 92 |
| 93 // Process a libjingle state change event on the |loop_|. | 93 // Process a libjingle state change event on the |loop_|. |
| 94 void StateChangeTask(ChromotocolConnection::State state); | 94 void StateChangeTask(protocol::Session::State state); |
| 95 | 95 |
| 96 // Process a data buffer received from libjingle. | 96 // Process a data buffer received from libjingle. |
| 97 void MessageReceivedTask(ChromotingClientMessage* message); | 97 void MessageReceivedTask(ChromotingClientMessage* message); |
| 98 | 98 |
| 99 void OnClosed(); | 99 void OnClosed(); |
| 100 | 100 |
| 101 // The libjingle channel used to send and receive data from the remote client. | 101 // The libjingle channel used to send and receive data from the remote client. |
| 102 scoped_refptr<ChromotocolConnection> connection_; | 102 scoped_refptr<protocol::Session> session_; |
| 103 | 103 |
| 104 ControlStreamWriter control_writer_; | 104 ControlStreamWriter control_writer_; |
| 105 MessageReader event_reader_; | 105 MessageReader event_reader_; |
| 106 scoped_ptr<VideoWriter> video_writer_; | 106 scoped_ptr<VideoWriter> video_writer_; |
| 107 | 107 |
| 108 // The message loop that this object runs on. | 108 // The message loop that this object runs on. |
| 109 MessageLoop* loop_; | 109 MessageLoop* loop_; |
| 110 | 110 |
| 111 // Event handler for handling events sent from this object. | 111 // Event handler for handling events sent from this object. |
| 112 EventHandler* handler_; | 112 EventHandler* handler_; |
| 113 | 113 |
| 114 DISALLOW_COPY_AND_ASSIGN(ClientConnection); | 114 DISALLOW_COPY_AND_ASSIGN(ClientConnection); |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 } // namespace remoting | 117 } // namespace remoting |
| 118 | 118 |
| 119 #endif // REMOTING_HOST_CLIENT_CONNECTION_H_ | 119 #endif // REMOTING_HOST_CLIENT_CONNECTION_H_ |
| OLD | NEW |