#ifndef CONTENT_CHILD_WEBTHREAD_IMPL_H_
#define CONTENT_CHILD_WEBTHREAD_IMPL_H_
#include <map>
#include "base/memory/scoped_ptr.h"
#include "base/threading/thread.h"
#include "content/common/content_export.h"
#include "third_party/WebKit/public/platform/WebThread.h"
namespace content {
class WebThreadBase : public blink::WebThread {
public:
virtual ~WebThreadBase();
virtual void addTaskObserver(TaskObserver* observer);
virtual void removeTaskObserver(TaskObserver* observer);
virtual bool isCurrentThread() const = 0;
protected:
WebThreadBase();
private:
class TaskObserverAdapter;
typedef std::map<TaskObserver*, TaskObserverAdapter*> TaskObserverMap;
TaskObserverMap task_observer_map_;
};
class WebThreadImpl : public WebThreadBase {
public:
CONTENT_EXPORT explicit WebThreadImpl(const char* name);
CONTENT_EXPORT virtual ~WebThreadImpl();
virtual void postTask(Task* task);
virtual void postDelayedTask(Task* task, long long delay_ms);
virtual void enterRunLoop();
virtual void exitRunLoop();
base::MessageLoop* message_loop() const { return thread_->message_loop(); }
private:
virtual bool isCurrentThread() const OVERRIDE;
scoped_ptr<base::Thread> thread_;
};
class WebThreadImplForMessageLoop : public WebThreadBase {
public:
CONTENT_EXPORT explicit WebThreadImplForMessageLoop(
base::MessageLoopProxy* message_loop);
CONTENT_EXPORT virtual ~WebThreadImplForMessageLoop();
virtual void postTask(Task* task);
virtual void postDelayedTask(Task* task, long long delay_ms);
virtual void enterRunLoop();
virtual void exitRunLoop();
private:
virtual bool isCurrentThread() const OVERRIDE;
scoped_refptr<base::MessageLoopProxy> message_loop_;
};
}
#endif