diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-12 08:51:38 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-12 08:51:38 +0000 |
commit | 5eb431e2dfe9d55eaff2acc7a3ea64f403dec669 (patch) | |
tree | 2dedc5eed71c34a111444dc341642a35ae3eb248 | |
parent | d48a64ebbf54a6d87d82c3787e12f35439e1f62b (diff) | |
download | chromium_src-5eb431e2dfe9d55eaff2acc7a3ea64f403dec669.zip chromium_src-5eb431e2dfe9d55eaff2acc7a3ea64f403dec669.tar.gz chromium_src-5eb431e2dfe9d55eaff2acc7a3ea64f403dec669.tar.bz2 |
Switch FileStream to use new CompletionCallback.
BUG=98719
TEST=none
Review URL: http://codereview.chromium.org/8139019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105042 0039d316-1c4b-4281-b951-d872f2087c98
26 files changed, 211 insertions, 199 deletions
diff --git a/chrome/browser/bookmarks/bookmark_html_writer.cc b/chrome/browser/bookmarks/bookmark_html_writer.cc index c6065ac..7349a8e 100644 --- a/chrome/browser/bookmarks/bookmark_html_writer.cc +++ b/chrome/browser/bookmarks/bookmark_html_writer.cc @@ -189,7 +189,8 @@ class Writer : public Task { // Writes raw text out returning true on success. This does not escape // the text in anyway. bool Write(const std::string& text) { - size_t wrote = file_stream_.Write(text.c_str(), text.length(), NULL); + size_t wrote = file_stream_.Write(text.c_str(), text.length(), + net::CompletionCallback()); bool result = (wrote == text.length()); DCHECK(result); return result; diff --git a/chrome/browser/safe_browsing/bloom_filter.cc b/chrome/browser/safe_browsing/bloom_filter.cc index da1c8ca..b734009 100644 --- a/chrome/browser/safe_browsing/bloom_filter.cc +++ b/chrome/browser/safe_browsing/bloom_filter.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -100,7 +100,7 @@ BloomFilter* BloomFilter::LoadFile(const FilePath& filter_name) { // Make sure we have a file version that we can understand. int file_version; int bytes_read = filter.Read(reinterpret_cast<char*>(&file_version), - sizeof(file_version), NULL); + sizeof(file_version), net::CompletionCallback()); if (bytes_read != sizeof(file_version) || file_version != kFileVersion) { RecordFailure(FAILURE_FILTER_READ_VERSION); return NULL; @@ -109,7 +109,7 @@ BloomFilter* BloomFilter::LoadFile(const FilePath& filter_name) { // Get all the random hash keys. int num_keys; bytes_read = filter.Read(reinterpret_cast<char*>(&num_keys), - sizeof(num_keys), NULL); + sizeof(num_keys), net::CompletionCallback()); if (bytes_read != sizeof(num_keys) || num_keys < 1 || num_keys > kNumHashKeys) { RecordFailure(FAILURE_FILTER_READ_NUM_KEYS); @@ -119,7 +119,8 @@ BloomFilter* BloomFilter::LoadFile(const FilePath& filter_name) { HashKeys hash_keys; for (int i = 0; i < num_keys; ++i) { HashKey key; - bytes_read = filter.Read(reinterpret_cast<char*>(&key), sizeof(key), NULL); + bytes_read = filter.Read( + reinterpret_cast<char*>(&key), sizeof(key), net::CompletionCallback()); if (bytes_read != sizeof(key)) { RecordFailure(FAILURE_FILTER_READ_KEY); return NULL; @@ -139,7 +140,7 @@ BloomFilter* BloomFilter::LoadFile(const FilePath& filter_name) { int byte_size = static_cast<int>(remaining64); scoped_array<char> data(new char[byte_size]); - bytes_read = filter.Read(data.get(), byte_size, NULL); + bytes_read = filter.Read(data.get(), byte_size, net::CompletionCallback()); if (bytes_read < byte_size) { RecordFailure(FAILURE_FILTER_READ_DATA_SHORT); return NULL; @@ -163,26 +164,28 @@ bool BloomFilter::WriteFile(const FilePath& filter_name) const { // Write the version information. int version = kFileVersion; int bytes_written = filter.Write(reinterpret_cast<char*>(&version), - sizeof(version), NULL); + sizeof(version), net::CompletionCallback()); if (bytes_written != sizeof(version)) return false; // Write the number of random hash keys. int num_keys = static_cast<int>(hash_keys_.size()); bytes_written = filter.Write(reinterpret_cast<char*>(&num_keys), - sizeof(num_keys), NULL); + sizeof(num_keys), net::CompletionCallback()); if (bytes_written != sizeof(num_keys)) return false; for (int i = 0; i < num_keys; ++i) { - bytes_written = filter.Write(reinterpret_cast<const char*>(&hash_keys_[i]), - sizeof(hash_keys_[i]), NULL); + bytes_written = + filter.Write(reinterpret_cast<const char*>(&hash_keys_[i]), + sizeof(hash_keys_[i]), net::CompletionCallback()); if (bytes_written != sizeof(hash_keys_[i])) return false; } // Write the filter data. - bytes_written = filter.Write(data_.get(), byte_size_, NULL); + bytes_written = + filter.Write(data_.get(), byte_size_, net::CompletionCallback()); if (bytes_written != byte_size_) return false; diff --git a/chrome/browser/sessions/session_backend.cc b/chrome/browser/sessions/session_backend.cc index 15b4b3c..a29719b 100644 --- a/chrome/browser/sessions/session_backend.cc +++ b/chrome/browser/sessions/session_backend.cc @@ -320,21 +320,21 @@ bool SessionBackend::AppendCommandsToFile(net::FileStream* file, else UMA_HISTOGRAM_COUNTS("SessionRestore.command_size", total_size); wrote = file->Write(reinterpret_cast<const char*>(&total_size), - sizeof(total_size), NULL); + sizeof(total_size), net::CompletionCallback()); if (wrote != sizeof(total_size)) { NOTREACHED() << "error writing"; return false; } id_type command_id = (*i)->id(); wrote = file->Write(reinterpret_cast<char*>(&command_id), - sizeof(command_id), NULL); + sizeof(command_id), net::CompletionCallback()); if (wrote != sizeof(command_id)) { NOTREACHED() << "error writing"; return false; } if (content_size > 0) { wrote = file->Write(reinterpret_cast<char*>((*i)->contents()), - content_size, NULL); + content_size, net::CompletionCallback()); if (wrote != content_size) { NOTREACHED() << "error writing"; return false; @@ -375,7 +375,7 @@ net::FileStream* SessionBackend::OpenAndWriteHeader(const FilePath& path) { header.signature = kFileSignature; header.version = kFileCurrentVersion; int wrote = file->Write(reinterpret_cast<char*>(&header), - sizeof(header), NULL); + sizeof(header), net::CompletionCallback()); if (wrote != sizeof(header)) return NULL; return file.release(); diff --git a/chrome/browser/ui/cocoa/tab_contents/web_drag_source.mm b/chrome/browser/ui/cocoa/tab_contents/web_drag_source.mm index 3c95df4..dd99146 100644 --- a/chrome/browser/ui/cocoa/tab_contents/web_drag_source.mm +++ b/chrome/browser/ui/cocoa/tab_contents/web_drag_source.mm @@ -116,7 +116,7 @@ void PromiseWriterTask::Run() { CHECK(file_stream_.get()); file_stream_->Write(drop_data_.file_contents.data(), drop_data_.file_contents.length(), - NULL); + net::CompletionCallback()); // Let our destructor take care of business. } diff --git a/chrome/common/zip.cc b/chrome/common/zip.cc index b834b9a..426f44f 100644 --- a/chrome/common/zip.cc +++ b/chrome/common/zip.cc @@ -88,7 +88,8 @@ static bool ExtractCurrentFile(unzFile zip_file, break; } if (num_bytes > 0) { - if (num_bytes != stream.Write(buf, num_bytes, NULL)) { + if (num_bytes != stream.Write(buf, num_bytes, + net::CompletionCallback())) { ret = false; break; } @@ -214,7 +215,7 @@ static bool AddFileToZip(zipFile zip_file, const FilePath& src_dir) { int num_bytes; char buf[kZipBufSize]; do { - num_bytes = stream.Read(buf, kZipBufSize, NULL); + num_bytes = stream.Read(buf, kZipBufSize, net::CompletionCallback()); if (num_bytes > 0) { if (ZIP_OK != zipWriteInFileInZip(zip_file, buf, num_bytes)) { LOG(ERROR) << "Could not write data to zip for path " diff --git a/content/browser/download/base_file.cc b/content/browser/download/base_file.cc index f2c2672..07c18f8 100644 --- a/content/browser/download/base_file.cc +++ b/content/browser/download/base_file.cc @@ -251,7 +251,8 @@ net::Error BaseFile::AppendDataToFile(const char* data, size_t data_len) { const char* current_data = data; while (len > 0) { write_count++; - int write_result = file_stream_->Write(current_data, len, NULL); + int write_result = + file_stream_->Write(current_data, len, net::CompletionCallback()); DCHECK_NE(0, write_result); // Check for errors. diff --git a/content/browser/renderer_host/redirect_to_file_resource_handler.cc b/content/browser/renderer_host/redirect_to_file_resource_handler.cc index 64d4fcf..19079a3 100644 --- a/content/browser/renderer_host/redirect_to_file_resource_handler.cc +++ b/content/browser/renderer_host/redirect_to_file_resource_handler.cc @@ -4,6 +4,7 @@ #include "content/browser/renderer_host/redirect_to_file_resource_handler.h" +#include "base/bind.h" #include "base/file_util.h" #include "base/file_util_proxy.h" #include "base/logging.h" @@ -34,8 +35,6 @@ RedirectToFileResourceHandler::RedirectToFileResourceHandler( buf_(new net::GrowableIOBuffer()), buf_write_pending_(false), write_cursor_(0), - write_callback_(ALLOW_THIS_IN_INITIALIZER_LIST(this), - &RedirectToFileResourceHandler::DidWriteToFile), write_callback_pending_(false), request_was_closed_(false), completed_during_write_(false) { @@ -222,9 +221,11 @@ bool RedirectToFileResourceHandler::WriteMore() { if (write_callback_pending_) return true; DCHECK(write_cursor_ < buf_->offset()); - int rv = file_stream_->Write(buf_->StartOfBuffer() + write_cursor_, - buf_->offset() - write_cursor_, - &write_callback_); + int rv = file_stream_->Write( + buf_->StartOfBuffer() + write_cursor_, + buf_->offset() - write_cursor_, + base::Bind(&RedirectToFileResourceHandler::DidWriteToFile, + base::Unretained(this))); if (rv == net::ERR_IO_PENDING) { write_callback_pending_ = true; return true; diff --git a/content/browser/renderer_host/redirect_to_file_resource_handler.h b/content/browser/renderer_host/redirect_to_file_resource_handler.h index 638ea50..c860b2d 100644 --- a/content/browser/renderer_host/redirect_to_file_resource_handler.h +++ b/content/browser/renderer_host/redirect_to_file_resource_handler.h @@ -11,7 +11,6 @@ #include "base/memory/scoped_ptr.h" #include "base/platform_file.h" #include "content/browser/renderer_host/resource_handler.h" -#include "net/base/completion_callback.h" #include "net/url_request/url_request_status.h" class RefCountedPlatformFile; @@ -77,7 +76,6 @@ class RedirectToFileResourceHandler : public ResourceHandler { int write_cursor_; scoped_ptr<net::FileStream> file_stream_; - net::OldCompletionCallbackImpl<RedirectToFileResourceHandler> write_callback_; bool write_callback_pending_; // We create a DeletableFileReference for the temp file created as diff --git a/net/base/file_stream.h b/net/base/file_stream.h index 2c8cccd..f2a8f7f 100644 --- a/net/base/file_stream.h +++ b/net/base/file_stream.h @@ -84,8 +84,8 @@ class NET_EXPORT FileStream { // // This method should not be called if the stream was opened WRITE_ONLY. // - // You can pass NULL as the callback for synchronous I/O. - virtual int Read(char* buf, int buf_len, OldCompletionCallback* callback); + // You can pass a null callback for synchronous I/O. + virtual int Read(char* buf, int buf_len, const CompletionCallback& callback); // Performs the same as Read, but ensures that exactly buf_len bytes // are copied into buf. A partial read may occur, but only as a result of @@ -112,8 +112,9 @@ class NET_EXPORT FileStream { // // This method should not be called if the stream was opened READ_ONLY. // - // You can pass NULL as the callback for synchronous I/O. - virtual int Write(const char* buf, int buf_len, OldCompletionCallback* callback); + // You can pass a null callback for synchronous I/O. + virtual int Write(const char* buf, int buf_len, + const CompletionCallback& callback); // Truncates the file to be |bytes| length. This is only valid for writable // files. After truncation the file stream is positioned at |bytes|. The new diff --git a/net/base/file_stream_posix.cc b/net/base/file_stream_posix.cc index f1c118b..45874e8 100644 --- a/net/base/file_stream_posix.cc +++ b/net/base/file_stream_posix.cc @@ -14,6 +14,7 @@ #include <errno.h> #include "base/basictypes.h" +#include "base/bind.h" #include "base/callback.h" #include "base/eintr_wrapper.h" #include "base/file_path.h" @@ -70,8 +71,8 @@ void ReadFileTask(base::PlatformFile file, char* buf, int buf_len, bool record_uma, - OldCompletionCallback* callback) { - callback->Run(ReadFile(file, buf, buf_len, record_uma)); + const CompletionCallback& callback) { + callback.Run(ReadFile(file, buf, buf_len, record_uma)); } // WriteFile() is a simple wrapper around write() that handles EINTR signals and @@ -89,8 +90,8 @@ int WriteFile(base::PlatformFile file, const char* buf, int buf_len, void WriteFileTask(base::PlatformFile file, const char* buf, int buf_len, bool record_uma, - OldCompletionCallback* callback) { - callback->Run(WriteFile(file, buf, buf_len, record_uma)); + const CompletionCallback& callback) { + callback.Run(WriteFile(file, buf, buf_len, record_uma)); } // FlushFile() is a simple wrapper around fsync() that handles EINTR signals and @@ -137,12 +138,12 @@ class FileStream::AsyncContext { // These methods post synchronous read() and write() calls to a WorkerThread. void InitiateAsyncRead( base::PlatformFile file, char* buf, int buf_len, - OldCompletionCallback* callback); + const CompletionCallback& callback); void InitiateAsyncWrite( base::PlatformFile file, const char* buf, int buf_len, - OldCompletionCallback* callback); + const CompletionCallback& callback); - OldCompletionCallback* callback() const { return callback_; } + const CompletionCallback& callback() const { return callback_; } // Called by the WorkerPool thread executing the IO after the IO completes. // This method queues RunAsynchronousCallback() on the MessageLoop and signals @@ -163,11 +164,7 @@ class FileStream::AsyncContext { // The MessageLoopForIO that this AsyncContext is running on. MessageLoopForIO* const message_loop_; - OldCompletionCallback* callback_; // The user provided callback. - - // A callback wrapper around OnBackgroundIOCompleted(). Run by the WorkerPool - // thread doing the background IO on our behalf. - OldCompletionCallbackImpl<AsyncContext> background_io_completed_callback_; + CompletionCallback callback_; // The user provided callback. // This is used to synchronize between the AsyncContext destructor (which runs // on the IO thread and OnBackgroundIOCompleted() which runs on the WorkerPool @@ -186,9 +183,6 @@ class FileStream::AsyncContext { FileStream::AsyncContext::AsyncContext() : message_loop_(MessageLoopForIO::current()), - callback_(NULL), - background_io_completed_callback_( - this, &AsyncContext::OnBackgroundIOCompleted), background_io_completed_(true, false), message_loop_task_(NULL), is_closing_(false), @@ -196,7 +190,7 @@ FileStream::AsyncContext::AsyncContext() FileStream::AsyncContext::~AsyncContext() { is_closing_ = true; - if (callback_) { + if (!callback_.is_null()) { // If |callback_| is non-NULL, that implies either the worker thread is // still running the IO task, or the completion callback is queued up on the // MessageLoopForIO, but AsyncContext() got deleted before then. @@ -213,32 +207,34 @@ FileStream::AsyncContext::~AsyncContext() { void FileStream::AsyncContext::InitiateAsyncRead( base::PlatformFile file, char* buf, int buf_len, - OldCompletionCallback* callback) { - DCHECK(!callback_); + const CompletionCallback& callback) { + DCHECK(callback_.is_null()); callback_ = callback; - base::WorkerPool::PostTask(FROM_HERE, - NewRunnableFunction( - &ReadFileTask, - file, buf, buf_len, - record_uma_, - &background_io_completed_callback_), - true /* task_is_slow */); + base::WorkerPool::PostTask( + FROM_HERE, + base::Bind(&ReadFileTask, file, buf, buf_len, + record_uma_, + base::Bind(&AsyncContext::OnBackgroundIOCompleted, + base::Unretained(this))), + true /* task_is_slow */); } void FileStream::AsyncContext::InitiateAsyncWrite( base::PlatformFile file, const char* buf, int buf_len, - OldCompletionCallback* callback) { - DCHECK(!callback_); + const CompletionCallback& callback) { + DCHECK(callback_.is_null()); callback_ = callback; - base::WorkerPool::PostTask(FROM_HERE, - NewRunnableFunction( - &WriteFileTask, - file, buf, buf_len, - record_uma_, - &background_io_completed_callback_), - true /* task_is_slow */); + base::WorkerPool::PostTask( + FROM_HERE, + base::Bind( + &WriteFileTask, + file, buf, buf_len, + record_uma_, + base::Bind(&AsyncContext::OnBackgroundIOCompleted, + base::Unretained(this))), + true /* task_is_slow */); } void FileStream::AsyncContext::OnBackgroundIOCompleted(int result) { @@ -261,15 +257,15 @@ void FileStream::AsyncContext::RunAsynchronousCallback() { message_loop_task_ = NULL; if (is_closing_) { - callback_ = NULL; + callback_.Reset(); return; } - DCHECK(callback_); - OldCompletionCallback* temp = NULL; + DCHECK(!callback_.is_null()); + CompletionCallback temp; std::swap(temp, callback_); background_io_completed_.Reset(); - temp->Run(result_); + temp.Run(result_); } // FileStream ------------------------------------------------------------ @@ -339,7 +335,7 @@ int64 FileStream::Seek(Whence whence, int64 offset) { return ERR_UNEXPECTED; // If we're in async, make sure we don't have a request in flight. - DCHECK(!async_context_.get() || !async_context_->callback()); + DCHECK(!async_context_.get() || async_context_->callback().is_null()); off_t res = lseek(file_, static_cast<off_t>(offset), static_cast<int>(whence)); @@ -370,18 +366,18 @@ int64 FileStream::Available() { } int FileStream::Read( - char* buf, int buf_len, OldCompletionCallback* callback) { + char* buf, int buf_len, const CompletionCallback& callback) { if (!IsOpen()) return ERR_UNEXPECTED; // read(..., 0) will return 0, which indicates end-of-file. - DCHECK(buf_len > 0); + DCHECK_GT(buf_len, 0); DCHECK(open_flags_ & base::PLATFORM_FILE_READ); if (async_context_.get()) { DCHECK(open_flags_ & base::PLATFORM_FILE_ASYNC); // If we're in async, make sure we don't have a request in flight. - DCHECK(!async_context_->callback()); + DCHECK(async_context_->callback().is_null()); if (record_uma_) async_context_->EnableErrorStatistics(); async_context_->InitiateAsyncRead(file_, buf, buf_len, callback); @@ -396,7 +392,7 @@ int FileStream::ReadUntilComplete(char *buf, int buf_len) { int bytes_total = 0; do { - int bytes_read = Read(buf, to_read, NULL); + int bytes_read = Read(buf, to_read, CompletionCallback()); if (bytes_read <= 0) { if (bytes_total == 0) return bytes_read; @@ -413,7 +409,7 @@ int FileStream::ReadUntilComplete(char *buf, int buf_len) { } int FileStream::Write( - const char* buf, int buf_len, OldCompletionCallback* callback) { + const char* buf, int buf_len, const CompletionCallback& callback) { // write(..., 0) will return 0, which indicates end-of-file. DCHECK_GT(buf_len, 0); @@ -423,7 +419,7 @@ int FileStream::Write( if (async_context_.get()) { DCHECK(open_flags_ & base::PLATFORM_FILE_ASYNC); // If we're in async, make sure we don't have a request in flight. - DCHECK(!async_context_->callback()); + DCHECK(async_context_->callback().is_null()); if (record_uma_) async_context_->EnableErrorStatistics(); async_context_->InitiateAsyncWrite(file_, buf, buf_len, callback); diff --git a/net/base/file_stream_unittest.cc b/net/base/file_stream_unittest.cc index 16c9fe3..966a829 100644 --- a/net/base/file_stream_unittest.cc +++ b/net/base/file_stream_unittest.cc @@ -2,12 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "net/base/file_stream.h" + +#include "base/bind.h" #include "base/callback.h" #include "base/file_util.h" #include "base/message_loop.h" #include "base/path_service.h" #include "base/platform_file.h" -#include "net/base/file_stream.h" #include "net/base/net_errors.h" #include "net/base/test_completion_callback.h" #include "testing/gtest/include/gtest/gtest.h" @@ -103,7 +105,8 @@ TEST_F(FileStreamTest, UseFileHandle) { ASSERT_EQ(kTestDataSize, read_stream.Available()); // Read into buffer and compare. char buffer[kTestDataSize]; - ASSERT_EQ(kTestDataSize, read_stream.Read(buffer, kTestDataSize, NULL)); + ASSERT_EQ(kTestDataSize, + read_stream.Read(buffer, kTestDataSize, CompletionCallback())); ASSERT_EQ(0, memcmp(kTestData, buffer, kTestDataSize)); read_stream.Close(); @@ -114,7 +117,8 @@ TEST_F(FileStreamTest, UseFileHandle) { FileStream write_stream(file, flags); ASSERT_EQ(0, write_stream.Seek(FROM_BEGIN, 0)); - ASSERT_EQ(kTestDataSize, write_stream.Write(kTestData, kTestDataSize, NULL)); + ASSERT_EQ(kTestDataSize, + write_stream.Write(kTestData, kTestDataSize, CompletionCallback())); write_stream.Close(); // Read into buffer and compare to make sure the handle worked fine. @@ -138,7 +142,7 @@ TEST_F(FileStreamTest, UseClosedStream) { // Try reading... char buf[10]; - int rv = stream.Read(buf, arraysize(buf), NULL); + int rv = stream.Read(buf, arraysize(buf), CompletionCallback()); EXPECT_EQ(ERR_UNEXPECTED, rv); } @@ -161,7 +165,7 @@ TEST_F(FileStreamTest, BasicRead) { std::string data_read; for (;;) { char buf[4]; - rv = stream.Read(buf, arraysize(buf), NULL); + rv = stream.Read(buf, arraysize(buf), CompletionCallback()); EXPECT_LE(0, rv); if (rv <= 0) break; @@ -187,14 +191,14 @@ TEST_F(FileStreamTest, AsyncRead) { int64 total_bytes_avail = stream.Available(); EXPECT_EQ(file_size, total_bytes_avail); - TestOldCompletionCallback callback; + TestCompletionCallback callback; int total_bytes_read = 0; std::string data_read; for (;;) { char buf[4]; - rv = stream.Read(buf, arraysize(buf), &callback); + rv = stream.Read(buf, arraysize(buf), callback.callback()); if (rv == ERR_IO_PENDING) rv = callback.WaitForResult(); EXPECT_LE(0, rv); @@ -222,10 +226,10 @@ TEST_F(FileStreamTest, AsyncRead_EarlyClose) { int64 total_bytes_avail = stream.Available(); EXPECT_EQ(file_size, total_bytes_avail); - TestOldCompletionCallback callback; + TestCompletionCallback callback; char buf[4]; - rv = stream.Read(buf, arraysize(buf), &callback); + rv = stream.Read(buf, arraysize(buf), callback.callback()); stream.Close(); if (rv < 0) { EXPECT_EQ(ERR_IO_PENDING, rv); @@ -260,7 +264,7 @@ TEST_F(FileStreamTest, BasicRead_FromOffset) { std::string data_read; for (;;) { char buf[4]; - rv = stream.Read(buf, arraysize(buf), NULL); + rv = stream.Read(buf, arraysize(buf), CompletionCallback()); EXPECT_LE(0, rv); if (rv <= 0) break; @@ -291,14 +295,14 @@ TEST_F(FileStreamTest, AsyncRead_FromOffset) { int64 total_bytes_avail = stream.Available(); EXPECT_EQ(file_size - kOffset, total_bytes_avail); - TestOldCompletionCallback callback; + TestCompletionCallback callback; int total_bytes_read = 0; std::string data_read; for (;;) { char buf[4]; - rv = stream.Read(buf, arraysize(buf), &callback); + rv = stream.Read(buf, arraysize(buf), callback.callback()); if (rv == ERR_IO_PENDING) rv = callback.WaitForResult(); EXPECT_LE(0, rv); @@ -346,7 +350,7 @@ TEST_F(FileStreamTest, BasicWrite) { EXPECT_TRUE(ok); EXPECT_EQ(0, file_size); - rv = stream.Write(kTestData, kTestDataSize, NULL); + rv = stream.Write(kTestData, kTestDataSize, CompletionCallback()); EXPECT_EQ(kTestDataSize, rv); stream.Close(); @@ -368,13 +372,13 @@ TEST_F(FileStreamTest, AsyncWrite) { EXPECT_TRUE(ok); EXPECT_EQ(0, file_size); - TestOldCompletionCallback callback; + TestCompletionCallback callback; int total_bytes_written = 0; while (total_bytes_written != kTestDataSize) { rv = stream.Write(kTestData + total_bytes_written, kTestDataSize - total_bytes_written, - &callback); + callback.callback()); if (rv == ERR_IO_PENDING) rv = callback.WaitForResult(); EXPECT_LT(0, rv); @@ -400,12 +404,12 @@ TEST_F(FileStreamTest, AsyncWrite_EarlyClose) { EXPECT_TRUE(ok); EXPECT_EQ(0, file_size); - TestOldCompletionCallback callback; + TestCompletionCallback callback; int total_bytes_written = 0; rv = stream.Write(kTestData + total_bytes_written, kTestDataSize - total_bytes_written, - &callback); + callback.callback()); stream.Close(); if (rv < 0) { EXPECT_EQ(ERR_IO_PENDING, rv); @@ -435,7 +439,7 @@ TEST_F(FileStreamTest, BasicWrite_FromOffset) { int64 new_offset = stream.Seek(FROM_END, kOffset); EXPECT_EQ(kTestDataSize, new_offset); - rv = stream.Write(kTestData, kTestDataSize, NULL); + rv = stream.Write(kTestData, kTestDataSize, CompletionCallback()); EXPECT_EQ(kTestDataSize, rv); stream.Close(); @@ -460,13 +464,13 @@ TEST_F(FileStreamTest, AsyncWrite_FromOffset) { int64 new_offset = stream.Seek(FROM_END, kOffset); EXPECT_EQ(kTestDataSize, new_offset); - TestOldCompletionCallback callback; + TestCompletionCallback callback; int total_bytes_written = 0; while (total_bytes_written != kTestDataSize) { rv = stream.Write(kTestData + total_bytes_written, kTestDataSize - total_bytes_written, - &callback); + callback.callback()); if (rv == ERR_IO_PENDING) rv = callback.WaitForResult(); EXPECT_LT(0, rv); @@ -499,7 +503,7 @@ TEST_F(FileStreamTest, BasicReadWrite) { std::string data_read; for (;;) { char buf[4]; - rv = stream.Read(buf, arraysize(buf), NULL); + rv = stream.Read(buf, arraysize(buf), CompletionCallback()); EXPECT_LE(0, rv); if (rv <= 0) break; @@ -509,7 +513,7 @@ TEST_F(FileStreamTest, BasicReadWrite) { EXPECT_EQ(file_size, total_bytes_read); EXPECT_TRUE(data_read == kTestData); - rv = stream.Write(kTestData, kTestDataSize, NULL); + rv = stream.Write(kTestData, kTestDataSize, CompletionCallback()); EXPECT_EQ(kTestDataSize, rv); stream.Close(); @@ -536,7 +540,7 @@ TEST_F(FileStreamTest, BasicWriteRead) { int64 offset = stream.Seek(FROM_END, 0); EXPECT_EQ(offset, file_size); - rv = stream.Write(kTestData, kTestDataSize, NULL); + rv = stream.Write(kTestData, kTestDataSize, CompletionCallback()); EXPECT_EQ(kTestDataSize, rv); offset = stream.Seek(FROM_BEGIN, 0); @@ -547,7 +551,7 @@ TEST_F(FileStreamTest, BasicWriteRead) { std::string data_read; for (;;) { char buf[4]; - rv = stream.Read(buf, arraysize(buf), NULL); + rv = stream.Read(buf, arraysize(buf), CompletionCallback()); EXPECT_LE(0, rv); if (rv <= 0) break; @@ -582,13 +586,13 @@ TEST_F(FileStreamTest, BasicAsyncReadWrite) { int64 total_bytes_avail = stream.Available(); EXPECT_EQ(file_size, total_bytes_avail); - TestOldCompletionCallback callback; + TestCompletionCallback callback; int64 total_bytes_read = 0; std::string data_read; for (;;) { char buf[4]; - rv = stream.Read(buf, arraysize(buf), &callback); + rv = stream.Read(buf, arraysize(buf), callback.callback()); if (rv == ERR_IO_PENDING) rv = callback.WaitForResult(); EXPECT_LE(0, rv); @@ -605,7 +609,7 @@ TEST_F(FileStreamTest, BasicAsyncReadWrite) { while (total_bytes_written != kTestDataSize) { rv = stream.Write(kTestData + total_bytes_written, kTestDataSize - total_bytes_written, - &callback); + callback.callback()); if (rv == ERR_IO_PENDING) rv = callback.WaitForResult(); EXPECT_LT(0, rv); @@ -640,13 +644,13 @@ TEST_F(FileStreamTest, BasicAsyncWriteRead) { int64 offset = stream.Seek(FROM_END, 0); EXPECT_EQ(offset, file_size); - TestOldCompletionCallback callback; + TestCompletionCallback callback; int total_bytes_written = 0; while (total_bytes_written != kTestDataSize) { rv = stream.Write(kTestData + total_bytes_written, kTestDataSize - total_bytes_written, - &callback); + callback.callback()); if (rv == ERR_IO_PENDING) rv = callback.WaitForResult(); EXPECT_LT(0, rv); @@ -665,7 +669,7 @@ TEST_F(FileStreamTest, BasicAsyncWriteRead) { std::string data_read; for (;;) { char buf[4]; - rv = stream.Read(buf, arraysize(buf), &callback); + rv = stream.Read(buf, arraysize(buf), callback.callback()); if (rv == ERR_IO_PENDING) rv = callback.WaitForResult(); EXPECT_LE(0, rv); @@ -686,9 +690,9 @@ TEST_F(FileStreamTest, BasicAsyncWriteRead) { EXPECT_EQ(kExpectedFileData, data_read); } -class TestWriteReadOldCompletionCallback : public Callback1<int>::Type { +class TestWriteReadCompletionCallback { public: - TestWriteReadOldCompletionCallback( + TestWriteReadCompletionCallback( FileStream* stream, int* total_bytes_written, int* total_bytes_read, @@ -699,7 +703,9 @@ class TestWriteReadOldCompletionCallback : public Callback1<int>::Type { stream_(stream), total_bytes_written_(total_bytes_written), total_bytes_read_(total_bytes_read), - data_read_(data_read) {} + data_read_(data_read), + callback_(base::Bind(&TestWriteReadCompletionCallback::OnComplete, + base::Unretained(this))) {} int WaitForResult() { DCHECK(!waiting_for_result_); @@ -712,10 +718,12 @@ class TestWriteReadOldCompletionCallback : public Callback1<int>::Type { return result_; } + const CompletionCallback& callback() const { return callback_; } + private: - virtual void RunWithParams(const Tuple1<int>& params) { - DCHECK_LT(0, params.a); - *total_bytes_written_ += params.a; + void OnComplete(int result) { + DCHECK_LT(0, result); + *total_bytes_written_ += result; int rv; @@ -723,11 +731,11 @@ class TestWriteReadOldCompletionCallback : public Callback1<int>::Type { // Recurse to finish writing all data. int total_bytes_written = 0, total_bytes_read = 0; std::string data_read; - TestWriteReadOldCompletionCallback callback( + TestWriteReadCompletionCallback callback( stream_, &total_bytes_written, &total_bytes_read, &data_read); rv = stream_->Write(kTestData + *total_bytes_written_, kTestDataSize - *total_bytes_written_, - &callback); + callback.callback()); DCHECK_EQ(ERR_IO_PENDING, rv); rv = callback.WaitForResult(); *total_bytes_written_ += total_bytes_written; @@ -736,10 +744,10 @@ class TestWriteReadOldCompletionCallback : public Callback1<int>::Type { } else { // We're done writing all data. Start reading the data. stream_->Seek(FROM_BEGIN, 0); - TestOldCompletionCallback callback; + TestCompletionCallback callback; for (;;) { char buf[4]; - rv = stream_->Read(buf, arraysize(buf), &callback); + rv = stream_->Read(buf, arraysize(buf), callback.callback()); if (rv == ERR_IO_PENDING) { bool old_state = MessageLoop::current()->NestableTasksAllowed(); MessageLoop::current()->SetNestableTasksAllowed(true); @@ -767,8 +775,9 @@ class TestWriteReadOldCompletionCallback : public Callback1<int>::Type { int* total_bytes_written_; int* total_bytes_read_; std::string* data_read_; + const CompletionCallback callback_; - DISALLOW_COPY_AND_ASSIGN(TestWriteReadOldCompletionCallback); + DISALLOW_COPY_AND_ASSIGN(TestWriteReadCompletionCallback); }; TEST_F(FileStreamTest, AsyncWriteRead) { @@ -793,12 +802,12 @@ TEST_F(FileStreamTest, AsyncWriteRead) { int total_bytes_written = 0; int total_bytes_read = 0; std::string data_read; - TestWriteReadOldCompletionCallback callback(&stream, &total_bytes_written, + TestWriteReadCompletionCallback callback(&stream, &total_bytes_written, &total_bytes_read, &data_read); rv = stream.Write(kTestData + total_bytes_written, kTestDataSize - static_cast<int>(total_bytes_written), - &callback); + callback.callback()); if (rv == ERR_IO_PENDING) rv = callback.WaitForResult(); EXPECT_LT(0, rv); @@ -816,14 +825,16 @@ TEST_F(FileStreamTest, AsyncWriteRead) { EXPECT_EQ(kExpectedFileData, data_read); } -class TestWriteCloseOldCompletionCallback : public Callback1<int>::Type { +class TestWriteCloseCompletionCallback { public: - TestWriteCloseOldCompletionCallback(FileStream* stream, int* total_bytes_written) + TestWriteCloseCompletionCallback(FileStream* stream, int* total_bytes_written) : result_(0), have_result_(false), waiting_for_result_(false), stream_(stream), - total_bytes_written_(total_bytes_written) {} + total_bytes_written_(total_bytes_written), + callback_(base::Bind(&TestWriteCloseCompletionCallback::OnComplete, + base::Unretained(this))) {} int WaitForResult() { DCHECK(!waiting_for_result_); @@ -836,20 +847,22 @@ class TestWriteCloseOldCompletionCallback : public Callback1<int>::Type { return result_; } + const CompletionCallback& callback() const { return callback_; } + private: - virtual void RunWithParams(const Tuple1<int>& params) { - DCHECK_LT(0, params.a); - *total_bytes_written_ += params.a; + void OnComplete(int result) { + DCHECK_LT(0, result); + *total_bytes_written_ += result; int rv; if (*total_bytes_written_ != kTestDataSize) { // Recurse to finish writing all data. int total_bytes_written = 0; - TestWriteCloseOldCompletionCallback callback(stream_, &total_bytes_written); + TestWriteCloseCompletionCallback callback(stream_, &total_bytes_written); rv = stream_->Write(kTestData + *total_bytes_written_, kTestDataSize - *total_bytes_written_, - &callback); + callback.callback()); DCHECK_EQ(ERR_IO_PENDING, rv); rv = callback.WaitForResult(); *total_bytes_written_ += total_bytes_written; @@ -868,8 +881,9 @@ class TestWriteCloseOldCompletionCallback : public Callback1<int>::Type { bool waiting_for_result_; FileStream* stream_; int* total_bytes_written_; + const CompletionCallback callback_; - DISALLOW_COPY_AND_ASSIGN(TestWriteCloseOldCompletionCallback); + DISALLOW_COPY_AND_ASSIGN(TestWriteCloseCompletionCallback); }; TEST_F(FileStreamTest, AsyncWriteClose) { @@ -892,9 +906,9 @@ TEST_F(FileStreamTest, AsyncWriteClose) { EXPECT_EQ(offset, file_size); int total_bytes_written = 0; - TestWriteCloseOldCompletionCallback callback(&stream, &total_bytes_written); + TestWriteCloseCompletionCallback callback(&stream, &total_bytes_written); - rv = stream.Write(kTestData, kTestDataSize, &callback); + rv = stream.Write(kTestData, kTestDataSize, callback.callback()); if (rv == ERR_IO_PENDING) total_bytes_written = callback.WaitForResult(); EXPECT_LT(0, total_bytes_written); @@ -914,13 +928,13 @@ TEST_F(FileStreamTest, Truncate) { // Write some data to the file. const char test_data[] = "0123456789"; - write_stream.Write(test_data, arraysize(test_data), NULL); + write_stream.Write(test_data, arraysize(test_data), CompletionCallback()); // Truncate the file. ASSERT_EQ(4, write_stream.Truncate(4)); // Write again. - write_stream.Write(test_data, 4, NULL); + write_stream.Write(test_data, 4, CompletionCallback()); // Close the stream. write_stream.Close(); diff --git a/net/base/file_stream_win.cc b/net/base/file_stream_win.cc index 86ee202..07d365f 100644 --- a/net/base/file_stream_win.cc +++ b/net/base/file_stream_win.cc @@ -48,16 +48,16 @@ int RecordAndMapError(int error, FileErrorSource source, bool record_uma) { class FileStream::AsyncContext : public MessageLoopForIO::IOHandler { public: AsyncContext(FileStream* owner) - : owner_(owner), context_(), callback_(NULL), is_closing_(false), + : owner_(owner), context_(), is_closing_(false), record_uma_(false), error_source_(FILE_ERROR_SOURCE_COUNT) { context_.handler = this; } ~AsyncContext(); - void IOCompletionIsPending(OldCompletionCallback* callback); + void IOCompletionIsPending(const CompletionCallback& callback); OVERLAPPED* overlapped() { return &context_.overlapped; } - OldCompletionCallback* callback() const { return callback_; } + const CompletionCallback& callback() const { return callback_; } void set_error_source(FileErrorSource source) { error_source_ = source; } @@ -71,7 +71,7 @@ class FileStream::AsyncContext : public MessageLoopForIO::IOHandler { FileStream* owner_; MessageLoopForIO::IOContext context_; - OldCompletionCallback* callback_; + CompletionCallback callback_; bool is_closing_; bool record_uma_; FileErrorSource error_source_; @@ -81,7 +81,7 @@ FileStream::AsyncContext::~AsyncContext() { is_closing_ = true; bool waited = false; base::TimeTicks start = base::TimeTicks::Now(); - while (callback_) { + while (!callback_.is_null()) { waited = true; MessageLoopForIO::current()->WaitForIOCompletion(INFINITE, this); } @@ -93,18 +93,18 @@ FileStream::AsyncContext::~AsyncContext() { } void FileStream::AsyncContext::IOCompletionIsPending( - OldCompletionCallback* callback) { - DCHECK(!callback_); + const CompletionCallback& callback) { + DCHECK(callback_.is_null()); callback_ = callback; } void FileStream::AsyncContext::OnIOCompleted( MessageLoopForIO::IOContext* context, DWORD bytes_read, DWORD error) { DCHECK_EQ(&context_, context); - DCHECK(callback_); + DCHECK(!callback_.is_null()); if (is_closing_) { - callback_ = NULL; + callback_.Reset(); return; } @@ -115,9 +115,9 @@ void FileStream::AsyncContext::OnIOCompleted( if (bytes_read) IncrementOffset(&context->overlapped, bytes_read); - OldCompletionCallback* temp = NULL; + CompletionCallback temp; std::swap(temp, callback_); - temp->Run(result); + temp.Run(result); } // FileStream ------------------------------------------------------------ @@ -192,7 +192,7 @@ int64 FileStream::Seek(Whence whence, int64 offset) { if (!IsOpen()) return ERR_UNEXPECTED; - DCHECK(!async_context_.get() || !async_context_->callback()); + DCHECK(!async_context_.get() || async_context_->callback().is_null()); LARGE_INTEGER distance, result; distance.QuadPart = offset; @@ -230,7 +230,7 @@ int64 FileStream::Available() { } int FileStream::Read( - char* buf, int buf_len, OldCompletionCallback* callback) { + char* buf, int buf_len, const CompletionCallback& callback) { if (!IsOpen()) return ERR_UNEXPECTED; @@ -238,12 +238,12 @@ int FileStream::Read( OVERLAPPED* overlapped = NULL; if (async_context_.get()) { - DCHECK(callback); - DCHECK(!async_context_->callback()); + DCHECK(!callback.is_null()); + DCHECK(async_context_->callback().is_null()); overlapped = async_context_->overlapped(); async_context_->set_error_source(FILE_ERROR_SOURCE_READ); } else { - DCHECK(!callback); + DCHECK(callback.is_null()); base::ThreadRestrictions::AssertIOAllowed(); } @@ -275,7 +275,7 @@ int FileStream::ReadUntilComplete(char *buf, int buf_len) { int bytes_total = 0; do { - int bytes_read = Read(buf, to_read, NULL); + int bytes_read = Read(buf, to_read, CompletionCallback()); if (bytes_read <= 0) { if (bytes_total == 0) return bytes_read; @@ -292,7 +292,7 @@ int FileStream::ReadUntilComplete(char *buf, int buf_len) { } int FileStream::Write( - const char* buf, int buf_len, OldCompletionCallback* callback) { + const char* buf, int buf_len, const CompletionCallback& callback) { if (!IsOpen()) return ERR_UNEXPECTED; @@ -300,12 +300,12 @@ int FileStream::Write( OVERLAPPED* overlapped = NULL; if (async_context_.get()) { - DCHECK(callback); - DCHECK(!async_context_->callback()); + DCHECK(!callback.is_null()); + DCHECK(async_context_->callback().is_null()); overlapped = async_context_->overlapped(); async_context_->set_error_source(FILE_ERROR_SOURCE_WRITE); } else { - DCHECK(!callback); + DCHECK(callback.is_null()); base::ThreadRestrictions::AssertIOAllowed(); } diff --git a/net/base/mock_file_stream.cc b/net/base/mock_file_stream.cc index 19a027f..cb59cf9 100644 --- a/net/base/mock_file_stream.cc +++ b/net/base/mock_file_stream.cc @@ -10,39 +10,39 @@ namespace testing { int MockFileStream::Open(const FilePath& path, int open_flags) { path_ = path; - return ReturnError(net::FileStream::Open(path, open_flags)); + return ReturnError(FileStream::Open(path, open_flags)); } -int64 MockFileStream::Seek(net::Whence whence, int64 offset) { - return ReturnError64(net::FileStream::Seek(whence, offset)); +int64 MockFileStream::Seek(Whence whence, int64 offset) { + return ReturnError64(FileStream::Seek(whence, offset)); } int64 MockFileStream::Available() { - return ReturnError64(net::FileStream::Available()); + return ReturnError64(FileStream::Available()); } int MockFileStream::Read(char* buf, - int buf_len, - net::OldCompletionCallback* callback) { - return ReturnError(net::FileStream::Read(buf, buf_len, callback)); + int buf_len, + const CompletionCallback& callback) { + return ReturnError(FileStream::Read(buf, buf_len, callback)); } int MockFileStream::ReadUntilComplete(char *buf, int buf_len) { - return ReturnError(net::FileStream::ReadUntilComplete(buf, buf_len)); + return ReturnError(FileStream::ReadUntilComplete(buf, buf_len)); } int MockFileStream::Write(const char* buf, - int buf_len, - net::OldCompletionCallback* callback) { - return ReturnError(net::FileStream::Write(buf, buf_len, callback)); + int buf_len, + const CompletionCallback& callback) { + return ReturnError(FileStream::Write(buf, buf_len, callback)); } int64 MockFileStream::Truncate(int64 bytes) { - return ReturnError64(net::FileStream::Truncate(bytes)); + return ReturnError64(FileStream::Truncate(bytes)); } int MockFileStream::Flush() { - return ReturnError(net::FileStream::Flush()); + return ReturnError(FileStream::Flush()); } } // namespace testing diff --git a/net/base/mock_file_stream.h b/net/base/mock_file_stream.h index 569937e..be711e1 100644 --- a/net/base/mock_file_stream.h +++ b/net/base/mock_file_stream.h @@ -31,11 +31,11 @@ class MockFileStream : public net::FileStream { virtual int64 Available() OVERRIDE; virtual int Read(char* buf, int buf_len, - net::OldCompletionCallback* callback) OVERRIDE; + const CompletionCallback& callback) OVERRIDE; virtual int ReadUntilComplete(char *buf, int buf_len) OVERRIDE; virtual int Write(const char* buf, int buf_len, - net::OldCompletionCallback* callback) OVERRIDE; + const CompletionCallback& callback) OVERRIDE; virtual int64 Truncate(int64 bytes) OVERRIDE; virtual int Flush() OVERRIDE; diff --git a/net/base/upload_data_stream.cc b/net/base/upload_data_stream.cc index 33cf120..79bfd1d 100644 --- a/net/base/upload_data_stream.cc +++ b/net/base/upload_data_stream.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -112,7 +112,8 @@ int UploadDataStream::FillBuf() { // Temporarily allow until fix: http://crbug.com/72001. base::ThreadRestrictions::ScopedAllowIO allow_io; if (next_element_stream_.get()) - rv = next_element_stream_->Read(buf_->data() + buf_len_, count, NULL); + rv = next_element_stream_->Read(buf_->data() + buf_len_, count, + CompletionCallback()); if (rv <= 0) { // If there's less data to read than we initially observed, then // pad with zero. Otherwise the server will hang waiting for the diff --git a/net/tools/dump_cache/dump_files.cc b/net/tools/dump_cache/dump_files.cc index ef680d53..f8913d8 100644 --- a/net/tools/dump_cache/dump_files.cc +++ b/net/tools/dump_cache/dump_files.cc @@ -34,7 +34,7 @@ bool ReadHeader(const std::wstring& name, char* header, int header_size) { return false; } - int read = file.Read(header, header_size, NULL); + int read = file.Read(header, header_size, net::CompletionCallback()); if (read != header_size) { printf("Unable to read file %ls\n", name.c_str()); return false; diff --git a/net/url_request/url_request_file_job.cc b/net/url_request/url_request_file_job.cc index 3cac55a..f3fdd11 100644 --- a/net/url_request/url_request_file_job.cc +++ b/net/url_request/url_request_file_job.cc @@ -19,6 +19,7 @@ #include "net/url_request/url_request_file_job.h" +#include "base/bind.h" #include "base/compiler_specific.h" #include "base/message_loop.h" #include "base/platform_file.h" @@ -84,8 +85,6 @@ URLRequestFileJob::URLRequestFileJob(URLRequest* request, const FilePath& file_path) : URLRequestJob(request), file_path_(file_path), - ALLOW_THIS_IN_INITIALIZER_LIST( - io_callback_(this, &URLRequestFileJob::DidRead)), is_directory_(false), remaining_bytes_(0), ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { @@ -183,7 +182,9 @@ bool URLRequestFileJob::ReadRawData(IOBuffer* dest, int dest_size, return true; } - int rv = stream_.Read(dest->data(), dest_size, &io_callback_); + int rv = stream_.Read(dest->data(), dest_size, + base::Bind(&URLRequestFileJob::DidRead, + base::Unretained(this))); if (rv >= 0) { // Data is immediately available. *bytes_read = rv; diff --git a/net/url_request/url_request_file_job.h b/net/url_request/url_request_file_job.h index 9bc42bd..6bc7d26 100644 --- a/net/url_request/url_request_file_job.h +++ b/net/url_request/url_request_file_job.h @@ -11,7 +11,6 @@ #include "base/file_path.h" #include "base/task.h" -#include "net/base/completion_callback.h" #include "net/base/file_stream.h" #include "net/base/net_export.h" #include "net/http/http_byte_range.h" @@ -57,7 +56,6 @@ class NET_EXPORT URLRequestFileJob : public URLRequestJob { // Callback after data is asynchronously read from the file. void DidRead(int result); - OldCompletionCallbackImpl<URLRequestFileJob> io_callback_; FileStream stream_; bool is_directory_; diff --git a/webkit/blob/blob_url_request_job.cc b/webkit/blob/blob_url_request_job.cc index 15d86ac..a02096f 100644 --- a/webkit/blob/blob_url_request_job.cc +++ b/webkit/blob/blob_url_request_job.cc @@ -4,6 +4,7 @@ #include "webkit/blob/blob_url_request_job.h" +#include "base/bind.h" #include "base/compiler_specific.h" #include "base/file_path.h" #include "base/file_util.h" @@ -54,8 +55,6 @@ BlobURLRequestJob::BlobURLRequestJob( callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), blob_data_(blob_data), file_thread_proxy_(file_thread_proxy), - ALLOW_THIS_IN_INITIALIZER_LIST( - io_callback_(this, &BlobURLRequestJob::DidRead)), item_index_(0), total_size_(0), current_item_offset_(0), @@ -355,7 +354,8 @@ bool BlobURLRequestJob::ReadFile(const BlobData::Item& item) { // Start the asynchronous reading. int rv = stream_->Read(read_buf_->data() + read_buf_offset_, bytes_to_read_, - &io_callback_); + base::Bind(&BlobURLRequestJob::DidRead, + base::Unretained(this))); // If I/O pending error is returned, we just need to wait. if (rv == net::ERR_IO_PENDING) { diff --git a/webkit/blob/blob_url_request_job.h b/webkit/blob/blob_url_request_job.h index 843d9ca..ff563b86 100644 --- a/webkit/blob/blob_url_request_job.h +++ b/webkit/blob/blob_url_request_job.h @@ -10,7 +10,6 @@ #include "base/memory/scoped_ptr.h" #include "base/platform_file.h" #include "base/task.h" -#include "net/base/completion_callback.h" #include "net/http/http_byte_range.h" #include "net/url_request/url_request_job.h" #include "webkit/blob/blob_data.h" @@ -72,7 +71,6 @@ class BlobURLRequestJob : public net::URLRequestJob { base::ScopedCallbackFactory<BlobURLRequestJob> callback_factory_; scoped_refptr<BlobData> blob_data_; scoped_refptr<base::MessageLoopProxy> file_thread_proxy_; - net::OldCompletionCallbackImpl<BlobURLRequestJob> io_callback_; std::vector<int64> item_length_list_; scoped_ptr<net::FileStream> stream_; size_t item_index_; diff --git a/webkit/fileapi/file_system_url_request_job.cc b/webkit/fileapi/file_system_url_request_job.cc index 34fec21..8cdf9d4 100644 --- a/webkit/fileapi/file_system_url_request_job.cc +++ b/webkit/fileapi/file_system_url_request_job.cc @@ -4,6 +4,7 @@ #include "webkit/fileapi/file_system_url_request_job.h" +#include "base/bind.h" #include "base/compiler_specific.h" #include "base/file_path.h" #include "base/file_util_proxy.h" @@ -107,8 +108,6 @@ FileSystemURLRequestJob::FileSystemURLRequestJob( file_thread_proxy_(file_thread_proxy), ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)), - ALLOW_THIS_IN_INITIALIZER_LIST( - io_callback_(this, &FileSystemURLRequestJob::DidRead)), stream_(NULL), is_directory_(false), remaining_bytes_(0) { @@ -154,7 +153,9 @@ bool FileSystemURLRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size, return true; } - int rv = stream_->Read(dest->data(), dest_size, &io_callback_); + int rv = stream_->Read(dest->data(), dest_size, + base::Bind(&FileSystemURLRequestJob::DidRead, + base::Unretained(this))); if (rv >= 0) { // Data is immediately available. *bytes_read = rv; diff --git a/webkit/fileapi/file_system_url_request_job.h b/webkit/fileapi/file_system_url_request_job.h index 1caa988..1c66708 100644 --- a/webkit/fileapi/file_system_url_request_job.h +++ b/webkit/fileapi/file_system_url_request_job.h @@ -13,7 +13,6 @@ #include "base/message_loop_proxy.h" #include "base/platform_file.h" #include "base/task.h" -#include "net/base/completion_callback.h" #include "net/http/http_byte_range.h" #include "net/url_request/url_request_job.h" @@ -64,7 +63,6 @@ class FileSystemURLRequestJob : public net::URLRequestJob { scoped_refptr<base::MessageLoopProxy> file_thread_proxy_; ScopedRunnableMethodFactory<FileSystemURLRequestJob> method_factory_; base::ScopedCallbackFactory<FileSystemURLRequestJob> callback_factory_; - net::OldCompletionCallbackImpl<FileSystemURLRequestJob> io_callback_; scoped_ptr<net::FileStream> stream_; bool is_directory_; scoped_ptr<net::HttpResponseInfo> response_info_; diff --git a/webkit/fileapi/file_writer_delegate.cc b/webkit/fileapi/file_writer_delegate.cc index 34339a5..4c4ab24 100644 --- a/webkit/fileapi/file_writer_delegate.cc +++ b/webkit/fileapi/file_writer_delegate.cc @@ -4,6 +4,7 @@ #include "webkit/fileapi/file_writer_delegate.h" +#include "base/bind.h" #include "base/file_util_proxy.h" #include "base/message_loop.h" #include "base/threading/thread_restrictions.h" @@ -94,8 +95,6 @@ FileWriterDelegate::FileWriterDelegate( total_bytes_written_(0), allowed_bytes_to_write_(0), io_buffer_(new net::IOBufferWithSize(kReadBufSize)), - io_callback_(ALLOW_THIS_IN_INITIALIZER_LIST(this), - &FileWriterDelegate::OnDataWritten), method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { } @@ -232,9 +231,11 @@ void FileWriterDelegate::Write() { if (bytes_to_write > allowed_bytes_to_write_ - total_bytes_written_) bytes_to_write = allowed_bytes_to_write_ - total_bytes_written_; - int write_response = file_stream_->Write(io_buffer_->data() + bytes_written_, - static_cast<int>(bytes_to_write), - &io_callback_); + int write_response = + file_stream_->Write(io_buffer_->data() + bytes_written_, + static_cast<int>(bytes_to_write), + base::Bind(&FileWriterDelegate::OnDataWritten, + base::Unretained(this))); if (write_response > 0) MessageLoop::current()->PostTask( FROM_HERE, diff --git a/webkit/fileapi/file_writer_delegate.h b/webkit/fileapi/file_writer_delegate.h index 18677fb..1fe4a8d 100644 --- a/webkit/fileapi/file_writer_delegate.h +++ b/webkit/fileapi/file_writer_delegate.h @@ -13,7 +13,6 @@ #include "base/platform_file.h" #include "base/task.h" #include "base/time.h" -#include "net/base/completion_callback.h" #include "net/base/file_stream.h" #include "net/base/io_buffer.h" #include "net/url_request/url_request.h" @@ -81,7 +80,6 @@ class FileWriterDelegate : public net::URLRequest::Delegate { scoped_refptr<net::IOBufferWithSize> io_buffer_; scoped_ptr<net::FileStream> file_stream_; net::URLRequest* request_; - net::OldCompletionCallbackImpl<FileWriterDelegate> io_callback_; ScopedRunnableMethodFactory<FileWriterDelegate> method_factory_; base::ScopedCallbackFactory<FileWriterDelegate> callback_factory_; }; diff --git a/webkit/glue/webfileutilities_impl.cc b/webkit/glue/webfileutilities_impl.cc index 5aeeb05..555003f 100644 --- a/webkit/glue/webfileutilities_impl.cc +++ b/webkit/glue/webfileutilities_impl.cc @@ -1,6 +1,6 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this -// source code is governed by a BSD-style license that can be found in the -// LICENSE file. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. #include "webkit/glue/webfileutilities_impl.h" @@ -147,7 +147,7 @@ int WebFileUtilitiesImpl::readFromFile(base::PlatformFile handle, std::string buffer; buffer.resize(length); net::FileStream file_stream(handle, base::PLATFORM_FILE_READ); - return file_stream.Read(data, length, NULL); + return file_stream.Read(data, length, net::CompletionCallback()); } int WebFileUtilitiesImpl::writeToFile(base::PlatformFile handle, @@ -156,7 +156,7 @@ int WebFileUtilitiesImpl::writeToFile(base::PlatformFile handle, if (handle == base::kInvalidPlatformFileValue || !data || length <= 0) return -1; net::FileStream file_stream(handle, base::PLATFORM_FILE_WRITE); - return file_stream.Write(data, length, NULL); + return file_stream.Write(data, length, net::CompletionCallback()); } } // namespace webkit_glue diff --git a/webkit/tools/test_shell/simple_resource_loader_bridge.cc b/webkit/tools/test_shell/simple_resource_loader_bridge.cc index 0a37103..0b355ac 100644 --- a/webkit/tools/test_shell/simple_resource_loader_bridge.cc +++ b/webkit/tools/test_shell/simple_resource_loader_bridge.cc @@ -411,7 +411,7 @@ class RequestProxy : public net::URLRequest::Delegate, virtual void OnReceivedData(int bytes_read) { if (download_to_file_) { - file_stream_.Write(buf_->data(), bytes_read, NULL); + file_stream_.Write(buf_->data(), bytes_read, net::CompletionCallback()); owner_loop_->PostTask( FROM_HERE, base::Bind(&RequestProxy::NotifyDownloadedData, this, bytes_read)); @@ -725,7 +725,7 @@ class SyncRequestProxy : public RequestProxy { virtual void OnReceivedData(int bytes_read) { if (download_to_file_) - file_stream_.Write(buf_->data(), bytes_read, NULL); + file_stream_.Write(buf_->data(), bytes_read, net::CompletionCallback()); else result_->data.append(buf_->data(), bytes_read); AsyncReadData(); // read more (may recurse) |