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

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

Issue 338049: Handle out of memory in GrowableIOBuffer more gracefully.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | net/base/io_buffer.cc » ('j') | net/base/io_buffer.cc » ('J')
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 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/ref_counted.h" 10 #include "base/ref_counted.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 int size_; 99 int size_;
100 int used_; 100 int used_;
101 }; 101 };
102 102
103 // This version provides a resizable buffer and a changeable offset. 103 // This version provides a resizable buffer and a changeable offset.
104 class GrowableIOBuffer : public IOBuffer { 104 class GrowableIOBuffer : public IOBuffer {
105 public: 105 public:
106 GrowableIOBuffer() : IOBuffer(), capacity_(0), offset_(0) {} 106 GrowableIOBuffer() : IOBuffer(), capacity_(0), offset_(0) {}
107 ~GrowableIOBuffer() { data_ = NULL; } 107 ~GrowableIOBuffer() { data_ = NULL; }
108 108
109
110 // realloc memory to the specified capacity. On failure, the capacity
wtc 2009/10/27 22:42:10 You need to document that true means success and f
111 // and buffer are unchanged.
112 bool SetCapacity(int capacity);
109 int capacity() { return capacity_; } 113 int capacity() { return capacity_; }
110 void set_capacity(int capacity);
111 114
112 // |offset| moves the |data_| pointer, allowing "seeking" in the data. 115 // |offset| moves the |data_| pointer, allowing "seeking" in the data.
116 void set_offset(int offset);
113 int offset() { return offset_; } 117 int offset() { return offset_; }
114 void set_offset(int offset);
115 118
116 int RemainingCapacity() { return capacity_ - offset_; } 119 int RemainingCapacity() { return capacity_ - offset_; }
117 char* StartOfBuffer() { return real_data_.get(); } 120 char* StartOfBuffer() { return real_data_.get(); }
118 121
119 private: 122 private:
120 scoped_ptr_malloc<char> real_data_; 123 scoped_ptr_malloc<char> real_data_;
121 int capacity_; 124 int capacity_;
122 int offset_; 125 int offset_;
123 }; 126 };
124 127
125 // This class allows the creation of a temporary IOBuffer that doesn't really 128 // This class allows the creation of a temporary IOBuffer that doesn't really
126 // own the underlying buffer. Please use this class only as a last resort. 129 // own the underlying buffer. Please use this class only as a last resort.
127 // A good example is the buffer for a synchronous operation, where we can be 130 // A good example is the buffer for a synchronous operation, where we can be
128 // sure that nobody is keeping an extra reference to this object so the lifetime 131 // sure that nobody is keeping an extra reference to this object so the lifetime
129 // of the buffer can be completely managed by its intended owner. 132 // of the buffer can be completely managed by its intended owner.
130 class WrappedIOBuffer : public IOBuffer { 133 class WrappedIOBuffer : public IOBuffer {
131 public: 134 public:
132 explicit WrappedIOBuffer(const char* data) 135 explicit WrappedIOBuffer(const char* data)
133 : IOBuffer(const_cast<char*>(data)) {} 136 : IOBuffer(const_cast<char*>(data)) {}
134 ~WrappedIOBuffer() { 137 ~WrappedIOBuffer() {
135 data_ = NULL; 138 data_ = NULL;
136 } 139 }
137 }; 140 };
138 141
139 } // namespace net 142 } // namespace net
140 143
141 #endif // NET_BASE_IO_BUFFER_H_ 144 #endif // NET_BASE_IO_BUFFER_H_
OLDNEW
« no previous file with comments | « no previous file | net/base/io_buffer.cc » ('j') | net/base/io_buffer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698