fileapi: Use standard task-runner to run the fileapi callbacks.

Instead of using the id of the worker-thread to keep track of the thread to
run the fileapi callbacks on, use the task-runner of the thread instead.

BUG=none
R=kinuko@chromium.org

Review URL: https://codereview.chromium.org/893233002

Cr-Commit-Position: refs/heads/master@{#314506}
parent efe44b45
This diff is collapsed.
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "base/thread_task_runner_handle.h"
#include "content/child/child_thread_impl.h" #include "content/child/child_thread_impl.h"
#include "content/child/fileapi/file_system_dispatcher.h" #include "content/child/fileapi/file_system_dispatcher.h"
#include "content/child/worker_task_runner.h" #include "content/child/worker_task_runner.h"
...@@ -31,7 +32,9 @@ class WebFileWriterImpl::WriterBridge ...@@ -31,7 +32,9 @@ class WebFileWriterImpl::WriterBridge
public: public:
WriterBridge(WebFileWriterImpl::Type type) WriterBridge(WebFileWriterImpl::Type type)
: request_id_(0), : request_id_(0),
thread_id_(WorkerTaskRunner::Instance()->CurrentWorkerId()), running_on_worker_(WorkerTaskRunner::Instance()->CurrentWorkerId() > 0),
task_runner_(running_on_worker_ ? base::ThreadTaskRunnerHandle::Get()
: nullptr),
written_bytes_(0) { written_bytes_(0) {
if (type == WebFileWriterImpl::TYPE_SYNC) if (type == WebFileWriterImpl::TYPE_SYNC)
waitable_event_.reset(new base::WaitableEvent(false, false)); waitable_event_.reset(new base::WaitableEvent(false, false));
...@@ -96,23 +99,25 @@ class WebFileWriterImpl::WriterBridge ...@@ -96,23 +99,25 @@ class WebFileWriterImpl::WriterBridge
void PostTaskToWorker(const base::Closure& closure) { void PostTaskToWorker(const base::Closure& closure) {
written_bytes_ = 0; written_bytes_ = 0;
if (!thread_id_) { if (!running_on_worker_) {
DCHECK(!waitable_event_); DCHECK(!waitable_event_);
closure.Run(); closure.Run();
return; return;
} }
DCHECK(task_runner_);
if (waitable_event_) { if (waitable_event_) {
results_closure_ = closure; results_closure_ = closure;
waitable_event_->Signal(); waitable_event_->Signal();
return; return;
} }
WorkerTaskRunner::Instance()->PostTask(thread_id_, closure); task_runner_->PostTask(FROM_HERE, closure);
} }
StatusCallback status_callback_; StatusCallback status_callback_;
WriteCallback write_callback_; WriteCallback write_callback_;
int request_id_; int request_id_;
int thread_id_; const bool running_on_worker_;
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
int written_bytes_; int written_bytes_;
scoped_ptr<base::WaitableEvent> waitable_event_; scoped_ptr<base::WaitableEvent> waitable_event_;
base::Closure results_closure_; base::Closure results_closure_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment