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