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

Side by Side Diff: content/shell/renderer/test_runner/WebTask.h

Issue 566833002: Update WebTask in chromium c++ style (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: resolved build error Created 6 years, 3 months 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
« no previous file with comments | « content/shell/BUILD.gn ('k') | content/shell/renderer/test_runner/WebTask.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTASK_H_
6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTASK_H_
7
8 #include <vector>
9
10 namespace content {
11
12 class WebTaskList;
13
14 // WebTask represents a task which can run by WebTestDelegate::postTask() or
15 // WebTestDelegate::postDelayedTask().
16 class WebTask {
17 public:
18 explicit WebTask(WebTaskList*);
19 virtual ~WebTask();
20
21 // The main code of this task.
22 // An implementation of run() should return immediately if cancel() was call ed.
23 virtual void run() = 0;
24 virtual void cancel() = 0;
25
26 protected:
27 WebTaskList* m_taskList;
28 };
29
30 class WebTaskList {
31 public:
32 WebTaskList();
33 ~WebTaskList();
34 void registerTask(WebTask*);
35 void unregisterTask(WebTask*);
36 void revokeAll();
37
38 private:
39 std::vector<WebTask*> m_tasks;
40 };
41
42 // A task containing an object pointer of class T. Derived classes should
43 // override runIfValid() which in turn can safely invoke methods on the
44 // m_object. The Class T must have "WebTaskList* mutable_task_list()".
45 template<class T>
46 class WebMethodTask : public WebTask {
47 public:
48 explicit WebMethodTask(T* object)
49 : WebTask(object->mutable_task_list())
50 , m_object(object)
51 {
52 }
53
54 virtual ~WebMethodTask() { }
55
56 virtual void run()
57 {
58 if (m_object)
59 runIfValid();
60 }
61
62 virtual void cancel()
63 {
64 m_object = 0;
65 m_taskList->unregisterTask(this);
66 m_taskList = 0;
67 }
68
69 virtual void runIfValid() = 0;
70
71 protected:
72 T* m_object;
73 };
74
75 } // namespace content
76
77 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTASK_H_
OLDNEW
« no previous file with comments | « content/shell/BUILD.gn ('k') | content/shell/renderer/test_runner/WebTask.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698