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

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

Issue 2576243003: Add an experiment to redirect DOMStorageTaskRunner to TaskScheduler. (Closed)
Patch Set: fix compile Created 4 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
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/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/sequence_checker.h" 9 #include "base/sequence_checker.h"
10 #include "base/sequenced_task_runner.h" 10 #include "base/sequenced_task_runner.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/threading/sequenced_worker_pool.h"
13 #include "base/time/time.h" 11 #include "base/time/time.h"
14 #include "content/common/content_export.h" 12 #include "content/common/content_export.h"
15 13
16 namespace base {
17 class SingleThreadTaskRunner;
18 }
19
20 namespace content { 14 namespace content {
21 15
22 // DOMStorage uses two task sequences (primary vs commit) to avoid 16 // DOMStorage uses two task sequences (primary vs commit) to avoid
23 // primary access from queuing up behind commits to disk. 17 // primary access from queuing up behind commits to disk.
24 // * Initialization, shutdown, and administrative tasks are performed as 18 // * Initialization, shutdown, and administrative tasks are performed as
25 // shutdown-blocking primary sequence tasks. 19 // shutdown-blocking primary sequence tasks.
26 // * Tasks directly related to the javascript'able interface are performed 20 // * Tasks directly related to the javascript'able interface are performed
27 // as shutdown-blocking primary sequence tasks. 21 // as shutdown-blocking primary sequence tasks.
28 // TODO(michaeln): Skip tasks for reading during shutdown. 22 // TODO(michaeln): Skip tasks for reading during shutdown.
29 // * Internal tasks related to committing changes to disk are performed as 23 // * Internal tasks related to committing changes to disk are performed as
(...skipping 21 matching lines...) Expand all
51 virtual void AssertIsRunningOnPrimarySequence() const = 0; 45 virtual void AssertIsRunningOnPrimarySequence() const = 0;
52 virtual void AssertIsRunningOnCommitSequence() const = 0; 46 virtual void AssertIsRunningOnCommitSequence() const = 0;
53 47
54 virtual scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner( 48 virtual scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner(
55 SequenceID sequence_id) = 0; 49 SequenceID sequence_id) = 0;
56 50
57 protected: 51 protected:
58 ~DOMStorageTaskRunner() override {} 52 ~DOMStorageTaskRunner() override {}
59 }; 53 };
60 54
61 // A derived class used in chromium that utilizes a SequenceWorkerPool 55 // A DOMStorageTaskRunner which manages a primary and a commit sequence.
62 // under dom_storage specific SequenceTokens. The |delayed_task_loop|
63 // is used to delay scheduling on the worker pool.
64 class CONTENT_EXPORT DOMStorageWorkerPoolTaskRunner : 56 class CONTENT_EXPORT DOMStorageWorkerPoolTaskRunner :
65 public DOMStorageTaskRunner { 57 public DOMStorageTaskRunner {
66 public: 58 public:
59 // |primary_sequence| and |commit_sequence| should have
60 // TaskShutdownBehaviour::BLOCK_SHUTDOWN semantics.
67 DOMStorageWorkerPoolTaskRunner( 61 DOMStorageWorkerPoolTaskRunner(
68 base::SequencedWorkerPool* sequenced_worker_pool, 62 scoped_refptr<base::SequencedTaskRunner> primary_sequence,
69 base::SequencedWorkerPool::SequenceToken primary_sequence_token, 63 scoped_refptr<base::SequencedTaskRunner> commit_sequence);
70 base::SequencedWorkerPool::SequenceToken commit_sequence_token,
71 base::SingleThreadTaskRunner* delayed_task_task_runner);
72 64
73 bool RunsTasksOnCurrentThread() const override; 65 bool RunsTasksOnCurrentThread() const override;
74 66
75 bool PostDelayedTask(const tracked_objects::Location& from_here, 67 bool PostDelayedTask(const tracked_objects::Location& from_here,
76 const base::Closure& task, 68 const base::Closure& task,
77 base::TimeDelta delay) override; 69 base::TimeDelta delay) override;
78 70
79 bool PostShutdownBlockingTask(const tracked_objects::Location& from_here, 71 bool PostShutdownBlockingTask(const tracked_objects::Location& from_here,
80 SequenceID sequence_id, 72 SequenceID sequence_id,
81 const base::Closure& task) override; 73 const base::Closure& task) override;
82 74
83 void AssertIsRunningOnPrimarySequence() const override; 75 void AssertIsRunningOnPrimarySequence() const override;
84 void AssertIsRunningOnCommitSequence() const override; 76 void AssertIsRunningOnCommitSequence() const override;
85 77
86 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner( 78 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner(
87 SequenceID sequence_id) override; 79 SequenceID sequence_id) override;
88 80
89 protected: 81 protected:
90 ~DOMStorageWorkerPoolTaskRunner() override; 82 ~DOMStorageWorkerPoolTaskRunner() override;
91 83
92 private: 84 private:
85 scoped_refptr<base::SequencedTaskRunner> primary_sequence_;
86 scoped_refptr<base::SequencedTaskRunner> commit_sequence_;
93 87
94 base::SequencedWorkerPool::SequenceToken IDtoToken(SequenceID id) const; 88 DISALLOW_COPY_AND_ASSIGN(DOMStorageWorkerPoolTaskRunner);
95
96 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
97 const scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_;
98 base::SequencedWorkerPool::SequenceToken primary_sequence_token_;
99 base::SequenceChecker primary_sequence_checker_;
100 base::SequencedWorkerPool::SequenceToken commit_sequence_token_;
101 base::SequenceChecker commit_sequence_checker_;
102 }; 89 };
103 90
104 // A derived class used in unit tests that ignores all delays so 91 // A derived class used in unit tests that ignores all delays so
105 // we don't block in unit tests waiting for timeouts to expire. 92 // we don't block in unit tests waiting for timeouts to expire.
106 // There is no distinction between [non]-shutdown-blocking or 93 // There is no distinction between [non]-shutdown-blocking or
107 // the primary sequence vs the commit sequence in the mock, 94 // the primary sequence vs the commit sequence in the mock,
108 // all tasks are scheduled on |message_loop| with zero delay. 95 // all tasks are scheduled on |task_runner| with zero delay.
109 class CONTENT_EXPORT MockDOMStorageTaskRunner : 96 class CONTENT_EXPORT MockDOMStorageTaskRunner :
110 public DOMStorageTaskRunner { 97 public DOMStorageTaskRunner {
111 public: 98 public:
112 explicit MockDOMStorageTaskRunner(base::SingleThreadTaskRunner* task_runner); 99 explicit MockDOMStorageTaskRunner(
100 scoped_refptr<base::SequencedTaskRunner> task_runner);
113 101
114 bool RunsTasksOnCurrentThread() const override; 102 bool RunsTasksOnCurrentThread() const override;
115 103
116 bool PostDelayedTask(const tracked_objects::Location& from_here, 104 bool PostDelayedTask(const tracked_objects::Location& from_here,
117 const base::Closure& task, 105 const base::Closure& task,
118 base::TimeDelta delay) override; 106 base::TimeDelta delay) override;
119 107
120 bool PostShutdownBlockingTask(const tracked_objects::Location& from_here, 108 bool PostShutdownBlockingTask(const tracked_objects::Location& from_here,
121 SequenceID sequence_id, 109 SequenceID sequence_id,
122 const base::Closure& task) override; 110 const base::Closure& task) override;
123 111
124 void AssertIsRunningOnPrimarySequence() const override; 112 void AssertIsRunningOnPrimarySequence() const override;
125 void AssertIsRunningOnCommitSequence() const override; 113 void AssertIsRunningOnCommitSequence() const override;
126 114
127 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner( 115 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner(
128 SequenceID sequence_id) override; 116 SequenceID sequence_id) override;
129 117
130 protected: 118 protected:
131 ~MockDOMStorageTaskRunner() override; 119 ~MockDOMStorageTaskRunner() override;
132 120
133 private: 121 private:
134 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 122 const scoped_refptr<base::SequencedTaskRunner> task_runner_;
123
124 DISALLOW_COPY_AND_ASSIGN(MockDOMStorageTaskRunner);
135 }; 125 };
136 126
137 } // namespace content 127 } // namespace content
138 128
139 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_H_ 129 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_H_
OLDNEW
« no previous file with comments | « content/browser/dom_storage/dom_storage_context_wrapper.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