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 <stdlib.h> | 7 #include <stdlib.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 } | 30 } |
31 | 31 |
32 RefCountedStaticMemory::~RefCountedStaticMemory() {} | 32 RefCountedStaticMemory::~RefCountedStaticMemory() {} |
33 | 33 |
34 RefCountedBytes::RefCountedBytes() {} | 34 RefCountedBytes::RefCountedBytes() {} |
35 | 35 |
36 RefCountedBytes::RefCountedBytes(const std::vector<unsigned char>& initializer) | 36 RefCountedBytes::RefCountedBytes(const std::vector<unsigned char>& initializer) |
37 : data_(initializer) { | 37 : data_(initializer) { |
38 } | 38 } |
39 | 39 |
| 40 RefCountedBytes::RefCountedBytes(const unsigned char* p, size_t size) |
| 41 : data_(p, p + size) {} |
| 42 |
40 RefCountedBytes* RefCountedBytes::TakeVector( | 43 RefCountedBytes* RefCountedBytes::TakeVector( |
41 std::vector<unsigned char>* to_destroy) { | 44 std::vector<unsigned char>* to_destroy) { |
42 RefCountedBytes* bytes = new RefCountedBytes; | 45 RefCountedBytes* bytes = new RefCountedBytes; |
43 bytes->data_.swap(*to_destroy); | 46 bytes->data_.swap(*to_destroy); |
44 return bytes; | 47 return bytes; |
45 } | 48 } |
46 | 49 |
47 const unsigned char* RefCountedBytes::front() const { | 50 const unsigned char* RefCountedBytes::front() const { |
48 // STL will assert if we do front() on an empty vector, but calling code | 51 // STL will assert if we do front() on an empty vector, but calling code |
49 // expects a NULL. | 52 // expects a NULL. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 91 |
89 size_t RefCountedMallocedMemory::size() const { | 92 size_t RefCountedMallocedMemory::size() const { |
90 return length_; | 93 return length_; |
91 } | 94 } |
92 | 95 |
93 RefCountedMallocedMemory::~RefCountedMallocedMemory() { | 96 RefCountedMallocedMemory::~RefCountedMallocedMemory() { |
94 free(data_); | 97 free(data_); |
95 } | 98 } |
96 | 99 |
97 } // namespace base | 100 } // namespace base |
OLD | NEW |