summaryrefslogtreecommitdiffstats
path: root/base/memory
diff options
context:
space:
mode:
authorjoth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-21 09:51:40 +0000
committerjoth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-21 09:51:40 +0000
commit289f5a7870a3f1e5ed7b465556125515a6e474b0 (patch)
tree6c2569a80bd165d905f7c84cc04798dda9fb0f60 /base/memory
parentdc20613ba3e16cf90dc862cdd27c989a1388a6b0 (diff)
downloadchromium_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')
-rw-r--r--base/memory/ref_counted_memory.cc34
-rw-r--r--base/memory/ref_counted_memory.h51
-rw-r--r--base/memory/ref_counted_memory_unittest.cc45
3 files changed, 12 insertions, 118 deletions
diff --git a/base/memory/ref_counted_memory.cc b/base/memory/ref_counted_memory.cc
index 7e034f9..aa16031 100644
--- a/base/memory/ref_counted_memory.cc
+++ b/base/memory/ref_counted_memory.cc
@@ -4,8 +4,6 @@
#include "base/memory/ref_counted_memory.h"
-#include "base/logging.h"
-
RefCountedMemory::RefCountedMemory() {
}
@@ -24,49 +22,25 @@ RefCountedBytes::RefCountedBytes() {
}
RefCountedBytes::RefCountedBytes(const std::vector<unsigned char>& initializer)
- : data_(initializer) {
+ : data(initializer) {
}
RefCountedBytes* RefCountedBytes::TakeVector(
std::vector<unsigned char>* to_destroy) {
RefCountedBytes* bytes = new RefCountedBytes;
- bytes->data_.swap(*to_destroy);
+ bytes->data.swap(*to_destroy);
return bytes;
}
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;
+ return size() ? &data.front() : NULL;
}
size_t RefCountedBytes::size() const {
- return data_.size();
+ return data.size();
}
RefCountedBytes::~RefCountedBytes() {
}
-
-namespace base {
-
-RefCountedString::RefCountedString() {}
-
-RefCountedString::~RefCountedString() {}
-
-// static
-RefCountedString* RefCountedString::TakeString(std::string* to_destroy) {
- RefCountedString* self = new RefCountedString;
- to_destroy->swap(self->data_);
- return self;
-}
-
-const unsigned char* RefCountedString::front() const {
- return data_.empty() ? NULL :
- reinterpret_cast<const unsigned char*>(data_.data());
-}
-
-size_t RefCountedString::size() const {
- return data_.size();
-}
-
-} // namespace base
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_
diff --git a/base/memory/ref_counted_memory_unittest.cc b/base/memory/ref_counted_memory_unittest.cc
deleted file mode 100644
index 1936040..0000000
--- a/base/memory/ref_counted_memory_unittest.cc
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright (c) 2011 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/memory/ref_counted_memory.h"
-
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace base {
-
-TEST(RefCountedMemoryUnitTest, RefCountedStaticMemory) {
- scoped_refptr<RefCountedMemory> mem = new RefCountedStaticMemory(
- reinterpret_cast<const uint8*>("static mem00"), 10);
-
- EXPECT_EQ(10U, mem->size());
- EXPECT_EQ("static mem",
- std::string(reinterpret_cast<const char*>(mem->front()),
- mem->size()));
-}
-
-TEST(RefCountedMemoryUnitTest, RefCountedBytes) {
- std::vector<uint8> data;
- data.push_back(45);
- data.push_back(99);
- scoped_refptr<RefCountedMemory> mem = RefCountedBytes::TakeVector(&data);
-
- EXPECT_EQ(0U, data.size());
-
- EXPECT_EQ(2U, mem->size());
- EXPECT_EQ(45U, mem->front()[0]);
- EXPECT_EQ(99U, mem->front()[1]);
-}
-
-TEST(RefCountedMemoryUnitTest, RefCountedString) {
- std::string s("destroy me");
- scoped_refptr<RefCountedMemory> mem = RefCountedString::TakeString(&s);
-
- EXPECT_EQ(0U, s.size());
-
- EXPECT_EQ(10U, mem->size());
- EXPECT_EQ('d', mem->front()[0]);
- EXPECT_EQ('e', mem->front()[1]);
-}
-
-} // namespace base