Chromium Code Reviews| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 public: | 44 public: |
| 45 // Should put serialized string in |data| and return true on successful | 45 // Should put serialized string in |data| and return true on successful |
| 46 // serialization. Will be called on the same thread on which | 46 // serialization. Will be called on the same thread on which |
| 47 // ImportantFileWriter has been created. | 47 // ImportantFileWriter has been created. |
| 48 virtual bool SerializeData(std::string* data) = 0; | 48 virtual bool SerializeData(std::string* data) = 0; |
| 49 | 49 |
| 50 protected: | 50 protected: |
| 51 virtual ~DataSerializer() {} | 51 virtual ~DataSerializer() {} |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 // Save |data| to |path|. Blocks and writes data on the current thread. | |
|
Mattias Nissler (ping if slow)
2012/11/26 15:48:57
Should mention that this uses save-to-tempfile-and
Ivan Korotkov
2012/11/27 11:37:25
WriteFileAtomically sounds good enough to me.
| |
| 55 static bool WriteToDisk(const FilePath& path, const std::string& data); | |
| 56 | |
| 54 // Initialize the writer. | 57 // Initialize the writer. |
| 55 // |path| is the name of file to write. | 58 // |path| is the name of file to write. |
| 56 // |task_runner| is the SequencedTaskRunner instance where on which we will | 59 // |task_runner| is the SequencedTaskRunner instance where on which we will |
| 57 // execute file I/O operations. | 60 // execute file I/O operations. |
| 58 // All non-const methods, ctor and dtor must be called on the same thread. | 61 // All non-const methods, ctor and dtor must be called on the same thread. |
| 59 ImportantFileWriter(const FilePath& path, | 62 ImportantFileWriter(const FilePath& path, |
| 60 base::SequencedTaskRunner* task_runner); | 63 base::SequencedTaskRunner* task_runner); |
| 61 | 64 |
| 62 // You have to ensure that there are no pending writes at the moment | 65 // You have to ensure that there are no pending writes at the moment |
| 63 // of destruction. | 66 // of destruction. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 | 110 |
| 108 // Time delta after which scheduled data will be written to disk. | 111 // Time delta after which scheduled data will be written to disk. |
| 109 TimeDelta commit_interval_; | 112 TimeDelta commit_interval_; |
| 110 | 113 |
| 111 DISALLOW_COPY_AND_ASSIGN(ImportantFileWriter); | 114 DISALLOW_COPY_AND_ASSIGN(ImportantFileWriter); |
| 112 }; | 115 }; |
| 113 | 116 |
| 114 } // namespace base | 117 } // namespace base |
| 115 | 118 |
| 116 #endif // BASE_FILES_IMPORTANT_FILE_WRITER_H_ | 119 #endif // BASE_FILES_IMPORTANT_FILE_WRITER_H_ |
| OLD | NEW |