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 COMPONENTS_HTML_VIEWER_WEB_THREAD_IMPL_H_
6 #define COMPONENTS_HTML_VIEWER_WEB_THREAD_IMPL_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/threading/thread.h"
12 #include "components/html_viewer/web_scheduler_impl.h"
13 #include "third_party/WebKit/public/platform/WebThread.h"
15 namespace html_viewer
{
17 class WebThreadBase
: public blink::WebThread
{
19 virtual ~WebThreadBase();
21 virtual void addTaskObserver(TaskObserver
* observer
);
22 virtual void removeTaskObserver(TaskObserver
* observer
);
24 virtual bool isCurrentThread() 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 ~WebThreadImpl() override
;
41 virtual void postTask(const blink::WebTraceLocation
& location
, Task
* task
);
42 virtual void postDelayedTask(const blink::WebTraceLocation
& location
,
46 virtual void enterRunLoop();
47 virtual void exitRunLoop();
49 virtual blink::WebScheduler
* scheduler() const;
51 base::MessageLoop
* message_loop() const { return thread_
->message_loop(); }
53 bool isCurrentThread() const override
;
54 virtual blink::PlatformThreadId
threadId() const;
57 scoped_ptr
<base::Thread
> thread_
;
58 scoped_ptr
<WebSchedulerImpl
> web_scheduler_
;
61 class WebThreadImplForMessageLoop
: public WebThreadBase
{
63 explicit WebThreadImplForMessageLoop(
64 base::MessageLoopProxy
* message_loop
);
65 ~WebThreadImplForMessageLoop() override
;
67 virtual void postTask(const blink::WebTraceLocation
& location
, Task
* task
);
68 virtual void postDelayedTask(const blink::WebTraceLocation
& location
,
72 virtual void enterRunLoop();
73 virtual void exitRunLoop();
75 virtual blink::WebScheduler
* scheduler() const;
78 bool isCurrentThread() const override
;
79 virtual blink::PlatformThreadId
threadId() const;
81 scoped_refptr
<base::MessageLoopProxy
> message_loop_
;
82 scoped_ptr
<WebSchedulerImpl
> web_scheduler_
;
83 blink::PlatformThreadId thread_id_
;
86 } // namespace html_viewer
88 #endif // COMPONENTS_HTML_VIEWER_WEB_THREAD_IMPL_H_