summaryrefslogtreecommitdiffstats
path: root/net/base
diff options
context:
space:
mode:
authoradamk@chromium.org <adamk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-11 01:40:32 +0000
committeradamk@chromium.org <adamk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-11 01:40:32 +0000
commitbf9cd1217599a49ba1ec9591d043b4efe8b6cb3b (patch)
treefe137e1ac1241b837b476e0243fddb9897dd17a0 /net/base
parent23e60c9040b7f83ae4b44882de3defd1a70ed652 (diff)
downloadchromium_src-bf9cd1217599a49ba1ec9591d043b4efe8b6cb3b.zip
chromium_src-bf9cd1217599a49ba1ec9591d043b4efe8b6cb3b.tar.gz
chromium_src-bf9cd1217599a49ba1ec9591d043b4efe8b6cb3b.tar.bz2
Use NewRunnableFunction in file_stream_posix.cc to get rid of custom Task subclasses.
BUG=none TEST=net_unittests Review URL: http://codereview.chromium.org/6676012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77752 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base')
-rw-r--r--net/base/file_stream_posix.cc83
1 files changed, 19 insertions, 64 deletions
diff --git a/net/base/file_stream_posix.cc b/net/base/file_stream_posix.cc
index 4ea3db8..2e0dac1 100644
--- a/net/base/file_stream_posix.cc
+++ b/net/base/file_stream_posix.cc
@@ -21,6 +21,7 @@
#include "base/message_loop.h"
#include "base/metrics/histogram.h"
#include "base/string_util.h"
+#include "base/task.h"
#include "base/threading/thread_restrictions.h"
#include "base/threading/worker_pool.h"
#include "base/synchronization/waitable_event.h"
@@ -63,6 +64,13 @@ int ReadFile(base::PlatformFile file, char* buf, int buf_len) {
return static_cast<int>(res);
}
+void ReadFileTask(base::PlatformFile file,
+ char* buf,
+ int buf_len,
+ CompletionCallback* callback) {
+ callback->Run(ReadFile(file, buf, buf_len));
+}
+
// WriteFile() is a simple wrapper around write() that handles EINTR signals and
// calls MapErrorCode() to map errno to net error codes. It tries to write to
// completion.
@@ -74,6 +82,13 @@ int WriteFile(base::PlatformFile file, const char* buf, int buf_len) {
return res;
}
+void WriteFileTask(base::PlatformFile file,
+ const char* buf,
+ int buf_len,
+ CompletionCallback* callback) {
+ callback->Run(WriteFile(file, buf, buf_len));
+}
+
// FlushFile() is a simple wrapper around fsync() that handles EINTR signals and
// calls MapErrorCode() to map errno to net error codes. It tries to flush to
// completion.
@@ -85,68 +100,6 @@ int FlushFile(base::PlatformFile file) {
return res;
}
-// BackgroundReadTask is a simple task that reads a file and then runs
-// |callback|. AsyncContext will post this task to the WorkerPool.
-class BackgroundReadTask : public Task {
- public:
- BackgroundReadTask(base::PlatformFile file, char* buf, int buf_len,
- CompletionCallback* callback);
- ~BackgroundReadTask();
-
- virtual void Run();
-
- private:
- const base::PlatformFile file_;
- char* const buf_;
- const int buf_len_;
- CompletionCallback* const callback_;
-
- DISALLOW_COPY_AND_ASSIGN(BackgroundReadTask);
-};
-
-BackgroundReadTask::BackgroundReadTask(
- base::PlatformFile file, char* buf, int buf_len,
- CompletionCallback* callback)
- : file_(file), buf_(buf), buf_len_(buf_len), callback_(callback) {}
-
-BackgroundReadTask::~BackgroundReadTask() {}
-
-void BackgroundReadTask::Run() {
- int result = ReadFile(file_, buf_, buf_len_);
- callback_->Run(result);
-}
-
-// BackgroundWriteTask is a simple task that writes to a file and then runs
-// |callback|. AsyncContext will post this task to the WorkerPool.
-class BackgroundWriteTask : public Task {
- public:
- BackgroundWriteTask(base::PlatformFile file, const char* buf, int buf_len,
- CompletionCallback* callback);
- ~BackgroundWriteTask();
-
- virtual void Run();
-
- private:
- const base::PlatformFile file_;
- const char* const buf_;
- const int buf_len_;
- CompletionCallback* const callback_;
-
- DISALLOW_COPY_AND_ASSIGN(BackgroundWriteTask);
-};
-
-BackgroundWriteTask::BackgroundWriteTask(
- base::PlatformFile file, const char* buf, int buf_len,
- CompletionCallback* callback)
- : file_(file), buf_(buf), buf_len_(buf_len), callback_(callback) {}
-
-BackgroundWriteTask::~BackgroundWriteTask() {}
-
-void BackgroundWriteTask::Run() {
- int result = WriteFile(file_, buf_, buf_len_);
- callback_->Run(result);
-}
-
} // namespace
// CancelableCallbackTask takes ownership of the Callback. This task gets
@@ -255,7 +208,8 @@ void FileStream::AsyncContext::InitiateAsyncRead(
callback_ = callback;
base::WorkerPool::PostTask(FROM_HERE,
- new BackgroundReadTask(
+ NewRunnableFunction(
+ &ReadFileTask,
file, buf, buf_len,
&background_io_completed_callback_),
true /* task_is_slow */);
@@ -268,7 +222,8 @@ void FileStream::AsyncContext::InitiateAsyncWrite(
callback_ = callback;
base::WorkerPool::PostTask(FROM_HERE,
- new BackgroundWriteTask(
+ NewRunnableFunction(
+ &WriteFileTask,
file, buf, buf_len,
&background_io_completed_callback_),
true /* task_is_slow */);