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

Side by Side Diff: content/shell/renderer/test_runner/web_task.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
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_WEB_TASK_H_
6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_WEB_TASK_H_
7
8 #include <vector>
9
10 #include "base/macros.h"
11
12 namespace content {
13
14 class WebTaskList;
15
16 // WebTask represents a task which can run by WebTestDelegate::postTask() or
17 // WebTestDelegate::postDelayedTask().
18 class WebTask {
19 public:
20 explicit WebTask(WebTaskList*);
21 virtual ~WebTask();
22
23 // The main code of this task.
24 // An implementation of run() should return immediately if cancel() was
25 // called.
26 virtual void run() = 0;
27 virtual void cancel() = 0;
28
29 protected:
30 WebTaskList* task_list_;
31 };
32
33 class WebTaskList {
34 public:
35 WebTaskList();
36 ~WebTaskList();
37 void RegisterTask(WebTask*);
38 void UnregisterTask(WebTask*);
39 void RevokeAll();
40
41 private:
42 std::vector<WebTask*> tasks_;
43
44 DISALLOW_COPY_AND_ASSIGN(WebTaskList);
45 };
46
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()".
50 template <class T>
51 class WebMethodTask : public WebTask {
52 public:
53 explicit WebMethodTask(T* object)
54 : WebTask(object->mutable_task_list()), object_(object) {}
55
56 virtual ~WebMethodTask() {}
57
58 virtual void run() {
59 if (object_)
60 RunIfValid();
61 }
62
63 virtual void cancel() {
64 object_ = 0;
65 task_list_->UnregisterTask(this);
66 task_list_ = 0;
67 }
68
69 virtual void RunIfValid() = 0;
70
71 protected:
72 T* object_;
73 };
74
75 } // namespace content
76
77 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_WEB_TASK_H_
OLDNEW
« no previous file with comments | « content/shell/renderer/test_runner/test_runner.cc ('k') | content/shell/renderer/test_runner/web_task.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698