Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: components/filesystem/public/cpp/prefs/filesystem_json_pref_store.h

Issue 1918083002: Convert //components/[f-n]* from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: … Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <set> 11 #include <set>
11 #include <string> 12 #include <string>
12 13
13 #include "base/callback_forward.h" 14 #include "base/callback_forward.h"
14 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
15 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
16 #include "base/gtest_prod_util.h" 17 #include "base/gtest_prod_util.h"
17 #include "base/macros.h" 18 #include "base/macros.h"
18 #include "base/memory/scoped_ptr.h"
19 #include "base/memory/weak_ptr.h" 19 #include "base/memory/weak_ptr.h"
20 #include "base/observer_list.h" 20 #include "base/observer_list.h"
21 #include "base/threading/non_thread_safe.h" 21 #include "base/threading/non_thread_safe.h"
22 #include "components/filesystem/public/interfaces/directory.mojom.h" 22 #include "components/filesystem/public/interfaces/directory.mojom.h"
23 #include "components/filesystem/public/interfaces/file.mojom.h" 23 #include "components/filesystem/public/interfaces/file.mojom.h"
24 #include "components/filesystem/public/interfaces/file_system.mojom.h" 24 #include "components/filesystem/public/interfaces/file_system.mojom.h"
25 #include "components/filesystem/public/interfaces/types.mojom.h" 25 #include "components/filesystem/public/interfaces/types.mojom.h"
26 #include "components/prefs/base_prefs_export.h" 26 #include "components/prefs/base_prefs_export.h"
27 #include "components/prefs/persistent_pref_store.h" 27 #include "components/prefs/persistent_pref_store.h"
28 #include "components/prefs/pref_filter.h" 28 #include "components/prefs/pref_filter.h"
(...skipping 27 matching lines...) Expand all
56 class FilesystemJsonPrefStore 56 class FilesystemJsonPrefStore
57 : public PersistentPrefStore, 57 : public PersistentPrefStore,
58 public filesystem::FileSystemClient, 58 public filesystem::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::FileSystemPtr filesystem,
66 scoped_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
76 // PersistentPrefStore overrides: 76 // PersistentPrefStore overrides:
77 bool GetMutableValue(const std::string& key, base::Value** result) override; 77 bool GetMutableValue(const std::string& key, base::Value** result) override;
78 void SetValue(const std::string& key, 78 void SetValue(const std::string& key,
79 scoped_ptr<base::Value> value, 79 std::unique_ptr<base::Value> value,
80 uint32_t flags) override; 80 uint32_t flags) override;
81 void SetValueSilently(const std::string& key, 81 void SetValueSilently(const std::string& key,
82 scoped_ptr<base::Value> value, 82 std::unique_ptr<base::Value> value,
83 uint32_t flags) override; 83 uint32_t flags) override;
84 void RemoveValue(const std::string& key, uint32_t flags) override; 84 void RemoveValue(const std::string& key, uint32_t flags) override;
85 bool ReadOnly() const override; 85 bool ReadOnly() const override;
86 PrefReadError GetReadError() const override; 86 PrefReadError GetReadError() const override;
87 // Note this method may be asynchronous if this instance has a |pref_filter_| 87 // Note this method may be asynchronous if this instance has a |pref_filter_|
88 // in which case it will return PREF_READ_ERROR_ASYNCHRONOUS_TASK_INCOMPLETE. 88 // in which case it will return PREF_READ_ERROR_ASYNCHRONOUS_TASK_INCOMPLETE.
89 // See details in pref_filter.h. 89 // See details in pref_filter.h.
90 PrefReadError ReadPrefs() override; 90 PrefReadError ReadPrefs() override;
91 void ReadPrefsAsync(ReadErrorDelegate* error_delegate) override; 91 void ReadPrefsAsync(ReadErrorDelegate* error_delegate) override;
92 void CommitPendingWrite() override; 92 void CommitPendingWrite() override;
(...skipping 13 matching lines...) Expand all
106 friend class base::JsonPrefStoreLossyWriteTest; 106 friend class base::JsonPrefStoreLossyWriteTest;
107 107
108 ~FilesystemJsonPrefStore() override; 108 ~FilesystemJsonPrefStore() override;
109 109
110 // This method is called after the JSON file has been read. It then hands 110 // This method is called after the JSON file has been read. It then hands
111 // |value| (or an empty dictionary in some read error cases) to the 111 // |value| (or an empty dictionary in some read error cases) to the
112 // |pref_filter| if one is set. It also gives a callback pointing at 112 // |pref_filter| if one is set. It also gives a callback pointing at
113 // FinalizeFileRead() to that |pref_filter_| which is then responsible for 113 // FinalizeFileRead() to that |pref_filter_| which is then responsible for
114 // invoking it when done. If there is no |pref_filter_|, FinalizeFileRead() 114 // invoking it when done. If there is no |pref_filter_|, FinalizeFileRead()
115 // is invoked directly. 115 // is invoked directly.
116 void OnFileRead(scoped_ptr<ReadResult> read_result); 116 void OnFileRead(std::unique_ptr<ReadResult> read_result);
117 117
118 // This method is called after the JSON file has been read and the result has 118 // This method is called after the JSON file has been read and the result has
119 // potentially been intercepted and modified by |pref_filter_|. 119 // potentially been intercepted and modified by |pref_filter_|.
120 // |schedule_write| indicates whether a write should be immediately scheduled 120 // |schedule_write| indicates whether a write should be immediately scheduled
121 // (typically because the |pref_filter_| has already altered the |prefs|) -- 121 // (typically because the |pref_filter_| has already altered the |prefs|) --
122 // this will be ignored if this store is read-only. 122 // this will be ignored if this store is read-only.
123 void FinalizeFileRead(scoped_ptr<base::DictionaryValue> prefs, 123 void FinalizeFileRead(std::unique_ptr<base::DictionaryValue> prefs,
124 bool schedule_write); 124 bool schedule_write);
125 125
126 // Schedule a write with the file writer as long as |flags| doesn't contain 126 // Schedule a write with the file writer as long as |flags| doesn't contain
127 // WriteablePrefStore::LOSSY_PREF_WRITE_FLAG. 127 // WriteablePrefStore::LOSSY_PREF_WRITE_FLAG.
128 void ScheduleWrite(uint32_t flags); 128 void ScheduleWrite(uint32_t flags);
129 129
130 // Actually performs a write. Unlike the //base version of this class, we 130 // Actually performs a write. Unlike the //base version of this class, we
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();
(...skipping 16 matching lines...) Expand all
150 void OnPreferencesFileRead(FileError err, mojo::Array<uint8_t> contents); 150 void OnPreferencesFileRead(FileError err, mojo::Array<uint8_t> contents);
151 151
152 const std::string path_; 152 const std::string path_;
153 mojo::Binding<filesystem::FileSystemClient> binding_; 153 mojo::Binding<filesystem::FileSystemClient> binding_;
154 filesystem::FileSystemPtr filesystem_; 154 filesystem::FileSystemPtr filesystem_;
155 155
156 // |directory_| is only bound after the first attempt to access the 156 // |directory_| is only bound after the first attempt to access the
157 // |filesystem. See OpenFilesystem(). 157 // |filesystem. See OpenFilesystem().
158 DirectoryPtr directory_; 158 DirectoryPtr directory_;
159 159
160 scoped_ptr<base::DictionaryValue> prefs_; 160 std::unique_ptr<base::DictionaryValue> prefs_;
161 161
162 bool read_only_; 162 bool read_only_;
163 163
164 scoped_ptr<PrefFilter> pref_filter_; 164 std::unique_ptr<PrefFilter> pref_filter_;
165 base::ObserverList<PrefStore::Observer, true> observers_; 165 base::ObserverList<PrefStore::Observer, true> observers_;
166 166
167 scoped_ptr<ReadErrorDelegate> error_delegate_; 167 std::unique_ptr<ReadErrorDelegate> error_delegate_;
168 168
169 bool initialized_; 169 bool initialized_;
170 bool filtering_in_progress_; 170 bool filtering_in_progress_;
171 bool pending_lossy_write_; 171 bool pending_lossy_write_;
172 PrefReadError read_error_; 172 PrefReadError read_error_;
173 173
174 DISALLOW_COPY_AND_ASSIGN(FilesystemJsonPrefStore); 174 DISALLOW_COPY_AND_ASSIGN(FilesystemJsonPrefStore);
175 }; 175 };
176 176
177 } // namespace filesystem 177 } // namespace filesystem
178 178
179 #endif // COMPONENTS_FILESYSTEM_PUBLIC_CPP_PREFS_FILESYSTEM_JSON_PREF_STORE_H_ 179 #endif // COMPONENTS_FILESYSTEM_PUBLIC_CPP_PREFS_FILESYSTEM_JSON_PREF_STORE_H_
OLDNEW
« no previous file with comments | « components/filesystem/file_system_impl.cc ('k') | components/filesystem/public/cpp/prefs/filesystem_json_pref_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698