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