Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / webkit / glue / webthread_impl.h
blobf84b9940f6ef371294e6d8eddf2762aa964cd233
1 // Copyright (c) 2012 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_GLUE_WEBTHREAD_IMPL_H_
5 #define WEBKIT_GLUE_WEBTHREAD_IMPL_H_
7 #include <map>
9 #include "base/threading/thread.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "third_party/WebKit/Source/Platform/chromium/public/WebThread.h"
12 #include "webkit/glue/webkit_glue_export.h"
14 namespace webkit_glue {
16 class WebThreadBase : public WebKit::WebThread {
17 public:
18 virtual ~WebThreadBase();
20 virtual void addTaskObserver(TaskObserver* observer);
21 virtual void removeTaskObserver(TaskObserver* observer);
23 protected:
24 WebThreadBase();
26 private:
27 class TaskObserverAdapter;
29 virtual bool IsCurrentThread() const = 0;
31 typedef std::map<TaskObserver*, TaskObserverAdapter*> TaskObserverMap;
32 TaskObserverMap task_observer_map_;
35 class WebThreadImpl : public WebThreadBase {
36 public:
37 WEBKIT_GLUE_EXPORT explicit WebThreadImpl(const char* name);
38 WEBKIT_GLUE_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 MessageLoop* message_loop() const { return thread_->message_loop(); }
48 private:
49 virtual bool IsCurrentThread() const OVERRIDE;
50 scoped_ptr<base::Thread> thread_;
53 class WebThreadImplForMessageLoop : public WebThreadBase {
54 public:
55 WEBKIT_GLUE_EXPORT explicit WebThreadImplForMessageLoop(
56 base::MessageLoopProxy* message_loop);
57 WEBKIT_GLUE_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();
65 private:
66 virtual bool IsCurrentThread() const OVERRIDE;
67 scoped_refptr<base::MessageLoopProxy> message_loop_;
70 } // namespace webkit_glue
72 #endif