Index: net/disk_cache/entry_impl.cc |
=================================================================== |
--- net/disk_cache/entry_impl.cc (revision 9532) |
+++ net/disk_cache/entry_impl.cc (working copy) |
@@ -7,6 +7,7 @@ |
#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" |
@@ -23,9 +24,9 @@ |
// operation from the actual net class. |
class SyncCallback: public disk_cache::FileIOCallback { |
public: |
- SyncCallback(disk_cache::EntryImpl* entry, |
+ SyncCallback(disk_cache::EntryImpl* entry, net::IOBuffer* buffer, |
net::CompletionCallback* callback ) |
- : entry_(entry), callback_(callback) { |
+ : entry_(entry), callback_(callback), buf_(buffer) { |
entry->AddRef(); |
entry->IncrementIoCount(); |
} |
@@ -36,6 +37,7 @@ |
private: |
disk_cache::EntryImpl* entry_; |
net::CompletionCallback* callback_; |
+ scoped_refptr<net::IOBuffer> buf_; |
DISALLOW_EVIL_CONSTRUCTORS(SyncCallback); |
}; |
@@ -50,6 +52,7 @@ |
void SyncCallback::Discard() { |
callback_ = NULL; |
+ buf_ = NULL; |
OnFileIOComplete(0); |
} |
@@ -194,7 +197,7 @@ |
return entry->Data()->data_size[index]; |
} |
-int EntryImpl::ReadData(int index, int offset, char* buf, int buf_len, |
+int EntryImpl::ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, |
net::CompletionCallback* completion_callback) { |
DCHECK(node_.Data()->dirty); |
if (index < 0 || index >= NUM_STREAMS) |
@@ -222,7 +225,7 @@ |
if (user_buffers_[index].get()) { |
// Complete the operation locally. |
DCHECK(kMaxBlockSize >= offset + buf_len); |
- memcpy(buf , user_buffers_[index].get() + offset, buf_len); |
+ memcpy(buf->data() , user_buffers_[index].get() + offset, buf_len); |
stats.AddTime(Time::Now() - start); |
return buf_len; |
} |
@@ -243,10 +246,10 @@ |
SyncCallback* io_callback = NULL; |
if (completion_callback) |
- io_callback = new SyncCallback(this, completion_callback); |
+ io_callback = new SyncCallback(this, buf, completion_callback); |
bool completed; |
- if (!file->Read(buf, buf_len, file_offset, io_callback, &completed)) { |
+ if (!file->Read(buf->data(), buf_len, file_offset, io_callback, &completed)) { |
if (io_callback) |
io_callback->Discard(); |
return net::ERR_FAILED; |
@@ -259,7 +262,7 @@ |
return (completed || !completion_callback) ? buf_len : net::ERR_IO_PENDING; |
} |
-int EntryImpl::WriteData(int index, int offset, const char* buf, int buf_len, |
+int EntryImpl::WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, |
net::CompletionCallback* completion_callback, |
bool truncate) { |
DCHECK(node_.Data()->dirty); |
@@ -317,8 +320,11 @@ |
if (user_buffers_[index].get()) { |
// Complete the operation locally. |
+ if (!buf_len) |
+ return 0; |
+ |
DCHECK(kMaxBlockSize >= offset + buf_len); |
- memcpy(user_buffers_[index].get() + offset, buf, buf_len); |
+ memcpy(user_buffers_[index].get() + offset, buf->data(), buf_len); |
stats.AddTime(Time::Now() - start); |
return buf_len; |
} |
@@ -342,10 +348,11 @@ |
SyncCallback* io_callback = NULL; |
if (completion_callback) |
- io_callback = new SyncCallback(this, completion_callback); |
+ io_callback = new SyncCallback(this, buf, completion_callback); |
bool completed; |
- if (!file->Write(buf, buf_len, file_offset, io_callback, &completed)) { |
+ if (!file->Write(buf->data(), buf_len, file_offset, io_callback, |
+ &completed)) { |
if (io_callback) |
io_callback->Discard(); |
return net::ERR_FAILED; |