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

Unified Diff: content/child/webthread_impl.h

Issue 922733002: scheduler: Implement task observers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Missed one. Created 5 years, 10 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_impl.h
diff --git a/content/child/webthread_impl.h b/content/child/webthread_impl.h
index ba2888f9bc70b007789d3f8ce022234ec45c3f33..edd39566e81dc79fc13373c1e1bf2db87d521049 100644
--- a/content/child/webthread_impl.h
+++ b/content/child/webthread_impl.h
@@ -22,18 +22,43 @@ class CONTENT_EXPORT WebThreadBase : public blink::WebThread {
public:
virtual ~WebThreadBase();
+ // blink::WebThread implementation.
+ virtual bool isCurrentThread() const;
+ virtual blink::PlatformThreadId threadId() const = 0;
+
+ virtual void postTask(const blink::WebTraceLocation& location, Task* task);
+ virtual void postDelayedTask(const blink::WebTraceLocation& location,
+ Task* task,
+ long long delay_ms);
+
+ virtual void enterRunLoop();
+ virtual void exitRunLoop();
+
virtual void addTaskObserver(TaskObserver* observer);
virtual void removeTaskObserver(TaskObserver* observer);
- virtual bool isCurrentThread() const = 0;
- virtual blink::PlatformThreadId threadId() const = 0;
+ // Returns the base::Bind-compatible task runner for posting tasks to this
+ // thread. Can be called from any thread.
+ virtual base::SingleThreadTaskRunner* TaskRunner() const = 0;
protected:
+ class TaskObserverAdapter;
+
WebThreadBase();
- private:
- class TaskObserverAdapter;
+ // Returns the underlying MessageLoop for this thread. Only used for entering
+ // and exiting a nested run loop. Only called on the thread that the
+ // WebThread belongs to.
+ virtual base::MessageLoop* MessageLoop() const = 0;
+
+ virtual void AddTaskObserverInternal(
+ base::MessageLoop::TaskObserver* observer);
+ virtual void RemoveTaskObserverInternal(
+ base::MessageLoop::TaskObserver* observer);
rmcilroy 2015/02/19 11:47:49 Can we remove the virtual AddTaskObserverInternal
Sami 2015/02/19 16:31:09 Ah yes, no need for that anymore. Done.
+
+ static void RunWebThreadTask(scoped_ptr<blink::WebThread::Task> task);
+ private:
typedef std::map<TaskObserver*, TaskObserverAdapter*> TaskObserverMap;
TaskObserverMap task_observer_map_;
};
@@ -43,24 +68,15 @@ class CONTENT_EXPORT WebThreadImpl : public WebThreadBase {
explicit WebThreadImpl(const char* name);
virtual ~WebThreadImpl();
- virtual void postTask(const blink::WebTraceLocation& location, Task* task);
- virtual void postDelayedTask(const blink::WebTraceLocation& location,
- Task* task,
- long long delay_ms);
-
- // TODO(skyostil): Remove once blink has migrated.
- virtual void postTask(Task* task);
- virtual void postDelayedTask(Task* task, long long delay_ms);
-
- virtual void enterRunLoop();
- virtual void exitRunLoop();
-
- base::MessageLoop* message_loop() const { return thread_->message_loop(); }
+ // blink::WebThread implementation.
+ blink::PlatformThreadId threadId() const override;
- virtual bool isCurrentThread() const override;
- virtual blink::PlatformThreadId threadId() const override;
+ // WebThreadBase implementation.
+ base::SingleThreadTaskRunner* TaskRunner() const override;
private:
+ base::MessageLoop* MessageLoop() const override;
+
scoped_ptr<base::Thread> thread_;
};
@@ -70,21 +86,14 @@ class WebThreadImplForMessageLoop : public WebThreadBase {
scoped_refptr<base::SingleThreadTaskRunner> owning_thread_task_runner);
CONTENT_EXPORT virtual ~WebThreadImplForMessageLoop();
- virtual void postTask(const blink::WebTraceLocation& location, Task* task);
- virtual void postDelayedTask(const blink::WebTraceLocation& location,
- Task* task,
- long long delay_ms);
-
- // TODO(skyostil): Remove once blink has migrated.
- virtual void postTask(Task* task);
- virtual void postDelayedTask(Task* task, long long delay_ms);
+ // blink::WebThread implementation.
+ blink::PlatformThreadId threadId() const override;
- virtual void enterRunLoop() override;
- virtual void exitRunLoop() override;
+ // WebThreadBase implementation.
+ base::MessageLoop* MessageLoop() const override;
private:
- virtual bool isCurrentThread() const override;
- virtual blink::PlatformThreadId threadId() const override;
+ base::SingleThreadTaskRunner* TaskRunner() const override;
scoped_refptr<base::SingleThreadTaskRunner> owning_thread_task_runner_;
blink::PlatformThreadId thread_id_;

Powered by Google App Engine
This is Rietveld 408576698