1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 #ifndef WEBKIT_CHILD_WEBTHREAD_IMPL_H_ 5 #define WEBKIT_CHILD_WEBTHREAD_IMPL_H_ 6 7 #include <map> 8 9 #include "base/memory/scoped_ptr.h" 10 #include "base/threading/thread.h" 11 #include "third_party/WebKit/public/platform/WebThread.h" 12 #include "webkit/child/webkit_child_export.h" 13 14 namespace webkit_glue { 15 16 class WebThreadBase : public blink::WebThread { 17 public: 18 virtual ~WebThreadBase(); 19 20 virtual void addTaskObserver(TaskObserver* observer); 21 virtual void removeTaskObserver(TaskObserver* observer); 22 23 virtual bool isCurrentThread() const = 0; 24 25 protected: 26 WebThreadBase(); 27 28 private: 29 class TaskObserverAdapter; 30 31 typedef std::map<TaskObserver*, TaskObserverAdapter*> TaskObserverMap; 32 TaskObserverMap task_observer_map_; 33 }; 34 35 class WebThreadImpl : public WebThreadBase { 36 public: 37 WEBKIT_CHILD_EXPORT explicit WebThreadImpl(const char* name); 38 WEBKIT_CHILD_EXPORT virtual ~WebThreadImpl(); 39 40 virtual void postTask(Task* task); 41 virtual void postDelayedTask(Task* task, long long delay_ms); 42 43 virtual void enterRunLoop(); 44 virtual void exitRunLoop(); 45 46 base::MessageLoop* message_loop() const { return thread_->message_loop(); } 47 48 private: 49 virtual bool isCurrentThread() const OVERRIDE; 50 scoped_ptr<base::Thread> thread_; 51 }; 52 53 class WebThreadImplForMessageLoop : public WebThreadBase { 54 public: 55 WEBKIT_CHILD_EXPORT explicit WebThreadImplForMessageLoop( 56 base::MessageLoopProxy* message_loop); 57 WEBKIT_CHILD_EXPORT virtual ~WebThreadImplForMessageLoop(); 58 59 virtual void postTask(Task* task); 60 virtual void postDelayedTask(Task* task, long long delay_ms); 61 62 virtual void enterRunLoop(); 63 virtual void exitRunLoop(); 64 65 private: 66 virtual bool isCurrentThread() const OVERRIDE; 67 scoped_refptr<base::MessageLoopProxy> message_loop_; 68 }; 69 70 } // namespace webkit_glue 71 72 #endif // WEBKIT_CHILD_WEBTHREAD_IMPL_H_ 73