Index: base/files/important_file_writer.h |
diff --git a/base/files/important_file_writer.h b/base/files/important_file_writer.h |
index 99f1a7c6814753ec9b1d63a85930399eddb0eeab..d4dbd57827fb2b8367e8fddc0d92db6ca1816b79 100644 |
--- a/base/files/important_file_writer.h |
+++ b/base/files/important_file_writer.h |
@@ -39,8 +39,8 @@ class Thread; |
// http://valhenson.livejournal.com/37921.html |
class BASE_EXPORT ImportantFileWriter : public NonThreadSafe { |
public: |
- // Used by ScheduleSave to lazily provide the data to be saved. Allows us |
- // to also batch data serializations. |
+ // Used to lazily provide the data to be saved. Allows us to also batch data |
+ // serializations. |
class BASE_EXPORT DataSerializer { |
public: |
// Should put serialized string in |data| and return true on successful |
@@ -52,33 +52,15 @@ class BASE_EXPORT ImportantFileWriter : public NonThreadSafe { |
virtual ~DataSerializer() {} |
}; |
- // Save |data| to |path| in an atomic manner (see the class comment above). |
- // Blocks and writes data on the current thread. |
- static bool WriteFileAtomically(const FilePath& path, |
- const std::string& data); |
- |
- // Initialize the writer. |
- // |path| is the name of file to write. |
- // |task_runner| is the SequencedTaskRunner instance where on which we will |
- // execute file I/O operations. |
- // All non-const methods, ctor and dtor must be called on the same thread. |
- ImportantFileWriter( |
- const FilePath& path, |
- const scoped_refptr<base::SequencedTaskRunner>& task_runner); |
- |
- // You have to ensure that there are no pending writes at the moment |
- // of destruction. |
- ~ImportantFileWriter(); |
- |
- const FilePath& path() const { return path_; } |
+ virtual ~ImportantFileWriter() {} |
// Returns true if there is a scheduled write pending which has not yet |
// been started. |
- bool HasPendingWrite() const; |
+ virtual bool HasPendingWrite() const = 0; |
// Save |data| to target filename. Does not block. If there is a pending write |
// scheduled by ScheduleWrite, it is cancelled. |
- void WriteNow(scoped_ptr<std::string> data); |
+ virtual void WriteNow(scoped_ptr<std::string> data) = 0; |
// Schedule a save to target filename. Data will be serialized and saved |
// to disk after the commit interval. If another ScheduleWrite is issued |
@@ -86,19 +68,50 @@ class BASE_EXPORT ImportantFileWriter : public NonThreadSafe { |
// the most recent |serializer| will be used. This operation does not block. |
// |serializer| should remain valid through the lifetime of |
// ImportantFileWriter. |
- void ScheduleWrite(DataSerializer* serializer); |
+ virtual void ScheduleWrite(DataSerializer* serializer) = 0; |
// Serialize data pending to be saved and execute write on backend thread. |
- void DoScheduledWrite(); |
+ virtual void DoScheduledWrite() = 0; |
// Registers |on_next_successful_write| to be called once, on the next |
// successful write event. Only one callback can be set at once. |
- void RegisterOnNextSuccessfulWriteCallback( |
- const base::Closure& on_next_successful_write); |
+ virtual void RegisterOnNextSuccessfulWriteCallback( |
+ const base::Closure& on_next_successful_write) = 0; |
- TimeDelta commit_interval() const { |
- return commit_interval_; |
- } |
+ // Returns the time delta after which scheduled data will be written to disk. |
+ virtual TimeDelta CommitInterval() const = 0; |
+}; |
+ |
+class BASE_EXPORT ImportantFileWriterImpl : public ImportantFileWriter { |
+ public: |
+ // Save |data| to |path| in an atomic manner (see the class comment above). |
+ // Blocks and writes data on the current thread. |
+ static bool WriteFileAtomically(const FilePath& path, |
+ const std::string& data); |
+ |
+ // Initialize the writer. |
+ // |path| is the name of file to write. |
+ // |task_runner| is the SequencedTaskRunner instance where on which we will |
+ // execute file I/O operations. |
+ // All non-const methods, ctor and dtor must be called on the same thread. |
+ ImportantFileWriterImpl( |
+ const FilePath& path, |
+ const scoped_refptr<base::SequencedTaskRunner>& task_runner); |
+ |
+ // You have to ensure that there are no pending writes at the moment |
+ // of destruction. |
+ ~ImportantFileWriterImpl() override; |
+ |
+ const FilePath& path() const { return path_; } |
+ |
+ // ImportantFileWriter overrides. |
+ bool HasPendingWrite() const override; |
+ void WriteNow(scoped_ptr<std::string> data) override; |
+ void ScheduleWrite(DataSerializer* serializer) override; |
+ void DoScheduledWrite() override; |
+ void RegisterOnNextSuccessfulWriteCallback( |
+ const base::Closure& on_next_successful_write) override; |
+ TimeDelta CommitInterval() const override; |
void set_commit_interval(const TimeDelta& interval) { |
commit_interval_ = interval; |
@@ -122,7 +135,7 @@ class BASE_EXPORT ImportantFileWriter : public NonThreadSafe { |
const scoped_refptr<base::SequencedTaskRunner> task_runner_; |
// Timer used to schedule commit after ScheduleWrite. |
- OneShotTimer<ImportantFileWriter> timer_; |
+ OneShotTimer<ImportantFileWriterImpl> timer_; |
// Serializer which will provide the data to be saved. |
DataSerializer* serializer_; |
@@ -130,9 +143,9 @@ class BASE_EXPORT ImportantFileWriter : public NonThreadSafe { |
// Time delta after which scheduled data will be written to disk. |
TimeDelta commit_interval_; |
- WeakPtrFactory<ImportantFileWriter> weak_factory_; |
+ WeakPtrFactory<ImportantFileWriterImpl> weak_factory_; |
- DISALLOW_COPY_AND_ASSIGN(ImportantFileWriter); |
+ DISALLOW_COPY_AND_ASSIGN(ImportantFileWriterImpl); |
}; |
} // namespace base |