| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef SERVICES_PREFERENCES_TRACKED_SEGREGATED_PREF_STORE_H_ | 5 #ifndef SERVICES_PREFERENCES_TRACKED_SEGREGATED_PREF_STORE_H_ |
| 6 #define SERVICES_PREFERENCES_TRACKED_SEGREGATED_PREF_STORE_H_ | 6 #define SERVICES_PREFERENCES_TRACKED_SEGREGATED_PREF_STORE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 18 #include "components/prefs/persistent_pref_store.h" | 18 #include "components/prefs/persistent_pref_store.h" |
| 19 #include "services/preferences/public/interfaces/tracked_preference_validation_d
elegate.mojom.h" | |
| 20 | 19 |
| 21 // Provides a unified PersistentPrefStore implementation that splits its storage | 20 // Provides a unified PersistentPrefStore implementation that splits its storage |
| 22 // and retrieval between two underlying PersistentPrefStore instances: a set of | 21 // and retrieval between two underlying PersistentPrefStore instances: a set of |
| 23 // preference names is used to partition the preferences. | 22 // preference names is used to partition the preferences. |
| 24 // | 23 // |
| 25 // Combines properties of the two stores as follows: | 24 // Combines properties of the two stores as follows: |
| 26 // * The unified read error will be: | 25 // * The unified read error will be: |
| 27 // Selected Store Error | 26 // Selected Store Error |
| 28 // Default Store Error | NO_ERROR | NO_FILE | other selected | | 27 // Default Store Error | NO_ERROR | NO_FILE | other selected | |
| 29 // NO_ERROR | NO_ERROR | NO_ERROR | other selected | | 28 // NO_ERROR | NO_ERROR | NO_ERROR | other selected | |
| 30 // NO_FILE | NO_FILE | NO_FILE | NO_FILE | | 29 // NO_FILE | NO_FILE | NO_FILE | NO_FILE | |
| 31 // other default | other default | other default | other default | | 30 // other default | other default | other default | other default | |
| 32 // * The unified initialization success, initialization completion, and | 31 // * The unified initialization success, initialization completion, and |
| 33 // read-only state are the boolean OR of the underlying stores' properties. | 32 // read-only state are the boolean OR of the underlying stores' properties. |
| 34 class SegregatedPrefStore : public PersistentPrefStore { | 33 class SegregatedPrefStore : public PersistentPrefStore { |
| 35 public: | 34 public: |
| 36 // Creates an instance that delegates to |selected_pref_store| for the | 35 // Creates an instance that delegates to |selected_pref_store| for the |
| 37 // preferences named in |selected_pref_names| and to |default_pref_store| | 36 // preferences named in |selected_pref_names| and to |default_pref_store| |
| 38 // for all others. If an unselected preference is present in | 37 // for all others. If an unselected preference is present in |
| 39 // |selected_pref_store| (i.e. because it was previously selected) it will | 38 // |selected_pref_store| (i.e. because it was previously selected) it will |
| 40 // be migrated back to |default_pref_store| upon access via a non-const | 39 // be migrated back to |default_pref_store| upon access via a non-const |
| 41 // method. | 40 // method. |
| 42 // |on_initialization| will be invoked when both stores have been initialized, | 41 // |on_initialization| will be invoked when both stores have been initialized, |
| 43 // before observers of the SegregatedPrefStore store are notified. | 42 // before observers of the SegregatedPrefStore store are notified. |
| 44 SegregatedPrefStore( | 43 SegregatedPrefStore( |
| 45 const scoped_refptr<PersistentPrefStore>& default_pref_store, | 44 const scoped_refptr<PersistentPrefStore>& default_pref_store, |
| 46 const scoped_refptr<PersistentPrefStore>& selected_pref_store, | 45 const scoped_refptr<PersistentPrefStore>& selected_pref_store, |
| 47 const std::set<std::string>& selected_pref_names, | 46 const std::set<std::string>& selected_pref_names); |
| 48 prefs::mojom::TrackedPreferenceValidationDelegatePtr validation_delegate); | |
| 49 | 47 |
| 50 // PrefStore implementation | 48 // PrefStore implementation |
| 51 void AddObserver(Observer* observer) override; | 49 void AddObserver(Observer* observer) override; |
| 52 void RemoveObserver(Observer* observer) override; | 50 void RemoveObserver(Observer* observer) override; |
| 53 bool HasObservers() const override; | 51 bool HasObservers() const override; |
| 54 bool IsInitializationComplete() const override; | 52 bool IsInitializationComplete() const override; |
| 55 bool GetValue(const std::string& key, | 53 bool GetValue(const std::string& key, |
| 56 const base::Value** result) const override; | 54 const base::Value** result) const override; |
| 57 std::unique_ptr<base::DictionaryValue> GetValues() const override; | 55 std::unique_ptr<base::DictionaryValue> GetValues() const override; |
| 58 | 56 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 DISALLOW_COPY_AND_ASSIGN(AggregatingObserver); | 94 DISALLOW_COPY_AND_ASSIGN(AggregatingObserver); |
| 97 }; | 95 }; |
| 98 | 96 |
| 99 ~SegregatedPrefStore() override; | 97 ~SegregatedPrefStore() override; |
| 100 | 98 |
| 101 // Returns |selected_pref_store| if |key| is selected and |default_pref_store| | 99 // Returns |selected_pref_store| if |key| is selected and |default_pref_store| |
| 102 // otherwise. | 100 // otherwise. |
| 103 PersistentPrefStore* StoreForKey(const std::string& key); | 101 PersistentPrefStore* StoreForKey(const std::string& key); |
| 104 const PersistentPrefStore* StoreForKey(const std::string& key) const; | 102 const PersistentPrefStore* StoreForKey(const std::string& key) const; |
| 105 | 103 |
| 106 // |validation_delegate_| is used by |default_pref_store_| and | |
| 107 // |selected_pref_store_| PrefHashFilters. Its lifetime is managed here since | |
| 108 // a single owner is required. | |
| 109 prefs::mojom::TrackedPreferenceValidationDelegatePtr validation_delegate_; | |
| 110 | |
| 111 scoped_refptr<PersistentPrefStore> default_pref_store_; | 104 scoped_refptr<PersistentPrefStore> default_pref_store_; |
| 112 scoped_refptr<PersistentPrefStore> selected_pref_store_; | 105 scoped_refptr<PersistentPrefStore> selected_pref_store_; |
| 113 std::set<std::string> selected_preference_names_; | 106 std::set<std::string> selected_preference_names_; |
| 114 | 107 |
| 115 std::unique_ptr<PersistentPrefStore::ReadErrorDelegate> read_error_delegate_; | 108 std::unique_ptr<PersistentPrefStore::ReadErrorDelegate> read_error_delegate_; |
| 116 base::ObserverList<PrefStore::Observer, true> observers_; | 109 base::ObserverList<PrefStore::Observer, true> observers_; |
| 117 AggregatingObserver aggregating_observer_; | 110 AggregatingObserver aggregating_observer_; |
| 118 | 111 |
| 119 DISALLOW_COPY_AND_ASSIGN(SegregatedPrefStore); | 112 DISALLOW_COPY_AND_ASSIGN(SegregatedPrefStore); |
| 120 }; | 113 }; |
| 121 | 114 |
| 122 #endif // SERVICES_PREFERENCES_TRACKED_SEGREGATED_PREF_STORE_H_ | 115 #endif // SERVICES_PREFERENCES_TRACKED_SEGREGATED_PREF_STORE_H_ |
| OLD | NEW |