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 CONTENT_CHILD_WEBTHREAD_IMPL_H_
6 #define CONTENT_CHILD_WEBTHREAD_IMPL_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/threading/thread.h"
12 #include "content/common/content_export.h"
13 #include "third_party/WebKit/public/platform/WebThread.h"
16 class WebTraceLocation
;
21 class CONTENT_EXPORT WebThreadBase
: public blink::WebThread
{
23 virtual ~WebThreadBase();
25 virtual void addTaskObserver(TaskObserver
* observer
);
26 virtual void removeTaskObserver(TaskObserver
* observer
);
28 virtual bool isCurrentThread() const = 0;
29 virtual blink::PlatformThreadId
threadId() const = 0;
35 class TaskObserverAdapter
;
37 typedef std::map
<TaskObserver
*, TaskObserverAdapter
*> TaskObserverMap
;
38 TaskObserverMap task_observer_map_
;
41 class CONTENT_EXPORT WebThreadImpl
: public WebThreadBase
{
43 explicit WebThreadImpl(const char* name
);
44 virtual ~WebThreadImpl();
46 virtual void postTask(const blink::WebTraceLocation
& location
, Task
* task
);
47 virtual void postDelayedTask(const blink::WebTraceLocation
& location
,
51 // TODO(skyostil): Remove once blink has migrated.
52 virtual void postTask(Task
* task
);
53 virtual void postDelayedTask(Task
* task
, long long delay_ms
);
55 virtual void enterRunLoop();
56 virtual void exitRunLoop();
58 base::MessageLoop
* message_loop() const { return thread_
->message_loop(); }
60 virtual bool isCurrentThread() const override
;
61 virtual blink::PlatformThreadId
threadId() const override
;
64 scoped_ptr
<base::Thread
> thread_
;
67 class WebThreadImplForMessageLoop
: public WebThreadBase
{
69 CONTENT_EXPORT
explicit WebThreadImplForMessageLoop(
70 scoped_refptr
<base::SingleThreadTaskRunner
> owning_thread_task_runner
);
71 CONTENT_EXPORT
virtual ~WebThreadImplForMessageLoop();
73 virtual void postTask(const blink::WebTraceLocation
& location
, Task
* task
);
74 virtual void postDelayedTask(const blink::WebTraceLocation
& location
,
78 // TODO(skyostil): Remove once blink has migrated.
79 virtual void postTask(Task
* task
);
80 virtual void postDelayedTask(Task
* task
, long long delay_ms
);
82 virtual void enterRunLoop() override
;
83 virtual void exitRunLoop() override
;
86 virtual bool isCurrentThread() const override
;
87 virtual blink::PlatformThreadId
threadId() const override
;
89 scoped_refptr
<base::SingleThreadTaskRunner
> owning_thread_task_runner_
;
90 blink::PlatformThreadId thread_id_
;
93 } // namespace content
95 #endif // CONTENT_CHILD_WEBTHREAD_IMPL_H_