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" |
12 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
13 #include "third_party/WebKit/public/platform/WebThread.h" | 14 #include "third_party/WebKit/public/platform/WebThread.h" |
14 | 15 |
15 namespace content { | 16 namespace content { |
16 | 17 |
17 class CONTENT_EXPORT WebThreadBase : public blink::WebThread { | 18 class CONTENT_EXPORT WebThreadBase : public blink::WebThread { |
18 public: | 19 public: |
19 virtual ~WebThreadBase(); | 20 virtual ~WebThreadBase(); |
20 | 21 |
21 virtual void addTaskObserver(TaskObserver* observer); | 22 virtual void addTaskObserver(TaskObserver* observer); |
22 virtual void removeTaskObserver(TaskObserver* observer); | 23 virtual void removeTaskObserver(TaskObserver* observer); |
23 | 24 |
24 virtual bool isCurrentThread() const = 0; | 25 virtual bool isCurrentThread() const = 0; |
25 | 26 |
| 27 typedef void (*SharedTimerFunction)(); |
| 28 virtual void setSharedTimerFiredFunction(SharedTimerFunction timerFunction) {} |
| 29 virtual void setSharedTimerFireInterval(double) {} |
| 30 virtual void stopSharedTimer() {} |
| 31 |
26 protected: | 32 protected: |
27 WebThreadBase(); | 33 WebThreadBase(); |
28 | 34 |
29 private: | 35 private: |
30 class TaskObserverAdapter; | 36 class TaskObserverAdapter; |
31 | 37 |
32 typedef std::map<TaskObserver*, TaskObserverAdapter*> TaskObserverMap; | 38 typedef std::map<TaskObserver*, TaskObserverAdapter*> TaskObserverMap; |
33 TaskObserverMap task_observer_map_; | 39 TaskObserverMap task_observer_map_; |
34 }; | 40 }; |
35 | 41 |
36 class CONTENT_EXPORT WebThreadImpl : public WebThreadBase { | 42 class CONTENT_EXPORT WebThreadImpl : public WebThreadBase { |
37 public: | 43 public: |
38 explicit WebThreadImpl(const char* name); | 44 explicit WebThreadImpl(const char* name); |
39 virtual ~WebThreadImpl(); | 45 virtual ~WebThreadImpl(); |
40 | 46 |
41 virtual void postTask(Task* task); | 47 virtual void postTask(Task* task); |
42 virtual void postDelayedTask(Task* task, long long delay_ms); | 48 virtual void postDelayedTask(Task* task, long long delay_ms); |
43 | 49 |
44 virtual void enterRunLoop(); | 50 virtual void enterRunLoop(); |
45 virtual void exitRunLoop(); | 51 virtual void exitRunLoop(); |
46 | 52 |
47 base::MessageLoop* message_loop() const { return thread_->message_loop(); } | 53 base::MessageLoop* message_loop() const { return thread_->message_loop(); } |
48 | 54 |
49 virtual bool isCurrentThread() const OVERRIDE; | 55 virtual bool isCurrentThread() const OVERRIDE; |
50 | 56 |
| 57 virtual void setSharedTimerFiredFunction( |
| 58 SharedTimerFunction timerFunction) OVERRIDE; |
| 59 virtual void setSharedTimerFireInterval(double interval_seconds) OVERRIDE; |
| 60 virtual void stopSharedTimer() OVERRIDE; |
| 61 |
51 private: | 62 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 |
52 scoped_ptr<base::Thread> thread_; | 70 scoped_ptr<base::Thread> thread_; |
53 }; | 71 }; |
54 | 72 |
55 class WebThreadImplForMessageLoop : public WebThreadBase { | 73 class WebThreadImplForMessageLoop : public WebThreadBase { |
56 public: | 74 public: |
57 CONTENT_EXPORT explicit WebThreadImplForMessageLoop( | 75 CONTENT_EXPORT explicit WebThreadImplForMessageLoop( |
58 base::MessageLoopProxy* message_loop); | 76 base::MessageLoopProxy* message_loop); |
59 CONTENT_EXPORT virtual ~WebThreadImplForMessageLoop(); | 77 CONTENT_EXPORT virtual ~WebThreadImplForMessageLoop(); |
60 | 78 |
61 virtual void postTask(Task* task) OVERRIDE; | 79 virtual void postTask(Task* task) OVERRIDE; |
62 virtual void postDelayedTask(Task* task, long long delay_ms) OVERRIDE; | 80 virtual void postDelayedTask(Task* task, long long delay_ms) OVERRIDE; |
63 | 81 |
64 virtual void enterRunLoop() OVERRIDE; | 82 virtual void enterRunLoop() OVERRIDE; |
65 virtual void exitRunLoop() OVERRIDE; | 83 virtual void exitRunLoop() OVERRIDE; |
66 | 84 |
67 private: | 85 private: |
68 virtual bool isCurrentThread() const OVERRIDE; | 86 virtual bool isCurrentThread() const OVERRIDE; |
69 scoped_refptr<base::MessageLoopProxy> message_loop_; | 87 scoped_refptr<base::MessageLoopProxy> message_loop_; |
70 }; | 88 }; |
71 | 89 |
72 } // namespace content | 90 } // namespace content |
73 | 91 |
74 #endif // CONTENT_CHILD_WEBTHREAD_IMPL_H_ | 92 #endif // CONTENT_CHILD_WEBTHREAD_IMPL_H_ |
OLD | NEW |