Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "net/base/io_buffer.h" | 5 #include "net/base/io_buffer.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 | 8 |
| 9 namespace net { | 9 namespace net { |
| 10 | 10 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 DCHECK_LE(bytes, size_); | 76 DCHECK_LE(bytes, size_); |
| 77 used_ = bytes; | 77 used_ = bytes; |
| 78 data_ = base_->data() + used_; | 78 data_ = base_->data() + used_; |
| 79 } | 79 } |
| 80 | 80 |
| 81 DrainableIOBuffer::~DrainableIOBuffer() { | 81 DrainableIOBuffer::~DrainableIOBuffer() { |
| 82 // The buffer is owned by the |base_| instance. | 82 // The buffer is owned by the |base_| instance. |
| 83 data_ = NULL; | 83 data_ = NULL; |
| 84 } | 84 } |
| 85 | 85 |
| 86 SeekableIOBuffer::SeekableIOBuffer(int capacity) | |
| 87 : IOBuffer(capacity), | |
| 88 real_data_(data_), | |
| 89 capacity_(capacity), | |
| 90 size_(0), | |
| 91 used_(0) { | |
| 92 } | |
| 93 | |
| 94 void SeekableIOBuffer::DidConsume(int bytes) { | |
| 95 SetOffset(used_ + bytes); | |
| 96 } | |
| 97 | |
| 98 int SeekableIOBuffer::BytesRemaining() const { | |
| 99 return size_ - used_; | |
| 100 } | |
| 101 | |
| 102 void SeekableIOBuffer::SetOffset(int bytes) { | |
| 103 DCHECK_GE(bytes, 0); | |
| 104 DCHECK_LE(bytes, size_); | |
| 105 used_ = bytes; | |
| 106 data_ = real_data_ + used_; | |
| 107 } | |
| 108 | |
| 109 void SeekableIOBuffer::DidAppend(int bytes) { | |
|
rvargas (doing something else)
2012/02/03 23:13:34
Add a dcheck for bytes > 0 (or >= )
satorux1
2012/02/03 23:46:11
Done.
| |
| 110 DCHECK_GE(size_ + bytes, 0); | |
| 111 DCHECK_LE(size_ + bytes, capacity_); | |
| 112 size_ += bytes; | |
| 113 } | |
| 114 | |
| 115 void SeekableIOBuffer::Clear() { | |
| 116 size_ = 0; | |
| 117 SetOffset(0); | |
| 118 } | |
| 119 | |
| 120 SeekableIOBuffer::~SeekableIOBuffer() { | |
| 121 // data_ will be deleted in IOBuffer::~IOBuffer(). | |
| 122 data_ = real_data_; | |
| 123 } | |
| 124 | |
| 86 GrowableIOBuffer::GrowableIOBuffer() | 125 GrowableIOBuffer::GrowableIOBuffer() |
| 87 : IOBuffer(), | 126 : IOBuffer(), |
| 88 capacity_(0), | 127 capacity_(0), |
| 89 offset_(0) { | 128 offset_(0) { |
| 90 } | 129 } |
| 91 | 130 |
| 92 void GrowableIOBuffer::SetCapacity(int capacity) { | 131 void GrowableIOBuffer::SetCapacity(int capacity) { |
| 93 DCHECK_GE(capacity, 0); | 132 DCHECK_GE(capacity, 0); |
| 94 // realloc will crash if it fails. | 133 // realloc will crash if it fails. |
| 95 real_data_.reset(static_cast<char*>(realloc(real_data_.release(), capacity))); | 134 real_data_.reset(static_cast<char*>(realloc(real_data_.release(), capacity))); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 | 168 |
| 130 WrappedIOBuffer::WrappedIOBuffer(const char* data) | 169 WrappedIOBuffer::WrappedIOBuffer(const char* data) |
| 131 : IOBuffer(const_cast<char*>(data)) { | 170 : IOBuffer(const_cast<char*>(data)) { |
| 132 } | 171 } |
| 133 | 172 |
| 134 WrappedIOBuffer::~WrappedIOBuffer() { | 173 WrappedIOBuffer::~WrappedIOBuffer() { |
| 135 data_ = NULL; | 174 data_ = NULL; |
| 136 } | 175 } |
| 137 | 176 |
| 138 } // namespace net | 177 } // namespace net |
| OLD | NEW |