#ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTASK_H_
#define CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTASK_H_
#include <vector>
namespace WebTestRunner {
class WebTaskList;
class WebTask {
public:
explicit WebTask(WebTaskList*);
virtual ~WebTask();
virtual void run() = 0;
virtual void cancel() = 0;
protected:
WebTaskList* m_taskList;
};
class WebTaskList {
public:
WebTaskList();
~WebTaskList();
void registerTask(WebTask*);
void unregisterTask(WebTask*);
void revokeAll();
private:
std::vector<WebTask*> m_tasks;
};
template<class T>
class WebMethodTask : public WebTask {
public:
explicit WebMethodTask(T* object)
: WebTask(object->taskList())
, m_object(object)
{
}
virtual ~WebMethodTask() { }
virtual void run()
{
if (m_object)
runIfValid();
}
virtual void cancel()
{
m_object = 0;
m_taskList->unregisterTask(this);
m_taskList = 0;
}
virtual void runIfValid() = 0;
protected:
T* m_object;
};
}
#endif