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| in an atomic manner (see the class comment above). |
| 55 // Blocks and writes data on the current thread. |
| 56 static bool WriteFileAtomically(const FilePath& path, |
| 57 const std::string& data); |
| 58 |
54 // Initialize the writer. | 59 // Initialize the writer. |
55 // |path| is the name of file to write. | 60 // |path| is the name of file to write. |
56 // |task_runner| is the SequencedTaskRunner instance where on which we will | 61 // |task_runner| is the SequencedTaskRunner instance where on which we will |
57 // execute file I/O operations. | 62 // execute file I/O operations. |
58 // All non-const methods, ctor and dtor must be called on the same thread. | 63 // All non-const methods, ctor and dtor must be called on the same thread. |
59 ImportantFileWriter(const FilePath& path, | 64 ImportantFileWriter(const FilePath& path, |
60 base::SequencedTaskRunner* task_runner); | 65 base::SequencedTaskRunner* task_runner); |
61 | 66 |
62 // You have to ensure that there are no pending writes at the moment | 67 // You have to ensure that there are no pending writes at the moment |
63 // of destruction. | 68 // of destruction. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 112 |
108 // Time delta after which scheduled data will be written to disk. | 113 // Time delta after which scheduled data will be written to disk. |
109 TimeDelta commit_interval_; | 114 TimeDelta commit_interval_; |
110 | 115 |
111 DISALLOW_COPY_AND_ASSIGN(ImportantFileWriter); | 116 DISALLOW_COPY_AND_ASSIGN(ImportantFileWriter); |
112 }; | 117 }; |
113 | 118 |
114 } // namespace base | 119 } // namespace base |
115 | 120 |
116 #endif // BASE_FILES_IMPORTANT_FILE_WRITER_H_ | 121 #endif // BASE_FILES_IMPORTANT_FILE_WRITER_H_ |
OLD | NEW |