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.
5 #ifndef COMPONENTS_TEST_RUNNER_WEB_TASK_H_
6 #define COMPONENTS_TEST_RUNNER_WEB_TASK_H_
10 #include "base/macros.h"
12 namespace test_runner
{
16 // WebTask represents a task which can run by WebTestDelegate::postTask() or
17 // WebTestDelegate::postDelayedTask().
20 explicit WebTask(WebTaskList
*);
23 // The main code of this task.
24 // An implementation of run() should return immediately if cancel() was
26 virtual void run() = 0;
27 virtual void cancel() = 0;
30 WebTaskList
* task_list_
;
37 void RegisterTask(WebTask
*);
38 void UnregisterTask(WebTask
*);
42 std::vector
<WebTask
*> tasks_
;
44 DISALLOW_COPY_AND_ASSIGN(WebTaskList
);
47 // A task containing an object pointer of class T. Derived classes should
48 // override RunIfValid() which in turn can safely invoke methods on the
49 // object_. The Class T must have "WebTaskList* mutable_task_list()".
51 class WebMethodTask
: public WebTask
{
53 explicit WebMethodTask(T
* object
)
54 : WebTask(object
->mutable_task_list()), object_(object
) {}
56 virtual ~WebMethodTask() {}
63 void cancel() override
{
65 task_list_
->UnregisterTask(this);
69 virtual void RunIfValid() = 0;
75 } // namespace test_runner
77 #endif // COMPONENTS_TEST_RUNNER_WEB_TASK_H_