Chromium Code Reviews| Index: chrome/browser/prefs/chrome_pref_service_factory.cc |
| diff --git a/chrome/browser/prefs/chrome_pref_service_factory.cc b/chrome/browser/prefs/chrome_pref_service_factory.cc |
| index 877ab2771c272fa417865f2d2558ed3f7c66118c..4b7044f497ca12779811fe7ea7d9f8543a23c3bf 100644 |
| --- a/chrome/browser/prefs/chrome_pref_service_factory.cc |
| +++ b/chrome/browser/prefs/chrome_pref_service_factory.cc |
| @@ -19,6 +19,7 @@ |
| #include "base/prefs/pref_service.h" |
| #include "base/prefs/pref_store.h" |
| #include "base/prefs/pref_value_store.h" |
| +#include "base/values.h" |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/prefs/command_line_pref_store.h" |
| #include "chrome/browser/prefs/pref_hash_filter.h" |
| @@ -265,6 +266,32 @@ void PrepareBuilder( |
| pref_filter.Pass())); |
| } |
| +// An in-memory PrefStore backed by an immutable DictionaryValue. |
| +class DictionaryPrefStore : public PrefStore { |
| + public: |
| + explicit DictionaryPrefStore(const base::DictionaryValue* dictionary) |
| + : dictionary_(dictionary) {} |
| + |
| + virtual bool GetValue(const std::string& key, |
| + const base::Value** result) const OVERRIDE { |
| + const base::Value* tmp = NULL; |
| + if (!dictionary_->Get(key, &tmp)) |
| + return false; |
| + |
| + if (result) |
| + *result = tmp; |
| + return true; |
| + } |
| + |
| + protected: |
| + virtual ~DictionaryPrefStore() {} |
|
Bernhard Bauer
2014/02/04 09:08:02
Nit: Make the destructor private? Protected implie
gab
2014/02/04 14:01:04
Done.
|
| + |
| + private: |
| + const base::DictionaryValue* dictionary_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DictionaryPrefStore); |
| +}; |
| + |
| // Waits for a PrefStore to be initialized and then initializes the |
| // corresponding PrefHashStore. |
| // The observer deletes itself when its work is completed. |
| @@ -296,8 +323,12 @@ void InitializeHashStoreObserver::OnPrefValueChanged(const std::string& key) {} |
| void InitializeHashStoreObserver::OnInitializationCompleted(bool succeeded) { |
| // If we successfully loaded the preferences _and_ the PrefHashStore hasn't |
| // been initialized by someone else in the meantime initialize it now. |
| - if (succeeded & !pref_hash_store_->IsInitialized()) |
| - CreatePrefHashFilter(pref_hash_store_.Pass())->Initialize(pref_store_); |
| + if (succeeded & !pref_hash_store_->IsInitialized()) { |
| + CreatePrefHashFilter( |
| + pref_hash_store_.Pass())->Initialize(*pref_store_); |
| + UMA_HISTOGRAM_BOOLEAN( |
| + "Settings.TrackedPreferencesInitializedForUnloadedProfile", true); |
| + } |
| pref_store_->RemoveObserver(this); |
| delete this; |
| } |
| @@ -346,7 +377,7 @@ scoped_ptr<PrefServiceSyncable> CreateProfilePrefs( |
| return factory.CreateSyncable(pref_registry.get()); |
| } |
| -void InitializeHashStoreForPrefFile( |
| +void InitializeHashStoreFromPrefFile( |
| const base::FilePath& pref_filename, |
| base::SequencedTaskRunner* pref_io_task_runner, |
| scoped_ptr<PrefHashStore> pref_hash_store) { |
| @@ -359,4 +390,12 @@ void InitializeHashStoreForPrefFile( |
| pref_store->ReadPrefsAsync(NULL); |
| } |
| +void InitializeHashStoreFromMasterPrefs( |
| + const base::DictionaryValue& master_prefs, |
| + scoped_ptr<PrefHashStore> pref_hash_store) { |
| + scoped_refptr<const PrefStore> pref_store( |
| + new DictionaryPrefStore(&master_prefs)); |
| + CreatePrefHashFilter(pref_hash_store.Pass())->Initialize(*pref_store); |
| +} |
| + |
| } // namespace chrome_prefs |