Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / shell / renderer / test_runner / WebTask.cpp
1 // Copyright 2013 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 #include "content/shell/renderer/test_runner/WebTask.h"
6
7 #include <algorithm>
8 #include "third_party/WebKit/public/web/WebKit.h"
9
10 using namespace std;
11
12 namespace content {
13
14 WebTask::WebTask(WebTaskList* list)
15     : m_taskList(list)
16 {
17     m_taskList->registerTask(this);
18 }
19
20 WebTask::~WebTask()
21 {
22     if (m_taskList)
23         m_taskList->unregisterTask(this);
24 }
25
26 WebTaskList::WebTaskList()
27 {
28 }
29
30 WebTaskList::~WebTaskList()
31 {
32     revokeAll();
33 }
34
35 void WebTaskList::registerTask(WebTask* task)
36 {
37     m_tasks.push_back(task);
38 }
39
40 void WebTaskList::unregisterTask(WebTask* task)
41 {
42     vector<WebTask*>::iterator iter = find(m_tasks.begin(), m_tasks.end(), task);
43     if (iter != m_tasks.end())
44         m_tasks.erase(iter);
45 }
46
47 void WebTaskList::revokeAll()
48 {
49     while (!m_tasks.empty())
50         m_tasks[0]->cancel();
51 }
52
53 }  // namespace content