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