| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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_COMMON_PREF_STORE_H_ | |
| 6 #define CHROME_COMMON_PREF_STORE_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 | |
| 13 namespace base { | |
| 14 class Value; | |
| 15 } | |
| 16 | |
| 17 // This is an abstract interface for reading and writing from/to a persistent | |
| 18 // preference store, used by PrefService. An implementation using a JSON file | |
| 19 // can be found in JsonPrefStore, while an implementation without any backing | |
| 20 // store for testing can be found in TestingPrefStore. Furthermore, there is | |
| 21 // CommandLinePrefStore, which bridges command line options to preferences and | |
| 22 // ConfigurationPolicyPrefStore, which is used for hooking up configuration | |
| 23 // policy with the preference subsystem. | |
| 24 class PrefStore : public base::RefCounted<PrefStore> { | |
| 25 public: | |
| 26 // Observer interface for monitoring PrefStore. | |
| 27 class Observer { | |
| 28 public: | |
| 29 // Called when the value for the given |key| in the store changes. | |
| 30 virtual void OnPrefValueChanged(const std::string& key) = 0; | |
| 31 // Notification about the PrefStore being fully initialized. | |
| 32 virtual void OnInitializationCompleted(bool succeeded) = 0; | |
| 33 | |
| 34 protected: | |
| 35 virtual ~Observer() {} | |
| 36 }; | |
| 37 | |
| 38 // Return values for GetValue(). | |
| 39 enum ReadResult { | |
| 40 // Value found and returned. | |
| 41 READ_OK, | |
| 42 // No value present, but skip other pref stores and use default. | |
| 43 READ_USE_DEFAULT, | |
| 44 // No value present. | |
| 45 READ_NO_VALUE, | |
| 46 }; | |
| 47 | |
| 48 PrefStore() {} | |
| 49 | |
| 50 // Add and remove observers. | |
| 51 virtual void AddObserver(Observer* observer) {} | |
| 52 virtual void RemoveObserver(Observer* observer) {} | |
| 53 virtual size_t NumberOfObservers() const; | |
| 54 | |
| 55 // Whether the store has completed all asynchronous initialization. | |
| 56 virtual bool IsInitializationComplete() const; | |
| 57 | |
| 58 // Get the value for a given preference |key| and stores it in |*result|. | |
| 59 // |*result| is only modified if the return value is READ_OK and if |result| | |
| 60 // is not NULL. Ownership of the |*result| value remains with the PrefStore. | |
| 61 virtual ReadResult GetValue(const std::string& key, | |
| 62 const base::Value** result) const = 0; | |
| 63 | |
| 64 protected: | |
| 65 friend class base::RefCounted<PrefStore>; | |
| 66 virtual ~PrefStore() {} | |
| 67 | |
| 68 private: | |
| 69 DISALLOW_COPY_AND_ASSIGN(PrefStore); | |
| 70 }; | |
| 71 | |
| 72 #endif // CHROME_COMMON_PREF_STORE_H_ | |
| OLD | NEW |