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

Side by Side Diff: webkit/dom_storage/dom_storage_task_runner.h

Issue 9718029: DomStorage commit task sequencing. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 WEBKIT_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_ 5 #ifndef WEBKIT_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_
6 #define WEBKIT_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_ 6 #define WEBKIT_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_
7 #pragma once 7 #pragma once
8 8
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/sequenced_task_runner.h" 10 #include "base/sequenced_task_runner.h"
11 #include "base/threading/sequenced_worker_pool.h" 11 #include "base/threading/sequenced_worker_pool.h"
12 #include "base/time.h" 12 #include "base/time.h"
13 13
14 namespace base { 14 namespace base {
15 class MessageLoopProxy; 15 class MessageLoopProxy;
16 } 16 }
17 17
18 namespace dom_storage { 18 namespace dom_storage {
19 19
20 // Tasks must run serially with respect to one another, but may 20 // Interface for posting dom storage related tasks. There
21 // execute on different OS threads. The base class is implemented 21 // are two logical task sequences, the primary sequence is
22 // in terms of a MessageLoopProxy. 22 // the read where most tasks are performed, the commit sequence
23 class DomStorageTaskRunner : public base::SequencedTaskRunner { 23 // is used internally for committing data to disk. The base TaskRunner
24 // interfaces maps to the primary sequence and allow callers to post
25 // non shutdown blocking tasks on it. An additional method allows callers
26 // to post shutdown blocking tasks to either sequence.
27 class DomStorageTaskRunner : public base::TaskRunner {
24 public: 28 public:
25 explicit DomStorageTaskRunner(base::MessageLoopProxy* message_loop); 29 enum SequenceID {
30 PRIMARY_SEQUENCE,
31 COMMIT_SEQUENCE
32 };
33
26 virtual ~DomStorageTaskRunner(); 34 virtual ~DomStorageTaskRunner();
27 35
28 // The PostTask() method, defined by TaskRunner, schedules a task 36 // The PostTask() method, defined by TaskRunner, schedules
29 // to run immediately. 37 // a non shutdown blocking READ_SEQUENCE task to run immediately.
benm (inactive) 2012/03/20 13:39:16 s/READ_/PRIMARY_/ and below
30 38
31 // Schedules a task to be run after a delay. 39 // Schedules a non shutdown blocking READ_SEQUENCE task to be run
40 // after a delay.
32 virtual bool PostDelayedTask( 41 virtual bool PostDelayedTask(
33 const tracked_objects::Location& from_here, 42 const tracked_objects::Location& from_here,
34 const base::Closure& task, 43 const base::Closure& task,
35 base::TimeDelta delay) OVERRIDE; 44 base::TimeDelta delay) OVERRIDE;
36 45
37 // DEPRECATED: Only here because base::TaskRunner requires it, implemented 46 // DEPRECATED: Only here because base::TaskRunner requires it, implemented
38 // by calling the virtual PostDelayedTask(..., TimeDelta) variant. 47 // by calling the virtual PostDelayedTask(..., TimeDelta) variant.
39 virtual bool PostDelayedTask( 48 virtual bool PostDelayedTask(
40 const tracked_objects::Location& from_here, 49 const tracked_objects::Location& from_here,
41 const base::Closure& task, 50 const base::Closure& task,
42 int64 delay_ms) OVERRIDE; 51 int64 delay_ms) OVERRIDE;
43 52
44 // Only here because base::TaskRunner requires it, the return 53 // Only here because base::TaskRunner requires it, the return
45 // value is hard coded to true. 54 // value is hard coded to true.
46 virtual bool RunsTasksOnCurrentThread() const OVERRIDE; 55 virtual bool RunsTasksOnCurrentThread() const OVERRIDE;
47 56
48 // SequencedTaskRunner overrides, these are implemented in 57 virtual bool PostShutdownBlockingTask(
49 // terms of PostDelayedTask and the latter is similarly deprecated.
50 virtual bool PostNonNestableDelayedTask(
51 const tracked_objects::Location& from_here, 58 const tracked_objects::Location& from_here,
52 const base::Closure& task, 59 SequenceID sequence_id,
53 base::TimeDelta delay) OVERRIDE; 60 const base::Closure& task) = 0;
54 virtual bool PostNonNestableDelayedTask(
55 const tracked_objects::Location& from_here,
56 const base::Closure& task,
57 int64 delay_ms) OVERRIDE;
58 61
59 protected: 62 protected:
63 explicit DomStorageTaskRunner(base::MessageLoopProxy* message_loop);
64
60 const scoped_refptr<base::MessageLoopProxy> message_loop_; 65 const scoped_refptr<base::MessageLoopProxy> message_loop_;
61 }; 66 };
62 67
63 // A derived class that utlizes the SequenceWorkerPool under a 68 // A derived class that utlizes the SequenceWorkerPool under a
benm (inactive) 2012/03/20 13:39:16 remove "a"
64 // dom_storage specific SequenceToken. The MessageLoopProxy 69 // dom_storage specific SequenceTokens. The MessageLoopProxy
65 // is used to delay scheduling on the worker pool. 70 // is used to delay scheduling on the worker pool.
66 class DomStorageWorkerPoolTaskRunner : public DomStorageTaskRunner { 71 class DomStorageWorkerPoolTaskRunner : public DomStorageTaskRunner {
67 public: 72 public:
68 DomStorageWorkerPoolTaskRunner( 73 DomStorageWorkerPoolTaskRunner(
69 base::SequencedWorkerPool* sequenced_worker_pool, 74 base::SequencedWorkerPool* sequenced_worker_pool,
70 base::SequencedWorkerPool::SequenceToken sequence_token, 75 base::SequencedWorkerPool::SequenceToken primary_sequence_token,
76 base::SequencedWorkerPool::SequenceToken commit_sequence_token,
71 base::MessageLoopProxy* delayed_task_loop); 77 base::MessageLoopProxy* delayed_task_loop);
72 virtual ~DomStorageWorkerPoolTaskRunner(); 78 virtual ~DomStorageWorkerPoolTaskRunner();
73 79
74 // Schedules a sequenced worker task to be run after a delay.
75 virtual bool PostDelayedTask( 80 virtual bool PostDelayedTask(
76 const tracked_objects::Location& from_here, 81 const tracked_objects::Location& from_here,
77 const base::Closure& task, 82 const base::Closure& task,
78 base::TimeDelta delay) OVERRIDE; 83 base::TimeDelta delay) OVERRIDE;
79 84
80 base::SequencedWorkerPool::SequenceToken sequence_token() const; 85 virtual bool PostShutdownBlockingTask(
86 const tracked_objects::Location& from_here,
87 SequenceID sequence_id,
88 const base::Closure& task) OVERRIDE;
81 89
82 private: 90 private:
83 const scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_; 91 const scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_;
84 base::SequencedWorkerPool::SequenceToken sequence_token_; 92 base::SequencedWorkerPool::SequenceToken primary_sequence_token_;
93 base::SequencedWorkerPool::SequenceToken commit_sequence_token_;
85 }; 94 };
86 95
87 // A derived class used in unit tests that causes us to ignore the 96 // A derived class used in unit tests that causes us to ignore the
88 // delay in PostDelayedTask so we don't need to block in unit tests 97 // delay in PostDelayedTask so we don't need to block in unit tests
89 // for the timeout to expire. 98 // for the timeout to expire.
90 class MockDomStorageTaskRunner : public DomStorageTaskRunner { 99 class MockDomStorageTaskRunner : public DomStorageTaskRunner {
91 public: 100 public:
92 explicit MockDomStorageTaskRunner(base::MessageLoopProxy* message_loop); 101 explicit MockDomStorageTaskRunner(base::MessageLoopProxy* message_loop);
93 virtual ~MockDomStorageTaskRunner() {} 102 virtual ~MockDomStorageTaskRunner() {}
94 103
95 virtual bool PostDelayedTask( 104 virtual bool PostDelayedTask(
96 const tracked_objects::Location& from_here, 105 const tracked_objects::Location& from_here,
97 const base::Closure& task, 106 const base::Closure& task,
98 base::TimeDelta delay) OVERRIDE; 107 base::TimeDelta delay) OVERRIDE;
108
109 virtual bool PostShutdownBlockingTask(
110 const tracked_objects::Location& from_here,
111 SequenceID sequence_id,
112 const base::Closure& task) OVERRIDE;
99 }; 113 };
100 114
101 } // namespace dom_storage 115 } // namespace dom_storage
102 116
103 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_ 117 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698