OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 COMPONENTS_FILESYSTEM_PUBLIC_CPP_PREFS_FILESYSTEM_JSON_PREF_STORE_H_ | 5 #ifndef COMPONENTS_FILESYSTEM_PUBLIC_CPP_PREFS_FILESYSTEM_JSON_PREF_STORE_H_ |
6 #define COMPONENTS_FILESYSTEM_PUBLIC_CPP_PREFS_FILESYSTEM_JSON_PREF_STORE_H_ | 6 #define COMPONENTS_FILESYSTEM_PUBLIC_CPP_PREFS_FILESYSTEM_JSON_PREF_STORE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 // In the long run, we'll want to replace the current PrefService code with | 48 // In the long run, we'll want to replace the current PrefService code with |
49 // something very different, especially since this component hard punts on all | 49 // something very different, especially since this component hard punts on all |
50 // the hard things that the preference service does (enterprise management, | 50 // the hard things that the preference service does (enterprise management, |
51 // parental controls, extension integration, etc.) and its interface is really | 51 // parental controls, extension integration, etc.) and its interface is really |
52 // not optimal for a mojoified world--there are a few places where we assume | 52 // not optimal for a mojoified world--there are a few places where we assume |
53 // that writing to disk is synchronous...but it no longer is! | 53 // that writing to disk is synchronous...but it no longer is! |
54 // | 54 // |
55 // Removing this class is a part of crbug.com/580652. | 55 // Removing this class is a part of crbug.com/580652. |
56 class FilesystemJsonPrefStore | 56 class FilesystemJsonPrefStore |
57 : public PersistentPrefStore, | 57 : public PersistentPrefStore, |
58 public filesystem::FileSystemClient, | 58 public filesystem::mojom::FileSystemClient, |
59 public base::SupportsWeakPtr<FilesystemJsonPrefStore>, | 59 public base::SupportsWeakPtr<FilesystemJsonPrefStore>, |
60 public base::NonThreadSafe { | 60 public base::NonThreadSafe { |
61 public: | 61 public: |
62 struct ReadResult; | 62 struct ReadResult; |
63 | 63 |
64 FilesystemJsonPrefStore(const std::string& pref_filename, | 64 FilesystemJsonPrefStore(const std::string& pref_filename, |
65 filesystem::FileSystemPtr filesystem, | 65 filesystem::mojom::FileSystemPtr filesystem, |
66 std::unique_ptr<PrefFilter> pref_filter); | 66 std::unique_ptr<PrefFilter> pref_filter); |
67 | 67 |
68 // PrefStore overrides: | 68 // PrefStore overrides: |
69 bool GetValue(const std::string& key, | 69 bool GetValue(const std::string& key, |
70 const base::Value** result) const override; | 70 const base::Value** result) const override; |
71 void AddObserver(PrefStore::Observer* observer) override; | 71 void AddObserver(PrefStore::Observer* observer) override; |
72 void RemoveObserver(PrefStore::Observer* observer) override; | 72 void RemoveObserver(PrefStore::Observer* observer) override; |
73 bool HasObservers() const override; | 73 bool HasObservers() const override; |
74 bool IsInitializationComplete() const override; | 74 bool IsInitializationComplete() const override; |
75 | 75 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 // don't use the ImportantFileWriter and instead write using the mojo | 131 // don't use the ImportantFileWriter and instead write using the mojo |
132 // filesystem API. | 132 // filesystem API. |
133 void PerformWrite(); | 133 void PerformWrite(); |
134 | 134 |
135 // Opens the filesystem and calls |callback| when completed, whether | 135 // Opens the filesystem and calls |callback| when completed, whether |
136 // successfully or unsuccessfully. | 136 // successfully or unsuccessfully. |
137 void OpenFilesystem(base::Closure callback); | 137 void OpenFilesystem(base::Closure callback); |
138 | 138 |
139 // Callback method which verifies that there were no errors on opening the | 139 // Callback method which verifies that there were no errors on opening the |
140 // filesystem, and if there aren't, invokes the passed in callback. | 140 // filesystem, and if there aren't, invokes the passed in callback. |
141 void OnOpenFilesystem(base::Closure callback, FileError err); | 141 void OnOpenFilesystem(base::Closure callback, mojom::FileError err); |
142 | 142 |
143 // Asynchronous implementation details of PerformWrite(). | 143 // Asynchronous implementation details of PerformWrite(). |
144 void OnTempFileWriteStart(); | 144 void OnTempFileWriteStart(); |
145 void OnTempFileWrite(FileError err); | 145 void OnTempFileWrite(mojom::FileError err); |
146 void OnTempFileRenamed(FileError err); | 146 void OnTempFileRenamed(mojom::FileError err); |
147 | 147 |
148 // Asynchronous implementation details of ReadPrefsAsync(). | 148 // Asynchronous implementation details of ReadPrefsAsync(). |
149 void OnPreferencesReadStart(); | 149 void OnPreferencesReadStart(); |
150 void OnPreferencesFileRead(FileError err, mojo::Array<uint8_t> contents); | 150 void OnPreferencesFileRead(mojom::FileError err, |
| 151 mojo::Array<uint8_t> contents); |
151 | 152 |
152 const std::string path_; | 153 const std::string path_; |
153 mojo::Binding<filesystem::FileSystemClient> binding_; | 154 mojo::Binding<filesystem::mojom::FileSystemClient> binding_; |
154 filesystem::FileSystemPtr filesystem_; | 155 filesystem::mojom::FileSystemPtr filesystem_; |
155 | 156 |
156 // |directory_| is only bound after the first attempt to access the | 157 // |directory_| is only bound after the first attempt to access the |
157 // |filesystem. See OpenFilesystem(). | 158 // |filesystem. See OpenFilesystem(). |
158 DirectoryPtr directory_; | 159 mojom::DirectoryPtr directory_; |
159 | 160 |
160 std::unique_ptr<base::DictionaryValue> prefs_; | 161 std::unique_ptr<base::DictionaryValue> prefs_; |
161 | 162 |
162 bool read_only_; | 163 bool read_only_; |
163 | 164 |
164 std::unique_ptr<PrefFilter> pref_filter_; | 165 std::unique_ptr<PrefFilter> pref_filter_; |
165 base::ObserverList<PrefStore::Observer, true> observers_; | 166 base::ObserverList<PrefStore::Observer, true> observers_; |
166 | 167 |
167 std::unique_ptr<ReadErrorDelegate> error_delegate_; | 168 std::unique_ptr<ReadErrorDelegate> error_delegate_; |
168 | 169 |
169 bool initialized_; | 170 bool initialized_; |
170 bool filtering_in_progress_; | 171 bool filtering_in_progress_; |
171 bool pending_lossy_write_; | 172 bool pending_lossy_write_; |
172 PrefReadError read_error_; | 173 PrefReadError read_error_; |
173 | 174 |
174 DISALLOW_COPY_AND_ASSIGN(FilesystemJsonPrefStore); | 175 DISALLOW_COPY_AND_ASSIGN(FilesystemJsonPrefStore); |
175 }; | 176 }; |
176 | 177 |
177 } // namespace filesystem | 178 } // namespace filesystem |
178 | 179 |
179 #endif // COMPONENTS_FILESYSTEM_PUBLIC_CPP_PREFS_FILESYSTEM_JSON_PREF_STORE_H_ | 180 #endif // COMPONENTS_FILESYSTEM_PUBLIC_CPP_PREFS_FILESYSTEM_JSON_PREF_STORE_H_ |
OLD | NEW |