Commit ab37ca87 authored by dgrogan@chromium.org's avatar dgrogan@chromium.org

Implementation of leveldb-backed PrefStore.

This is not hooked up yet, migration code from Json-backed stores is needed, among other things.

BUG=362814

Review URL: https://codereview.chromium.org/169323003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271602 0039d316-1c4b-4281-b951-d872f2087c98
parent aae544d7
......@@ -330,6 +330,11 @@ void JsonPrefStore::OnFileRead(scoped_ptr<base::Value> value,
// operation itself.
NOTREACHED();
break;
case PREF_READ_ERROR_LEVELDB_IO:
case PREF_READ_ERROR_LEVELDB_CORRUPTION_READ_ONLY:
case PREF_READ_ERROR_LEVELDB_CORRUPTION:
// These are specific to LevelDBPrefStore.
NOTREACHED();
case PREF_READ_ERROR_MAX_ENUM:
NOTREACHED();
break;
......
......@@ -33,6 +33,9 @@ class BASE_PREFS_EXPORT PersistentPrefStore : public WriteablePrefStore {
// Indicates that ReadPrefs() couldn't complete synchronously and is waiting
// for an asynchronous task to complete first.
PREF_READ_ERROR_ASYNCHRONOUS_TASK_INCOMPLETE = 10,
PREF_READ_ERROR_LEVELDB_IO = 11,
PREF_READ_ERROR_LEVELDB_CORRUPTION_READ_ONLY = 12,
PREF_READ_ERROR_LEVELDB_CORRUPTION = 13,
PREF_READ_ERROR_MAX_ENUM
};
......
......@@ -313,7 +313,8 @@ void HandleReadError(PersistentPrefStore::PrefReadError error) {
// an example problem that this can cause.
// Do some diagnosis and try to avoid losing data.
int message_id = 0;
if (error <= PersistentPrefStore::PREF_READ_ERROR_JSON_TYPE) {
if (error <= PersistentPrefStore::PREF_READ_ERROR_JSON_TYPE ||
error == PersistentPrefStore::PREF_READ_ERROR_LEVELDB_CORRUPTION) {
message_id = IDS_PREFERENCES_CORRUPT_ERROR;
} else if (error != PersistentPrefStore::PREF_READ_ERROR_NO_FILE) {
message_id = IDS_PREFERENCES_UNREADABLE_ERROR;
......
This diff is collapsed.
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_PREFS_LEVELDB_PREF_STORE_H_
#define CHROME_BROWSER_PREFS_LEVELDB_PREF_STORE_H_
#include <set>
#include <string>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/observer_list.h"
#include "base/prefs/persistent_pref_store.h"
#include "base/prefs/pref_value_map.h"
#include "base/timer/timer.h"
namespace base {
class DictionaryValue;
class SequencedTaskRunner;
class Value;
}
namespace leveldb {
class DB;
}
// A writable PrefStore implementation that is used for user preferences.
class LevelDBPrefStore : public PersistentPrefStore {
public:
// |sequenced_task_runner| is must be a shutdown-blocking task runner, ideally
// created by GetTaskRunnerForFile() method above.
LevelDBPrefStore(const base::FilePath& pref_filename,
base::SequencedTaskRunner* sequenced_task_runner);
// PrefStore overrides:
virtual bool GetValue(const std::string& key,
const base::Value** result) const OVERRIDE;
virtual void AddObserver(PrefStore::Observer* observer) OVERRIDE;
virtual void RemoveObserver(PrefStore::Observer* observer) OVERRIDE;
virtual bool HasObservers() const OVERRIDE;
virtual bool IsInitializationComplete() const OVERRIDE;
// 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;
virtual void RemoveValue(const std::string& key) OVERRIDE;
virtual bool ReadOnly() const OVERRIDE;
virtual PrefReadError GetReadError() const OVERRIDE;
virtual PrefReadError ReadPrefs() OVERRIDE;
virtual void ReadPrefsAsync(ReadErrorDelegate* error_delegate) OVERRIDE;
virtual void CommitPendingWrite() OVERRIDE;
virtual void ReportValueChanged(const std::string& key) OVERRIDE;
private:
struct ReadingResults;
class FileThreadSerializer;
virtual ~LevelDBPrefStore();
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_;
PrefValueMap prefs_;
bool read_only_;
ObserverList<PrefStore::Observer, true> observers_;
scoped_ptr<ReadErrorDelegate> error_delegate_;
bool initialized_;
PrefReadError read_error_;
// 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_;
// Changes are accumulated in |keys_to_delete_| and |keys_to_set_| and are
// stored in the database according to |timer_|.
std::set<std::string> keys_to_delete_;
std::map<std::string, std::string> keys_to_set_;
base::OneShotTimer<LevelDBPrefStore> timer_;
base::WeakPtrFactory<LevelDBPrefStore> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(LevelDBPrefStore);
};
#endif // CHROME_BROWSER_PREFS_LEVELDB_PREF_STORE_H_
This diff is collapsed.
......@@ -1549,6 +1549,8 @@
'browser/prefs/incognito_mode_prefs.h',
'browser/prefs/interceptable_pref_filter.cc',
'browser/prefs/interceptable_pref_filter.h',
'browser/prefs/leveldb_pref_store.cc',
'browser/prefs/leveldb_pref_store.h',
'browser/prefs/pref_hash_calculator.cc',
'browser/prefs/pref_hash_calculator.h',
'browser/prefs/pref_hash_filter.cc',
......
......@@ -1154,6 +1154,7 @@
'browser/prefs/chrome_pref_service_unittest.cc',
'browser/prefs/command_line_pref_store_unittest.cc',
'browser/prefs/incognito_mode_prefs_unittest.cc',
'browser/prefs/leveldb_pref_store_unittest.cc',
'browser/prefs/pref_hash_calculator_unittest.cc',
'browser/prefs/pref_hash_filter_unittest.cc',
'browser/prefs/pref_hash_store_impl_unittest.cc',
......
MANIFEST-000007
\ No newline at end of file
......@@ -8989,6 +8989,14 @@ Therefore, the affected-histogram name has to have at least one dot in it.
</summary>
</histogram>
<histogram name="LevelDBPrefStore.ReadErrors" enum="LevelDBPrefStoreErrorCodes">
<owner>dgrogan@chromium.org</owner>
<summary>
Bitfield that indicates errors and recovery that occurred when opening a
LevelDB preferences database.
</summary>
</histogram>
<histogram name="LibraryLoader.NativeLibraryHack" enum="BooleanUsage">
<owner>feng@chromium.org</owner>
<summary>
......@@ -37275,6 +37283,36 @@ Therefore, the affected-histogram name has to have at least one dot in it.
<int value="20" label="GetChildren"/>
</enum>
<enum name="LevelDBPrefStoreErrorCodes" type="int">
<int value="1" label="OPENED"/>
<int value="5" label="REPAIRED | OPENED"/>
<int value="6" label="REPAIRED | DESTROYED"/>
<int value="7" label="REPAIRED | DESTROYED | OPENED"/>
<int value="12" label="REPAIRED | DESTROY_FAILED"/>
<int value="18" label="REPAIR_FAILED | DESTROYED"/>
<int value="19" label="REPAIR_FAILED | DESTROYED | OPENED"/>
<int value="24" label="REPAIR_FAILED | DESTROY_FAILED"/>
<int value="32" label="IO_ERROR"/>
<int value="36" label="REPAIRED | IO_ERROR"/>
<int value="38" label="REPAIRED | DESTROYED | IO_ERROR"/>
<int value="50" label="REPAIR_FAILED | DESTROYED | IO_ERROR"/>
<int value="65" label="OPENED | DATA_LOST"/>
<int value="69" label="REPAIRED | OPENED | DATA_LOST"/>
<int value="71" label="REPAIRED | DESTROYED | OPENED | DATA_LOST"/>
<int value="83" label="REPAIR_FAILED | DESTROYED | OPENED | DATA_LOST"/>
<int value="129" label="OPENED | ITER_NOT_OK"/>
<int value="133" label="REPAIRED | OPENED | ITER_NOT_OK"/>
<int value="135" label="REPAIRED | DESTROYED | OPENED | ITER_NOT_OK"/>
<int value="147" label="REPAIR_FAILED | DESTROYED | OPENED | ITER_NOT_OK"/>
<int value="193" label="OPENED | DATA_LOST | ITER_NOT_OK"/>
<int value="197" label="REPAIRED | OPENED | DATA_LOST | ITER_NOT_OK"/>
<int value="199"
label="REPAIRED | DESTROYED | OPENED | DATA_LOST | ITER_NOT_OK"/>
<int value="211"
label="REPAIR_FAILED | DESTROYED | OPENED | DATA_LOST | ITER_NOT_OK"/>
<int value="256" label="FILE_NOT_SPECIFIED"/>
</enum>
<enum name="LinkMonitorFailureType" type="int">
<int value="0" label="Local MAC Address Not Found"/>
<int value="1" label="Client Startup Failure"/>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment