OLD | NEW |
---|---|
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 BASE_FILES_IMPORTANT_FILE_WRITER_H_ | 5 #ifndef BASE_FILES_IMPORTANT_FILE_WRITER_H_ |
6 #define BASE_FILES_IMPORTANT_FILE_WRITER_H_ | 6 #define BASE_FILES_IMPORTANT_FILE_WRITER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 // the most recent |serializer| will be used. This operation does not block. | 90 // the most recent |serializer| will be used. This operation does not block. |
91 // |serializer| should remain valid through the lifetime of | 91 // |serializer| should remain valid through the lifetime of |
92 // ImportantFileWriter. | 92 // ImportantFileWriter. |
93 void ScheduleWrite(DataSerializer* serializer); | 93 void ScheduleWrite(DataSerializer* serializer); |
94 | 94 |
95 // Serialize data pending to be saved and execute write on backend thread. | 95 // Serialize data pending to be saved and execute write on backend thread. |
96 void DoScheduledWrite(); | 96 void DoScheduledWrite(); |
97 | 97 |
98 // Registers |on_next_successful_write| to be called once, on the next | 98 // Registers |on_next_successful_write| to be called once, on the next |
99 // successful write event. Only one callback can be set at once. | 99 // successful write event. Only one callback can be set at once. |
100 void RegisterOnNextSuccessfulWriteCallback( | 100 void RegisterOnNextSuccessfulWriteCallback( |
gab
2016/08/03 18:19:34
Similar to comment below, suggest updating this to
proberge
2016/08/04 00:13:45
Done.
| |
101 const Closure& on_next_successful_write); | 101 const Closure& on_next_successful_write); |
102 | 102 |
103 // Registers |on_next_successful_write| to be called once, on the next | |
104 // successful write event. Multiple callbacks can be set at once. | |
gab
2016/08/03 18:19:34
Your implementation only allows a single callback,
proberge
2016/08/04 00:13:45
Done.
| |
105 void RegisterOnNextSuccessfulWriteBlockingCallback( | |
gab
2016/08/03 18:19:34
The ImportantFileWriter doesn't have a notion of t
proberge
2016/08/04 00:13:45
Done.
| |
106 const Closure& on_next_successful_write); | |
107 | |
103 TimeDelta commit_interval() const { | 108 TimeDelta commit_interval() const { |
104 return commit_interval_; | 109 return commit_interval_; |
105 } | 110 } |
106 | 111 |
107 private: | 112 private: |
108 // Helper method for WriteNow(). | 113 // Helper method for WriteNow(). |
109 bool PostWriteTask(const Callback<bool()>& task); | 114 bool PostWriteTask(const Callback<bool()>& task); |
110 | 115 |
111 // If |result| is true and |on_next_successful_write_| is set, invokes | 116 // If |result| is true and |on_next_successful_write_| is set, invokes |
112 // |on_successful_write_| and then resets it; no-ops otherwise. | 117 // |on_successful_write_| and then resets it; no-ops otherwise. |
113 void ForwardSuccessfulWrite(bool result); | 118 void ForwardSuccessfulWrite(bool result); |
114 | 119 |
115 // Invoked once and then reset on the next successful write event. | 120 // Invoked once and then reset on the next successful write event. |
116 Closure on_next_successful_write_; | 121 Closure on_next_successful_write_; |
gab
2016/08/03 18:19:34
on_next_successful_write_reply_
proberge
2016/08/04 00:13:45
Done.
| |
117 | 122 |
123 // Invoked on the blocking pool and then reset on the next successful write | |
124 // event. | |
125 Closure blocking_on_next_successful_write_; | |
gab
2016/08/03 18:19:34
// Invoked synchronously on the next successful wr
proberge
2016/08/04 00:13:45
Done.
| |
126 | |
118 // Path being written to. | 127 // Path being written to. |
119 const FilePath path_; | 128 const FilePath path_; |
120 | 129 |
121 // TaskRunner for the thread on which file I/O can be done. | 130 // TaskRunner for the thread on which file I/O can be done. |
122 const scoped_refptr<SequencedTaskRunner> task_runner_; | 131 const scoped_refptr<SequencedTaskRunner> task_runner_; |
123 | 132 |
124 // Timer used to schedule commit after ScheduleWrite. | 133 // Timer used to schedule commit after ScheduleWrite. |
125 OneShotTimer timer_; | 134 OneShotTimer timer_; |
126 | 135 |
127 // Serializer which will provide the data to be saved. | 136 // Serializer which will provide the data to be saved. |
128 DataSerializer* serializer_; | 137 DataSerializer* serializer_; |
129 | 138 |
130 // Time delta after which scheduled data will be written to disk. | 139 // Time delta after which scheduled data will be written to disk. |
131 const TimeDelta commit_interval_; | 140 const TimeDelta commit_interval_; |
132 | 141 |
133 WeakPtrFactory<ImportantFileWriter> weak_factory_; | 142 WeakPtrFactory<ImportantFileWriter> weak_factory_; |
134 | 143 |
135 DISALLOW_COPY_AND_ASSIGN(ImportantFileWriter); | 144 DISALLOW_COPY_AND_ASSIGN(ImportantFileWriter); |
136 }; | 145 }; |
137 | 146 |
138 } // namespace base | 147 } // namespace base |
139 | 148 |
140 #endif // BASE_FILES_IMPORTANT_FILE_WRITER_H_ | 149 #endif // BASE_FILES_IMPORTANT_FILE_WRITER_H_ |
OLD | NEW |