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

Side by Side Diff: base/files/important_file_writer.h

Issue 2299523003: Add synchronous callback support to important_file_writer.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Try move logic from ImportantFileWriter to JsonPrefStore Created 4 years, 3 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
« no previous file with comments | « no previous file | base/files/important_file_writer.cc » ('j') | base/files/important_file_writer.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 // to disk after the commit interval. If another ScheduleWrite is issued 87 // to disk after the commit interval. If another ScheduleWrite is issued
88 // before that, only one serialization and write to disk will happen, and 88 // before that, only one serialization and write to disk will happen, and
89 // the most recent |serializer| will be used. This operation does not block. 89 // the most recent |serializer| will be used. This operation does not block.
90 // |serializer| should remain valid through the lifetime of 90 // |serializer| should remain valid through the lifetime of
91 // ImportantFileWriter. 91 // ImportantFileWriter.
92 void ScheduleWrite(DataSerializer* serializer); 92 void ScheduleWrite(DataSerializer* serializer);
93 93
94 // Serialize data pending to be saved and execute write on backend thread. 94 // Serialize data pending to be saved and execute write on backend thread.
95 void DoScheduledWrite(); 95 void DoScheduledWrite();
96 96
97 // Registers |on_next_successful_write| to be called once, on the next 97 // Registers |on_next_write_callback| to be synchronously invoked from
98 // successful write event. Only one callback can be set at once. 98 // WriteFileAtomically() on its next write (i.e. from |task_runner_|), with
99 void RegisterOnNextSuccessfulWriteCallback( 99 // |success| indicating whether it succeeded or not.
100 const Closure& on_next_successful_write); 100 // |on_next_write_callback| must be thread safe, as it will be called on
101 // |task_runner_| and may be called during Chrome shutdown.
102 // If called more than once before a write is done, the latest callback
gab 2016/09/19 18:01:30 s/before a write is done/before a write is schedul
proberge 2016/09/19 21:24:25 Done.
103 // clobbers the others.
104 void RegisterOnNextWriteCallback(
105 const Callback<void(bool success)>& on_next_write_callback);
101 106
102 TimeDelta commit_interval() const { 107 TimeDelta commit_interval() const {
103 return commit_interval_; 108 return commit_interval_;
104 } 109 }
105 110
106 private: 111 private:
107 // Helper method for WriteNow(). 112 // Invoked synchronously on the next write event.
108 bool PostWriteTask(const Callback<bool()>& task); 113 Callback<void(bool success)> on_next_write_callback_;
109
110 // If |result| is true and |on_next_successful_write_| is set, invokes
111 // |on_successful_write_| and then resets it; no-ops otherwise.
112 void ForwardSuccessfulWrite(bool result);
113
114 // Invoked once and then reset on the next successful write event.
115 Closure on_next_successful_write_;
116 114
117 // Path being written to. 115 // Path being written to.
118 const FilePath path_; 116 const FilePath path_;
119 117
120 // TaskRunner for the thread on which file I/O can be done. 118 // TaskRunner for the thread on which file I/O can be done.
121 const scoped_refptr<SequencedTaskRunner> task_runner_; 119 const scoped_refptr<SequencedTaskRunner> task_runner_;
122 120
123 // Timer used to schedule commit after ScheduleWrite. 121 // Timer used to schedule commit after ScheduleWrite.
124 OneShotTimer timer_; 122 OneShotTimer timer_;
125 123
126 // Serializer which will provide the data to be saved. 124 // Serializer which will provide the data to be saved.
127 DataSerializer* serializer_; 125 DataSerializer* serializer_;
128 126
129 // Time delta after which scheduled data will be written to disk. 127 // Time delta after which scheduled data will be written to disk.
130 const TimeDelta commit_interval_; 128 const TimeDelta commit_interval_;
131 129
132 WeakPtrFactory<ImportantFileWriter> weak_factory_; 130 WeakPtrFactory<ImportantFileWriter> weak_factory_;
133 131
134 DISALLOW_COPY_AND_ASSIGN(ImportantFileWriter); 132 DISALLOW_COPY_AND_ASSIGN(ImportantFileWriter);
135 }; 133 };
136 134
137 } // namespace base 135 } // namespace base
138 136
139 #endif // BASE_FILES_IMPORTANT_FILE_WRITER_H_ 137 #endif // BASE_FILES_IMPORTANT_FILE_WRITER_H_
OLDNEW
« no previous file with comments | « no previous file | base/files/important_file_writer.cc » ('j') | base/files/important_file_writer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698