OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_CHILD_WEBTHREAD_IMPL_H_ | 5 #ifndef CONTENT_CHILD_WEBTHREAD_IMPL_H_ |
6 #define CONTENT_CHILD_WEBTHREAD_IMPL_H_ | 6 #define CONTENT_CHILD_WEBTHREAD_IMPL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
12 #include "base/timer/timer.h" | |
13 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
14 #include "third_party/WebKit/public/platform/WebThread.h" | 13 #include "third_party/WebKit/public/platform/WebThread.h" |
15 | 14 |
16 namespace content { | 15 namespace content { |
17 | 16 |
18 class CONTENT_EXPORT WebThreadBase : public blink::WebThread { | 17 class CONTENT_EXPORT WebThreadBase : public blink::WebThread { |
19 public: | 18 public: |
20 virtual ~WebThreadBase(); | 19 virtual ~WebThreadBase(); |
21 | 20 |
22 virtual void addTaskObserver(TaskObserver* observer); | 21 virtual void addTaskObserver(TaskObserver* observer); |
23 virtual void removeTaskObserver(TaskObserver* observer); | 22 virtual void removeTaskObserver(TaskObserver* observer); |
24 | 23 |
25 virtual bool isCurrentThread() const = 0; | 24 virtual bool isCurrentThread() const = 0; |
26 | 25 |
27 typedef void (*SharedTimerFunction)(); | |
28 virtual void setSharedTimerFiredFunction(SharedTimerFunction timerFunction) {} | |
29 virtual void setSharedTimerFireInterval(double) {} | |
30 virtual void stopSharedTimer() {} | |
31 | |
32 protected: | 26 protected: |
33 WebThreadBase(); | 27 WebThreadBase(); |
34 | 28 |
35 private: | 29 private: |
36 class TaskObserverAdapter; | 30 class TaskObserverAdapter; |
37 | 31 |
38 typedef std::map<TaskObserver*, TaskObserverAdapter*> TaskObserverMap; | 32 typedef std::map<TaskObserver*, TaskObserverAdapter*> TaskObserverMap; |
39 TaskObserverMap task_observer_map_; | 33 TaskObserverMap task_observer_map_; |
40 }; | 34 }; |
41 | 35 |
42 class CONTENT_EXPORT WebThreadImpl : public WebThreadBase { | 36 class CONTENT_EXPORT WebThreadImpl : public WebThreadBase { |
43 public: | 37 public: |
44 explicit WebThreadImpl(const char* name); | 38 explicit WebThreadImpl(const char* name); |
45 virtual ~WebThreadImpl(); | 39 virtual ~WebThreadImpl(); |
46 | 40 |
47 virtual void postTask(Task* task); | 41 virtual void postTask(Task* task); |
48 virtual void postDelayedTask(Task* task, long long delay_ms); | 42 virtual void postDelayedTask(Task* task, long long delay_ms); |
49 | 43 |
50 virtual void enterRunLoop(); | 44 virtual void enterRunLoop(); |
51 virtual void exitRunLoop(); | 45 virtual void exitRunLoop(); |
52 | 46 |
53 base::MessageLoop* message_loop() const { return thread_->message_loop(); } | 47 base::MessageLoop* message_loop() const { return thread_->message_loop(); } |
54 | 48 |
55 virtual bool isCurrentThread() const OVERRIDE; | 49 virtual bool isCurrentThread() const OVERRIDE; |
56 | 50 |
57 virtual void setSharedTimerFiredFunction( | |
58 SharedTimerFunction timerFunction) OVERRIDE; | |
59 virtual void setSharedTimerFireInterval(double interval_seconds) OVERRIDE; | |
60 virtual void stopSharedTimer() OVERRIDE; | |
61 | |
62 private: | 51 private: |
63 void OnTimeout() { | |
64 if (shared_timer_function_) | |
65 shared_timer_function_(); | |
66 } | |
67 base::OneShotTimer<WebThreadImpl> shared_timer_; | |
68 SharedTimerFunction shared_timer_function_; | |
69 | |
70 scoped_ptr<base::Thread> thread_; | 52 scoped_ptr<base::Thread> thread_; |
71 }; | 53 }; |
72 | 54 |
73 class WebThreadImplForMessageLoop : public WebThreadBase { | 55 class WebThreadImplForMessageLoop : public WebThreadBase { |
74 public: | 56 public: |
75 CONTENT_EXPORT explicit WebThreadImplForMessageLoop( | 57 CONTENT_EXPORT explicit WebThreadImplForMessageLoop( |
76 base::MessageLoopProxy* message_loop); | 58 base::MessageLoopProxy* message_loop); |
77 CONTENT_EXPORT virtual ~WebThreadImplForMessageLoop(); | 59 CONTENT_EXPORT virtual ~WebThreadImplForMessageLoop(); |
78 | 60 |
79 virtual void postTask(Task* task) OVERRIDE; | 61 virtual void postTask(Task* task) OVERRIDE; |
80 virtual void postDelayedTask(Task* task, long long delay_ms) OVERRIDE; | 62 virtual void postDelayedTask(Task* task, long long delay_ms) OVERRIDE; |
81 | 63 |
82 virtual void enterRunLoop() OVERRIDE; | 64 virtual void enterRunLoop() OVERRIDE; |
83 virtual void exitRunLoop() OVERRIDE; | 65 virtual void exitRunLoop() OVERRIDE; |
84 | 66 |
85 private: | 67 private: |
86 virtual bool isCurrentThread() const OVERRIDE; | 68 virtual bool isCurrentThread() const OVERRIDE; |
87 scoped_refptr<base::MessageLoopProxy> message_loop_; | 69 scoped_refptr<base::MessageLoopProxy> message_loop_; |
88 }; | 70 }; |
89 | 71 |
90 } // namespace content | 72 } // namespace content |
91 | 73 |
92 #endif // CONTENT_CHILD_WEBTHREAD_IMPL_H_ | 74 #endif // CONTENT_CHILD_WEBTHREAD_IMPL_H_ |
OLD | NEW |