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

Unified Diff: base/prefs/leveldb_pref_store.h

Issue 169323003: Implementation of leveldb-backed PrefStore (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: now with FileThreadDeserializer Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
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 60%
copy from base/prefs/json_pref_store.h
copy to base/prefs/leveldb_pref_store.h
index ad13feba3f6e1279c7c2bee4d597df35d1698842..e7eabf42f02cc8f529417a7cb95e6a3629dbc475 100644
--- a/base/prefs/json_pref_store.h
+++ b/base/prefs/leveldb_pref_store.h
@@ -5,46 +5,34 @@
#ifndef BASE_PREFS_JSON_PREF_STORE_H_
#define BASE_PREFS_JSON_PREF_STORE_H_
-#include <set>
#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"
-
-class PrefFilter;
+#include "base/prefs/pref_value_map.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 +45,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 +57,27 @@ 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(leveldb::DB* db,
+ scoped_ptr<PrefValueMap> map,
+ PrefReadError error,
+ bool no_dir);
private:
- virtual ~JsonPrefStore();
+ virtual ~LevelDBPrefStore();
- // ImportantFileWriter::DataSerializer overrides:
- virtual bool SerializeData(std::string* output) OVERRIDE;
+ void PersistFromUIThread(const std::string& key, base::Value* value);
+ void RemoveFromUIThread(const std::string& key);
+
+ void NotifyObservers(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 +85,10 @@ class BASE_PREFS_EXPORT JsonPrefStore
bool initialized_;
PrefReadError read_error_;
- std::set<std::string> keys_need_empty_value_;
+ class FileThreadSerializer;
+ scoped_ptr<FileThreadSerializer> helper_;
Mattias Nissler (ping if slow) 2014/03/05 18:28:15 This should probably be named |serializer_|.
dgrogan 2014/03/06 03:03:40 Done.
- DISALLOW_COPY_AND_ASSIGN(JsonPrefStore);
+ DISALLOW_COPY_AND_ASSIGN(LevelDBPrefStore);
};
#endif // BASE_PREFS_JSON_PREF_STORE_H_

Powered by Google App Engine
This is Rietveld 408576698