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" |
19 | 20 |
20 // Provides a unified PersistentPrefStore implementation that splits its storage | 21 // Provides a unified PersistentPrefStore implementation that splits its storage |
21 // and retrieval between two underlying PersistentPrefStore instances: a set of | 22 // and retrieval between two underlying PersistentPrefStore instances: a set of |
22 // preference names is used to partition the preferences. | 23 // preference names is used to partition the preferences. |
23 // | 24 // |
24 // Combines properties of the two stores as follows: | 25 // Combines properties of the two stores as follows: |
25 // * The unified read error will be: | 26 // * The unified read error will be: |
26 // Selected Store Error | 27 // Selected Store Error |
27 // Default Store Error | NO_ERROR | NO_FILE | other selected | | 28 // Default Store Error | NO_ERROR | NO_FILE | other selected | |
28 // NO_ERROR | NO_ERROR | NO_ERROR | other selected | | 29 // NO_ERROR | NO_ERROR | NO_ERROR | other selected | |
29 // NO_FILE | NO_FILE | NO_FILE | NO_FILE | | 30 // NO_FILE | NO_FILE | NO_FILE | NO_FILE | |
30 // other default | other default | other default | other default | | 31 // other default | other default | other default | other default | |
31 // * The unified initialization success, initialization completion, and | 32 // * The unified initialization success, initialization completion, and |
32 // read-only state are the boolean OR of the underlying stores' properties. | 33 // read-only state are the boolean OR of the underlying stores' properties. |
33 class SegregatedPrefStore : public PersistentPrefStore { | 34 class SegregatedPrefStore : public PersistentPrefStore { |
34 public: | 35 public: |
35 // Creates an instance that delegates to |selected_pref_store| for the | 36 // Creates an instance that delegates to |selected_pref_store| for the |
36 // preferences named in |selected_pref_names| and to |default_pref_store| | 37 // preferences named in |selected_pref_names| and to |default_pref_store| |
37 // for all others. If an unselected preference is present in | 38 // for all others. If an unselected preference is present in |
38 // |selected_pref_store| (i.e. because it was previously selected) it will | 39 // |selected_pref_store| (i.e. because it was previously selected) it will |
39 // be migrated back to |default_pref_store| upon access via a non-const | 40 // be migrated back to |default_pref_store| upon access via a non-const |
40 // method. | 41 // method. |
41 // |on_initialization| will be invoked when both stores have been initialized, | 42 // |on_initialization| will be invoked when both stores have been initialized, |
42 // before observers of the SegregatedPrefStore store are notified. | 43 // before observers of the SegregatedPrefStore store are notified. |
43 SegregatedPrefStore( | 44 SegregatedPrefStore( |
44 const scoped_refptr<PersistentPrefStore>& default_pref_store, | 45 const scoped_refptr<PersistentPrefStore>& default_pref_store, |
45 const scoped_refptr<PersistentPrefStore>& selected_pref_store, | 46 const scoped_refptr<PersistentPrefStore>& selected_pref_store, |
46 const std::set<std::string>& selected_pref_names); | 47 const std::set<std::string>& selected_pref_names, |
| 48 prefs::mojom::TrackedPreferenceValidationDelegatePtr validation_delegate); |
47 | 49 |
48 // PrefStore implementation | 50 // PrefStore implementation |
49 void AddObserver(Observer* observer) override; | 51 void AddObserver(Observer* observer) override; |
50 void RemoveObserver(Observer* observer) override; | 52 void RemoveObserver(Observer* observer) override; |
51 bool HasObservers() const override; | 53 bool HasObservers() const override; |
52 bool IsInitializationComplete() const override; | 54 bool IsInitializationComplete() const override; |
53 bool GetValue(const std::string& key, | 55 bool GetValue(const std::string& key, |
54 const base::Value** result) const override; | 56 const base::Value** result) const override; |
55 std::unique_ptr<base::DictionaryValue> GetValues() const override; | 57 std::unique_ptr<base::DictionaryValue> GetValues() const override; |
56 | 58 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 DISALLOW_COPY_AND_ASSIGN(AggregatingObserver); | 96 DISALLOW_COPY_AND_ASSIGN(AggregatingObserver); |
95 }; | 97 }; |
96 | 98 |
97 ~SegregatedPrefStore() override; | 99 ~SegregatedPrefStore() override; |
98 | 100 |
99 // Returns |selected_pref_store| if |key| is selected and |default_pref_store| | 101 // Returns |selected_pref_store| if |key| is selected and |default_pref_store| |
100 // otherwise. | 102 // otherwise. |
101 PersistentPrefStore* StoreForKey(const std::string& key); | 103 PersistentPrefStore* StoreForKey(const std::string& key); |
102 const PersistentPrefStore* StoreForKey(const std::string& key) const; | 104 const PersistentPrefStore* StoreForKey(const std::string& key) const; |
103 | 105 |
| 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 |
104 scoped_refptr<PersistentPrefStore> default_pref_store_; | 111 scoped_refptr<PersistentPrefStore> default_pref_store_; |
105 scoped_refptr<PersistentPrefStore> selected_pref_store_; | 112 scoped_refptr<PersistentPrefStore> selected_pref_store_; |
106 std::set<std::string> selected_preference_names_; | 113 std::set<std::string> selected_preference_names_; |
107 | 114 |
108 std::unique_ptr<PersistentPrefStore::ReadErrorDelegate> read_error_delegate_; | 115 std::unique_ptr<PersistentPrefStore::ReadErrorDelegate> read_error_delegate_; |
109 base::ObserverList<PrefStore::Observer, true> observers_; | 116 base::ObserverList<PrefStore::Observer, true> observers_; |
110 AggregatingObserver aggregating_observer_; | 117 AggregatingObserver aggregating_observer_; |
111 | 118 |
112 DISALLOW_COPY_AND_ASSIGN(SegregatedPrefStore); | 119 DISALLOW_COPY_AND_ASSIGN(SegregatedPrefStore); |
113 }; | 120 }; |
114 | 121 |
115 #endif // SERVICES_PREFERENCES_TRACKED_SEGREGATED_PREF_STORE_H_ | 122 #endif // SERVICES_PREFERENCES_TRACKED_SEGREGATED_PREF_STORE_H_ |
OLD | NEW |