summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/base/completion_callback.h17
-rw-r--r--net/base/io_buffer.h16
-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
-rw-r--r--net/http/http_cache.cc33
-rw-r--r--net/http/http_cache_unittest.cc8
-rw-r--r--net/http/http_network_transaction.cc1
-rw-r--r--net/http/http_transaction.h1
-rw-r--r--net/http/http_transaction_unittest.h1
-rw-r--r--net/tools/dump_cache/upgrade.cc12
-rw-r--r--net/url_request/url_request_view_cache_job.cc6
18 files changed, 282 insertions, 314 deletions
diff --git a/net/base/completion_callback.h b/net/base/completion_callback.h
index 4013f71..f9bb233 100644
--- a/net/base/completion_callback.h
+++ b/net/base/completion_callback.h
@@ -6,6 +6,7 @@
#define NET_BASE_COMPLETION_CALLBACK_H__
#include "base/task.h"
+#include "net/base/io_buffer.h"
namespace net {
@@ -41,8 +42,23 @@ class CancelableCompletionCallback :
is_canceled_ = true;
}
+ // Attaches the given buffer to this callback so it is valid until the
+ // operation completes. TODO(rvargas): This is a temporal fix for bug 5325
+ // while I send IOBuffer to the lower layers of code.
+ void UseBuffer(net::IOBuffer* buffer) {
+ DCHECK(!buffer_.get());
+ buffer_ = buffer;
+ }
+
+ // The callback is not expected anymore so release the buffer.
+ void ReleaseBuffer() {
+ DCHECK(buffer_.get());
+ buffer_ = NULL;
+ }
+
virtual void RunWithParams(const Tuple1<int>& params) {
if (is_canceled_) {
+ CancelableCompletionCallback<T>::ReleaseBuffer();
base::RefCounted<CancelableCompletionCallback<T> >::Release();
} else {
CompletionCallbackImpl<T>::RunWithParams(params);
@@ -50,6 +66,7 @@ class CancelableCompletionCallback :
}
private:
+ scoped_refptr<net::IOBuffer> buffer_;
bool is_canceled_;
};
diff --git a/net/base/io_buffer.h b/net/base/io_buffer.h
index 88066c2..39399ad 100644
--- a/net/base/io_buffer.h
+++ b/net/base/io_buffer.h
@@ -19,7 +19,7 @@ class IOBuffer : public base::RefCountedThreadSafe<IOBuffer> {
DCHECK(buffer_size);
data_ = new char[buffer_size];
}
- explicit IOBuffer(char* data) : data_(data) {}
+ explicit IOBuffer(char* buffer) : data_(buffer) {}
virtual ~IOBuffer() {
delete[] data_;
}
@@ -30,20 +30,6 @@ class IOBuffer : public base::RefCountedThreadSafe<IOBuffer> {
char* data_;
};
-// This class allows the creation of a temporary IOBuffer that doesn't really
-// own the underlying buffer. Please use this class only as a last resort.
-// A good example is the buffer for a synchronous operation, where we can be
-// sure that nobody is keeping an extra reference to this object so the lifetime
-// of the buffer can be completely managed by its intended owner.
-class WrappedIOBuffer : public net::IOBuffer {
- public:
- explicit WrappedIOBuffer(const char* data)
- : net::IOBuffer(const_cast<char*>(data)) {}
- ~WrappedIOBuffer() {
- data_ = NULL;
- }
-};
-
} // namespace net
#endif // NET_BASE_IO_BUFFER_H_
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);
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc
index f1132fc..accd7da 100644
--- a/net/http/http_cache.cc
+++ b/net/http/http_cache.cc
@@ -12,7 +12,6 @@
#include "base/ref_counted.h"
#include "base/string_util.h"
#include "base/time.h"
-#include "net/base/io_buffer.h"
#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
#include "net/disk_cache/disk_cache.h"
@@ -169,6 +168,7 @@ class HttpCache::Transaction : public HttpTransaction {
network_trans_(NULL),
callback_(NULL),
mode_(NONE),
+ read_buf_(NULL),
read_offset_(0),
effective_load_flags_(0),
final_upload_progress_(0),
@@ -278,13 +278,13 @@ class HttpCache::Transaction : public HttpTransaction {
// Called to write data to the cache entry. If the write fails, then the
// cache entry is destroyed. Future calls to this function will just do
// nothing without side-effect.
- void WriteToEntry(int index, int offset, IOBuffer* data, int data_len);
+ void WriteToEntry(int index, int offset, const char* data, int data_len);
// Called to write response_ to the cache entry.
void WriteResponseInfoToEntry();
// Called to append response data to the cache entry.
- void AppendResponseDataToEntry(IOBuffer* data, int data_len);
+ void AppendResponseDataToEntry(const char* data, int data_len);
// Called when we are done writing to the cache entry.
void DoneWritingToEntry(bool success);
@@ -308,7 +308,7 @@ class HttpCache::Transaction : public HttpTransaction {
HttpResponseInfo auth_response_;
std::string cache_key_;
Mode mode_;
- scoped_refptr<IOBuffer> read_buf_;
+ char* read_buf_;
int read_offset_;
int effective_load_flags_;
uint64 final_upload_progress_;
@@ -435,20 +435,23 @@ int HttpCache::Transaction::Read(IOBuffer* buf, int buf_len,
case WRITE:
DCHECK(network_trans_.get());
rv = network_trans_->Read(buf, buf_len, &network_read_callback_);
- read_buf_ = buf;
+ read_buf_ = buf->data();
if (rv >= 0)
OnNetworkReadCompleted(rv);
break;
case READ:
DCHECK(entry_);
cache_read_callback_->AddRef(); // Balanced in OnCacheReadCompleted.
+ cache_read_callback_->UseBuffer(buf);
rv = entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_,
- buf, buf_len, cache_read_callback_);
- read_buf_ = buf;
+ buf->data(), buf_len,
+ cache_read_callback_);
+ read_buf_ = buf->data();
if (rv >= 0) {
OnCacheReadCompleted(rv);
} else if (rv != ERR_IO_PENDING) {
cache_read_callback_->Release();
+ cache_read_callback_->ReleaseBuffer();
}
break;
default:
@@ -774,7 +777,7 @@ int HttpCache::Transaction::ReadResponseInfoFromEntry() {
}
void HttpCache::Transaction::WriteToEntry(int index, int offset,
- IOBuffer* data, int data_len) {
+ const char* data, int data_len) {
if (!entry_)
return;
@@ -817,7 +820,7 @@ void HttpCache::Transaction::WriteResponseInfoToEntry() {
}
}
-void HttpCache::Transaction::AppendResponseDataToEntry(IOBuffer* data,
+void HttpCache::Transaction::AppendResponseDataToEntry(const char* data,
int data_len) {
if (!entry_)
return;
@@ -906,6 +909,7 @@ void HttpCache::Transaction::OnNetworkReadCompleted(int result) {
void HttpCache::Transaction::OnCacheReadCompleted(int result) {
DCHECK(cache_);
cache_read_callback_->Release(); // Balance the AddRef() from Start().
+ cache_read_callback_->ReleaseBuffer();
if (result > 0) {
read_offset_ += result;
@@ -997,14 +1001,16 @@ bool HttpCache::ReadResponseInfo(disk_cache::Entry* disk_entry,
HttpResponseInfo* response_info) {
int size = disk_entry->GetDataSize(kResponseInfoIndex);
- scoped_refptr<IOBuffer> buffer = new IOBuffer(size);
- int rv = disk_entry->ReadData(kResponseInfoIndex, 0, buffer, size, NULL);
+ std::string data;
+ int rv = disk_entry->ReadData(kResponseInfoIndex, 0,
+ WriteInto(&data, size + 1),
+ size, NULL);
if (rv != size) {
DLOG(ERROR) << "ReadData failed: " << rv;
return false;
}
- Pickle pickle(buffer->data(), size);
+ Pickle pickle(data.data(), static_cast<int>(data.size()));
void* iter = NULL;
// read flags and verify version
@@ -1102,8 +1108,7 @@ bool HttpCache::WriteResponseInfo(disk_cache::Entry* disk_entry,
if (response_info->vary_data.is_valid())
response_info->vary_data.Persist(&pickle);
- scoped_refptr<WrappedIOBuffer> data = new WrappedIOBuffer(
- reinterpret_cast<const char*>(pickle.data()));
+ const char* data = static_cast<const char*>(pickle.data());
int len = static_cast<int>(pickle.size());
return disk_entry->WriteData(kResponseInfoIndex, 0, data, len, NULL,
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc
index 91bec6e..0a71854 100644
--- a/net/http/http_cache_unittest.cc
+++ b/net/http/http_cache_unittest.cc
@@ -65,7 +65,7 @@ class MockDiskEntry : public disk_cache::Entry,
return static_cast<int32>(data_[index].size());
}
- 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* callback) {
DCHECK(index >= 0 && index < 2);
@@ -75,7 +75,7 @@ class MockDiskEntry : public disk_cache::Entry,
return 0;
int num = std::min(buf_len, static_cast<int>(data_[index].size()) - offset);
- memcpy(buf->data(), &data_[index][offset], num);
+ memcpy(buf, &data_[index][offset], num);
if (!callback || (test_mode_ & TEST_MODE_SYNC_CACHE_READ))
return num;
@@ -84,7 +84,7 @@ class MockDiskEntry : public disk_cache::Entry,
return net::ERR_IO_PENDING;
}
- 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* callback, bool truncate) {
DCHECK(index >= 0 && index < 2);
DCHECK(truncate);
@@ -94,7 +94,7 @@ class MockDiskEntry : public disk_cache::Entry,
data_[index].resize(offset + buf_len);
if (buf_len)
- memcpy(&data_[index][offset], buf->data(), buf_len);
+ memcpy(&data_[index][offset], buf, buf_len);
return buf_len;
}
diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc
index e54ec04..25b21d6 100644
--- a/net/http/http_network_transaction.cc
+++ b/net/http/http_network_transaction.cc
@@ -13,7 +13,6 @@
#include "net/base/connection_type_histograms.h"
#include "net/base/dns_resolution_observer.h"
#include "net/base/host_resolver.h"
-#include "net/base/io_buffer.h"
#include "net/base/load_flags.h"
#include "net/base/net_util.h"
#include "net/base/ssl_client_socket.h"
diff --git a/net/http/http_transaction.h b/net/http/http_transaction.h
index ffb25c6..46c7671 100644
--- a/net/http/http_transaction.h
+++ b/net/http/http_transaction.h
@@ -12,7 +12,6 @@ namespace net {
class HttpRequestInfo;
class HttpResponseInfo;
-class IOBuffer;
// Represents a single HTTP transaction (i.e., a single request/response pair).
// HTTP redirects are not followed and authentication challenges are not
diff --git a/net/http/http_transaction_unittest.h b/net/http/http_transaction_unittest.h
index 9ef6bf8..0c26178 100644
--- a/net/http/http_transaction_unittest.h
+++ b/net/http/http_transaction_unittest.h
@@ -13,7 +13,6 @@
#include "base/compiler_specific.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/base/load_flags.h"
#include "net/base/test_completion_callback.h"
diff --git a/net/tools/dump_cache/upgrade.cc b/net/tools/dump_cache/upgrade.cc
index 6b4a2da..d048c6f 100644
--- a/net/tools/dump_cache/upgrade.cc
+++ b/net/tools/dump_cache/upgrade.cc
@@ -5,7 +5,6 @@
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/string_util.h"
-#include "net/base/io_buffer.h"
#include "net/disk_cache/backend_impl.h"
#include "net/disk_cache/entry_impl.h"
@@ -445,10 +444,8 @@ void MasterSM::DoReadData(int bytes_read) {
return SendReadData();
}
- scoped_refptr<net::WrappedIOBuffer> buf =
- new net::WrappedIOBuffer(input_->buffer);
- if (read_size != entry_->WriteData(stream_, offset_, buf, read_size, NULL,
- false))
+ if (read_size != entry_->WriteData(stream_, offset_, input_->buffer,
+ read_size, NULL, false))
return Fail();
offset_ += read_size;
@@ -716,9 +713,8 @@ void SlaveSM::DoReadData() {
stream < 0 || stream > 1 || size > kBufferSize) {
msg.result = RESULT_INVALID_PARAMETER;
} else {
- scoped_refptr<net::WrappedIOBuffer> buf =
- new net::WrappedIOBuffer(output_->buffer);
- int ret = entry_->ReadData(stream, input_->msg.arg3, buf, size, NULL);
+ int ret = entry_->ReadData(stream, input_->msg.arg3, output_->buffer, size,
+ NULL);
msg.buffer_bytes = (ret < 0) ? 0 : ret;
msg.result = RESULT_OK;
diff --git a/net/url_request/url_request_view_cache_job.cc b/net/url_request/url_request_view_cache_job.cc
index 0cd4efd..5a4a23c 100644
--- a/net/url_request/url_request_view_cache_job.cc
+++ b/net/url_request/url_request_view_cache_job.cc
@@ -87,9 +87,9 @@ static std::string FormatEntryDetails(disk_cache::Entry* entry) {
int data_size = entry->GetDataSize(i);
- scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(data_size);
- if (entry->ReadData(i, 0, buffer, data_size, NULL) == data_size)
- HexDump(buffer->data(), data_size, &result);
+ char* data = new char[data_size];
+ if (entry->ReadData(i, 0, data, data_size, NULL) == data_size)
+ HexDump(data, data_size, &result);
result.append("</pre>");
}