Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Unified Diff: net/base/upload_file_element_reader.cc

Issue 11778016: net: Stop using base::WorkerPool from UploadFileElementReader (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix CF Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/upload_file_element_reader.h ('k') | net/base/upload_file_element_reader_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/upload_file_element_reader.cc
diff --git a/net/base/upload_file_element_reader.cc b/net/base/upload_file_element_reader.cc
index 32cb27ff42e3cc7758129cbd562b51fd9d0c8d93..0d2cff40fe819de05a8bbd7a8c31f619b942bf34 100644
--- a/net/base/upload_file_element_reader.cc
+++ b/net/base/upload_file_element_reader.cc
@@ -8,7 +8,6 @@
#include "base/file_util.h"
#include "base/location.h"
#include "base/task_runner_util.h"
-#include "base/threading/worker_pool.h"
#include "net/base/file_stream.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
@@ -22,11 +21,12 @@ namespace {
uint64 overriding_content_length = 0;
// This function is used to implement Init().
+template<typename FileStreamDeleter>
int InitInternal(const FilePath& path,
uint64 range_offset,
uint64 range_length,
const base::Time& expected_modification_time,
- UploadFileElementReader::ScopedFileStreamPtr* out_file_stream,
+ scoped_ptr<FileStream, FileStreamDeleter>* out_file_stream,
uint64* out_content_length) {
scoped_ptr<FileStream> file_stream(new FileStream(NULL));
int64 rv = file_stream->OpenSync(
@@ -92,28 +92,38 @@ int ReadInternal(scoped_refptr<IOBuffer> buf,
} // namespace
+UploadFileElementReader::FileStreamDeleter::FileStreamDeleter(
+ base::TaskRunner* task_runner) : task_runner_(task_runner) {
+ DCHECK(task_runner_);
+}
+
+UploadFileElementReader::FileStreamDeleter::~FileStreamDeleter() {}
+
void UploadFileElementReader::FileStreamDeleter::operator() (
FileStream* file_stream) const {
if (file_stream) {
- base::WorkerPool::PostTask(FROM_HERE,
- base::Bind(&base::DeletePointer<FileStream>,
- file_stream),
- true /* task_is_slow */);
+ task_runner_->PostTask(FROM_HERE,
+ base::Bind(&base::DeletePointer<FileStream>,
+ file_stream));
}
}
UploadFileElementReader::UploadFileElementReader(
+ base::TaskRunner* task_runner,
const FilePath& path,
uint64 range_offset,
uint64 range_length,
const base::Time& expected_modification_time)
- : path_(path),
+ : task_runner_(task_runner),
+ path_(path),
range_offset_(range_offset),
range_length_(range_length),
expected_modification_time_(expected_modification_time),
+ file_stream_(NULL, FileStreamDeleter(task_runner_)),
content_length_(0),
bytes_remaining_(0),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
+ DCHECK(task_runner_);
}
UploadFileElementReader::~UploadFileElementReader() {
@@ -127,12 +137,13 @@ int UploadFileElementReader::Init(const CompletionCallback& callback) {
DCHECK(!callback.is_null());
Reset();
- ScopedFileStreamPtr* file_stream = new ScopedFileStreamPtr;
+ ScopedFileStreamPtr* file_stream =
+ new ScopedFileStreamPtr(NULL, FileStreamDeleter(task_runner_));
uint64* content_length = new uint64;
const bool posted = base::PostTaskAndReplyWithResult(
- base::WorkerPool::GetTaskRunner(true /* task_is_slow */),
+ task_runner_,
FROM_HERE,
- base::Bind(&InitInternal,
+ base::Bind(&InitInternal<FileStreamDeleter>,
path_,
range_offset_,
range_length_,
@@ -171,7 +182,7 @@ int UploadFileElementReader::Read(IOBuffer* buf,
// Pass the ownership of file_stream_ to the worker pool to safely perform
// operation even when |this| is destructed before the read completes.
const bool posted = base::PostTaskAndReplyWithResult(
- base::WorkerPool::GetTaskRunner(true /* task_is_slow */),
+ task_runner_,
FROM_HERE,
base::Bind(&ReadInternal,
scoped_refptr<IOBuffer>(buf),
@@ -249,12 +260,9 @@ int UploadFileElementReaderSync::Init(const CompletionCallback& callback) {
content_length_ = 0;
file_stream_.reset();
- UploadFileElementReader::ScopedFileStreamPtr file_stream;
-
const int result = InitInternal(path_, range_offset_, range_length_,
expected_modification_time_,
- &file_stream, &content_length_);
- file_stream_.reset(file_stream.release());
+ &file_stream_, &content_length_);
bytes_remaining_ = GetContentLength();
return result;
}
« no previous file with comments | « net/base/upload_file_element_reader.h ('k') | net/base/upload_file_element_reader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698