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

Side by Side Diff: content/browser/dom_storage/dom_storage_task_runner.h

Issue 2726523002: Pass Callback to TaskRunner by value and consume it on invocation (1) (Closed)
Patch Set: erase Closure* Created 3 years, 8 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_H_ 5 #ifndef CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_H_
6 #define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_H_ 6 #define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_H_
7 7
8 #include "base/callback.h"
8 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
9 #include "base/sequence_checker.h" 10 #include "base/sequence_checker.h"
10 #include "base/sequenced_task_runner.h" 11 #include "base/sequenced_task_runner.h"
11 #include "base/time/time.h" 12 #include "base/time/time.h"
12 #include "content/common/content_export.h" 13 #include "content/common/content_export.h"
13 14
14 namespace content { 15 namespace content {
15 16
16 // DOMStorage uses two task sequences (primary vs commit) to avoid 17 // DOMStorage uses two task sequences (primary vs commit) to avoid
17 // primary access from queuing up behind commits to disk. 18 // primary access from queuing up behind commits to disk.
18 // * Initialization, shutdown, and administrative tasks are performed as 19 // * Initialization, shutdown, and administrative tasks are performed as
19 // shutdown-blocking primary sequence tasks. 20 // shutdown-blocking primary sequence tasks.
20 // * Tasks directly related to the javascript'able interface are performed 21 // * Tasks directly related to the javascript'able interface are performed
21 // as shutdown-blocking primary sequence tasks. 22 // as shutdown-blocking primary sequence tasks.
22 // TODO(michaeln): Skip tasks for reading during shutdown. 23 // TODO(michaeln): Skip tasks for reading during shutdown.
23 // * Internal tasks related to committing changes to disk are performed as 24 // * Internal tasks related to committing changes to disk are performed as
24 // shutdown-blocking commit sequence tasks. 25 // shutdown-blocking commit sequence tasks.
25 class CONTENT_EXPORT DOMStorageTaskRunner 26 class CONTENT_EXPORT DOMStorageTaskRunner
26 : public base::TaskRunner { 27 : public base::TaskRunner {
27 public: 28 public:
28 enum SequenceID { 29 enum SequenceID {
29 PRIMARY_SEQUENCE, 30 PRIMARY_SEQUENCE,
30 COMMIT_SEQUENCE 31 COMMIT_SEQUENCE
31 }; 32 };
32 33
33 // The PostTask() and PostDelayedTask() methods defined by TaskRunner 34 // The PostTask() and PostDelayedTask() methods defined by TaskRunner
34 // post shutdown-blocking tasks on the primary sequence. 35 // post shutdown-blocking tasks on the primary sequence.
35 bool PostDelayedTask(const tracked_objects::Location& from_here, 36 bool PostDelayedTask(const tracked_objects::Location& from_here,
36 const base::Closure& task, 37 base::Closure task,
37 base::TimeDelta delay) override = 0; 38 base::TimeDelta delay) override = 0;
38 39
39 // Posts a shutdown blocking task to |sequence_id|. 40 // Posts a shutdown blocking task to |sequence_id|.
40 virtual bool PostShutdownBlockingTask( 41 virtual bool PostShutdownBlockingTask(
41 const tracked_objects::Location& from_here, 42 const tracked_objects::Location& from_here,
42 SequenceID sequence_id, 43 SequenceID sequence_id,
43 const base::Closure& task) = 0; 44 base::Closure task) = 0;
44 45
45 virtual void AssertIsRunningOnPrimarySequence() const = 0; 46 virtual void AssertIsRunningOnPrimarySequence() const = 0;
46 virtual void AssertIsRunningOnCommitSequence() const = 0; 47 virtual void AssertIsRunningOnCommitSequence() const = 0;
47 48
48 virtual scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner( 49 virtual scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner(
49 SequenceID sequence_id) = 0; 50 SequenceID sequence_id) = 0;
50 51
51 protected: 52 protected:
52 ~DOMStorageTaskRunner() override {} 53 ~DOMStorageTaskRunner() override {}
53 }; 54 };
54 55
55 // A DOMStorageTaskRunner which manages a primary and a commit sequence. 56 // A DOMStorageTaskRunner which manages a primary and a commit sequence.
56 class CONTENT_EXPORT DOMStorageWorkerPoolTaskRunner : 57 class CONTENT_EXPORT DOMStorageWorkerPoolTaskRunner :
57 public DOMStorageTaskRunner { 58 public DOMStorageTaskRunner {
58 public: 59 public:
59 // |primary_sequence| and |commit_sequence| should have 60 // |primary_sequence| and |commit_sequence| should have
60 // TaskShutdownBehaviour::BLOCK_SHUTDOWN semantics. 61 // TaskShutdownBehaviour::BLOCK_SHUTDOWN semantics.
61 DOMStorageWorkerPoolTaskRunner( 62 DOMStorageWorkerPoolTaskRunner(
62 scoped_refptr<base::SequencedTaskRunner> primary_sequence, 63 scoped_refptr<base::SequencedTaskRunner> primary_sequence,
63 scoped_refptr<base::SequencedTaskRunner> commit_sequence); 64 scoped_refptr<base::SequencedTaskRunner> commit_sequence);
64 65
65 bool RunsTasksOnCurrentThread() const override; 66 bool RunsTasksOnCurrentThread() const override;
66 67
67 bool PostDelayedTask(const tracked_objects::Location& from_here, 68 bool PostDelayedTask(const tracked_objects::Location& from_here,
68 const base::Closure& task, 69 base::Closure task,
69 base::TimeDelta delay) override; 70 base::TimeDelta delay) override;
70 71
71 bool PostShutdownBlockingTask(const tracked_objects::Location& from_here, 72 bool PostShutdownBlockingTask(const tracked_objects::Location& from_here,
72 SequenceID sequence_id, 73 SequenceID sequence_id,
73 const base::Closure& task) override; 74 base::Closure task) override;
74 75
75 void AssertIsRunningOnPrimarySequence() const override; 76 void AssertIsRunningOnPrimarySequence() const override;
76 void AssertIsRunningOnCommitSequence() const override; 77 void AssertIsRunningOnCommitSequence() const override;
77 78
78 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner( 79 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner(
79 SequenceID sequence_id) override; 80 SequenceID sequence_id) override;
80 81
81 protected: 82 protected:
82 ~DOMStorageWorkerPoolTaskRunner() override; 83 ~DOMStorageWorkerPoolTaskRunner() override;
83 84
(...skipping 11 matching lines...) Expand all
95 // all tasks are scheduled on |task_runner| with zero delay. 96 // all tasks are scheduled on |task_runner| with zero delay.
96 class CONTENT_EXPORT MockDOMStorageTaskRunner : 97 class CONTENT_EXPORT MockDOMStorageTaskRunner :
97 public DOMStorageTaskRunner { 98 public DOMStorageTaskRunner {
98 public: 99 public:
99 explicit MockDOMStorageTaskRunner( 100 explicit MockDOMStorageTaskRunner(
100 scoped_refptr<base::SequencedTaskRunner> task_runner); 101 scoped_refptr<base::SequencedTaskRunner> task_runner);
101 102
102 bool RunsTasksOnCurrentThread() const override; 103 bool RunsTasksOnCurrentThread() const override;
103 104
104 bool PostDelayedTask(const tracked_objects::Location& from_here, 105 bool PostDelayedTask(const tracked_objects::Location& from_here,
105 const base::Closure& task, 106 base::Closure task,
106 base::TimeDelta delay) override; 107 base::TimeDelta delay) override;
107 108
108 bool PostShutdownBlockingTask(const tracked_objects::Location& from_here, 109 bool PostShutdownBlockingTask(const tracked_objects::Location& from_here,
109 SequenceID sequence_id, 110 SequenceID sequence_id,
110 const base::Closure& task) override; 111 base::Closure task) override;
111 112
112 void AssertIsRunningOnPrimarySequence() const override; 113 void AssertIsRunningOnPrimarySequence() const override;
113 void AssertIsRunningOnCommitSequence() const override; 114 void AssertIsRunningOnCommitSequence() const override;
114 115
115 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner( 116 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner(
116 SequenceID sequence_id) override; 117 SequenceID sequence_id) override;
117 118
118 protected: 119 protected:
119 ~MockDOMStorageTaskRunner() override; 120 ~MockDOMStorageTaskRunner() override;
120 121
121 private: 122 private:
122 const scoped_refptr<base::SequencedTaskRunner> task_runner_; 123 const scoped_refptr<base::SequencedTaskRunner> task_runner_;
123 124
124 DISALLOW_COPY_AND_ASSIGN(MockDOMStorageTaskRunner); 125 DISALLOW_COPY_AND_ASSIGN(MockDOMStorageTaskRunner);
125 }; 126 };
126 127
127 } // namespace content 128 } // namespace content
128 129
129 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_H_ 130 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_H_
OLDNEW
« no previous file with comments | « content/browser/compositor/reflector_impl_unittest.cc ('k') | content/browser/dom_storage/dom_storage_task_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698