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

Side by Side Diff: net/base/io_buffer.h

Issue 3412016: FBTF: Move a bunch of code to the headers and remove includes. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Rebase + fixed windows issues locally Created 10 years, 3 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
« no previous file with comments | « net/base/host_mapping_rules.cc ('k') | net/base/io_buffer.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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 NET_BASE_IO_BUFFER_H_ 5 #ifndef NET_BASE_IO_BUFFER_H_
6 #define NET_BASE_IO_BUFFER_H_ 6 #define NET_BASE_IO_BUFFER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 28 matching lines...) Expand all
39 // doesn't have to keep track of that value. 39 // doesn't have to keep track of that value.
40 // NOTE: This doesn't mean that we want to stop sending the size as an explicit 40 // NOTE: This doesn't mean that we want to stop sending the size as an explicit
41 // argument to IO functions. Please keep using IOBuffer* for API declarations. 41 // argument to IO functions. Please keep using IOBuffer* for API declarations.
42 class IOBufferWithSize : public IOBuffer { 42 class IOBufferWithSize : public IOBuffer {
43 public: 43 public:
44 explicit IOBufferWithSize(int size); 44 explicit IOBufferWithSize(int size);
45 45
46 int size() const { return size_; } 46 int size() const { return size_; }
47 47
48 private: 48 private:
49 ~IOBufferWithSize() {} 49 virtual ~IOBufferWithSize();
50 50
51 int size_; 51 int size_;
52 }; 52 };
53 53
54 // This is a read only IOBuffer. The data is stored in a string and 54 // This is a read only IOBuffer. The data is stored in a string and
55 // the IOBuffer interface does not provide a proper way to modify it. 55 // the IOBuffer interface does not provide a proper way to modify it.
56 class StringIOBuffer : public IOBuffer { 56 class StringIOBuffer : public IOBuffer {
57 public: 57 public:
58 explicit StringIOBuffer(const std::string& s); 58 explicit StringIOBuffer(const std::string& s);
59 59
60 int size() const { return string_data_.size(); } 60 int size() const { return string_data_.size(); }
61 61
62 private: 62 private:
63 ~StringIOBuffer(); 63 virtual ~StringIOBuffer();
64 64
65 std::string string_data_; 65 std::string string_data_;
66 }; 66 };
67 67
68 // This version wraps an existing IOBuffer and provides convenient functions 68 // This version wraps an existing IOBuffer and provides convenient functions
69 // to progressively read all the data. 69 // to progressively read all the data.
70 class DrainableIOBuffer : public IOBuffer { 70 class DrainableIOBuffer : public IOBuffer {
71 public: 71 public:
72 DrainableIOBuffer(IOBuffer* base, int size); 72 DrainableIOBuffer(IOBuffer* base, int size);
73 73
74 // DidConsume() changes the |data_| pointer so that |data_| always points 74 // DidConsume() changes the |data_| pointer so that |data_| always points
75 // to the first unconsumed byte. 75 // to the first unconsumed byte.
76 void DidConsume(int bytes); 76 void DidConsume(int bytes);
77 77
78 // Returns the number of unconsumed bytes. 78 // Returns the number of unconsumed bytes.
79 int BytesRemaining() const; 79 int BytesRemaining() const;
80 80
81 // Returns the number of consumed bytes. 81 // Returns the number of consumed bytes.
82 int BytesConsumed() const; 82 int BytesConsumed() const;
83 83
84 // Seeks to an arbitrary point in the buffer. The notion of bytes consumed 84 // Seeks to an arbitrary point in the buffer. The notion of bytes consumed
85 // and remaining are updated appropriately. 85 // and remaining are updated appropriately.
86 void SetOffset(int bytes); 86 void SetOffset(int bytes);
87 87
88 int size() const { return size_; } 88 int size() const { return size_; }
89 89
90 private: 90 private:
91 ~DrainableIOBuffer(); 91 virtual ~DrainableIOBuffer();
92 92
93 scoped_refptr<IOBuffer> base_; 93 scoped_refptr<IOBuffer> base_;
94 int size_; 94 int size_;
95 int used_; 95 int used_;
96 }; 96 };
97 97
98 // This version provides a resizable buffer and a changeable offset. 98 // This version provides a resizable buffer and a changeable offset.
99 class GrowableIOBuffer : public IOBuffer { 99 class GrowableIOBuffer : public IOBuffer {
100 public: 100 public:
101 GrowableIOBuffer(); 101 GrowableIOBuffer();
102 102
103 // realloc memory to the specified capacity. 103 // realloc memory to the specified capacity.
104 void SetCapacity(int capacity); 104 void SetCapacity(int capacity);
105 int capacity() { return capacity_; } 105 int capacity() { return capacity_; }
106 106
107 // |offset| moves the |data_| pointer, allowing "seeking" in the data. 107 // |offset| moves the |data_| pointer, allowing "seeking" in the data.
108 void set_offset(int offset); 108 void set_offset(int offset);
109 int offset() { return offset_; } 109 int offset() { return offset_; }
110 110
111 int RemainingCapacity(); 111 int RemainingCapacity();
112 char* StartOfBuffer(); 112 char* StartOfBuffer();
113 113
114 private: 114 private:
115 ~GrowableIOBuffer(); 115 virtual ~GrowableIOBuffer();
116 116
117 scoped_ptr_malloc<char> real_data_; 117 scoped_ptr_malloc<char> real_data_;
118 int capacity_; 118 int capacity_;
119 int offset_; 119 int offset_;
120 }; 120 };
121 121
122 // This versions allows a pickle to be used as the storage for a write-style 122 // This versions allows a pickle to be used as the storage for a write-style
123 // operation, avoiding an extra data copy. 123 // operation, avoiding an extra data copy.
124 class PickledIOBuffer : public IOBuffer { 124 class PickledIOBuffer : public IOBuffer {
125 public: 125 public:
126 PickledIOBuffer(); 126 PickledIOBuffer();
127 127
128 Pickle* pickle() { return &pickle_; } 128 Pickle* pickle() { return &pickle_; }
129 129
130 // Signals that we are done writing to the picke and we can use it for a 130 // Signals that we are done writing to the picke and we can use it for a
131 // write-style IO operation. 131 // write-style IO operation.
132 void Done(); 132 void Done();
133 133
134 private: 134 private:
135 ~PickledIOBuffer(); 135 virtual ~PickledIOBuffer();
136 136
137 Pickle pickle_; 137 Pickle pickle_;
138 }; 138 };
139 139
140 // This class allows the creation of a temporary IOBuffer that doesn't really 140 // This class allows the creation of a temporary IOBuffer that doesn't really
141 // own the underlying buffer. Please use this class only as a last resort. 141 // own the underlying buffer. Please use this class only as a last resort.
142 // A good example is the buffer for a synchronous operation, where we can be 142 // A good example is the buffer for a synchronous operation, where we can be
143 // sure that nobody is keeping an extra reference to this object so the lifetime 143 // sure that nobody is keeping an extra reference to this object so the lifetime
144 // of the buffer can be completely managed by its intended owner. 144 // of the buffer can be completely managed by its intended owner.
145 class WrappedIOBuffer : public IOBuffer { 145 class WrappedIOBuffer : public IOBuffer {
146 public: 146 public:
147 explicit WrappedIOBuffer(const char* data); 147 explicit WrappedIOBuffer(const char* data);
148 148
149 protected: 149 protected:
150 ~WrappedIOBuffer(); 150 virtual ~WrappedIOBuffer();
151 }; 151 };
152 152
153 } // namespace net 153 } // namespace net
154 154
155 #endif // NET_BASE_IO_BUFFER_H_ 155 #endif // NET_BASE_IO_BUFFER_H_
OLDNEW
« no previous file with comments | « net/base/host_mapping_rules.cc ('k') | net/base/io_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698