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
3 // found in the LICENSE file.
5 #ifndef MOJO_SERVICES_HTML_VIEWER_WEBTHREAD_IMPL_H_
6 #define MOJO_SERVICES_HTML_VIEWER_WEBTHREAD_IMPL_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/threading/thread.h"
12 #include "third_party/WebKit/public/platform/WebThread.h"
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;
24 virtual blink::PlatformThreadId
threadId() const = 0;
30 class TaskObserverAdapter
;
32 typedef std::map
<TaskObserver
*, TaskObserverAdapter
*> TaskObserverMap
;
33 TaskObserverMap task_observer_map_
;
36 class WebThreadImpl
: public WebThreadBase
{
38 explicit WebThreadImpl(const char* name
);
39 virtual ~WebThreadImpl();
41 virtual void postTask(Task
* task
);
42 virtual void postDelayedTask(Task
* task
, long long delay_ms
);
44 virtual void enterRunLoop();
45 virtual void exitRunLoop();
47 base::MessageLoop
* message_loop() const { return thread_
->message_loop(); }
49 virtual bool isCurrentThread() const;
50 virtual blink::PlatformThreadId
threadId() const;
53 scoped_ptr
<base::Thread
> thread_
;
56 class WebThreadImplForMessageLoop
: public WebThreadBase
{
58 explicit WebThreadImplForMessageLoop(
59 base::MessageLoopProxy
* message_loop
);
60 virtual ~WebThreadImplForMessageLoop();
62 virtual void postTask(Task
* task
);
63 virtual void postDelayedTask(Task
* task
, long long delay_ms
);
65 virtual void enterRunLoop();
66 virtual void exitRunLoop();
69 virtual bool isCurrentThread() const;
70 virtual blink::PlatformThreadId
threadId() const;
72 scoped_refptr
<base::MessageLoopProxy
> message_loop_
;
73 blink::PlatformThreadId thread_id_
;
78 #endif // MOJO_SERVICES_HTML_VIEWER_WEBTHREAD_IMPL_H_