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 postIdleTask(const blink::WebTraceLocation
& location
,
32 virtual void postIdleTaskAfterWakeup(const blink::WebTraceLocation
& location
,
35 virtual void addTaskObserver(TaskObserver
* observer
);
36 virtual void removeTaskObserver(TaskObserver
* observer
);
38 // Returns the base::Bind-compatible task runner for posting tasks to this
39 // thread. Can be called from any thread.
40 virtual base::SingleThreadTaskRunner
* TaskRunner() const = 0;
42 // Returns the base::Bind-compatible task runner for posting idle tasks to
43 // this thread. Can be called from any thread.
44 virtual scheduler::SingleThreadIdleTaskRunner
* IdleTaskRunner() const = 0;
47 class TaskObserverAdapter
;
51 virtual void AddTaskObserverInternal(
52 base::MessageLoop::TaskObserver
* observer
);
53 virtual void RemoveTaskObserverInternal(
54 base::MessageLoop::TaskObserver
* observer
);
56 static void RunWebThreadIdleTask(
57 scoped_ptr
<blink::WebThread::IdleTask
> idle_task
,
58 base::TimeTicks deadline
);
61 typedef std::map
<TaskObserver
*, TaskObserverAdapter
*> TaskObserverMap
;
62 TaskObserverMap task_observer_map_
;
65 } // namespace scheduler
67 #endif // COMPONENTS_SCHEDULER_CHILD_WEBTHREAD_BASE_H_