Update .DEPS.git
[chromium-blink-merge.git] / base / memory / ref_counted_memory.cc
blob9bcde32b60ec77bb1bc88721256f59d0e3f9f67b
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"
9 namespace base {
11 RefCountedMemory::RefCountedMemory() {}
13 RefCountedMemory::~RefCountedMemory() {}
15 const unsigned char* RefCountedStaticMemory::front() const {
16 return data_;
19 size_t RefCountedStaticMemory::size() const {
20 return length_;
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);
35 return bytes;
38 const unsigned char* RefCountedBytes::front() const {
39 // STL will assert if we do front() on an empty vector, but calling code
40 // expects a NULL.
41 return size() ? &data_.front() : NULL;
44 size_t RefCountedBytes::size() const {
45 return data_.size();
48 RefCountedBytes::~RefCountedBytes() {}
50 RefCountedString::RefCountedString() {}
52 RefCountedString::~RefCountedString() {}
54 // static
55 RefCountedString* RefCountedString::TakeString(std::string* to_destroy) {
56 RefCountedString* self = new RefCountedString;
57 to_destroy->swap(self->data_);
58 return self;
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 {
67 return data_.size();
70 } // namespace base