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
3 // found in the LICENSE file.
5 #include "base/memory/ref_counted_memory.h"
7 #include "base/logging.h"
9 RefCountedMemory::RefCountedMemory() {
12 RefCountedMemory::~RefCountedMemory() {
15 const unsigned char* RefCountedStaticMemory::front() const {
19 size_t RefCountedStaticMemory::size() const {
23 RefCountedBytes::RefCountedBytes() {
26 RefCountedBytes::RefCountedBytes(const std::vector<unsigned char>& initializer)
27 : data_(initializer) {
30 RefCountedBytes* RefCountedBytes::TakeVector(
31 std::vector<unsigned char>* to_destroy) {
32 RefCountedBytes* bytes = new RefCountedBytes;
33 bytes->data_.swap(*to_destroy);
37 const unsigned char* RefCountedBytes::front() const {
38 // STL will assert if we do front() on an empty vector, but calling code
40 return size() ? &data_.front() : NULL;
43 size_t RefCountedBytes::size() const {
47 RefCountedBytes::~RefCountedBytes() {
52 RefCountedString::RefCountedString() {}
54 RefCountedString::~RefCountedString() {}
57 RefCountedString* RefCountedString::TakeString(std::string* to_destroy) {
58 RefCountedString* self = new RefCountedString;
59 to_destroy->swap(self->data_);
63 const unsigned char* RefCountedString::front() const {
64 return data_.empty() ? NULL :
65 reinterpret_cast<const unsigned char*>(data_.data());
68 size_t RefCountedString::size() const {