| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_write_callback| to be synchronously invoked from | 97 // Registers |before_next_write_callback| and |after_next_write_callback| to |
| 98 // WriteFileAtomically() on its next write (i.e. from |task_runner_|), with | 98 // be synchronously invoked from WriteFileAtomically() before its next write |
| 99 // |success| indicating whether it succeeded or not. | 99 // and after its next write, respectively. The boolean passed to |
| 100 // |on_next_write_callback| must be thread safe, as it will be called on | 100 // |after_next_write_callback| indicates whether the write was successful. |
| 101 // |task_runner_| and may be called during Chrome shutdown. | 101 // Both callbacks must be thread safe as they will be called on |task_runner_| |
| 102 // and may be called during Chrome shutdown. |
| 102 // If called more than once before a write is scheduled on |task_runner|, the | 103 // If called more than once before a write is scheduled on |task_runner|, the |
| 103 // latest callback clobbers the others. | 104 // latest callbacks clobber the others. |
| 104 void RegisterOnNextWriteCallback( | 105 void RegisterOnNextWriteCallbacks( |
| 105 const Callback<void(bool success)>& on_next_write_callback); | 106 const Closure& before_next_write_callback, |
| 107 const Callback<void(bool success)>& after_next_write_callback); |
| 106 | 108 |
| 107 TimeDelta commit_interval() const { | 109 TimeDelta commit_interval() const { |
| 108 return commit_interval_; | 110 return commit_interval_; |
| 109 } | 111 } |
| 110 | 112 |
| 111 private: | 113 private: |
| 112 // Invoked synchronously on the next write event. | 114 // Invoked synchronously on the next write event. |
| 113 Callback<void(bool success)> on_next_write_callback_; | 115 Closure before_next_write_callback_; |
| 116 Callback<void(bool success)> after_next_write_callback_; |
| 114 | 117 |
| 115 // Path being written to. | 118 // Path being written to. |
| 116 const FilePath path_; | 119 const FilePath path_; |
| 117 | 120 |
| 118 // TaskRunner for the thread on which file I/O can be done. | 121 // TaskRunner for the thread on which file I/O can be done. |
| 119 const scoped_refptr<SequencedTaskRunner> task_runner_; | 122 const scoped_refptr<SequencedTaskRunner> task_runner_; |
| 120 | 123 |
| 121 // Timer used to schedule commit after ScheduleWrite. | 124 // Timer used to schedule commit after ScheduleWrite. |
| 122 OneShotTimer timer_; | 125 OneShotTimer timer_; |
| 123 | 126 |
| 124 // Serializer which will provide the data to be saved. | 127 // Serializer which will provide the data to be saved. |
| 125 DataSerializer* serializer_; | 128 DataSerializer* serializer_; |
| 126 | 129 |
| 127 // Time delta after which scheduled data will be written to disk. | 130 // Time delta after which scheduled data will be written to disk. |
| 128 const TimeDelta commit_interval_; | 131 const TimeDelta commit_interval_; |
| 129 | 132 |
| 130 WeakPtrFactory<ImportantFileWriter> weak_factory_; | 133 WeakPtrFactory<ImportantFileWriter> weak_factory_; |
| 131 | 134 |
| 132 DISALLOW_COPY_AND_ASSIGN(ImportantFileWriter); | 135 DISALLOW_COPY_AND_ASSIGN(ImportantFileWriter); |
| 133 }; | 136 }; |
| 134 | 137 |
| 135 } // namespace base | 138 } // namespace base |
| 136 | 139 |
| 137 #endif // BASE_FILES_IMPORTANT_FILE_WRITER_H_ | 140 #endif // BASE_FILES_IMPORTANT_FILE_WRITER_H_ |
| OLD | NEW |