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 58% |
copy from base/prefs/json_pref_store.h |
copy to base/prefs/leveldb_pref_store.h |
index ad13feba3f6e1279c7c2bee4d597df35d1698842..a195af05cecd7f5b3351d56fdf42c784a79ebfa1 100644 |
--- a/base/prefs/json_pref_store.h |
+++ b/base/prefs/leveldb_pref_store.h |
@@ -11,40 +11,30 @@ |
#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" |
- |
-class PrefFilter; |
+#include "base/prefs/pref_value_map.h" |
+#include "base/timer/timer.h" |
namespace base { |
class DictionaryValue; |
-class FilePath; |
class SequencedTaskRunner; |
-class SequencedWorkerPool; |
class Value; |
} |
+namespace leveldb { |
+class DB; |
+} |
// 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 +47,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,29 +59,37 @@ 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); |
- |
private: |
- virtual ~JsonPrefStore(); |
+ struct ReadingResults; |
+ class FileThreadSerializer; |
+ |
+ virtual ~LevelDBPrefStore(); |
- // ImportantFileWriter::DataSerializer overrides: |
- virtual bool SerializeData(std::string* output) OVERRIDE; |
+ static scoped_ptr<ReadingResults> DoReading(const base::FilePath& path); |
+ static void OpenDB(const base::FilePath& path, |
+ ReadingResults* reading_results); |
+ void OnStorageRead(scoped_ptr<ReadingResults> reading_results); |
+ |
+ void PersistFromUIThread(); |
+ void RemoveFromUIThread(const std::string& key); |
+ void ScheduleWrite(); |
+ |
+ void SetValueInternal(const std::string& key, |
+ base::Value* value, |
+ bool notify); |
+ void NotifyObservers(const std::string& key); |
+ void MarkForInsertion(const std::string& key, const std::string& value); |
+ void MarkForDeletion(const std::string& key); |
base::FilePath path_; |
+ |
const scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; |
+ const scoped_refptr<base::SequencedTaskRunner> original_task_runner_; |
- scoped_ptr<base::DictionaryValue> prefs_; |
+ PrefValueMap prefs_; |
bool read_only_; |
- // Helper for safely writing pref data. |
- base::ImportantFileWriter writer_; |
- |
- scoped_ptr<PrefFilter> pref_filter_; |
ObserverList<PrefStore::Observer, true> observers_; |
scoped_ptr<ReadErrorDelegate> error_delegate_; |
@@ -98,9 +97,17 @@ class BASE_PREFS_EXPORT JsonPrefStore |
bool initialized_; |
PrefReadError read_error_; |
- std::set<std::string> keys_need_empty_value_; |
+ // This object is created on the UI thread right after preferences are loaded |
+ // from disk. A message to delete it is sent to the FILE thread by |
+ // ~LevelDBPrefStore. |
+ scoped_ptr<FileThreadSerializer> serializer_; |
+ std::set<std::string> keys_to_delete_; |
Mattias Nissler (ping if slow)
2014/04/14 10:11:41
Please document |keys_to_delete_|, |keys_to_set_|
dgrogan
2014/04/17 01:10:27
Done.
|
+ std::map<std::string, std::string> keys_to_set_; |
+ base::OneShotTimer<LevelDBPrefStore> timer_; |
+ |
+ base::WeakPtrFactory<LevelDBPrefStore> weak_ptr_factory_; |
- DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); |
+ DISALLOW_COPY_AND_ASSIGN(LevelDBPrefStore); |
}; |
#endif // BASE_PREFS_JSON_PREF_STORE_H_ |