Speculative fix for the white/stale tab issue on Windows.
[chromium-blink-merge.git] / base / memory / ref_counted_memory.cc
blobb048a6e0d8d2352936e9cb995479058c13f17ba4
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 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);
18 RefCountedMemory::RefCountedMemory() {}
20 RefCountedMemory::~RefCountedMemory() {}
22 const unsigned char* RefCountedStaticMemory::front() const {
23 return data_;
26 size_t RefCountedStaticMemory::size() const {
27 return length_;
30 RefCountedStaticMemory::~RefCountedStaticMemory() {}
32 RefCountedBytes::RefCountedBytes() {}
34 RefCountedBytes::RefCountedBytes(const std::vector<unsigned char>& initializer)
35 : data_(initializer) {
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;
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;
51 size_t RefCountedBytes::size() const {
52 return data_.size();
55 RefCountedBytes::~RefCountedBytes() {}
57 RefCountedString::RefCountedString() {}
59 RefCountedString::~RefCountedString() {}
61 // static
62 RefCountedString* RefCountedString::TakeString(std::string* to_destroy) {
63 RefCountedString* self = new RefCountedString;
64 to_destroy->swap(self->data_);
65 return self;
68 const unsigned char* RefCountedString::front() const {
69 return data_.empty() ? NULL :
70 reinterpret_cast<const unsigned char*>(data_.data());
73 size_t RefCountedString::size() const {
74 return data_.size();
77 } // namespace base