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

Side by Side Diff: src/cancelable-task.h

Issue 1258923010: Add CancelableIdleTask. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix override Created 5 years, 4 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 | « no previous file | src/cancelable-task.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_CANCELABLE_TASK_H_ 5 #ifndef V8_CANCELABLE_TASK_H_
6 #define V8_CANCELABLE_TASK_H_ 6 #define V8_CANCELABLE_TASK_H_
7 7
8 #include "include/v8-platform.h" 8 #include "include/v8-platform.h"
9 #include "src/base/macros.h" 9 #include "src/base/macros.h"
10 10
11 namespace v8 { 11 namespace v8 {
12 namespace internal { 12 namespace internal {
13 13
14 class Isolate; 14 class Isolate;
15 15
16 class CancelableTask : public Task { 16
17 class Cancelable {
17 public: 18 public:
18 explicit CancelableTask(Isolate* isolate); 19 explicit Cancelable(Isolate* isolate);
19 ~CancelableTask() override; 20 virtual ~Cancelable();
20 21
21 void Cancel() { is_cancelled_ = true; } 22 virtual void Cancel() { is_cancelled_ = true; }
22 23
24 protected:
25 Isolate* isolate_;
26 bool is_cancelled_;
27
28 private:
29 DISALLOW_COPY_AND_ASSIGN(Cancelable);
30 };
31
32
33 // Multiple inheritance can be used because Task is a pure interface.
34 class CancelableTask : public Cancelable, public Task {
35 public:
36 explicit CancelableTask(Isolate* isolate) : Cancelable(isolate) {}
37
38 // Task overrides.
23 void Run() final { 39 void Run() final {
24 if (!is_cancelled_) { 40 if (!is_cancelled_) {
25 RunInternal(); 41 RunInternal();
26 } 42 }
27 } 43 }
28 44
29 virtual void RunInternal() = 0; 45 virtual void RunInternal() = 0;
30 46
31 protected: 47 private:
32 Isolate* isolate_; 48 DISALLOW_COPY_AND_ASSIGN(CancelableTask);
49 };
50
51
52 // Multiple inheritance can be used because IdleTask is a pure interface.
53 class CancelableIdleTask : public Cancelable, public IdleTask {
54 public:
55 explicit CancelableIdleTask(Isolate* isolate) : Cancelable(isolate) {}
56
57 // IdleTask overrides.
58 void Run(double deadline_in_seconds) final {
59 if (!is_cancelled_) {
60 RunInternal(deadline_in_seconds);
61 }
62 }
63
64 virtual void RunInternal(double deadline_in_seconds) = 0;
33 65
34 private: 66 private:
35 bool is_cancelled_; 67 DISALLOW_COPY_AND_ASSIGN(CancelableIdleTask);
68 };
36 69
37 DISALLOW_COPY_AND_ASSIGN(CancelableTask);
38 };
39 70
40 } // namespace internal 71 } // namespace internal
41 } // namespace v8 72 } // namespace v8
42 73
43 #endif // V8_CANCELABLE_TASK_H_ 74 #endif // V8_CANCELABLE_TASK_H_
OLDNEW
« no previous file with comments | « no previous file | src/cancelable-task.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698