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
3 // found in the LICENSE file.
5 #include "base/memory/ref_counted_memory.h"
7 #include "base/logging.h"
11 RefCountedMemory::RefCountedMemory() {}
13 RefCountedMemory::~RefCountedMemory() {}
15 const unsigned char* RefCountedStaticMemory::front() const {
19 size_t RefCountedStaticMemory::size() const {
23 RefCountedStaticMemory::~RefCountedStaticMemory() {}
25 RefCountedBytes::RefCountedBytes() {}
27 RefCountedBytes::RefCountedBytes(const std::vector
<unsigned char>& initializer
)
28 : data_(initializer
) {
31 RefCountedBytes
* RefCountedBytes::TakeVector(
32 std::vector
<unsigned char>* to_destroy
) {
33 RefCountedBytes
* bytes
= new RefCountedBytes
;
34 bytes
->data_
.swap(*to_destroy
);
38 const unsigned char* RefCountedBytes::front() const {
39 // STL will assert if we do front() on an empty vector, but calling code
41 return size() ? &data_
.front() : NULL
;
44 size_t RefCountedBytes::size() const {
48 RefCountedBytes::~RefCountedBytes() {}
50 RefCountedString::RefCountedString() {}
52 RefCountedString::~RefCountedString() {}
55 RefCountedString
* RefCountedString::TakeString(std::string
* to_destroy
) {
56 RefCountedString
* self
= new RefCountedString
;
57 to_destroy
->swap(self
->data_
);
61 const unsigned char* RefCountedString::front() const {
62 return data_
.empty() ? NULL
:
63 reinterpret_cast<const unsigned char*>(data_
.data());
66 size_t RefCountedString::size() const {