| Index: base/memory/ref_counted_memory.h
|
| diff --git a/base/memory/ref_counted_memory.h b/base/memory/ref_counted_memory.h
|
| index 1a0f51eec4aebf8784f7ed02e6b91c5964fb18c5..7438d573270d4321e024bb422a12aa0e6fcb550a 100644
|
| --- a/base/memory/ref_counted_memory.h
|
| +++ b/base/memory/ref_counted_memory.h
|
| @@ -6,9 +6,11 @@
|
| #define BASE_MEMORY_REF_COUNTED_MEMORY_H_
|
| #pragma once
|
|
|
| +#include <string>
|
| #include <vector>
|
|
|
| #include "base/base_api.h"
|
| +#include "base/compiler_specific.h"
|
| #include "base/memory/ref_counted.h"
|
|
|
| // TODO(erg): The contents of this file should be in a namespace. This would
|
| @@ -40,11 +42,11 @@ class BASE_API RefCountedStaticMemory : public RefCountedMemory {
|
| RefCountedStaticMemory()
|
| : data_(NULL), length_(0) {}
|
| RefCountedStaticMemory(const unsigned char* data, size_t length)
|
| - : data_(data), length_(length) {}
|
| + : data_(length ? data : NULL), length_(length) {}
|
|
|
| - // Overriden from RefCountedMemory:
|
| - virtual const unsigned char* front() const;
|
| - virtual size_t size() const;
|
| + // Overridden from RefCountedMemory:
|
| + virtual const unsigned char* front() const OVERRIDE;
|
| + virtual size_t size() const OVERRIDE;
|
|
|
| private:
|
| const unsigned char* data_;
|
| @@ -67,18 +69,51 @@ class BASE_API RefCountedBytes : public RefCountedMemory {
|
| // vector.)
|
| static RefCountedBytes* TakeVector(std::vector<unsigned char>* to_destroy);
|
|
|
| - // Overriden from RefCountedMemory:
|
| - virtual const unsigned char* front() const;
|
| - virtual size_t size() const;
|
| + // Overridden from RefCountedMemory:
|
| + virtual const unsigned char* front() const OVERRIDE;
|
| + virtual size_t size() const OVERRIDE;
|
|
|
| - std::vector<unsigned char> data;
|
| + const std::vector<unsigned char>& data() const { return data_; }
|
| + std::vector<unsigned char>& data() { return data_; }
|
|
|
| - protected:
|
| + private:
|
| friend class base::RefCountedThreadSafe<RefCountedBytes>;
|
| virtual ~RefCountedBytes();
|
|
|
| - private:
|
| + std::vector<unsigned char> data_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(RefCountedBytes);
|
| };
|
|
|
| +namespace base {
|
| +
|
| +// An implementation of RefCountedMemory, where the bytes are stored in an STL
|
| +// string. Use this if your data naturally arrives in that format.
|
| +class BASE_API RefCountedString : public RefCountedMemory {
|
| + public:
|
| + RefCountedString();
|
| +
|
| + // Constructs a RefCountedString object by performing a swap. (To non
|
| + // destructively build a RefCountedString, use the default constructor and
|
| + // copy into object->data()).
|
| + static RefCountedString* TakeString(std::string* to_destroy);
|
| +
|
| + // Overridden from RefCountedMemory:
|
| + virtual const unsigned char* front() const OVERRIDE;
|
| + virtual size_t size() const OVERRIDE;
|
| +
|
| + const std::string& data() const { return data_; }
|
| + std::string& data() { return data_; }
|
| +
|
| + private:
|
| + friend class base::RefCountedThreadSafe<RefCountedString>;
|
| + virtual ~RefCountedString();
|
| +
|
| + std::string data_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(RefCountedString);
|
| +};
|
| +
|
| +} // namespace base
|
| +
|
| #endif // BASE_MEMORY_REF_COUNTED_MEMORY_H_
|
|
|