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_
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"
14 namespace webkit_glue
{
16 class WebThreadBase
: public blink::WebThread
{
18 virtual ~WebThreadBase();
20 virtual void addTaskObserver(TaskObserver
* observer
);
21 virtual void removeTaskObserver(TaskObserver
* observer
);
23 virtual bool isCurrentThread() const = 0;
29 class TaskObserverAdapter
;
31 typedef std::map
<TaskObserver
*, TaskObserverAdapter
*> TaskObserverMap
;
32 TaskObserverMap task_observer_map_
;
35 class WebThreadImpl
: public WebThreadBase
{
37 WEBKIT_CHILD_EXPORT
explicit WebThreadImpl(const char* name
);
38 WEBKIT_CHILD_EXPORT
virtual ~WebThreadImpl();
40 virtual void postTask(Task
* task
);
41 virtual void postDelayedTask(Task
* task
, long long delay_ms
);
43 virtual void enterRunLoop();
44 virtual void exitRunLoop();
46 base::MessageLoop
* message_loop() const { return thread_
->message_loop(); }
49 virtual bool isCurrentThread() const OVERRIDE
;
50 scoped_ptr
<base::Thread
> thread_
;
53 class WebThreadImplForMessageLoop
: public WebThreadBase
{
55 WEBKIT_CHILD_EXPORT
explicit WebThreadImplForMessageLoop(
56 base::MessageLoopProxy
* message_loop
);
57 WEBKIT_CHILD_EXPORT
virtual ~WebThreadImplForMessageLoop();
59 virtual void postTask(Task
* task
);
60 virtual void postDelayedTask(Task
* task
, long long delay_ms
);
62 virtual void enterRunLoop();
63 virtual void exitRunLoop();
66 virtual bool isCurrentThread() const OVERRIDE
;
67 scoped_refptr
<base::MessageLoopProxy
> message_loop_
;
70 } // namespace webkit_glue
72 #endif // WEBKIT_CHILD_WEBTHREAD_IMPL_H_