diff options
Diffstat (limited to 'base')
-rw-r--r-- | base/base.gypi | 1 | ||||
-rw-r--r-- | base/ref_counted_memory.cc | 37 | ||||
-rw-r--r-- | base/ref_counted_memory.h | 27 |
3 files changed, 47 insertions, 18 deletions
diff --git a/base/base.gypi b/base/base.gypi index 2553ab5..cad0256 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -176,6 +176,7 @@ 'raw_scoped_refptr_mismatch_checker.h', 'ref_counted.cc', 'ref_counted.h', + 'ref_counted_memory.cc', 'ref_counted_memory.h', 'registry.cc', 'registry.h', diff --git a/base/ref_counted_memory.cc b/base/ref_counted_memory.cc new file mode 100644 index 0000000..04a2634 --- /dev/null +++ b/base/ref_counted_memory.cc @@ -0,0 +1,37 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/ref_counted_memory.h" + +const unsigned char* RefCountedStaticMemory::front() const { + return data_; +} + +size_t RefCountedStaticMemory::size() const { + return length_; +} + +RefCountedBytes* RefCountedBytes::TakeVector( + std::vector<unsigned char>* to_destroy) { + RefCountedBytes* bytes = new RefCountedBytes; + bytes->data.swap(*to_destroy); + return bytes; +} + +RefCountedBytes::RefCountedBytes() { +} + +RefCountedBytes::RefCountedBytes(const std::vector<unsigned char>& initializer) + : data(initializer) { +} + +const unsigned char* RefCountedBytes::front() const { + // STL will assert if we do front() on an empty vector, but calling code + // expects a NULL. + return size() ? &data.front() : NULL; +} + +size_t RefCountedBytes::size() const { + return data.size(); +} diff --git a/base/ref_counted_memory.h b/base/ref_counted_memory.h index a5323cd..9ff8335 100644 --- a/base/ref_counted_memory.h +++ b/base/ref_counted_memory.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -40,8 +40,8 @@ class RefCountedStaticMemory : public RefCountedMemory { RefCountedStaticMemory(const unsigned char* data, size_t length) : data_(data), length_(length) {} - virtual const unsigned char* front() const { return data_; } - virtual size_t size() const { return length_; } + virtual const unsigned char* front() const; + virtual size_t size() const; private: const unsigned char* data_; @@ -57,24 +57,15 @@ class RefCountedBytes : public RefCountedMemory { // Constructs a RefCountedBytes object by performing a swap. (To non // destructively build a RefCountedBytes, use the constructor that takes a // vector.) - static RefCountedBytes* TakeVector(std::vector<unsigned char>* to_destroy) { - RefCountedBytes* bytes = new RefCountedBytes; - bytes->data.swap(*to_destroy); - return bytes; - } + static RefCountedBytes* TakeVector(std::vector<unsigned char>* to_destroy); - RefCountedBytes() {} + RefCountedBytes(); // Constructs a RefCountedBytes object by _copying_ from |initializer|. - RefCountedBytes(const std::vector<unsigned char>& initializer) - : data(initializer) {} - - virtual const unsigned char* front() const { - // STL will assert if we do front() on an empty vector, but calling code - // expects a NULL. - return size() ? &data.front() : NULL; - } - virtual size_t size() const { return data.size(); } + RefCountedBytes(const std::vector<unsigned char>& initializer); + + virtual const unsigned char* front() const; + virtual size_t size() const; std::vector<unsigned char> data; |