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

Side by Side Diff: remoting/protocol/message_reader.h

Issue 850983002: Implement video frame acknowledgements in the chromoting protocol. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_PROTOCOL_MESSAGE_READER_H_ 5 #ifndef REMOTING_PROTOCOL_MESSAGE_READER_H_
6 #define REMOTING_PROTOCOL_MESSAGE_READER_H_ 6 #define REMOTING_PROTOCOL_MESSAGE_READER_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "base/threading/non_thread_safe.h" 11 #include "base/threading/non_thread_safe.h"
12 #include "base/time/time.h"
12 #include "remoting/base/compound_buffer.h" 13 #include "remoting/base/compound_buffer.h"
13 #include "remoting/protocol/message_decoder.h" 14 #include "remoting/protocol/message_decoder.h"
14 15
15 namespace net { 16 namespace net {
16 class IOBuffer; 17 class IOBuffer;
17 class Socket; 18 class Socket;
18 } // namespace net 19 } // namespace net
19 20
20 namespace remoting { 21 namespace remoting {
21 namespace protocol { 22 namespace protocol {
(...skipping 16 matching lines...) Expand all
38 39
39 MessageReader(); 40 MessageReader();
40 virtual ~MessageReader(); 41 virtual ~MessageReader();
41 42
42 // Sets the callback to be called for each incoming message. 43 // Sets the callback to be called for each incoming message.
43 void SetMessageReceivedCallback(const MessageReceivedCallback& callback); 44 void SetMessageReceivedCallback(const MessageReceivedCallback& callback);
44 45
45 // Starts reading from |socket|. 46 // Starts reading from |socket|.
46 void StartReading(net::Socket* socket); 47 void StartReading(net::Socket* socket);
47 48
49 // The time delta between first and last bytes of the last message for which
50 // MessageReceivedCallback has been invoked.
51 base::TimeDelta last_message_read_duration() {
52 return last_message_read_duration_;
53 }
54
48 private: 55 private:
49 void DoRead(); 56 void DoRead();
50 void OnRead(int result); 57 void OnRead(int result);
51 void HandleReadResult(int result); 58 void HandleReadResult(int result);
52 void OnDataReceived(net::IOBuffer* data, int data_size); 59 void OnDataReceived(net::IOBuffer* data, int data_size);
53 void RunCallback(scoped_ptr<CompoundBuffer> message); 60 void RunCallback(scoped_ptr<CompoundBuffer> message,
61 base::TimeDelta read_duration);
54 void OnMessageDone(); 62 void OnMessageDone();
55 63
56 net::Socket* socket_; 64 net::Socket* socket_;
57 65
58 // Set to true, when we have a socket read pending, and expecting 66 // Set to true, when we have a socket read pending, and expecting
59 // OnRead() to be called when new data is received. 67 // OnRead() to be called when new data is received.
60 bool read_pending_; 68 bool read_pending_;
61 69
62 // Number of messages that we received, but haven't finished 70 // Number of messages that we received, but haven't finished
63 // processing yet, i.e. |done_task| hasn't been called for these 71 // processing yet, i.e. |done_task| hasn't been called for these
64 // messages. 72 // messages.
65 int pending_messages_; 73 int pending_messages_;
66 74
67 bool closed_; 75 bool closed_;
68 scoped_refptr<net::IOBuffer> read_buffer_; 76 scoped_refptr<net::IOBuffer> read_buffer_;
69 77
70 MessageDecoder message_decoder_; 78 MessageDecoder message_decoder_;
71 79
72 // Callback is called when a message is received. 80 // Callback is called when a message is received.
73 MessageReceivedCallback message_received_callback_; 81 MessageReceivedCallback message_received_callback_;
74 82
83 // Used to track the time taken to receive each message.
84 base::TimeTicks last_message_started_time_;
85 base::TimeDelta last_message_read_duration_;
86
75 base::WeakPtrFactory<MessageReader> weak_factory_; 87 base::WeakPtrFactory<MessageReader> weak_factory_;
76 88
77 DISALLOW_COPY_AND_ASSIGN(MessageReader); 89 DISALLOW_COPY_AND_ASSIGN(MessageReader);
78 }; 90 };
79 91
80 } // namespace protocol 92 } // namespace protocol
81 } // namespace remoting 93 } // namespace remoting
82 94
83 #endif // REMOTING_PROTOCOL_MESSAGE_READER_H_ 95 #endif // REMOTING_PROTOCOL_MESSAGE_READER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698