diff options
author | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-21 09:51:40 +0000 |
---|---|---|
committer | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-21 09:51:40 +0000 |
commit | 289f5a7870a3f1e5ed7b465556125515a6e474b0 (patch) | |
tree | 6c2569a80bd165d905f7c84cc04798dda9fb0f60 /base/memory/ref_counted_memory.h | |
parent | dc20613ba3e16cf90dc862cdd27c989a1388a6b0 (diff) | |
download | chromium_src-289f5a7870a3f1e5ed7b465556125515a6e474b0.zip chromium_src-289f5a7870a3f1e5ed7b465556125515a6e474b0.tar.gz chromium_src-289f5a7870a3f1e5ed7b465556125515a6e474b0.tar.bz2 |
Revert 93365 - it broke on Chrome OS
Added RefCountedString, as this is what many RefCountedMemory users seem to want
Made data member of RefCountedBytes private, as per style guide
Changed base64 APIs to accept StringPiece, as it's sometimes better and never worse than string.
BUG=None
TEST=All existing tests pass. Extended ref_counted_memory_unittests
Review URL: http://codereview.chromium.org/7397021
TBR=joth@chromium.org
Review URL: http://codereview.chromium.org/7471033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93367 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/memory/ref_counted_memory.h')
-rw-r--r-- | base/memory/ref_counted_memory.h | 51 |
1 files changed, 8 insertions, 43 deletions
diff --git a/base/memory/ref_counted_memory.h b/base/memory/ref_counted_memory.h index 0d48f64..1a0f51ee 100644 --- a/base/memory/ref_counted_memory.h +++ b/base/memory/ref_counted_memory.h @@ -6,11 +6,9 @@ #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 @@ -42,9 +40,9 @@ class BASE_API RefCountedStaticMemory : public RefCountedMemory { RefCountedStaticMemory() : data_(NULL), length_(0) {} RefCountedStaticMemory(const unsigned char* data, size_t length) - : data_(length ? data : NULL), length_(length) {} + : data_(data), length_(length) {} - // Overridden from RefCountedMemory: + // Overriden from RefCountedMemory: virtual const unsigned char* front() const; virtual size_t size() const; @@ -69,51 +67,18 @@ class BASE_API RefCountedBytes : public RefCountedMemory { // vector.) static RefCountedBytes* TakeVector(std::vector<unsigned char>* to_destroy); - // Overridden from RefCountedMemory: - virtual const unsigned char* front() const OVERRIDE; - virtual size_t size() const OVERRIDE; + // Overriden from RefCountedMemory: + virtual const unsigned char* front() const; + virtual size_t size() const; - const std::vector<unsigned char>& data() const { return data_; } - std::vector<unsigned char>& data() { return data_; } + std::vector<unsigned char> data; - private: + protected: friend class base::RefCountedThreadSafe<RefCountedBytes>; virtual ~RefCountedBytes(); - 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); + DISALLOW_COPY_AND_ASSIGN(RefCountedBytes); }; -} // namespace base - #endif // BASE_MEMORY_REF_COUNTED_MEMORY_H_ |