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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 CHECK_LT(s.size(), static_cast<size_t>(INT_MAX)); | 45 CHECK_LT(s.size(), static_cast<size_t>(INT_MAX)); |
| 46 data_ = const_cast<char*>(string_data_.data()); | 46 data_ = const_cast<char*>(string_data_.data()); |
| 47 } | 47 } |
| 48 | 48 |
| 49 StringIOBuffer::~StringIOBuffer() { | 49 StringIOBuffer::~StringIOBuffer() { |
| 50 // We haven't allocated the buffer, so remove it before the base class | 50 // We haven't allocated the buffer, so remove it before the base class |
| 51 // destructor tries to delete[] it. | 51 // destructor tries to delete[] it. |
| 52 data_ = NULL; | 52 data_ = NULL; |
| 53 } | 53 } |
| 54 | 54 |
| 55 ZeroCopyStringIOBuffer::ZeroCopyStringIOBuffer(std::string* s) : IOBuffer() { | |
| 56 string_.swap(*s); | |
| 57 CHECK_LT(s->size(), static_cast<size_t>(INT_MAX)); | |
| 58 data_ = const_cast<char*>(string_.data()); | |
| 59 } | |
| 60 | |
| 61 ZeroCopyStringIOBuffer::~ZeroCopyStringIOBuffer() { | |
| 62 data_ = NULL; | |
|
michaeln
2014/08/14 22:59:01
is this needed? oh i see the comment in ~StringIOB
jkarlin
2014/08/15 11:49:44
No longer necessary after merge into StringIOBuffe
| |
| 63 } | |
| 64 | |
| 55 DrainableIOBuffer::DrainableIOBuffer(IOBuffer* base, int size) | 65 DrainableIOBuffer::DrainableIOBuffer(IOBuffer* base, int size) |
| 56 : IOBuffer(base->data()), | 66 : IOBuffer(base->data()), |
| 57 base_(base), | 67 base_(base), |
| 58 size_(size), | 68 size_(size), |
| 59 used_(0) { | 69 used_(0) { |
| 60 } | 70 } |
| 61 | 71 |
| 62 void DrainableIOBuffer::DidConsume(int bytes) { | 72 void DrainableIOBuffer::DidConsume(int bytes) { |
| 63 SetOffset(used_ + bytes); | 73 SetOffset(used_ + bytes); |
| 64 } | 74 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 | 140 |
| 131 WrappedIOBuffer::WrappedIOBuffer(const char* data) | 141 WrappedIOBuffer::WrappedIOBuffer(const char* data) |
| 132 : IOBuffer(const_cast<char*>(data)) { | 142 : IOBuffer(const_cast<char*>(data)) { |
| 133 } | 143 } |
| 134 | 144 |
| 135 WrappedIOBuffer::~WrappedIOBuffer() { | 145 WrappedIOBuffer::~WrappedIOBuffer() { |
| 136 data_ = NULL; | 146 data_ = NULL; |
| 137 } | 147 } |
| 138 | 148 |
| 139 } // namespace net | 149 } // namespace net |
| OLD | NEW |