OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef COMPONENTS_HTML_VIEWER_WEB_THREAD_IMPL_H_ | |
6 #define COMPONENTS_HTML_VIEWER_WEB_THREAD_IMPL_H_ | |
7 | |
8 #include <map> | |
9 | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/threading/thread.h" | |
12 #include "components/html_viewer/web_scheduler_impl.h" | |
13 #include "third_party/WebKit/public/platform/WebThread.h" | |
14 | |
15 namespace html_viewer { | |
16 | |
17 class WebThreadBase : public blink::WebThread { | |
18 public: | |
19 virtual ~WebThreadBase(); | |
20 | |
21 virtual void addTaskObserver(TaskObserver* observer); | |
22 virtual void removeTaskObserver(TaskObserver* observer); | |
23 | |
24 virtual bool isCurrentThread() const = 0; | |
25 | |
26 protected: | |
27 WebThreadBase(); | |
28 | |
29 private: | |
30 class TaskObserverAdapter; | |
31 | |
32 typedef std::map<TaskObserver*, TaskObserverAdapter*> TaskObserverMap; | |
33 TaskObserverMap task_observer_map_; | |
34 }; | |
35 | |
36 class WebThreadImpl : public WebThreadBase { | |
37 public: | |
38 explicit WebThreadImpl(const char* name); | |
39 ~WebThreadImpl() override; | |
40 | |
41 virtual void postTask(const blink::WebTraceLocation& location, Task* task); | |
42 virtual void postDelayedTask(const blink::WebTraceLocation& location, | |
43 Task* task, | |
44 long long delay_ms); | |
45 | |
46 virtual void enterRunLoop(); | |
47 virtual void exitRunLoop(); | |
48 | |
49 virtual blink::WebScheduler* scheduler() const; | |
50 | |
51 base::MessageLoop* message_loop() const { return thread_->message_loop(); } | |
52 | |
53 bool isCurrentThread() const override; | |
54 virtual blink::PlatformThreadId threadId() const; | |
55 | |
56 private: | |
57 scoped_ptr<base::Thread> thread_; | |
58 scoped_ptr<WebSchedulerImpl> web_scheduler_; | |
59 }; | |
60 | |
61 class WebThreadImplForMessageLoop : public WebThreadBase { | |
62 public: | |
63 explicit WebThreadImplForMessageLoop( | |
64 base::MessageLoopProxy* message_loop); | |
65 ~WebThreadImplForMessageLoop() override; | |
66 | |
67 virtual void postTask(const blink::WebTraceLocation& location, Task* task); | |
68 virtual void postDelayedTask(const blink::WebTraceLocation& location, | |
69 Task* task, | |
70 long long delay_ms); | |
71 | |
72 virtual void enterRunLoop(); | |
73 virtual void exitRunLoop(); | |
74 | |
75 virtual blink::WebScheduler* scheduler() const; | |
76 | |
77 private: | |
78 bool isCurrentThread() const override; | |
79 virtual blink::PlatformThreadId threadId() const; | |
80 | |
81 scoped_refptr<base::MessageLoopProxy> message_loop_; | |
82 scoped_ptr<WebSchedulerImpl> web_scheduler_; | |
83 blink::PlatformThreadId thread_id_; | |
84 }; | |
85 | |
86 } // namespace html_viewer | |
87 | |
88 #endif // COMPONENTS_HTML_VIEWER_WEB_THREAD_IMPL_H_ | |
OLD | NEW |