summaryrefslogtreecommitdiffstats
path: root/net/disk_cache
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-10 23:40:27 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-10 23:40:27 +0000
commitc12519fb92c4e6ae39b20376badc19c825d62d2c (patch)
tree659e1f599702c63ef54dcf4c262ea1995fc01b20 /net/disk_cache
parent0b9803cdd8e63251ad6485608dc7c00d439c0729 (diff)
downloadchromium_src-c12519fb92c4e6ae39b20376badc19c825d62d2c.zip
chromium_src-c12519fb92c4e6ae39b20376badc19c825d62d2c.tar.gz
chromium_src-c12519fb92c4e6ae39b20376badc19c825d62d2c.tar.bz2
Revert cl 9528 to fix mac test_shell_tests
Review URL: http://codereview.chromium.org/21236 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9532 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r--net/disk_cache/backend_unittest.cc64
-rw-r--r--net/disk_cache/disk_cache.h14
-rw-r--r--net/disk_cache/disk_cache_perftest.cc30
-rw-r--r--net/disk_cache/entry_impl.cc24
-rw-r--r--net/disk_cache/entry_impl.h4
-rw-r--r--net/disk_cache/entry_unittest.cc333
-rw-r--r--net/disk_cache/mem_entry_impl.cc14
-rw-r--r--net/disk_cache/mem_entry_impl.h4
-rw-r--r--net/disk_cache/stress_cache.cc14
9 files changed, 234 insertions, 267 deletions
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc
index d23ea7f..6d3dfb3 100644
--- a/net/disk_cache/backend_unittest.cc
+++ b/net/disk_cache/backend_unittest.cc
@@ -7,7 +7,6 @@
#include "base/path_service.h"
#include "base/platform_thread.h"
#include "base/string_util.h"
-#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/disk_cache/backend_impl.h"
#include "net/disk_cache/disk_cache_test_base.h"
@@ -210,21 +209,21 @@ TEST_F(DiskCacheBackendTest, ExternalFiles) {
std::wstring filename = GetCachePath();
file_util::AppendToPath(&filename, L"f_000001");
- const int kSize = 50;
- scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize);
- CacheTestFillBuffer(buffer1->data(), kSize, false);
- ASSERT_EQ(kSize, file_util::WriteFile(filename, buffer1->data(), kSize));
+ const int kDataSize = 50;
+ char data[kDataSize];
+ CacheTestFillBuffer(data, kDataSize, false);
+ ASSERT_EQ(kDataSize, file_util::WriteFile(filename, data, kDataSize));
// Now let's create a file with the cache.
disk_cache::Entry* entry;
ASSERT_TRUE(cache_->CreateEntry("key", &entry));
- ASSERT_EQ(0, entry->WriteData(0, 20000, buffer1, 0, NULL, false));
+ ASSERT_EQ(0, entry->WriteData(0, 20000, data, 0, NULL, false));
entry->Close();
// And verify that the first file is still there.
- scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize);
- ASSERT_EQ(kSize, file_util::ReadFile(filename, buffer2->data(), kSize));
- EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize));
+ char buffer[kDataSize];
+ ASSERT_EQ(kDataSize, file_util::ReadFile(filename, buffer, kDataSize));
+ EXPECT_EQ(0, memcmp(data, buffer, kDataSize));
}
void DiskCacheBackendTest::BackendSetSize() {
@@ -238,8 +237,7 @@ void DiskCacheBackendTest::BackendSetSize() {
disk_cache::Entry* entry;
ASSERT_TRUE(cache_->CreateEntry(first, &entry));
- scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(cache_size);
- memset(buffer->data(), 0, cache_size);
+ char buffer[cache_size] = {0};
EXPECT_EQ(cache_size / 10, entry->WriteData(0, 0, buffer, cache_size / 10,
NULL, false)) << "normal file";
@@ -340,20 +338,20 @@ TEST_F(DiskCacheBackendTest, ValidEntry) {
disk_cache::Entry* entry1;
ASSERT_TRUE(cache_->CreateEntry(key, &entry1));
- const int kSize = 50;
- scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize);
- base::strlcpy(buffer1->data(), "And the data to save", kSize);
- EXPECT_EQ(kSize, entry1->WriteData(0, 0, buffer1, kSize, NULL, false));
+ char data[] = "And the data to save";
+ EXPECT_TRUE(sizeof(data) == entry1->WriteData(0, 0, data, sizeof(data), NULL,
+ false));
entry1->Close();
SimulateCrash();
ASSERT_TRUE(cache_->OpenEntry(key, &entry1));
- scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize);
- memset(buffer2->data(), 0, kSize);
- EXPECT_EQ(kSize, entry1->ReadData(0, 0, buffer2, kSize, NULL));
+ char buffer[40];
+ memset(buffer, 0, sizeof(buffer));
+ EXPECT_TRUE(sizeof(data) == entry1->ReadData(0, 0, buffer, sizeof(data),
+ NULL));
entry1->Close();
- EXPECT_STREQ(buffer1->data(), buffer2->data());
+ EXPECT_STREQ(data, buffer);
}
// The same logic of the previous test (ValidEntry), but this time force the
@@ -368,10 +366,9 @@ TEST_F(DiskCacheBackendTest, InvalidEntry) {
disk_cache::Entry* entry1;
ASSERT_TRUE(cache_->CreateEntry(key, &entry1));
- const int kSize = 50;
- scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize);
- base::strlcpy(buffer1->data(), "And the data to save", kSize);
- EXPECT_EQ(kSize, entry1->WriteData(0, 0, buffer1, kSize, NULL, false));
+ char data[] = "And the data to save";
+ EXPECT_TRUE(sizeof(data) == entry1->WriteData(0, 0, data, sizeof(data), NULL,
+ false));
SimulateCrash();
EXPECT_FALSE(cache_->OpenEntry(key, &entry1));
@@ -389,13 +386,12 @@ TEST_F(DiskCacheBackendTest, InvalidEntryRead) {
disk_cache::Entry* entry1;
ASSERT_TRUE(cache_->CreateEntry(key, &entry1));
- const int kSize = 50;
- scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize);
- base::strlcpy(buffer1->data(), "And the data to save", kSize);
- EXPECT_EQ(kSize, entry1->WriteData(0, 0, buffer1, kSize, NULL, false));
+ char data[] = "And the data to save";
+ EXPECT_TRUE(sizeof(data) == entry1->WriteData(0, 0, data, sizeof(data), NULL,
+ false));
entry1->Close();
ASSERT_TRUE(cache_->OpenEntry(key, &entry1));
- EXPECT_EQ(kSize, entry1->ReadData(0, 0, buffer1, kSize, NULL));
+ EXPECT_TRUE(sizeof(data) == entry1->ReadData(0, 0, data, sizeof(data), NULL));
SimulateCrash();
@@ -466,8 +462,7 @@ TEST_F(DiskCacheBackendTest, TrimInvalidEntry) {
disk_cache::Entry* entry;
ASSERT_TRUE(cache_->CreateEntry(first, &entry));
- scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(cache_size);
- memset(buffer->data(), 0, cache_size);
+ char buffer[cache_size] = {0};
EXPECT_EQ(cache_size * 19 / 20, entry->WriteData(0, 0, buffer,
cache_size * 19 / 20, NULL, false));
@@ -554,13 +549,12 @@ TEST_F(DiskCacheBackendTest, InvalidEntryEnumeration) {
disk_cache::Entry *entry, *entry1, *entry2;
ASSERT_TRUE(cache_->CreateEntry(key, &entry1));
- const int kSize = 50;
- scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize);
- base::strlcpy(buffer1->data(), "And the data to save", kSize);
- EXPECT_EQ(kSize, entry1->WriteData(0, 0, buffer1, kSize, NULL, false));
+ char data[] = "And the data to save";
+ EXPECT_TRUE(sizeof(data) == entry1->WriteData(0, 0, data, sizeof(data), NULL,
+ false));
entry1->Close();
ASSERT_TRUE(cache_->OpenEntry(key, &entry1));
- EXPECT_EQ(kSize, entry1->ReadData(0, 0, buffer1, kSize, NULL));
+ EXPECT_TRUE(sizeof(data) == entry1->ReadData(0, 0, data, sizeof(data), NULL));
std::string key2("Another key");
ASSERT_TRUE(cache_->CreateEntry(key2, &entry2));
diff --git a/net/disk_cache/disk_cache.h b/net/disk_cache/disk_cache.h
index 59d2ad2..ab01086 100644
--- a/net/disk_cache/disk_cache.h
+++ b/net/disk_cache/disk_cache.h
@@ -15,10 +15,6 @@
#include "base/time.h"
#include "net/base/completion_callback.h"
-namespace net {
-class IOBuffer;
-}
-
namespace disk_cache {
class Entry;
@@ -127,13 +123,12 @@ class Entry {
// operation is complete. Otherwise, completion_callback will be
// called on the current thread once the read completes. Returns the
// number of bytes read or a network error code. If a completion callback is
- // provided then it will be called if this function returns ERR_IO_PENDING,
- // and a reference to |buf| will be retained until the callback is called.
+ // provided then it will be called if this function returns ERR_IO_PENDING.
// Note that the callback will be invoked in any case, even after Close has
// been called; in other words, the caller may close this entry without
// having to wait for all the callbacks, and still rely on the cleanup
// performed from the callback code.
- virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len,
+ virtual int ReadData(int index, int offset, char* buf, int buf_len,
net::CompletionCallback* completion_callback) = 0;
// Copies cache data from the given buffer of length |buf_len|. If
@@ -141,15 +136,14 @@ class Entry {
// operation is complete. Otherwise, completion_callback will be
// called on the current thread once the write completes. Returns the
// number of bytes written or a network error code. If a completion callback
- // is provided then it will be called if this function returns ERR_IO_PENDING,
- // and a reference to |buf| will be retained until the callback is called.
+ // is provided then it will be called if this function returns ERR_IO_PENDING.
// Note that the callback will be invoked in any case, even after Close has
// been called; in other words, the caller may close this entry without
// having to wait for all the callbacks, and still rely on the cleanup
// performed from the callback code.
// If truncate is true, this call will truncate the stored data at the end of
// what we are writing here.
- virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
+ virtual int WriteData(int index, int offset, const char* buf, int buf_len,
net::CompletionCallback* completion_callback,
bool truncate) = 0;
diff --git a/net/disk_cache/disk_cache_perftest.cc b/net/disk_cache/disk_cache_perftest.cc
index 74cac65..0a869b2 100644
--- a/net/disk_cache/disk_cache_perftest.cc
+++ b/net/disk_cache/disk_cache_perftest.cc
@@ -11,7 +11,6 @@
#include "base/string_util.h"
#include "base/test_file_util.h"
#include "base/timer.h"
-#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/disk_cache/block_files.h"
#include "net/disk_cache/disk_cache.h"
@@ -42,12 +41,11 @@ const int kMaxSize = 16 * 1024 - 1;
// to kMaxSize of data to each entry.
int TimeWrite(int num_entries, disk_cache::Backend* cache,
TestEntries* entries) {
- const int kSize1 = 200;
- scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize1);
- scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kMaxSize);
+ char buffer1[200];
+ char buffer2[kMaxSize];
- CacheTestFillBuffer(buffer1->data(), kSize1, false);
- CacheTestFillBuffer(buffer2->data(), kMaxSize, false);
+ CacheTestFillBuffer(buffer1, sizeof(buffer1), false);
+ CacheTestFillBuffer(buffer2, sizeof(buffer2), false);
CallbackTest callback(1);
g_cache_tests_error = false;
@@ -62,16 +60,17 @@ int TimeWrite(int num_entries, disk_cache::Backend* cache,
for (int i = 0; i < num_entries; i++) {
TestEntry entry;
entry.key = GenerateKey(true);
- entry.data_len = rand() % kMaxSize;
+ entry.data_len = rand() % sizeof(buffer2);
entries->push_back(entry);
disk_cache::Entry* cache_entry;
if (!cache->CreateEntry(entry.key, &cache_entry))
break;
- int ret = cache_entry->WriteData(0, 0, buffer1, kSize1, &callback, false);
+ int ret = cache_entry->WriteData(0, 0, buffer1, sizeof(buffer1), &callback,
+ false);
if (net::ERR_IO_PENDING == ret)
expected++;
- else if (kSize1 != ret)
+ else if (sizeof(buffer1) != ret)
break;
ret = cache_entry->WriteData(1, 0, buffer2, entry.data_len, &callback,
@@ -92,12 +91,11 @@ int TimeWrite(int num_entries, disk_cache::Backend* cache,
// Reads the data and metadata from each entry listed on |entries|.
int TimeRead(int num_entries, disk_cache::Backend* cache,
const TestEntries& entries, bool cold) {
- const int kSize1 = 200;
- scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize1);
- scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kMaxSize);
+ char buffer1[200];
+ char buffer2[kMaxSize];
- CacheTestFillBuffer(buffer1->data(), kSize1, false);
- CacheTestFillBuffer(buffer2->data(), kMaxSize, false);
+ CacheTestFillBuffer(buffer1, sizeof(buffer1), false);
+ CacheTestFillBuffer(buffer2, sizeof(buffer2), false);
CallbackTest callback(1);
g_cache_tests_error = false;
@@ -115,10 +113,10 @@ int TimeRead(int num_entries, disk_cache::Backend* cache,
disk_cache::Entry* cache_entry;
if (!cache->OpenEntry(entries[i].key, &cache_entry))
break;
- int ret = cache_entry->ReadData(0, 0, buffer1, kSize1, &callback);
+ int ret = cache_entry->ReadData(0, 0, buffer1, sizeof(buffer1), &callback);
if (net::ERR_IO_PENDING == ret)
expected++;
- else if (kSize1 != ret)
+ else if (sizeof(buffer1) != ret)
break;
ret = cache_entry->ReadData(1, 0, buffer2, entries[i].data_len, &callback);
diff --git a/net/disk_cache/entry_impl.cc b/net/disk_cache/entry_impl.cc
index 21fb7c4..0f6d426 100644
--- a/net/disk_cache/entry_impl.cc
+++ b/net/disk_cache/entry_impl.cc
@@ -7,7 +7,6 @@
#include "base/histogram.h"
#include "base/message_loop.h"
#include "base/string_util.h"
-#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/disk_cache/backend_impl.h"
#include "net/disk_cache/cache_util.h"
@@ -24,9 +23,9 @@ const int kKeyFileIndex = 3;
// operation from the actual net class.
class SyncCallback: public disk_cache::FileIOCallback {
public:
- SyncCallback(disk_cache::EntryImpl* entry, net::IOBuffer* buffer,
+ SyncCallback(disk_cache::EntryImpl* entry,
net::CompletionCallback* callback )
- : entry_(entry), callback_(callback), buf_(buffer) {
+ : entry_(entry), callback_(callback) {
entry->AddRef();
entry->IncrementIoCount();
}
@@ -37,7 +36,6 @@ class SyncCallback: public disk_cache::FileIOCallback {
private:
disk_cache::EntryImpl* entry_;
net::CompletionCallback* callback_;
- scoped_refptr<net::IOBuffer> buf_;
DISALLOW_EVIL_CONSTRUCTORS(SyncCallback);
};
@@ -52,7 +50,6 @@ void SyncCallback::OnFileIOComplete(int bytes_copied) {
void SyncCallback::Discard() {
callback_ = NULL;
- buf_ = NULL;
OnFileIOComplete(0);
}
@@ -197,7 +194,7 @@ int32 EntryImpl::GetDataSize(int index) const {
return entry->Data()->data_size[index];
}
-int EntryImpl::ReadData(int index, int offset, net::IOBuffer* buf, int buf_len,
+int EntryImpl::ReadData(int index, int offset, char* buf, int buf_len,
net::CompletionCallback* completion_callback) {
DCHECK(node_.Data()->dirty);
if (index < 0 || index >= NUM_STREAMS)
@@ -225,7 +222,7 @@ int EntryImpl::ReadData(int index, int offset, net::IOBuffer* buf, int buf_len,
if (user_buffers_[index].get()) {
// Complete the operation locally.
DCHECK(kMaxBlockSize >= offset + buf_len);
- memcpy(buf->data() , user_buffers_[index].get() + offset, buf_len);
+ memcpy(buf , user_buffers_[index].get() + offset, buf_len);
stats.AddTime(Time::Now() - start);
return buf_len;
}
@@ -246,10 +243,10 @@ int EntryImpl::ReadData(int index, int offset, net::IOBuffer* buf, int buf_len,
SyncCallback* io_callback = NULL;
if (completion_callback)
- io_callback = new SyncCallback(this, buf, completion_callback);
+ io_callback = new SyncCallback(this, completion_callback);
bool completed;
- if (!file->Read(buf->data(), buf_len, file_offset, io_callback, &completed)) {
+ if (!file->Read(buf, buf_len, file_offset, io_callback, &completed)) {
if (io_callback)
io_callback->Discard();
return net::ERR_FAILED;
@@ -262,7 +259,7 @@ int EntryImpl::ReadData(int index, int offset, net::IOBuffer* buf, int buf_len,
return (completed || !completion_callback) ? buf_len : net::ERR_IO_PENDING;
}
-int EntryImpl::WriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
+int EntryImpl::WriteData(int index, int offset, const char* buf, int buf_len,
net::CompletionCallback* completion_callback,
bool truncate) {
DCHECK(node_.Data()->dirty);
@@ -321,7 +318,7 @@ int EntryImpl::WriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
if (user_buffers_[index].get()) {
// Complete the operation locally.
DCHECK(kMaxBlockSize >= offset + buf_len);
- memcpy(user_buffers_[index].get() + offset, buf->data(), buf_len);
+ memcpy(user_buffers_[index].get() + offset, buf, buf_len);
stats.AddTime(Time::Now() - start);
return buf_len;
}
@@ -345,11 +342,10 @@ int EntryImpl::WriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
SyncCallback* io_callback = NULL;
if (completion_callback)
- io_callback = new SyncCallback(this, buf, completion_callback);
+ io_callback = new SyncCallback(this, completion_callback);
bool completed;
- if (!file->Write(buf->data(), buf_len, file_offset, io_callback,
- &completed)) {
+ if (!file->Write(buf, buf_len, file_offset, io_callback, &completed)) {
if (io_callback)
io_callback->Discard();
return net::ERR_FAILED;
diff --git a/net/disk_cache/entry_impl.h b/net/disk_cache/entry_impl.h
index 0b08a58..9b26c80 100644
--- a/net/disk_cache/entry_impl.h
+++ b/net/disk_cache/entry_impl.h
@@ -27,9 +27,9 @@ class EntryImpl : public Entry, public base::RefCounted<EntryImpl> {
virtual base::Time GetLastUsed() const;
virtual base::Time GetLastModified() const;
virtual int32 GetDataSize(int index) const;
- virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len,
+ virtual int ReadData(int index, int offset, char* buf, int buf_len,
net::CompletionCallback* completion_callback);
- virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
+ virtual int WriteData(int index, int offset, const char* buf, int buf_len,
net::CompletionCallback* completion_callback,
bool truncate);
diff --git a/net/disk_cache/entry_unittest.cc b/net/disk_cache/entry_unittest.cc
index 1fc1aaa..4a93151 100644
--- a/net/disk_cache/entry_unittest.cc
+++ b/net/disk_cache/entry_unittest.cc
@@ -6,7 +6,6 @@
#include "base/platform_thread.h"
#include "base/timer.h"
#include "base/string_util.h"
-#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/disk_cache/disk_cache_test_base.h"
#include "net/disk_cache/disk_cache_test_util.h"
@@ -41,35 +40,32 @@ void DiskCacheEntryTest::InternalSyncIO() {
ASSERT_TRUE(cache_->CreateEntry("the first key", &entry1));
ASSERT_TRUE(NULL != entry1);
- const int kSize1 = 10;
- scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize1);
- CacheTestFillBuffer(buffer1->data(), kSize1, false);
- EXPECT_EQ(0, entry1->ReadData(0, 0, buffer1, kSize1, NULL));
- base::strlcpy(buffer1->data(), "the data", kSize1);
- EXPECT_EQ(10, entry1->WriteData(0, 0, buffer1, kSize1, NULL, false));
- memset(buffer1->data(), 0, kSize1);
- EXPECT_EQ(10, entry1->ReadData(0, 0, buffer1, kSize1, NULL));
- EXPECT_STREQ("the data", buffer1->data());
-
- const int kSize2 = 5000;
- const int kSize3 = 10000;
- scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize2);
- scoped_refptr<net::IOBuffer> buffer3 = new net::IOBuffer(kSize3);
- memset(buffer3->data(), 0, kSize3);
- CacheTestFillBuffer(buffer2->data(), kSize2, false);
- base::strlcpy(buffer2->data(), "The really big data goes here", kSize2);
- EXPECT_EQ(5000, entry1->WriteData(1, 1500, buffer2, kSize2, NULL, false));
- memset(buffer2->data(), 0, kSize2);
- EXPECT_EQ(4989, entry1->ReadData(1, 1511, buffer2, kSize2, NULL));
- EXPECT_STREQ("big data goes here", buffer2->data());
- EXPECT_EQ(5000, entry1->ReadData(1, 0, buffer2, kSize2, NULL));
- EXPECT_EQ(0, memcmp(buffer2->data(), buffer3->data(), 1500));
- EXPECT_EQ(1500, entry1->ReadData(1, 5000, buffer2, kSize2, NULL));
-
- EXPECT_EQ(0, entry1->ReadData(1, 6500, buffer2, kSize2, NULL));
- EXPECT_EQ(6500, entry1->ReadData(1, 0, buffer3, kSize3, NULL));
+ char buffer1[10];
+ CacheTestFillBuffer(buffer1, sizeof(buffer1), false);
+ EXPECT_EQ(0, entry1->ReadData(0, 0, buffer1, sizeof(buffer1), NULL));
+ base::strlcpy(buffer1, "the data", arraysize(buffer1));
+ EXPECT_EQ(10, entry1->WriteData(0, 0, buffer1, sizeof(buffer1), NULL, false));
+ memset(buffer1, 0, sizeof(buffer1));
+ EXPECT_EQ(10, entry1->ReadData(0, 0, buffer1, sizeof(buffer1), NULL));
+ EXPECT_STREQ("the data", buffer1);
+
+ char buffer2[5000];
+ char buffer3[10000] = {0};
+ CacheTestFillBuffer(buffer2, sizeof(buffer2), false);
+ base::strlcpy(buffer2, "The really big data goes here", arraysize(buffer2));
+ EXPECT_EQ(5000, entry1->WriteData(1, 1500, buffer2, sizeof(buffer2), NULL,
+ false));
+ memset(buffer2, 0, sizeof(buffer2));
+ EXPECT_EQ(4989, entry1->ReadData(1, 1511, buffer2, sizeof(buffer2), NULL));
+ EXPECT_STREQ("big data goes here", buffer2);
+ EXPECT_EQ(5000, entry1->ReadData(1, 0, buffer2, sizeof(buffer2), NULL));
+ EXPECT_EQ(0, memcmp(buffer2, buffer3, 1500));
+ EXPECT_EQ(1500, entry1->ReadData(1, 5000, buffer2, sizeof(buffer2), NULL));
+
+ EXPECT_EQ(0, entry1->ReadData(1, 6500, buffer2, sizeof(buffer2), NULL));
+ EXPECT_EQ(6500, entry1->ReadData(1, 0, buffer3, sizeof(buffer3), NULL));
EXPECT_EQ(8192, entry1->WriteData(1, 0, buffer3, 8192, NULL, false));
- EXPECT_EQ(8192, entry1->ReadData(1, 0, buffer3, kSize3, NULL));
+ EXPECT_EQ(8192, entry1->ReadData(1, 0, buffer3, sizeof(buffer3), NULL));
EXPECT_EQ(8192, entry1->GetDataSize(1));
entry1->Doom();
@@ -114,66 +110,64 @@ void DiskCacheEntryTest::InternalAsyncIO() {
MessageLoopHelper helper;
- const int kSize1 = 10;
- const int kSize2 = 5000;
- const int kSize3 = 10000;
- scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize1);
- scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize2);
- scoped_refptr<net::IOBuffer> buffer3 = new net::IOBuffer(kSize3);
- CacheTestFillBuffer(buffer1->data(), kSize1, false);
- CacheTestFillBuffer(buffer2->data(), kSize2, false);
- CacheTestFillBuffer(buffer3->data(), kSize3, false);
-
- EXPECT_EQ(0, entry1->ReadData(0, 0, buffer1, kSize1, &callback1));
- base::strlcpy(buffer1->data(), "the data", kSize1);
+ char buffer1[10];
+ char buffer2[5000];
+ char buffer3[10000];
+ CacheTestFillBuffer(buffer1, sizeof(buffer1), false);
+ CacheTestFillBuffer(buffer2, sizeof(buffer2), false);
+ CacheTestFillBuffer(buffer3, sizeof(buffer3), false);
+
+ EXPECT_EQ(0, entry1->ReadData(0, 0, buffer1, sizeof(buffer1), &callback1));
+ base::strlcpy(buffer1, "the data", arraysize(buffer1));
int expected = 0;
- int ret = entry1->WriteData(0, 0, buffer1, kSize1, &callback2, false);
+ int ret = entry1->WriteData(0, 0, buffer1, sizeof(buffer1), &callback2,
+ false);
EXPECT_TRUE(10 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
- memset(buffer2->data(), 0, kSize1);
- ret = entry1->ReadData(0, 0, buffer2, kSize1, &callback3);
+ memset(buffer2, 0, sizeof(buffer1));
+ ret = entry1->ReadData(0, 0, buffer2, sizeof(buffer1), &callback3);
EXPECT_TRUE(10 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
g_cache_tests_max_id = 3;
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
- EXPECT_STREQ("the data", buffer2->data());
+ EXPECT_STREQ("the data", buffer2);
- base::strlcpy(buffer2->data(), "The really big data goes here", kSize2);
- ret = entry1->WriteData(1, 1500, buffer2, kSize2, &callback4, false);
+ base::strlcpy(buffer2, "The really big data goes here", arraysize(buffer2));
+ ret = entry1->WriteData(1, 1500, buffer2, sizeof(buffer2), &callback4, false);
EXPECT_TRUE(5000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
- memset(buffer3->data(), 0, kSize2);
- ret = entry1->ReadData(1, 1511, buffer3, kSize2, &callback5);
+ memset(buffer3, 0, sizeof(buffer2));
+ ret = entry1->ReadData(1, 1511, buffer3, sizeof(buffer2), &callback5);
EXPECT_TRUE(4989 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
g_cache_tests_max_id = 5;
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
- EXPECT_STREQ("big data goes here", buffer3->data());
- ret = entry1->ReadData(1, 0, buffer2, kSize2, &callback6);
+ EXPECT_STREQ("big data goes here", buffer3);
+ ret = entry1->ReadData(1, 0, buffer2, sizeof(buffer2), &callback6);
EXPECT_TRUE(5000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
- memset(buffer3->data(), 0, kSize3);
+ memset(buffer3, 0, sizeof(buffer3));
g_cache_tests_max_id = 6;
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
- EXPECT_EQ(0, memcmp(buffer2->data(), buffer3->data(), 1500));
- ret = entry1->ReadData(1, 5000, buffer2, kSize2, &callback7);
+ EXPECT_EQ(0, memcmp(buffer2, buffer3, 1500));
+ ret = entry1->ReadData(1, 5000, buffer2, sizeof(buffer2), &callback7);
EXPECT_TRUE(1500 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
- EXPECT_EQ(0, entry1->ReadData(1, 6500, buffer2, kSize2, &callback8));
- ret = entry1->ReadData(1, 0, buffer3, kSize3, &callback9);
+ EXPECT_EQ(0, entry1->ReadData(1, 6500, buffer2, sizeof(buffer2), &callback8));
+ ret = entry1->ReadData(1, 0, buffer3, sizeof(buffer3), &callback9);
EXPECT_TRUE(6500 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
@@ -183,19 +177,19 @@ void DiskCacheEntryTest::InternalAsyncIO() {
if (net::ERR_IO_PENDING == ret)
expected++;
- ret = entry1->ReadData(1, 0, buffer3, kSize3, &callback11);
+ ret = entry1->ReadData(1, 0, buffer3, sizeof(buffer3), &callback11);
EXPECT_TRUE(8192 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
EXPECT_EQ(8192, entry1->GetDataSize(1));
- ret = entry1->ReadData(0, 0, buffer1, kSize1, &callback12);
+ ret = entry1->ReadData(0, 0, buffer1, sizeof(buffer1), &callback12);
EXPECT_TRUE(10 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
- ret = entry1->ReadData(1, 0, buffer2, kSize2, &callback13);
+ ret = entry1->ReadData(1, 0, buffer2, sizeof(buffer2), &callback13);
EXPECT_TRUE(5000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
@@ -226,30 +220,30 @@ void DiskCacheEntryTest::ExternalSyncIO() {
disk_cache::Entry *entry1;
ASSERT_TRUE(cache_->CreateEntry("the first key", &entry1));
- const int kSize1 = 17000;
- const int kSize2 = 25000;
- scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize1);
- scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize2);
- CacheTestFillBuffer(buffer1->data(), kSize1, false);
- CacheTestFillBuffer(buffer2->data(), kSize2, false);
- base::strlcpy(buffer1->data(), "the data", kSize1);
- EXPECT_EQ(17000, entry1->WriteData(0, 0, buffer1, kSize1, NULL, false));
- memset(buffer1->data(), 0, kSize1);
- EXPECT_EQ(17000, entry1->ReadData(0, 0, buffer1, kSize1, NULL));
- EXPECT_STREQ("the data", buffer1->data());
-
- base::strlcpy(buffer2->data(), "The really big data goes here", kSize2);
- EXPECT_EQ(25000, entry1->WriteData(1, 10000, buffer2, kSize2, NULL, false));
- memset(buffer2->data(), 0, kSize2);
- EXPECT_EQ(24989, entry1->ReadData(1, 10011, buffer2, kSize2, NULL));
- EXPECT_STREQ("big data goes here", buffer2->data());
- EXPECT_EQ(25000, entry1->ReadData(1, 0, buffer2, kSize2, NULL));
- EXPECT_EQ(0, memcmp(buffer2->data(), buffer2->data(), 10000));
- EXPECT_EQ(5000, entry1->ReadData(1, 30000, buffer2, kSize2, NULL));
-
- EXPECT_EQ(0, entry1->ReadData(1, 35000, buffer2, kSize2, NULL));
- EXPECT_EQ(17000, entry1->ReadData(1, 0, buffer1, kSize1, NULL));
- EXPECT_EQ(17000, entry1->WriteData(1, 20000, buffer1, kSize1, NULL, false));
+ char buffer1[17000], buffer2[25000];
+ CacheTestFillBuffer(buffer1, sizeof(buffer1), false);
+ CacheTestFillBuffer(buffer2, sizeof(buffer2), false);
+ base::strlcpy(buffer1, "the data", arraysize(buffer1));
+ EXPECT_EQ(17000, entry1->WriteData(0, 0, buffer1, sizeof(buffer1), NULL,
+ false));
+ memset(buffer1, 0, sizeof(buffer1));
+ EXPECT_EQ(17000, entry1->ReadData(0, 0, buffer1, sizeof(buffer1), NULL));
+ EXPECT_STREQ("the data", buffer1);
+
+ base::strlcpy(buffer2, "The really big data goes here", arraysize(buffer2));
+ EXPECT_EQ(25000, entry1->WriteData(1, 10000, buffer2, sizeof(buffer2), NULL,
+ false));
+ memset(buffer2, 0, sizeof(buffer2));
+ EXPECT_EQ(24989, entry1->ReadData(1, 10011, buffer2, sizeof(buffer2), NULL));
+ EXPECT_STREQ("big data goes here", buffer2);
+ EXPECT_EQ(25000, entry1->ReadData(1, 0, buffer2, sizeof(buffer2), NULL));
+ EXPECT_EQ(0, memcmp(buffer2, buffer2, 10000));
+ EXPECT_EQ(5000, entry1->ReadData(1, 30000, buffer2, sizeof(buffer2), NULL));
+
+ EXPECT_EQ(0, entry1->ReadData(1, 35000, buffer2, sizeof(buffer2), NULL));
+ EXPECT_EQ(17000, entry1->ReadData(1, 0, buffer1, sizeof(buffer1), NULL));
+ EXPECT_EQ(17000, entry1->WriteData(1, 20000, buffer1, sizeof(buffer1), NULL,
+ false));
EXPECT_EQ(37000, entry1->GetDataSize(1));
entry1->Doom();
@@ -290,17 +284,13 @@ void DiskCacheEntryTest::ExternalAsyncIO() {
MessageLoopHelper helper;
- const int kSize1 = 17000;
- const int kSize2 = 25000;
- const int kSize3 = 25000;
- scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize1);
- scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize2);
- scoped_refptr<net::IOBuffer> buffer3 = new net::IOBuffer(kSize3);
- CacheTestFillBuffer(buffer1->data(), kSize1, false);
- CacheTestFillBuffer(buffer2->data(), kSize2, false);
- CacheTestFillBuffer(buffer3->data(), kSize3, false);
- base::strlcpy(buffer1->data(), "the data", kSize1);
- int ret = entry1->WriteData(0, 0, buffer1, kSize1, &callback1, false);
+ char buffer1[17000], buffer2[25000], buffer3[25000];
+ CacheTestFillBuffer(buffer1, sizeof(buffer1), false);
+ CacheTestFillBuffer(buffer2, sizeof(buffer2), false);
+ CacheTestFillBuffer(buffer3, sizeof(buffer3), false);
+ base::strlcpy(buffer1, "the data", arraysize(buffer1));
+ int ret = entry1->WriteData(0, 0, buffer1, sizeof(buffer1), &callback1,
+ false);
EXPECT_TRUE(17000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
@@ -308,18 +298,19 @@ void DiskCacheEntryTest::ExternalAsyncIO() {
g_cache_tests_max_id = 1;
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
- memset(buffer2->data(), 0, kSize1);
- ret = entry1->ReadData(0, 0, buffer2, kSize1, &callback2);
+ memset(buffer2, 0, sizeof(buffer1));
+ ret = entry1->ReadData(0, 0, buffer2, sizeof(buffer1), &callback2);
EXPECT_TRUE(17000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
g_cache_tests_max_id = 2;
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
- EXPECT_STREQ("the data", buffer1->data());
+ EXPECT_STREQ("the data", buffer1);
- base::strlcpy(buffer2->data(), "The really big data goes here", kSize2);
- ret = entry1->WriteData(1, 10000, buffer2, kSize2, &callback3, false);
+ base::strlcpy(buffer2, "The really big data goes here", arraysize(buffer2));
+ ret = entry1->WriteData(1, 10000, buffer2, sizeof(buffer2), &callback3,
+ false);
EXPECT_TRUE(25000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
@@ -327,34 +318,36 @@ void DiskCacheEntryTest::ExternalAsyncIO() {
g_cache_tests_max_id = 3;
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
- memset(buffer3->data(), 0, kSize3);
- ret = entry1->ReadData(1, 10011, buffer3, kSize3, &callback4);
+ memset(buffer3, 0, sizeof(buffer3));
+ ret = entry1->ReadData(1, 10011, buffer3, sizeof(buffer3), &callback4);
EXPECT_TRUE(24989 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
g_cache_tests_max_id = 4;
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
- EXPECT_STREQ("big data goes here", buffer3->data());
- ret = entry1->ReadData(1, 0, buffer2, kSize2, &callback5);
+ EXPECT_STREQ("big data goes here", buffer3);
+ ret = entry1->ReadData(1, 0, buffer2, sizeof(buffer2), &callback5);
EXPECT_TRUE(25000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
g_cache_tests_max_id = 5;
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
- EXPECT_EQ(0, memcmp(buffer2->data(), buffer2->data(), 10000));
- ret = entry1->ReadData(1, 30000, buffer2, kSize2, &callback6);
+ EXPECT_EQ(0, memcmp(buffer2, buffer2, 10000));
+ ret = entry1->ReadData(1, 30000, buffer2, sizeof(buffer2), &callback6);
EXPECT_TRUE(5000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
- EXPECT_EQ(0, entry1->ReadData(1, 35000, buffer2, kSize2, &callback7));
- ret = entry1->ReadData(1, 0, buffer1, kSize1, &callback8);
+ EXPECT_EQ(0, entry1->ReadData(1, 35000, buffer2, sizeof(buffer2),
+ &callback7));
+ ret = entry1->ReadData(1, 0, buffer1, sizeof(buffer1), &callback8);
EXPECT_TRUE(17000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
- ret = entry1->WriteData(1, 20000, buffer1, kSize1, &callback9, false);
+ ret = entry1->WriteData(1, 20000, buffer1, sizeof(buffer1), &callback9,
+ false);
EXPECT_TRUE(17000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
@@ -388,17 +381,17 @@ void DiskCacheEntryTest::StreamAccess() {
ASSERT_TRUE(NULL != entry);
const int kBufferSize = 1024;
- scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kBufferSize);
- scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kBufferSize);
+ char buffer1[kBufferSize];
+ char buffer2[kBufferSize];
const int kNumStreams = 3;
for (int i = 0; i < kNumStreams; i++) {
- CacheTestFillBuffer(buffer1->data(), kBufferSize, false);
+ CacheTestFillBuffer(buffer1, kBufferSize, false);
EXPECT_EQ(kBufferSize, entry->WriteData(i, 0, buffer1, kBufferSize, NULL,
false));
- memset(buffer2->data(), 0, kBufferSize);
+ memset(buffer2, 0, kBufferSize);
EXPECT_EQ(kBufferSize, entry->ReadData(i, 0, buffer2, kBufferSize, NULL));
- EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kBufferSize));
+ EXPECT_EQ(0, memcmp(buffer1, buffer2, kBufferSize));
}
EXPECT_EQ(net::ERR_INVALID_ARGUMENT,
@@ -468,30 +461,30 @@ void DiskCacheEntryTest::GrowData() {
disk_cache::Entry *entry1, *entry2;
ASSERT_TRUE(cache_->CreateEntry(key1, &entry1));
- const int kSize = 20000;
- scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize);
- scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize);
- CacheTestFillBuffer(buffer1->data(), kSize, false);
- memset(buffer2->data(), 0, kSize);
+ char buffer1[20000];
+ char buffer2[20000];
+ CacheTestFillBuffer(buffer1, sizeof(buffer1), false);
+ memset(buffer2, 0, sizeof(buffer2));
- base::strlcpy(buffer1->data(), "the data", kSize);
+ base::strlcpy(buffer1, "the data", arraysize(buffer1));
EXPECT_EQ(10, entry1->WriteData(0, 0, buffer1, 10, NULL, false));
EXPECT_EQ(10, entry1->ReadData(0, 0, buffer2, 10, NULL));
- EXPECT_STREQ("the data", buffer2->data());
+ EXPECT_STREQ("the data", buffer2);
EXPECT_EQ(10, entry1->GetDataSize(0));
EXPECT_EQ(2000, entry1->WriteData(0, 0, buffer1, 2000, NULL, false));
EXPECT_EQ(2000, entry1->GetDataSize(0));
EXPECT_EQ(2000, entry1->ReadData(0, 0, buffer2, 2000, NULL));
- EXPECT_TRUE(!memcmp(buffer1->data(), buffer2->data(), 2000));
+ EXPECT_TRUE(!memcmp(buffer1, buffer2, 2000));
- EXPECT_EQ(20000, entry1->WriteData(0, 0, buffer1, kSize, NULL, false));
+ EXPECT_EQ(20000, entry1->WriteData(0, 0, buffer1, sizeof(buffer1), NULL,
+ false));
EXPECT_EQ(20000, entry1->GetDataSize(0));
- EXPECT_EQ(20000, entry1->ReadData(0, 0, buffer2, kSize, NULL));
- EXPECT_TRUE(!memcmp(buffer1->data(), buffer2->data(), kSize));
+ EXPECT_EQ(20000, entry1->ReadData(0, 0, buffer2, sizeof(buffer2), NULL));
+ EXPECT_TRUE(!memcmp(buffer1, buffer2, sizeof(buffer1)));
entry1->Close();
- memset(buffer2->data(), 0, kSize);
+ memset(buffer2, 0, sizeof(buffer2));
ASSERT_TRUE(cache_->CreateEntry("Second key", &entry2));
EXPECT_EQ(10, entry2->WriteData(0, 0, buffer1, 10, NULL, false));
EXPECT_EQ(10, entry2->GetDataSize(0));
@@ -502,16 +495,17 @@ void DiskCacheEntryTest::GrowData() {
EXPECT_EQ(2000, entry2->WriteData(0, 0, buffer1, 2000, NULL, false));
EXPECT_EQ(2000, entry2->GetDataSize(0));
EXPECT_EQ(2000, entry2->ReadData(0, 0, buffer2, 2000, NULL));
- EXPECT_TRUE(!memcmp(buffer1->data(), buffer2->data(), 2000));
+ EXPECT_TRUE(!memcmp(buffer1, buffer2, 2000));
entry2->Close();
- memset(buffer2->data(), 0, kSize);
+ memset(buffer2, 0, sizeof(buffer2));
// Go from an internal address to an external one.
ASSERT_TRUE(cache_->OpenEntry("Second key", &entry2));
- EXPECT_EQ(20000, entry2->WriteData(0, 0, buffer1, kSize, NULL, false));
+ EXPECT_EQ(20000, entry2->WriteData(0, 0, buffer1, sizeof(buffer1), NULL,
+ false));
EXPECT_EQ(20000, entry2->GetDataSize(0));
- EXPECT_EQ(20000, entry2->ReadData(0, 0, buffer2, kSize, NULL));
- EXPECT_TRUE(!memcmp(buffer1->data(), buffer2->data(), kSize));
+ EXPECT_EQ(20000, entry2->ReadData(0, 0, buffer2, sizeof(buffer2), NULL));
+ EXPECT_TRUE(!memcmp(buffer1, buffer2, sizeof(buffer1)));
entry2->Close();
}
@@ -531,13 +525,11 @@ void DiskCacheEntryTest::TruncateData() {
disk_cache::Entry *entry1;
ASSERT_TRUE(cache_->CreateEntry(key1, &entry1));
- const int kSize1 = 20000;
- const int kSize2 = 20000;
- scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize1);
- scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize2);
+ char buffer1[20000];
+ char buffer2[20000];
- CacheTestFillBuffer(buffer1->data(), kSize1, false);
- memset(buffer2->data(), 0, kSize2);
+ CacheTestFillBuffer(buffer1, sizeof(buffer1), false);
+ memset(buffer2, 0, sizeof(buffer2));
// Simple truncation:
EXPECT_EQ(200, entry1->WriteData(0, 0, buffer1, 200, NULL, false));
@@ -557,8 +549,8 @@ void DiskCacheEntryTest::TruncateData() {
EXPECT_EQ(20000, entry1->WriteData(0, 0, buffer1, 20000, NULL, true));
EXPECT_EQ(20000, entry1->GetDataSize(0));
EXPECT_EQ(20000, entry1->ReadData(0, 0, buffer2, 20000, NULL));
- EXPECT_TRUE(!memcmp(buffer1->data(), buffer2->data(), 20000));
- memset(buffer2->data(), 0, kSize2);
+ EXPECT_TRUE(!memcmp(buffer1, buffer2, 20000));
+ memset(buffer2, 0, sizeof(buffer2));
// External file truncation
EXPECT_EQ(18000, entry1->WriteData(0, 0, buffer1, 18000, NULL, false));
@@ -572,10 +564,9 @@ void DiskCacheEntryTest::TruncateData() {
EXPECT_EQ(600, entry1->WriteData(0, 1000, buffer1, 600, NULL, true));
EXPECT_EQ(1600, entry1->GetDataSize(0));
EXPECT_EQ(600, entry1->ReadData(0, 1000, buffer2, 600, NULL));
- EXPECT_TRUE(!memcmp(buffer1->data(), buffer2->data(), 600));
+ EXPECT_TRUE(!memcmp(buffer1, buffer2, 600));
EXPECT_EQ(1000, entry1->ReadData(0, 0, buffer2, 1000, NULL));
- EXPECT_TRUE(!memcmp(buffer1->data(), buffer2->data(), 1000)) <<
- "Preserves previous data";
+ EXPECT_TRUE(!memcmp(buffer1, buffer2, 1000)) << "Preserves previous data";
// Go from external file to zero length.
EXPECT_EQ(20000, entry1->WriteData(0, 0, buffer1, 20000, NULL, true));
@@ -613,12 +604,12 @@ void DiskCacheEntryTest::ReuseEntry(int size) {
std::string key2("the second key");
ASSERT_TRUE(cache_->CreateEntry(key2, &entry));
- scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(size);
- CacheTestFillBuffer(buffer->data(), size, false);
+ scoped_array<char> buffer(new char[size]);
+ CacheTestFillBuffer(buffer.get(), size, false);
for (int i = 0; i < 15; i++) {
- EXPECT_EQ(0, entry->WriteData(0, 0, buffer, 0, NULL, true));
- EXPECT_EQ(size, entry->WriteData(0, 0, buffer, size, NULL, false));
+ EXPECT_EQ(0, entry->WriteData(0, 0, buffer.get(), 0, NULL, true));
+ EXPECT_EQ(size, entry->WriteData(0, 0, buffer.get(), size, NULL, false));
entry->Close();
ASSERT_TRUE(cache_->OpenEntry(key2, &entry));
}
@@ -664,21 +655,18 @@ void DiskCacheEntryTest::InvalidData() {
disk_cache::Entry *entry1;
ASSERT_TRUE(cache_->CreateEntry(key1, &entry1));
- const int kSize1 = 20000;
- const int kSize2 = 20000;
- const int kSize3 = 20000;
- scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize1);
- scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize2);
- scoped_refptr<net::IOBuffer> buffer3 = new net::IOBuffer(kSize3);
+ char buffer1[20000];
+ char buffer2[20000];
+ char buffer3[20000];
- CacheTestFillBuffer(buffer1->data(), kSize1, false);
- memset(buffer2->data(), 0, kSize2);
+ CacheTestFillBuffer(buffer1, sizeof(buffer1), false);
+ memset(buffer2, 0, sizeof(buffer2));
// Simple data grow:
EXPECT_EQ(200, entry1->WriteData(0, 400, buffer1, 200, NULL, false));
EXPECT_EQ(600, entry1->GetDataSize(0));
EXPECT_EQ(100, entry1->ReadData(0, 300, buffer3, 100, NULL));
- EXPECT_TRUE(!memcmp(buffer3->data(), buffer2->data(), 100));
+ EXPECT_TRUE(!memcmp(buffer3, buffer2, 100));
entry1->Close();
ASSERT_TRUE(cache_->OpenEntry(key1, &entry1));
@@ -686,7 +674,7 @@ void DiskCacheEntryTest::InvalidData() {
EXPECT_EQ(200, entry1->WriteData(0, 800, buffer1, 200, NULL, false));
EXPECT_EQ(1000, entry1->GetDataSize(0));
EXPECT_EQ(100, entry1->ReadData(0, 700, buffer3, 100, NULL));
- EXPECT_TRUE(!memcmp(buffer3->data(), buffer2->data(), 100));
+ EXPECT_TRUE(!memcmp(buffer3, buffer2, 100));
entry1->Close();
ASSERT_TRUE(cache_->OpenEntry(key1, &entry1));
@@ -694,31 +682,31 @@ void DiskCacheEntryTest::InvalidData() {
EXPECT_EQ(200, entry1->WriteData(0, 1800, buffer1, 200, NULL, true));
EXPECT_EQ(2000, entry1->GetDataSize(0));
EXPECT_EQ(100, entry1->ReadData(0, 1500, buffer3, 100, NULL));
- EXPECT_TRUE(!memcmp(buffer3->data(), buffer2->data(), 100));
+ EXPECT_TRUE(!memcmp(buffer3, buffer2, 100));
// Go to an external file.
EXPECT_EQ(200, entry1->WriteData(0, 19800, buffer1, 200, NULL, false));
EXPECT_EQ(20000, entry1->GetDataSize(0));
EXPECT_EQ(4000, entry1->ReadData(0, 14000, buffer3, 4000, NULL));
- EXPECT_TRUE(!memcmp(buffer3->data(), buffer2->data(), 4000));
+ EXPECT_TRUE(!memcmp(buffer3, buffer2, 4000));
// And back to an internal block.
EXPECT_EQ(600, entry1->WriteData(0, 1000, buffer1, 600, NULL, true));
EXPECT_EQ(1600, entry1->GetDataSize(0));
EXPECT_EQ(600, entry1->ReadData(0, 1000, buffer3, 600, NULL));
- EXPECT_TRUE(!memcmp(buffer3->data(), buffer1->data(), 600));
+ EXPECT_TRUE(!memcmp(buffer3, buffer1, 600));
// Extend it again.
EXPECT_EQ(600, entry1->WriteData(0, 2000, buffer1, 600, NULL, false));
EXPECT_EQ(2600, entry1->GetDataSize(0));
EXPECT_EQ(200, entry1->ReadData(0, 1800, buffer3, 200, NULL));
- EXPECT_TRUE(!memcmp(buffer3->data(), buffer2->data(), 200));
+ EXPECT_TRUE(!memcmp(buffer3, buffer2, 200));
// And again (with truncation flag).
EXPECT_EQ(600, entry1->WriteData(0, 3000, buffer1, 600, NULL, true));
EXPECT_EQ(3600, entry1->GetDataSize(0));
EXPECT_EQ(200, entry1->ReadData(0, 2800, buffer3, 200, NULL));
- EXPECT_TRUE(!memcmp(buffer3->data(), buffer2->data(), 200));
+ EXPECT_TRUE(!memcmp(buffer3, buffer2, 200));
entry1->Close();
}
@@ -741,15 +729,14 @@ void DiskCacheEntryTest::DoomEntry() {
entry1->Doom();
entry1->Close();
- const int kSize = 20000;
- scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize);
- CacheTestFillBuffer(buffer->data(), kSize, true);
- buffer->data()[19999] = '\0';
+ char key_buffer[20000];
+ CacheTestFillBuffer(key_buffer, sizeof(key_buffer), true);
+ key_buffer[19999] = '\0';
- key1 = buffer->data();
+ key1 = key_buffer;
ASSERT_TRUE(cache_->CreateEntry(key1, &entry1));
- EXPECT_EQ(20000, entry1->WriteData(0, 0, buffer, kSize, NULL, false));
- EXPECT_EQ(20000, entry1->WriteData(1, 0, buffer, kSize, NULL, false));
+ EXPECT_EQ(20000, entry1->WriteData(0, 0, key_buffer, 20000, NULL, false));
+ EXPECT_EQ(20000, entry1->WriteData(1, 0, key_buffer, 20000, NULL, false));
entry1->Doom();
entry1->Close();
@@ -778,16 +765,14 @@ void DiskCacheEntryTest::DoomedEntry() {
Time initial = Time::Now();
PlatformThread::Sleep(20);
- const int kSize1 = 2000;
- const int kSize2 = 2000;
- scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize1);
- scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize2);
- CacheTestFillBuffer(buffer1->data(), kSize1, false);
- memset(buffer2->data(), 0, kSize2);
+ char buffer1[2000];
+ char buffer2[2000];
+ CacheTestFillBuffer(buffer1, sizeof(buffer1), false);
+ memset(buffer2, 0, sizeof(buffer2));
EXPECT_EQ(2000, entry->WriteData(0, 0, buffer1, 2000, NULL, false));
EXPECT_EQ(2000, entry->ReadData(0, 0, buffer2, 2000, NULL));
- EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize1));
+ EXPECT_EQ(0, memcmp(buffer1, buffer2, sizeof(buffer1)));
EXPECT_TRUE(initial < entry->GetLastModified());
EXPECT_TRUE(initial < entry->GetLastUsed());
diff --git a/net/disk_cache/mem_entry_impl.cc b/net/disk_cache/mem_entry_impl.cc
index 99c53cd..6bc7b6b 100644
--- a/net/disk_cache/mem_entry_impl.cc
+++ b/net/disk_cache/mem_entry_impl.cc
@@ -4,7 +4,6 @@
#include "net/disk_cache/mem_entry_impl.h"
-#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/disk_cache/mem_backend_impl.h"
@@ -83,8 +82,8 @@ int32 MemEntryImpl::GetDataSize(int index) const {
return data_size_[index];
}
-int MemEntryImpl::ReadData(int index, int offset, net::IOBuffer* buf,
- int buf_len, net::CompletionCallback* completion_callback) {
+int MemEntryImpl::ReadData(int index, int offset, char* buf, int buf_len,
+ net::CompletionCallback* completion_callback) {
if (index < 0 || index >= NUM_STREAMS)
return net::ERR_INVALID_ARGUMENT;
@@ -100,12 +99,13 @@ int MemEntryImpl::ReadData(int index, int offset, net::IOBuffer* buf,
UpdateRank(false);
- memcpy(buf->data() , &(data_[index])[offset], buf_len);
+ memcpy(buf , &(data_[index])[offset], buf_len);
return buf_len;
}
-int MemEntryImpl::WriteData(int index, int offset, net::IOBuffer* buf,
- int buf_len, net::CompletionCallback* completion_callback, bool truncate) {
+int MemEntryImpl::WriteData(int index, int offset, const char* buf, int buf_len,
+ net::CompletionCallback* completion_callback,
+ bool truncate) {
if (index < 0 || index >= NUM_STREAMS)
return net::ERR_INVALID_ARGUMENT;
@@ -143,7 +143,7 @@ int MemEntryImpl::WriteData(int index, int offset, net::IOBuffer* buf,
if (!buf_len)
return 0;
- memcpy(&(data_[index])[offset], buf->data(), buf_len);
+ memcpy(&(data_[index])[offset], buf, buf_len);
return buf_len;
}
diff --git a/net/disk_cache/mem_entry_impl.h b/net/disk_cache/mem_entry_impl.h
index cd8c6e7..d6e44dd 100644
--- a/net/disk_cache/mem_entry_impl.h
+++ b/net/disk_cache/mem_entry_impl.h
@@ -24,9 +24,9 @@ class MemEntryImpl : public Entry {
virtual base::Time GetLastUsed() const;
virtual base::Time GetLastModified() const;
virtual int32 GetDataSize(int index) const;
- virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len,
+ virtual int ReadData(int index, int offset, char* buf, int buf_len,
net::CompletionCallback* completion_callback);
- virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
+ virtual int WriteData(int index, int offset, const char* buf, int buf_len,
net::CompletionCallback* completion_callback,
bool truncate);
diff --git a/net/disk_cache/stress_cache.cc b/net/disk_cache/stress_cache.cc
index e35a195..a7fb144 100644
--- a/net/disk_cache/stress_cache.cc
+++ b/net/disk_cache/stress_cache.cc
@@ -23,7 +23,6 @@
#include "base/process_util.h"
#include "base/string_util.h"
#include "base/thread.h"
-#include "net/base/io_buffer.h"
#include "net/disk_cache/disk_cache.h"
#include "net/disk_cache/disk_cache_test_util.h"
@@ -97,9 +96,9 @@ void StressTheCache(int iteration) {
keys[i] = GenerateKey(true);
}
- const int kSize = 4000;
- scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize);
- memset(buffer->data(), 'k', kSize);
+ const int kDataLen = 4000;
+ char data[kDataLen];
+ memset(data, 'k', kDataLen);
for (int i = 0;; i++) {
int slot = rand() % kNumEntries;
@@ -111,8 +110,9 @@ void StressTheCache(int iteration) {
if (!cache->OpenEntry(keys[key], &entries[slot]))
CHECK(cache->CreateEntry(keys[key], &entries[slot]));
- base::snprintf(buffer->data(), kSize, "%d %d", iteration, i);
- CHECK(kSize == entries[slot]->WriteData(0, 0, buffer, kSize, NULL, false));
+ base::snprintf(data, kDataLen, "%d %d", iteration, i);
+ CHECK(kDataLen == entries[slot]->WriteData(0, 0, data, kDataLen, NULL,
+ false));
if (rand() % 100 > 80) {
key = rand() % kNumKeys;
@@ -188,7 +188,7 @@ int main(int argc, const char* argv[]) {
// Some time for the memory manager to flush stuff.
PlatformThread::Sleep(3000);
- MessageLoop message_loop(MessageLoop::TYPE_IO);
+ MessageLoop message_loop;
char* end;
long int iteration = strtol(argv[1], &end, 0);