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