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

Unified Diff: content/child/webthread_base.cc

Issue 1033643004: Add a WorkerScheduler and a WebThreadImplForWorker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix bug where tasks posted to a worker thread did not always run when the thread was shutdown Created 5 years, 8 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
Index: content/child/webthread_base.cc
diff --git a/content/child/webthread_impl.cc b/content/child/webthread_base.cc
similarity index 80%
rename from content/child/webthread_impl.cc
rename to content/child/webthread_base.cc
index 572e5890bb53409078ac70da898081855c491450..818c960ac1f38248f04c8a6a75d3930d1ba87d45 100644
--- a/content/child/webthread_impl.cc
+++ b/content/child/webthread_base.cc
@@ -5,12 +5,13 @@
// An implementation of WebThread in terms of base::MessageLoop and
// base::Thread
-#include "content/child/webthread_impl.h"
+#include "content/child/webthread_base.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/pending_task.h"
#include "base/threading/platform_thread.h"
+#include "content/child/scheduler/single_thread_idle_task_runner.h"
#include "third_party/WebKit/public/platform/WebTraceLocation.h"
namespace content {
@@ -29,7 +30,7 @@ class WebThreadBase::TaskObserverAdapter
observer_->didProcessTask();
}
-private:
+ private:
WebThread::TaskObserver* observer_;
};
@@ -100,6 +101,13 @@ void WebThreadBase::RunWebThreadTask(scoped_ptr<blink::WebThread::Task> task) {
task->run();
}
+// static
+void WebThreadBase::RunWebThreadIdleTask(
+ scoped_ptr<blink::WebThread::IdleTask> idle_task,
+ base::TimeTicks deadline) {
+ idle_task->run((deadline - base::TimeTicks()).InSecondsF());
+}
+
void WebThreadBase::postTask(const blink::WebTraceLocation& location,
Task* task) {
postDelayedTask(location, task, 0);
@@ -116,6 +124,25 @@ void WebThreadBase::postDelayedTask(const blink::WebTraceLocation& web_location,
base::TimeDelta::FromMilliseconds(delay_ms));
}
+void WebThreadBase::postIdleTask(const blink::WebTraceLocation& web_location,
+ IdleTask* idle_task) {
+ tracked_objects::Location location(web_location.functionName(),
+ web_location.fileName(), -1, nullptr);
+ IdleTaskRunner()->PostIdleTask(
+ location, base::Bind(&WebThreadBase::RunWebThreadIdleTask,
+ base::Passed(make_scoped_ptr(idle_task))));
+}
+
+void WebThreadBase::postIdleTaskAfterWakeup(
+ const blink::WebTraceLocation& web_location,
+ IdleTask* idle_task) {
+ tracked_objects::Location location(web_location.functionName(),
+ web_location.fileName(), -1, nullptr);
+ IdleTaskRunner()->PostIdleTaskAfterWakeup(
+ location, base::Bind(&WebThreadBase::RunWebThreadIdleTask,
+ base::Passed(make_scoped_ptr(idle_task))));
+}
+
void WebThreadBase::enterRunLoop() {
CHECK(isCurrentThread());
CHECK(MessageLoop());
@@ -134,25 +161,4 @@ bool WebThreadBase::isCurrentThread() const {
return TaskRunner()->BelongsToCurrentThread();
}
-blink::PlatformThreadId WebThreadImpl::threadId() const {
- return thread_->thread_id();
-}
-
-WebThreadImpl::WebThreadImpl(const char* name)
- : thread_(new base::Thread(name)) {
- thread_->Start();
-}
-
-WebThreadImpl::~WebThreadImpl() {
- thread_->Stop();
-}
-
-base::MessageLoop* WebThreadImpl::MessageLoop() const {
- return nullptr;
-}
-
-base::SingleThreadTaskRunner* WebThreadImpl::TaskRunner() const {
- return thread_->message_loop_proxy().get();
-}
-
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698