Roll src/third_party/WebKit 605a979:06cb9e9 (svn 202556:202558)
[chromium-blink-merge.git] / components / scheduler / child / webthread_base.h
blob02598e17281f5c068fbaff06767d25636e1e3b1e
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_
8 #include <map>
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"
15 namespace blink {
16 class WebTraceLocation;
19 namespace scheduler {
20 class SingleThreadIdleTaskRunner;
22 class SCHEDULER_EXPORT WebThreadBase : public blink::WebThread {
23 public:
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,
31 IdleTask* idle_task);
32 virtual void postIdleTaskAfterWakeup(const blink::WebTraceLocation& location,
33 IdleTask* idle_task);
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;
46 protected:
47 class TaskObserverAdapter;
49 WebThreadBase();
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);
60 private:
61 typedef std::map<TaskObserver*, TaskObserverAdapter*> TaskObserverMap;
62 TaskObserverMap task_observer_map_;
65 } // namespace scheduler
67 #endif // COMPONENTS_SCHEDULER_CHILD_WEBTHREAD_BASE_H_