1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_SCHEDULER_CHILD_WEBTHREAD_BASE_H_
6 #define COMPONENTS_SCHEDULER_CHILD_WEBTHREAD_BASE_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/threading/thread.h"
12 #include "components/scheduler/scheduler_export.h"
13 #include "third_party/WebKit/public/platform/WebThread.h"
16 class WebTraceLocation
;
20 class SingleThreadIdleTaskRunner
;
22 class SCHEDULER_EXPORT WebThreadBase
: public blink::WebThread
{
24 virtual ~WebThreadBase();
26 // blink::WebThread implementation.
27 virtual bool isCurrentThread() const;
28 virtual blink::PlatformThreadId
threadId() const = 0;
30 virtual void postTask(const blink::WebTraceLocation
& location
, Task
* task
);
31 virtual void postDelayedTask(const blink::WebTraceLocation
& location
,
34 virtual void postIdleTask(const blink::WebTraceLocation
& location
,
36 virtual void postIdleTaskAfterWakeup(const blink::WebTraceLocation
& location
,
39 virtual void addTaskObserver(TaskObserver
* observer
);
40 virtual void removeTaskObserver(TaskObserver
* observer
);
42 // Returns the base::Bind-compatible task runner for posting tasks to this
43 // thread. Can be called from any thread.
44 virtual base::SingleThreadTaskRunner
* TaskRunner() const = 0;
46 // Returns the base::Bind-compatible task runner for posting idle tasks to
47 // this thread. Can be called from any thread.
48 virtual scheduler::SingleThreadIdleTaskRunner
* IdleTaskRunner() const = 0;
51 class TaskObserverAdapter
;
55 virtual void AddTaskObserverInternal(
56 base::MessageLoop::TaskObserver
* observer
);
57 virtual void RemoveTaskObserverInternal(
58 base::MessageLoop::TaskObserver
* observer
);
60 static void RunWebThreadTask(scoped_ptr
<blink::WebThread::Task
> task
);
61 static void RunWebThreadIdleTask(
62 scoped_ptr
<blink::WebThread::IdleTask
> idle_task
,
63 base::TimeTicks deadline
);
66 typedef std::map
<TaskObserver
*, TaskObserverAdapter
*> TaskObserverMap
;
67 TaskObserverMap task_observer_map_
;
70 } // namespace scheduler
72 #endif // COMPONENTS_SCHEDULER_CHILD_WEBTHREAD_BASE_H_