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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 // Save |data| to |path| in an atomic manner (see the class comment above). | 55 // Save |data| to |path| in an atomic manner (see the class comment above). |
56 // Blocks and writes data on the current thread. | 56 // Blocks and writes data on the current thread. |
57 static bool WriteFileAtomically(const FilePath& path, | 57 static bool WriteFileAtomically(const FilePath& path, |
58 const std::string& data); | 58 const std::string& data); |
59 | 59 |
60 // Initialize the writer. | 60 // Initialize the writer. |
61 // |path| is the name of file to write. | 61 // |path| is the name of file to write. |
62 // |task_runner| is the SequencedTaskRunner instance where on which we will | 62 // |task_runner| is the SequencedTaskRunner instance where on which we will |
63 // execute file I/O operations. | 63 // execute file I/O operations. |
64 // All non-const methods, ctor and dtor must be called on the same thread. | 64 // All non-const methods, ctor and dtor must be called on the same thread. |
65 ImportantFileWriter(const FilePath& path, | 65 ImportantFileWriter( |
66 base::SequencedTaskRunner* task_runner); | 66 const FilePath& path, |
| 67 const scoped_refptr<base::SequencedTaskRunner>& task_runner); |
67 | 68 |
68 // You have to ensure that there are no pending writes at the moment | 69 // You have to ensure that there are no pending writes at the moment |
69 // of destruction. | 70 // of destruction. |
70 ~ImportantFileWriter(); | 71 ~ImportantFileWriter(); |
71 | 72 |
72 const FilePath& path() const { return path_; } | 73 const FilePath& path() const { return path_; } |
73 | 74 |
74 // Returns true if there is a scheduled write pending which has not yet | 75 // Returns true if there is a scheduled write pending which has not yet |
75 // been started. | 76 // been started. |
76 bool HasPendingWrite() const; | 77 bool HasPendingWrite() const; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 TimeDelta commit_interval_; | 131 TimeDelta commit_interval_; |
131 | 132 |
132 WeakPtrFactory<ImportantFileWriter> weak_factory_; | 133 WeakPtrFactory<ImportantFileWriter> weak_factory_; |
133 | 134 |
134 DISALLOW_COPY_AND_ASSIGN(ImportantFileWriter); | 135 DISALLOW_COPY_AND_ASSIGN(ImportantFileWriter); |
135 }; | 136 }; |
136 | 137 |
137 } // namespace base | 138 } // namespace base |
138 | 139 |
139 #endif // BASE_FILES_IMPORTANT_FILE_WRITER_H_ | 140 #endif // BASE_FILES_IMPORTANT_FILE_WRITER_H_ |
OLD | NEW |