Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: content/public/test/layout_tests/WebTask.h

Issue 110533009: Import TestRunner library into chromium. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 /*
6 * Copyright (C) 2010 Google Inc. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following disclaimer
16 * in the documentation and/or other materials provided with the
17 * distribution.
18 * * Neither the name of Google Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived from
20 * this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #ifndef WebTask_h
36 #define WebTask_h
37
38 #include <vector>
39
40 #include "content/public/test/layout_tests/WebTestCommon.h"
41
42 namespace WebTestRunner {
43
44 class WebTaskList;
45
46 // WebTask represents a task which can run by WebTestDelegate::postTask() or
47 // WebTestDelegate::postDelayedTask().
48 class WEBTESTRUNNER_EXPORT WebTask {
49 public:
50 explicit WebTask(WebTaskList*);
51 virtual ~WebTask();
52
53 // The main code of this task.
54 // An implementation of run() should return immediately if cancel() was call ed.
55 virtual void run() = 0;
56 virtual void cancel() = 0;
57
58 protected:
59 WebTaskList* m_taskList;
60 };
61
62 class WEBTESTRUNNER_EXPORT WebTaskList {
63 public:
64 WebTaskList();
65 ~WebTaskList();
66 void registerTask(WebTask*);
67 void unregisterTask(WebTask*);
68 void revokeAll();
69
70 private:
71 std::vector<WebTask*> m_tasks;
72 };
73
74 // A task containing an object pointer of class T. Derived classes should
75 // override runIfValid() which in turn can safely invoke methods on the
76 // m_object. The Class T must have "WebTaskList* taskList()".
77 template<class T>
78 class WebMethodTask : public WebTask {
79 public:
80 explicit WebMethodTask(T* object)
81 : WebTask(object->taskList())
82 , m_object(object)
83 {
84 }
85
86 virtual ~WebMethodTask() { }
87
88 virtual void run()
89 {
90 if (m_object)
91 runIfValid();
92 }
93
94 virtual void cancel()
95 {
96 m_object = 0;
97 m_taskList->unregisterTask(this);
98 m_taskList = 0;
99 }
100
101 virtual void runIfValid() = 0;
102
103 protected:
104 T* m_object;
105 };
106
107 }
108
109 #endif // WebTask_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698