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

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 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 allows 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 // * Initialization, shutdown, and administrative tasks are performed as
28 // shutdown-blocking primary sequence tasks.
29 // * Methods that return values to the java-scriptable interface are
30 // performed as non-shutdown-blocking primary sequence tasks.
31 // * Interal tasks related to committing changes to disk are performed
32 // as shutdown-blocking commit sequence tasks.
33 class DomStorageTaskRunner : public base::TaskRunner {
24 public: 34 public:
25 explicit DomStorageTaskRunner(base::MessageLoopProxy* message_loop); 35 enum SequenceID {
26 virtual ~DomStorageTaskRunner(); 36 PRIMARY_SEQUENCE,
37 COMMIT_SEQUENCE
38 };
27 39
28 // The PostTask() method, defined by TaskRunner, schedules a task 40 // The PostTask() and PostDelayedTask() methods defined by TaskRunner
29 // to run immediately. 41 // post non-shutdown-blocking tasks on the primary sequence.
30
31 // Schedules a task to be run after a delay.
32 virtual bool PostDelayedTask( 42 virtual bool PostDelayedTask(
33 const tracked_objects::Location& from_here, 43 const tracked_objects::Location& from_here,
34 const base::Closure& task, 44 const base::Closure& task,
35 base::TimeDelta delay) OVERRIDE; 45 base::TimeDelta delay) = 0;
46
47 // Posts a shutdown blocking task to |sequence_id|.
48 virtual bool PostShutdownBlockingTask(
49 const tracked_objects::Location& from_here,
50 SequenceID sequence_id,
51 const base::Closure& task) = 0;
52
53 // Only here because base::TaskRunner requires it, the return
54 // value is hard coded to true, do not rely on this method.
55 virtual bool RunsTasksOnCurrentThread() const OVERRIDE;
36 56
37 // DEPRECATED: Only here because base::TaskRunner requires it, implemented 57 // DEPRECATED: Only here because base::TaskRunner requires it, implemented
38 // by calling the virtual PostDelayedTask(..., TimeDelta) variant. 58 // by calling the virtual PostDelayedTask(..., TimeDelta) variant.
39 virtual bool PostDelayedTask( 59 virtual bool PostDelayedTask(
40 const tracked_objects::Location& from_here, 60 const tracked_objects::Location& from_here,
41 const base::Closure& task, 61 const base::Closure& task,
42 int64 delay_ms) OVERRIDE; 62 int64 delay_ms) OVERRIDE;
43
44 // Only here because base::TaskRunner requires it, the return
45 // value is hard coded to true.
46 virtual bool RunsTasksOnCurrentThread() const OVERRIDE;
47
48 // SequencedTaskRunner overrides, these are implemented in
49 // terms of PostDelayedTask and the latter is similarly deprecated.
50 virtual bool PostNonNestableDelayedTask(
51 const tracked_objects::Location& from_here,
52 const base::Closure& task,
53 base::TimeDelta delay) OVERRIDE;
54 virtual bool PostNonNestableDelayedTask(
55 const tracked_objects::Location& from_here,
56 const base::Closure& task,
57 int64 delay_ms) OVERRIDE;
58
59 protected:
60 const scoped_refptr<base::MessageLoopProxy> message_loop_;
61 }; 63 };
62 64
63 // A derived class that utlizes the SequenceWorkerPool under a 65 // A derived class that utlizes a SequenceWorkerPool under
64 // dom_storage specific SequenceToken. The MessageLoopProxy 66 // dom_storage specific SequenceTokens. The |delayed_task_loop|
65 // is used to delay scheduling on the worker pool. 67 // is used to delay scheduling on the worker pool.
66 class DomStorageWorkerPoolTaskRunner : public DomStorageTaskRunner { 68 class DomStorageWorkerPoolTaskRunner : public DomStorageTaskRunner {
67 public: 69 public:
68 DomStorageWorkerPoolTaskRunner( 70 DomStorageWorkerPoolTaskRunner(
69 base::SequencedWorkerPool* sequenced_worker_pool, 71 base::SequencedWorkerPool* sequenced_worker_pool,
70 base::SequencedWorkerPool::SequenceToken sequence_token, 72 base::SequencedWorkerPool::SequenceToken primary_sequence_token,
73 base::SequencedWorkerPool::SequenceToken commit_sequence_token,
71 base::MessageLoopProxy* delayed_task_loop); 74 base::MessageLoopProxy* delayed_task_loop);
72 virtual ~DomStorageWorkerPoolTaskRunner();
73 75
74 // Schedules a sequenced worker task to be run after a delay.
75 virtual bool PostDelayedTask( 76 virtual bool PostDelayedTask(
76 const tracked_objects::Location& from_here, 77 const tracked_objects::Location& from_here,
77 const base::Closure& task, 78 const base::Closure& task,
78 base::TimeDelta delay) OVERRIDE; 79 base::TimeDelta delay) OVERRIDE;
79 80
80 base::SequencedWorkerPool::SequenceToken sequence_token() const; 81 virtual bool PostShutdownBlockingTask(
82 const tracked_objects::Location& from_here,
83 SequenceID sequence_id,
84 const base::Closure& task) OVERRIDE;
81 85
82 private: 86 private:
87 virtual ~DomStorageWorkerPoolTaskRunner();
88 const scoped_refptr<base::MessageLoopProxy> message_loop_;
83 const scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_; 89 const scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_;
84 base::SequencedWorkerPool::SequenceToken sequence_token_; 90 base::SequencedWorkerPool::SequenceToken primary_sequence_token_;
91 base::SequencedWorkerPool::SequenceToken commit_sequence_token_;
85 }; 92 };
86 93
87 // A derived class used in unit tests that causes us to ignore the 94 // A derived class used in unit tests that ignores all delays so
88 // delay in PostDelayedTask so we don't need to block in unit tests 95 // we don't block in unit tests waiting for timeouts to expire.
89 // for the timeout to expire. 96 // There is no distinction between [non]-shutdown-blocking or
97 // the primary sequence vs the commit sequence in the mock,
98 // all tasks are scheduled on |message_loop| with zero delay.
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() {}
94 102
95 virtual bool PostDelayedTask( 103 virtual bool PostDelayedTask(
96 const tracked_objects::Location& from_here, 104 const tracked_objects::Location& from_here,
97 const base::Closure& task, 105 const base::Closure& task,
98 base::TimeDelta delay) OVERRIDE; 106 base::TimeDelta delay) OVERRIDE;
107
108 virtual bool PostShutdownBlockingTask(
109 const tracked_objects::Location& from_here,
110 SequenceID sequence_id,
111 const base::Closure& task) OVERRIDE;
112
113 private:
114 virtual ~MockDomStorageTaskRunner();
115 const scoped_refptr<base::MessageLoopProxy> message_loop_;
99 }; 116 };
100 117
101 } // namespace dom_storage 118 } // namespace dom_storage
102 119
103 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_ 120 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_
OLDNEW
« no previous file with comments | « webkit/dom_storage/dom_storage_namespace.cc ('k') | webkit/dom_storage/dom_storage_task_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698