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

Side by Side Diff: remoting/base/multiple_array_input_stream.h

Issue 4017002: HostMessageDispatcher to parse control messages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged again Created 10 years, 1 month 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 | « no previous file | remoting/base/multiple_array_input_stream.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // MultipleArrayInputStream implements ZeroCopyInputStream to be used by
6 // protobuf to decode bytes into a protocol buffer message.
7 //
8 // This input stream is made of multiple IOBuffers received from the network.
9 // This object retains the IOBuffers added to it.
10 //
11 // Internally, we wrap each added IOBuffer in a DrainableIOBuffer. This allows
12 // us to track how much data has been consumed from each IOBuffer.
13
5 #ifndef REMOTING_BASE_MULTIPLE_ARRAY_INPUT_STREAM_H_ 14 #ifndef REMOTING_BASE_MULTIPLE_ARRAY_INPUT_STREAM_H_
6 #define REMOTING_BASE_MULTIPLE_ARRAY_INPUT_STREAM_H_ 15 #define REMOTING_BASE_MULTIPLE_ARRAY_INPUT_STREAM_H_
7 16
8 #include <vector> 17 #include <vector>
9 18
10 #include "base/basictypes.h" 19 #include "base/basictypes.h"
20 #include "base/ref_counted.h"
11 #include "google/protobuf/io/zero_copy_stream.h" 21 #include "google/protobuf/io/zero_copy_stream.h"
12 22
23 namespace net {
24 class DrainableIOBuffer;
25 class IOBuffer;
26 } // namespace net
27
13 namespace remoting { 28 namespace remoting {
14 29
15 // A MultipleArrayInputStream provides a ZeroCopyInputStream with multiple
16 // backing arrays.
17 class MultipleArrayInputStream : 30 class MultipleArrayInputStream :
18 public google::protobuf::io::ZeroCopyInputStream { 31 public google::protobuf::io::ZeroCopyInputStream {
19 public: 32 public:
20 // Construct a MultipleArrayInputStream with |count| backing arrays.
21 // TODO(hclam): Consider adding block size to see if it has a performance
22 // gain.
23 MultipleArrayInputStream(); 33 MultipleArrayInputStream();
24 virtual ~MultipleArrayInputStream(); 34 virtual ~MultipleArrayInputStream();
25 35
26 // Add a new buffer to the list. 36 // Add a buffer to the list. |buffer| is retained by this object.
27 void AddBuffer(const char* buffer, int size); 37 void AddBuffer(net::IOBuffer* buffer, int size);
28 38
29 // google::protobuf::io::ZeroCopyInputStream interface. 39 // google::protobuf::io::ZeroCopyInputStream interface.
30 virtual bool Next(const void** data, int* size); 40 virtual bool Next(const void** data, int* size);
31 virtual void BackUp(int count); 41 virtual void BackUp(int count);
32 virtual bool Skip(int count); 42 virtual bool Skip(int count);
33 virtual int64 ByteCount() const; 43 virtual int64 ByteCount() const;
34 44
35 private: 45 private:
36 std::vector<const char*> buffers_; 46 std::vector<scoped_refptr<net::DrainableIOBuffer> > buffers_;
37 std::vector<int> buffer_sizes_;
38 47
39 size_t current_buffer_; 48 size_t current_buffer_;
40 int current_buffer_offset_;
41 int position_; 49 int position_;
42 int last_returned_size_; 50 int last_returned_size_;
43 51
44 DISALLOW_COPY_AND_ASSIGN(MultipleArrayInputStream); 52 DISALLOW_COPY_AND_ASSIGN(MultipleArrayInputStream);
45 }; 53 };
46 54
47 } // namespace remoting 55 } // namespace remoting
48 56
49 #endif // REMOTING_BASE_MULTIPLE_ARRAY_INPUT_STREAM_H_ 57 #endif // REMOTING_BASE_MULTIPLE_ARRAY_INPUT_STREAM_H_
OLDNEW
« no previous file with comments | « no previous file | remoting/base/multiple_array_input_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698