| 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 "base/memory/ref_counted_memory.h" | 5 #include "base/memory/ref_counted_memory.h" |
| 6 | 6 |
| 7 #include "base/logging.h" |
| 8 |
| 7 RefCountedMemory::RefCountedMemory() { | 9 RefCountedMemory::RefCountedMemory() { |
| 8 } | 10 } |
| 9 | 11 |
| 10 RefCountedMemory::~RefCountedMemory() { | 12 RefCountedMemory::~RefCountedMemory() { |
| 11 } | 13 } |
| 12 | 14 |
| 13 const unsigned char* RefCountedStaticMemory::front() const { | 15 const unsigned char* RefCountedStaticMemory::front() const { |
| 14 return data_; | 16 return data_; |
| 15 } | 17 } |
| 16 | 18 |
| 17 size_t RefCountedStaticMemory::size() const { | 19 size_t RefCountedStaticMemory::size() const { |
| 18 return length_; | 20 return length_; |
| 19 } | 21 } |
| 20 | 22 |
| 21 RefCountedBytes::RefCountedBytes() { | 23 RefCountedBytes::RefCountedBytes() { |
| 22 } | 24 } |
| 23 | 25 |
| 24 RefCountedBytes::RefCountedBytes(const std::vector<unsigned char>& initializer) | 26 RefCountedBytes::RefCountedBytes(const std::vector<unsigned char>& initializer) |
| 25 : data(initializer) { | 27 : data_(initializer) { |
| 26 } | 28 } |
| 27 | 29 |
| 28 RefCountedBytes* RefCountedBytes::TakeVector( | 30 RefCountedBytes* RefCountedBytes::TakeVector( |
| 29 std::vector<unsigned char>* to_destroy) { | 31 std::vector<unsigned char>* to_destroy) { |
| 30 RefCountedBytes* bytes = new RefCountedBytes; | 32 RefCountedBytes* bytes = new RefCountedBytes; |
| 31 bytes->data.swap(*to_destroy); | 33 bytes->data_.swap(*to_destroy); |
| 32 return bytes; | 34 return bytes; |
| 33 } | 35 } |
| 34 | 36 |
| 35 const unsigned char* RefCountedBytes::front() const { | 37 const unsigned char* RefCountedBytes::front() const { |
| 36 // STL will assert if we do front() on an empty vector, but calling code | 38 // STL will assert if we do front() on an empty vector, but calling code |
| 37 // expects a NULL. | 39 // expects a NULL. |
| 38 return size() ? &data.front() : NULL; | 40 return size() ? &data_.front() : NULL; |
| 39 } | 41 } |
| 40 | 42 |
| 41 size_t RefCountedBytes::size() const { | 43 size_t RefCountedBytes::size() const { |
| 42 return data.size(); | 44 return data_.size(); |
| 43 } | 45 } |
| 44 | 46 |
| 45 RefCountedBytes::~RefCountedBytes() { | 47 RefCountedBytes::~RefCountedBytes() { |
| 46 } | 48 } |
| 49 |
| 50 namespace base { |
| 51 |
| 52 RefCountedString::RefCountedString() {} |
| 53 |
| 54 RefCountedString::~RefCountedString() {} |
| 55 |
| 56 // static |
| 57 RefCountedString* RefCountedString::TakeString(std::string* to_destroy) { |
| 58 RefCountedString* self = new RefCountedString; |
| 59 to_destroy->swap(self->data_); |
| 60 return self; |
| 61 } |
| 62 |
| 63 const unsigned char* RefCountedString::front() const { |
| 64 return data_.empty() ? NULL : |
| 65 reinterpret_cast<const unsigned char*>(data_.data()); |
| 66 } |
| 67 |
| 68 size_t RefCountedString::size() const { |
| 69 return data_.size(); |
| 70 } |
| 71 |
| 72 } // namespace base |
| OLD | NEW |