Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_PREFS_TRACKED_PROTECTED_PREF_STORE_H_ | |
| 6 #define CHROME_BROWSER_PREFS_TRACKED_PROTECTED_PREF_STORE_H_ | |
| 7 | |
| 8 #include <set> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/callback.h" | |
| 12 #include "base/compiler_specific.h" | |
| 13 #include "base/macros.h" | |
| 14 #include "base/observer_list.h" | |
| 15 #include "base/prefs/persistent_pref_store.h" | |
| 16 #include "base/strings/string_piece.h" | |
| 17 #include "chrome/browser/prefs/pref_hash_filter.h" | |
| 18 | |
| 19 class PrefHashStore; | |
| 20 | |
| 21 | |
| 22 // Provides a unified PersistentPrefStore implementation that splits its storage | |
| 23 // and retrieval between two underlying PersistentPrefStore instances: one each | |
| 24 // for protected and unprotected preferences. | |
| 25 class ProtectedPrefStore : public PersistentPrefStore { | |
| 26 public: | |
| 27 // Creates an instance that delegates to |protected_pref_store| for the | |
| 28 // preferences named in |protected_pref_names| and to |unprotected_pref_store| | |
| 29 // for all others. If an unprotected preference is present in | |
| 30 // |protected_pref_store| (i.e. because it was previously protected) it will | |
| 31 // be migrated back to |unprotected_pref_store| upon access. | |
| 32 // |on_initialization| will be invoked when both stores have been initialized, | |
| 33 // before observers of the combined store are notified. | |
| 34 ProtectedPrefStore( | |
| 35 const scoped_refptr<PersistentPrefStore>& unprotected_pref_store, | |
| 36 const scoped_refptr<PersistentPrefStore>& protected_pref_store, | |
| 37 const std::set<std::string>& protected_pref_names, | |
| 38 const base::Closure& on_initialization); | |
| 39 | |
| 40 // PrefStore implementation | |
| 41 virtual void AddObserver(Observer* observer) OVERRIDE; | |
| 42 virtual void RemoveObserver(Observer* observer) OVERRIDE; | |
| 43 virtual bool HasObservers() const OVERRIDE; | |
| 44 virtual bool IsInitializationComplete() const OVERRIDE; | |
| 45 virtual bool GetValue(const std::string& key, | |
| 46 const base::Value** result) const OVERRIDE; | |
| 47 | |
| 48 // WriteablePrefStore implementation | |
| 49 virtual void SetValue(const std::string& key, base::Value* value) OVERRIDE; | |
| 50 virtual void RemoveValue(const std::string& key) OVERRIDE; | |
| 51 | |
| 52 // PersistentPrefStore implementation | |
| 53 virtual bool GetMutableValue(const std::string& key, | |
| 54 base::Value** result) OVERRIDE; | |
| 55 virtual void ReportValueChanged(const std::string& key) OVERRIDE; | |
| 56 virtual void SetValueSilently(const std::string& key, | |
| 57 base::Value* value) OVERRIDE; | |
| 58 virtual bool ReadOnly() const OVERRIDE; | |
| 59 virtual PrefReadError GetReadError() const OVERRIDE; | |
| 60 virtual PrefReadError ReadPrefs() OVERRIDE; | |
| 61 virtual void ReadPrefsAsync(ReadErrorDelegate* error_delegate) OVERRIDE; | |
| 62 virtual void CommitPendingWrite() OVERRIDE; | |
| 63 | |
| 64 private: | |
| 65 // Combines events from the underlying stores and reports them to the | |
| 66 // observers of the combined store. | |
|
robertshield
2014/03/25 03:05:12
Also document how this invokes the on_initializati
erikwright (departed)
2014/03/25 20:28:26
Done.
| |
| 67 class TeeObserver : public PrefStore::Observer { | |
|
robertshield
2014/03/25 03:05:12
Naming is hard. NotificationAggregator maybe? Mayb
erikwright (departed)
2014/03/25 20:28:26
In Unix there is a utility named tee that takes in
| |
| 68 public: | |
| 69 explicit TeeObserver(ProtectedPrefStore* outer); | |
|
robertshield
2014/03/25 03:05:12
Should pass just the |observers_| list and the |on
erikwright (departed)
2014/03/25 20:28:26
There are three members of the outer class that ar
erikwright (departed)
2014/03/25 20:41:11
Also, in the current patchset we now access outer_
| |
| 70 | |
| 71 // PrefStore::Observer implementation | |
| 72 virtual void OnPrefValueChanged(const std::string& key) OVERRIDE; | |
| 73 virtual void OnInitializationCompleted(bool succeeded) OVERRIDE; | |
| 74 | |
| 75 private: | |
| 76 ProtectedPrefStore* outer_; | |
| 77 uint8 failed_sub_initializations_; | |
| 78 uint8 successful_sub_initializations_; | |
| 79 | |
| 80 DISALLOW_COPY_AND_ASSIGN(TeeObserver); | |
| 81 }; | |
| 82 | |
| 83 virtual ~ProtectedPrefStore(); | |
| 84 | |
| 85 // Returns |protected_pref_store| if |key| is protected or a value is present | |
| 86 // in |protected_pref_store|. This could happen if |key| was previously | |
| 87 // protected. | |
| 88 const PersistentPrefStore* StoreForKey(const std::string& key) const; | |
| 89 | |
| 90 // Returns |protected_pref_store| if |key| is protected. If |key| is | |
| 91 // unprotected but has a value in |protected_pref_store|, moves the value to | |
| 92 // |unprotected_pref_store| before returning |unprotected_pref_store|. | |
| 93 PersistentPrefStore* StoreForKey(const std::string& key); | |
| 94 | |
| 95 scoped_refptr<PersistentPrefStore> unprotected_pref_store_; | |
| 96 scoped_refptr<PersistentPrefStore> protected_pref_store_; | |
| 97 std::set<std::string> protected_preference_names_; | |
| 98 base::Closure on_initialization_; | |
| 99 | |
| 100 ObserverList<PrefStore::Observer, true> observers_; | |
| 101 TeeObserver tee_observer_; | |
| 102 | |
| 103 DISALLOW_COPY_AND_ASSIGN(ProtectedPrefStore); | |
| 104 }; | |
| 105 | |
| 106 #endif // CHROME_BROWSER_PREFS_TRACKED_PROTECTED_PREF_STORE_H_ | |
| OLD | NEW |