| 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 "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
| 13 #include "third_party/WebKit/public/platform/WebThread.h" | 13 #include "third_party/WebKit/public/platform/WebThread.h" |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 class WebTraceLocation; | 16 class WebTraceLocation; |
| 17 } | 17 } |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 | 20 |
| 21 class CONTENT_EXPORT WebThreadBase : public blink::WebThread { | 21 class CONTENT_EXPORT WebThreadBase : public blink::WebThread { |
| 22 public: | 22 public: |
| 23 virtual ~WebThreadBase(); | 23 virtual ~WebThreadBase(); |
| 24 | 24 |
| 25 // blink::WebThread implementation. |
| 26 virtual bool isCurrentThread() const; |
| 27 virtual blink::PlatformThreadId threadId() const = 0; |
| 28 |
| 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); |
| 33 |
| 34 virtual void enterRunLoop(); |
| 35 virtual void exitRunLoop(); |
| 36 |
| 25 virtual void addTaskObserver(TaskObserver* observer); | 37 virtual void addTaskObserver(TaskObserver* observer); |
| 26 virtual void removeTaskObserver(TaskObserver* observer); | 38 virtual void removeTaskObserver(TaskObserver* observer); |
| 27 | 39 |
| 28 virtual bool isCurrentThread() const = 0; | 40 // Returns the base::Bind-compatible task runner for posting tasks to this |
| 29 virtual blink::PlatformThreadId threadId() const = 0; | 41 // thread. Can be called from any thread. |
| 42 virtual base::SingleThreadTaskRunner* TaskRunner() const = 0; |
| 30 | 43 |
| 31 protected: | 44 protected: |
| 45 class TaskObserverAdapter; |
| 46 |
| 32 WebThreadBase(); | 47 WebThreadBase(); |
| 33 | 48 |
| 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; |
| 53 |
| 54 static void RunWebThreadTask(scoped_ptr<blink::WebThread::Task> task); |
| 55 |
| 34 private: | 56 private: |
| 35 class TaskObserverAdapter; | |
| 36 | |
| 37 typedef std::map<TaskObserver*, TaskObserverAdapter*> TaskObserverMap; | 57 typedef std::map<TaskObserver*, TaskObserverAdapter*> TaskObserverMap; |
| 38 TaskObserverMap task_observer_map_; | 58 TaskObserverMap task_observer_map_; |
| 39 }; | 59 }; |
| 40 | 60 |
| 41 class CONTENT_EXPORT WebThreadImpl : public WebThreadBase { | 61 class CONTENT_EXPORT WebThreadImpl : public WebThreadBase { |
| 42 public: | 62 public: |
| 43 explicit WebThreadImpl(const char* name); | 63 explicit WebThreadImpl(const char* name); |
| 44 virtual ~WebThreadImpl(); | 64 virtual ~WebThreadImpl(); |
| 45 | 65 |
| 46 virtual void postTask(const blink::WebTraceLocation& location, Task* task); | 66 // blink::WebThread implementation. |
| 47 virtual void postDelayedTask(const blink::WebTraceLocation& location, | 67 blink::PlatformThreadId threadId() const override; |
| 48 Task* task, | |
| 49 long long delay_ms); | |
| 50 | 68 |
| 51 // TODO(skyostil): Remove once blink has migrated. | 69 // WebThreadBase implementation. |
| 52 virtual void postTask(Task* task); | 70 base::SingleThreadTaskRunner* TaskRunner() const override; |
| 53 virtual void postDelayedTask(Task* task, long long delay_ms); | |
| 54 | |
| 55 virtual void enterRunLoop(); | |
| 56 virtual void exitRunLoop(); | |
| 57 | |
| 58 base::MessageLoop* message_loop() const { return thread_->message_loop(); } | |
| 59 | |
| 60 virtual bool isCurrentThread() const override; | |
| 61 virtual blink::PlatformThreadId threadId() const override; | |
| 62 | 71 |
| 63 private: | 72 private: |
| 73 base::MessageLoop* MessageLoop() const override; |
| 74 |
| 64 scoped_ptr<base::Thread> thread_; | 75 scoped_ptr<base::Thread> thread_; |
| 65 }; | 76 }; |
| 66 | 77 |
| 67 class WebThreadImplForMessageLoop : public WebThreadBase { | 78 class WebThreadImplForMessageLoop : public WebThreadBase { |
| 68 public: | 79 public: |
| 69 CONTENT_EXPORT explicit WebThreadImplForMessageLoop( | 80 CONTENT_EXPORT explicit WebThreadImplForMessageLoop( |
| 70 scoped_refptr<base::SingleThreadTaskRunner> owning_thread_task_runner); | 81 scoped_refptr<base::SingleThreadTaskRunner> owning_thread_task_runner); |
| 71 CONTENT_EXPORT virtual ~WebThreadImplForMessageLoop(); | 82 CONTENT_EXPORT virtual ~WebThreadImplForMessageLoop(); |
| 72 | 83 |
| 73 virtual void postTask(const blink::WebTraceLocation& location, Task* task); | 84 // blink::WebThread implementation. |
| 74 virtual void postDelayedTask(const blink::WebTraceLocation& location, | 85 blink::PlatformThreadId threadId() const override; |
| 75 Task* task, | |
| 76 long long delay_ms); | |
| 77 | 86 |
| 78 // TODO(skyostil): Remove once blink has migrated. | 87 // WebThreadBase implementation. |
| 79 virtual void postTask(Task* task); | 88 base::MessageLoop* MessageLoop() const override; |
| 80 virtual void postDelayedTask(Task* task, long long delay_ms); | |
| 81 | |
| 82 virtual void enterRunLoop() override; | |
| 83 virtual void exitRunLoop() override; | |
| 84 | 89 |
| 85 private: | 90 private: |
| 86 virtual bool isCurrentThread() const override; | 91 base::SingleThreadTaskRunner* TaskRunner() const override; |
| 87 virtual blink::PlatformThreadId threadId() const override; | |
| 88 | 92 |
| 89 scoped_refptr<base::SingleThreadTaskRunner> owning_thread_task_runner_; | 93 scoped_refptr<base::SingleThreadTaskRunner> owning_thread_task_runner_; |
| 90 blink::PlatformThreadId thread_id_; | 94 blink::PlatformThreadId thread_id_; |
| 91 }; | 95 }; |
| 92 | 96 |
| 93 } // namespace content | 97 } // namespace content |
| 94 | 98 |
| 95 #endif // CONTENT_CHILD_WEBTHREAD_IMPL_H_ | 99 #endif // CONTENT_CHILD_WEBTHREAD_IMPL_H_ |
| OLD | NEW |