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) {} | |
jochen (gone - plz use gerrit)
2014/07/17 09:48:03
why not = 0?
nasko
2014/07/17 10:49:32
If I make them pure virtual, then I have to provid
| |
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(SharedTimerFunction timerFunction); | |
58 virtual void setSharedTimerFireInterval(double interval_seconds); | |
59 virtual void stopSharedTimer(); | |
60 | |
51 private: | 61 private: |
62 void OnTimeout() { | |
63 if (shared_timer_function_) | |
64 shared_timer_function_(); | |
65 } | |
66 base::OneShotTimer<WebThreadImpl> shared_timer_; | |
67 SharedTimerFunction shared_timer_function_; | |
68 | |
52 scoped_ptr<base::Thread> thread_; | 69 scoped_ptr<base::Thread> thread_; |
53 }; | 70 }; |
54 | 71 |
55 class WebThreadImplForMessageLoop : public WebThreadBase { | 72 class WebThreadImplForMessageLoop : public WebThreadBase { |
56 public: | 73 public: |
57 CONTENT_EXPORT explicit WebThreadImplForMessageLoop( | 74 CONTENT_EXPORT explicit WebThreadImplForMessageLoop( |
58 base::MessageLoopProxy* message_loop); | 75 base::MessageLoopProxy* message_loop); |
59 CONTENT_EXPORT virtual ~WebThreadImplForMessageLoop(); | 76 CONTENT_EXPORT virtual ~WebThreadImplForMessageLoop(); |
60 | 77 |
61 virtual void postTask(Task* task) OVERRIDE; | 78 virtual void postTask(Task* task) OVERRIDE; |
62 virtual void postDelayedTask(Task* task, long long delay_ms) OVERRIDE; | 79 virtual void postDelayedTask(Task* task, long long delay_ms) OVERRIDE; |
63 | 80 |
64 virtual void enterRunLoop() OVERRIDE; | 81 virtual void enterRunLoop() OVERRIDE; |
65 virtual void exitRunLoop() OVERRIDE; | 82 virtual void exitRunLoop() OVERRIDE; |
66 | 83 |
67 private: | 84 private: |
68 virtual bool isCurrentThread() const OVERRIDE; | 85 virtual bool isCurrentThread() const OVERRIDE; |
69 scoped_refptr<base::MessageLoopProxy> message_loop_; | 86 scoped_refptr<base::MessageLoopProxy> message_loop_; |
70 }; | 87 }; |
71 | 88 |
72 } // namespace content | 89 } // namespace content |
73 | 90 |
74 #endif // CONTENT_CHILD_WEBTHREAD_IMPL_H_ | 91 #endif // CONTENT_CHILD_WEBTHREAD_IMPL_H_ |
OLD | NEW |