Revert of [Android WebView] Synthesize a fake page loading event on page source modif...
[chromium-blink-merge.git] / content / child / webthread_impl.h
blobedd39566e81dc79fc13373c1e1bf2db87d521049
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 CONTENT_CHILD_WEBTHREAD_IMPL_H_
6 #define CONTENT_CHILD_WEBTHREAD_IMPL_H_
8 #include <map>
10 #include "base/memory/scoped_ptr.h"
11 #include "base/threading/thread.h"
12 #include "content/common/content_export.h"
13 #include "third_party/WebKit/public/platform/WebThread.h"
15 namespace blink {
16 class WebTraceLocation;
19 namespace content {
21 class CONTENT_EXPORT WebThreadBase : public blink::WebThread {
22 public:
23 virtual ~WebThreadBase();
25 // blink::WebThread implementation.
26 virtual bool isCurrentThread() const;
27 virtual blink::PlatformThreadId threadId() const = 0;
29 virtual void postTask(const blink::WebTraceLocation& location, Task* task);
30 virtual void postDelayedTask(const blink::WebTraceLocation& location,
31 Task* task,
32 long long delay_ms);
34 virtual void enterRunLoop();
35 virtual void exitRunLoop();
37 virtual void addTaskObserver(TaskObserver* observer);
38 virtual void removeTaskObserver(TaskObserver* observer);
40 // Returns the base::Bind-compatible task runner for posting tasks to this
41 // thread. Can be called from any thread.
42 virtual base::SingleThreadTaskRunner* TaskRunner() const = 0;
44 protected:
45 class TaskObserverAdapter;
47 WebThreadBase();
49 // Returns the underlying MessageLoop for this thread. Only used for entering
50 // and exiting a nested run loop. Only called on the thread that the
51 // WebThread belongs to.
52 virtual base::MessageLoop* MessageLoop() const = 0;
54 virtual void AddTaskObserverInternal(
55 base::MessageLoop::TaskObserver* observer);
56 virtual void RemoveTaskObserverInternal(
57 base::MessageLoop::TaskObserver* observer);
59 static void RunWebThreadTask(scoped_ptr<blink::WebThread::Task> task);
61 private:
62 typedef std::map<TaskObserver*, TaskObserverAdapter*> TaskObserverMap;
63 TaskObserverMap task_observer_map_;
66 class CONTENT_EXPORT WebThreadImpl : public WebThreadBase {
67 public:
68 explicit WebThreadImpl(const char* name);
69 virtual ~WebThreadImpl();
71 // blink::WebThread implementation.
72 blink::PlatformThreadId threadId() const override;
74 // WebThreadBase implementation.
75 base::SingleThreadTaskRunner* TaskRunner() const override;
77 private:
78 base::MessageLoop* MessageLoop() const override;
80 scoped_ptr<base::Thread> thread_;
83 class WebThreadImplForMessageLoop : public WebThreadBase {
84 public:
85 CONTENT_EXPORT explicit WebThreadImplForMessageLoop(
86 scoped_refptr<base::SingleThreadTaskRunner> owning_thread_task_runner);
87 CONTENT_EXPORT virtual ~WebThreadImplForMessageLoop();
89 // blink::WebThread implementation.
90 blink::PlatformThreadId threadId() const override;
92 // WebThreadBase implementation.
93 base::MessageLoop* MessageLoop() const override;
95 private:
96 base::SingleThreadTaskRunner* TaskRunner() const override;
98 scoped_refptr<base::SingleThreadTaskRunner> owning_thread_task_runner_;
99 blink::PlatformThreadId thread_id_;
102 } // namespace content
104 #endif // CONTENT_CHILD_WEBTHREAD_IMPL_H_