summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorerg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-27 20:45:08 +0000
committererg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-27 20:45:08 +0000
commitd8fef52b071be812fd8a0f7ebea6c577bdb38592 (patch)
tree3ad1d267a3d978e4e68c0f3c49c3781e155e1a3f /base
parent19e0ff7bf0b74a121d52a75b1d883222d266b789 (diff)
downloadchromium_src-d8fef52b071be812fd8a0f7ebea6c577bdb38592.zip
chromium_src-d8fef52b071be812fd8a0f7ebea6c577bdb38592.tar.gz
chromium_src-d8fef52b071be812fd8a0f7ebea6c577bdb38592.tar.bz2
Modify DataPacks so they can return RefCountedStaticMemory objects.
(This is in preparation for a very large reworking of BrowserThemeProvider). BUG=http://crbug.com/21121 Review URL: http://codereview.chromium.org/338027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30241 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/data_pack.cc11
-rw-r--r--base/data_pack.h8
-rw-r--r--base/data_pack_unittest.cc10
3 files changed, 22 insertions, 7 deletions
diff --git a/base/data_pack.cc b/base/data_pack.cc
index 46f3cb4..27054d3 100644
--- a/base/data_pack.cc
+++ b/base/data_pack.cc
@@ -89,7 +89,7 @@ bool DataPack::Load(const FilePath& path) {
return true;
}
-bool DataPack::Get(uint32_t resource_id, StringPiece* data) {
+bool DataPack::GetStringPiece(uint32_t resource_id, StringPiece* data) {
// It won't be hard to make this endian-agnostic, but it's not worth
// bothering to do right now.
#if defined(__BYTE_ORDER)
@@ -113,4 +113,13 @@ bool DataPack::Get(uint32_t resource_id, StringPiece* data) {
return true;
}
+RefCountedStaticMemory* DataPack::GetStaticMemory(uint32_t resource_id) {
+ base::StringPiece piece;
+ if (!GetStringPiece(resource_id, &piece))
+ return NULL;
+
+ return new RefCountedStaticMemory(
+ reinterpret_cast<const unsigned char*>(piece.data()), piece.length());
+}
+
} // namespace base
diff --git a/base/data_pack.h b/base/data_pack.h
index 02a3849..7c9abde 100644
--- a/base/data_pack.h
+++ b/base/data_pack.h
@@ -10,6 +10,7 @@
#define BASE_DATA_PACK_H_
#include "base/basictypes.h"
+#include "base/ref_counted_memory.h"
#include "base/scoped_ptr.h"
namespace file_util {
@@ -32,7 +33,12 @@ class DataPack {
// Get resource by id |resource_id|, filling in |data|.
// The data is owned by the DataPack object and should not be modified.
// Returns false if the resource id isn't found.
- bool Get(uint32_t resource_id, StringPiece* data);
+ bool GetStringPiece(uint32_t resource_id, StringPiece* data);
+
+ // Like GetStringPiece(), but returns a reference to memory. This interface
+ // is used for image data, while the StringPiece interface is usually used
+ // for localization strings.
+ RefCountedStaticMemory* GetStaticMemory(uint32_t resource_id);
private:
// The memory-mapped data.
diff --git a/base/data_pack_unittest.cc b/base/data_pack_unittest.cc
index 7c2cfeb..a62acf0 100644
--- a/base/data_pack_unittest.cc
+++ b/base/data_pack_unittest.cc
@@ -25,17 +25,17 @@ TEST_F(DataPackTest, Load) {
ASSERT_TRUE(pack.Load(data_path_));
base::StringPiece data;
- ASSERT_TRUE(pack.Get(4, &data));
+ ASSERT_TRUE(pack.GetStringPiece(4, &data));
EXPECT_EQ("this is id 4", data);
- ASSERT_TRUE(pack.Get(6, &data));
+ ASSERT_TRUE(pack.GetStringPiece(6, &data));
EXPECT_EQ("this is id 6", data);
// Try reading zero-length data blobs, just in case.
- ASSERT_TRUE(pack.Get(1, &data));
+ ASSERT_TRUE(pack.GetStringPiece(1, &data));
EXPECT_EQ(0U, data.length());
- ASSERT_TRUE(pack.Get(10, &data));
+ ASSERT_TRUE(pack.GetStringPiece(10, &data));
EXPECT_EQ(0U, data.length());
// Try looking up an invalid key.
- ASSERT_FALSE(pack.Get(140, &data));
+ ASSERT_FALSE(pack.GetStringPiece(140, &data));
}