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