Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(993)

Side by Side Diff: remoting/host/client_connection.h

Issue 2690003: Copy the (early prototype of) remoting in Chrome into the public tree.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/host/capturer_mac_unittest.cc ('k') | remoting/host/client_connection.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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_HOST_CLIENT_CONNECTION_H_
6 #define REMOTING_HOST_CLIENT_CONNECTION_H_
7
8 #include <deque>
9 #include <vector>
10
11 #include "base/message_loop.h"
12 #include "base/ref_counted.h"
13 #include "base/scoped_ptr.h"
14 #include "remoting/base/protocol_decoder.h"
15 #include "remoting/base/protocol/chromotocol.pb.h"
16 #include "remoting/jingle_glue/jingle_channel.h"
17
18 namespace media {
19
20 class DataBuffer;
21
22 } // namespace media
23
24 namespace remoting {
25
26 // This class represents a remote viewer connected to the chromoting host
27 // through a libjingle connection. A viewer object is responsible for sending
28 // screen updates and other messages to the remote viewer. It is also
29 // responsible for receiving and parsing data from the remote viewer and
30 // delegating events to the event handler.
31 class ClientConnection : public base::RefCountedThreadSafe<ClientConnection>,
32 public JingleChannel::Callback {
33 public:
34 class EventHandler {
35 public:
36 virtual ~EventHandler() {}
37
38 // Handles an event received by the ClientConnection. Receiver will own the
39 // ClientMessages in ClientMessageList and needs to delete them.
40 // Note that the sender of messages will not reference messages
41 // again so it is okay to clear |messages| in this method.
42 virtual void HandleMessages(ClientConnection* viewer,
43 ClientMessageList* messages) = 0;
44
45 // Called when the network connection is opened.
46 virtual void OnConnectionOpened(ClientConnection* viewer) = 0;
47
48 // Called when the network connection is closed.
49 virtual void OnConnectionClosed(ClientConnection* viewer) = 0;
50
51 // Called when the network connection has failed.
52 virtual void OnConnectionFailed(ClientConnection* viewer) = 0;
53 };
54
55 // Constructs a ClientConnection object. |message_loop| is the message loop
56 // that this object runs on. A viewer object receives events and messages from
57 // a libjingle channel, these events are delegated to |handler|.
58 // It is guranteed that |handler| is called only on the |message_loop|.
59 ClientConnection(MessageLoop* message_loop,
60 ProtocolDecoder* decoder,
61 EventHandler* handler);
62
63 virtual ~ClientConnection();
64
65 virtual void set_jingle_channel(JingleChannel* channel) {
66 channel_ = channel;
67 }
68
69 // Returns the channel in use.
70 virtual JingleChannel* jingle_channel() { return channel_; }
71
72 // Send information to the client for initialization.
73 virtual void SendInitClientMessage(int width, int height);
74
75 // Notifies the viewer the start of an update stream.
76 virtual void SendBeginUpdateStreamMessage();
77
78 // Send encoded update stream data to the viewer. The viewer
79 // should not take ownership of the data.
80 virtual void SendUpdateStreamPacketMessage(
81 chromotocol_pb::UpdateStreamPacketHeader* header,
82 scoped_refptr<media::DataBuffer> data);
83
84 // Notifies the viewer the update stream has ended.
85 virtual void SendEndUpdateStreamMessage();
86
87 // Gets the number of update stream messages not yet transmitted.
88 // Note that the value returned is an estimate using average size of the
89 // most recent update streams.
90 // TODO(hclam): Report this number accurately.
91 virtual int GetPendingUpdateStreamMessages();
92
93 // Disconnect the remote viewer.
94 virtual void Disconnect();
95
96 /////////////////////////////////////////////////////////////////////////////
97 // JingleChannel::Callback implmentations
98 virtual void OnStateChange(JingleChannel* channel,
99 JingleChannel::State state);
100 virtual void OnPacketReceived(JingleChannel* channel,
101 scoped_refptr<media::DataBuffer> data);
102
103 protected:
104 // Protected constructor used by unit test.
105 ClientConnection() {}
106
107 private:
108 // Process a libjingle state change event on the |loop_|.
109 void StateChangeTask(JingleChannel::State state);
110
111 // Process a data buffer received from libjingle.
112 void PacketReceivedTask(scoped_refptr<media::DataBuffer> data);
113
114 // The libjingle channel used to send and receive data from the remote viewer.
115 scoped_refptr<JingleChannel> channel_;
116
117 // The message loop that this object runs on.
118 MessageLoop* loop_;
119
120 // An object used by the ClientConnection to decode data received from the
121 // network.
122 scoped_ptr<ProtocolDecoder> decoder_;
123
124 // A queue to count the sizes of the last 10 update streams.
125 std::deque<int> size_queue_;
126
127 // Count the sum of sizes in the queue.
128 int size_in_queue_;
129
130 // Measure the number of bytes of the current upstream stream.
131 int update_stream_size_;
132
133 // Event handler for handling events sent from this object.
134 EventHandler* handler_;
135
136 DISALLOW_COPY_AND_ASSIGN(ClientConnection);
137 };
138
139 } // namespace remoting
140
141 #endif // REMOTING_HOST_CLIENT_CONNECTION_H_
OLDNEW
« no previous file with comments | « remoting/host/capturer_mac_unittest.cc ('k') | remoting/host/client_connection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698