Chromium Code Reviews| Index: base/prefs/leveldb_pref_store.h |
| diff --git a/base/prefs/json_pref_store.h b/base/prefs/leveldb_pref_store.h |
| similarity index 62% |
| copy from base/prefs/json_pref_store.h |
| copy to base/prefs/leveldb_pref_store.h |
| index ad13feba3f6e1279c7c2bee4d597df35d1698842..9e72f983f2a9bbc14036111722c64219894ca34b 100644 |
| --- a/base/prefs/json_pref_store.h |
| +++ b/base/prefs/leveldb_pref_store.h |
| @@ -9,42 +9,29 @@ |
| #include <string> |
| #include "base/basictypes.h" |
| -#include "base/compiler_specific.h" |
| #include "base/files/file_path.h" |
| -#include "base/files/important_file_writer.h" |
| #include "base/memory/scoped_ptr.h" |
| -#include "base/message_loop/message_loop_proxy.h" |
| #include "base/observer_list.h" |
| #include "base/prefs/base_prefs_export.h" |
| #include "base/prefs/persistent_pref_store.h" |
| +#include "base/prefs/pref_value_map.h" |
| +#include "third_party/leveldatabase/src/include/leveldb/db.h" |
|
Mattias Nissler (ping if slow)
2014/02/24 09:00:40
could be forward-declared instead?
dgrogan
2014/02/25 03:32:08
Done.
|
| class PrefFilter; |
| namespace base { |
| -class DictionaryValue; |
| class FilePath; |
| class SequencedTaskRunner; |
| -class SequencedWorkerPool; |
| class Value; |
| } |
| - |
| // A writable PrefStore implementation that is used for user preferences. |
| -class BASE_PREFS_EXPORT JsonPrefStore |
| - : public PersistentPrefStore, |
| - public base::ImportantFileWriter::DataSerializer { |
| +class BASE_PREFS_EXPORT LevelDBPrefStore : public PersistentPrefStore { |
| public: |
| - // Returns instance of SequencedTaskRunner which guarantees that file |
| - // operations on the same file will be executed in sequenced order. |
| - static scoped_refptr<base::SequencedTaskRunner> GetTaskRunnerForFile( |
| - const base::FilePath& pref_filename, |
| - base::SequencedWorkerPool* worker_pool); |
| - |
| // |sequenced_task_runner| is must be a shutdown-blocking task runner, ideally |
| // created by GetTaskRunnerForFile() method above. |
| - JsonPrefStore(const base::FilePath& pref_filename, |
| - base::SequencedTaskRunner* sequenced_task_runner, |
| - scoped_ptr<PrefFilter> pref_filter); |
| + LevelDBPrefStore(const base::FilePath& pref_filename, |
| + base::SequencedTaskRunner* sequenced_task_runner); |
| // PrefStore overrides: |
| virtual bool GetValue(const std::string& key, |
| @@ -57,6 +44,7 @@ class BASE_PREFS_EXPORT JsonPrefStore |
| // PersistentPrefStore overrides: |
| virtual bool GetMutableValue(const std::string& key, |
| base::Value** result) OVERRIDE; |
| + // Takes ownership of value. |
| virtual void SetValue(const std::string& key, base::Value* value) OVERRIDE; |
| virtual void SetValueSilently(const std::string& key, |
| base::Value* value) OVERRIDE; |
| @@ -68,27 +56,24 @@ class BASE_PREFS_EXPORT JsonPrefStore |
| virtual void CommitPendingWrite() OVERRIDE; |
| virtual void ReportValueChanged(const std::string& key) OVERRIDE; |
| - // This method is called after JSON file has been read. Method takes |
| - // ownership of the |value| pointer. Note, this method is used with |
| - // asynchronous file reading, so class exposes it only for the internal needs. |
| - // (read: do not call it manually). |
| - void OnFileRead(base::Value* value_owned, PrefReadError error, bool no_dir); |
| + void OnStorageRead(PrefReadError error, bool no_dir); |
|
Mattias Nissler (ping if slow)
2014/02/24 09:00:40
Does this need to be public?
dgrogan
2014/02/25 03:32:08
Nope, changed.
|
| private: |
| - virtual ~JsonPrefStore(); |
| + virtual ~LevelDBPrefStore(); |
| - // ImportantFileWriter::DataSerializer overrides: |
| - virtual bool SerializeData(std::string* output) OVERRIDE; |
| + void PersistOnFileThread(const std::string& key, const std::string& value); |
| + void PersistFromUIThread(const std::string& key, base::Value* value); |
| base::FilePath path_; |
| const scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; |
| - scoped_ptr<base::DictionaryValue> prefs_; |
| + PrefValueMap prefs_; |
| - bool read_only_; |
| + // Open writes some stuff to the DB so we can't necessarily do it on the UI |
| + // thread. |
|
Mattias Nissler (ping if slow)
2014/02/24 09:00:40
This comment seems out of place here?
dgrogan
2014/02/25 03:32:08
Agreed, removed.
|
| + scoped_ptr<leveldb::DB> db_; |
| - // Helper for safely writing pref data. |
| - base::ImportantFileWriter writer_; |
| + bool read_only_; |
| scoped_ptr<PrefFilter> pref_filter_; |
| ObserverList<PrefStore::Observer, true> observers_; |
| @@ -98,9 +83,10 @@ class BASE_PREFS_EXPORT JsonPrefStore |
| bool initialized_; |
| PrefReadError read_error_; |
| + // Only access from the UI thread. |
| std::set<std::string> keys_need_empty_value_; |
| - DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); |
| + DISALLOW_COPY_AND_ASSIGN(LevelDBPrefStore); |
| }; |
| #endif // BASE_PREFS_JSON_PREF_STORE_H_ |