Upstream version 9.37.197.0
[platform/framework/web/crosswalk.git] / src / mojo / examples / html_viewer / webthread_impl.h
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.
4
5 #ifndef MOJO_EXAMPLES_HTML_VIEWER_WEBTHREAD_IMPL_H_
6 #define MOJO_EXAMPLES_HTML_VIEWER_WEBTHREAD_IMPL_H_
7
8 #include <map>
9
10 #include "base/memory/scoped_ptr.h"
11 #include "base/threading/thread.h"
12 #include "third_party/WebKit/public/platform/WebThread.h"
13
14 namespace mojo {
15 namespace examples {
16
17 class WebThreadBase : public blink::WebThread {
18  public:
19   virtual ~WebThreadBase();
20
21   virtual void addTaskObserver(TaskObserver* observer);
22   virtual void removeTaskObserver(TaskObserver* observer);
23
24   virtual bool isCurrentThread() const = 0;
25
26  protected:
27   WebThreadBase();
28
29  private:
30   class TaskObserverAdapter;
31
32   typedef std::map<TaskObserver*, TaskObserverAdapter*> TaskObserverMap;
33   TaskObserverMap task_observer_map_;
34 };
35
36 class WebThreadImpl : public WebThreadBase {
37  public:
38   explicit WebThreadImpl(const char* name);
39   virtual ~WebThreadImpl();
40
41   virtual void postTask(Task* task);
42   virtual void postDelayedTask(Task* task, long long delay_ms);
43
44   virtual void enterRunLoop();
45   virtual void exitRunLoop();
46
47   base::MessageLoop* message_loop() const { return thread_->message_loop(); }
48
49   virtual bool isCurrentThread() const;
50
51  private:
52   scoped_ptr<base::Thread> thread_;
53 };
54
55 class WebThreadImplForMessageLoop : public WebThreadBase {
56  public:
57   explicit WebThreadImplForMessageLoop(
58       base::MessageLoopProxy* message_loop);
59   virtual ~WebThreadImplForMessageLoop();
60
61   virtual void postTask(Task* task);
62   virtual void postDelayedTask(Task* task, long long delay_ms);
63
64   virtual void enterRunLoop();
65   virtual void exitRunLoop();
66
67  private:
68   virtual bool isCurrentThread() const;
69   scoped_refptr<base::MessageLoopProxy> message_loop_;
70 };
71
72 }  // namespace examples
73 }  // namespace mojo
74
75 #endif  // MOJO_EXAMPLES_HTML_VIEWER_WEBTHREAD_IMPL_H_