[email protected] | d3b05ea | 2012-01-24 22:57:05 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 03b9b4e | 2012-10-22 20:01:52 | [diff] [blame] | 5 | #ifndef BASE_PREFS_PREF_STORE_H_ |
6 | #define BASE_PREFS_PREF_STORE_H_ | ||||
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 7 | |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 8 | #include <string> |
9 | |||||
10 | #include "base/basictypes.h" | ||||
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 11 | #include "base/memory/ref_counted.h" |
[email protected] | f59f33e | 2012-11-01 12:05:27 | [diff] [blame] | 12 | #include "base/prefs/base_prefs_export.h" |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 13 | |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 14 | namespace base { |
[email protected] | ce1850e9 | 2010-10-15 08:40:58 | [diff] [blame] | 15 | class Value; |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 16 | } |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 17 | |
18 | // This is an abstract interface for reading and writing from/to a persistent | ||||
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 19 | // preference store, used by PrefService. An implementation using a JSON file |
20 | // can be found in JsonPrefStore, while an implementation without any backing | ||||
21 | // store for testing can be found in TestingPrefStore. Furthermore, there is | ||||
22 | // CommandLinePrefStore, which bridges command line options to preferences and | ||||
23 | // ConfigurationPolicyPrefStore, which is used for hooking up configuration | ||||
24 | // policy with the preference subsystem. | ||||
[email protected] | f59f33e | 2012-11-01 12:05:27 | [diff] [blame] | 25 | class BASE_PREFS_EXPORT PrefStore : public base::RefCounted<PrefStore> { |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 26 | public: |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 27 | // Observer interface for monitoring PrefStore. |
[email protected] | f59f33e | 2012-11-01 12:05:27 | [diff] [blame] | 28 | class BASE_PREFS_EXPORT Observer { |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 29 | public: |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 30 | // Called when the value for the given |key| in the store changes. |
31 | virtual void OnPrefValueChanged(const std::string& key) = 0; | ||||
32 | // Notification about the PrefStore being fully initialized. | ||||
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 33 | virtual void OnInitializationCompleted(bool succeeded) = 0; |
[email protected] | 512d03f | 2012-06-26 01:06:06 | [diff] [blame] | 34 | |
35 | protected: | ||||
36 | virtual ~Observer() {} | ||||
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 37 | }; |
38 | |||||
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 39 | PrefStore() {} |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 40 | |
41 | // Add and remove observers. | ||||
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 42 | virtual void AddObserver(Observer* observer) {} |
43 | virtual void RemoveObserver(Observer* observer) {} | ||||
[email protected] | 14e0ec6 | 2013-08-26 22:01:39 | [diff] [blame] | 44 | virtual bool HasObservers() const; |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 45 | |
46 | // Whether the store has completed all asynchronous initialization. | ||||
[email protected] | 0f1afed | 2010-12-15 17:22:28 | [diff] [blame] | 47 | virtual bool IsInitializationComplete() const; |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 48 | |
[email protected] | a78e948 | 2011-07-14 19:22:29 | [diff] [blame] | 49 | // Get the value for a given preference |key| and stores it in |*result|. |
[email protected] | 892f1d6 | 2012-11-08 18:24:34 | [diff] [blame] | 50 | // |*result| is only modified if the return value is true and if |result| |
[email protected] | a78e948 | 2011-07-14 19:22:29 | [diff] [blame] | 51 | // is not NULL. Ownership of the |*result| value remains with the PrefStore. |
[email protected] | 892f1d6 | 2012-11-08 18:24:34 | [diff] [blame] | 52 | virtual bool GetValue(const std::string& key, |
53 | const base::Value** result) const = 0; | ||||
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 54 | |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 55 | protected: |
56 | friend class base::RefCounted<PrefStore>; | ||||
57 | virtual ~PrefStore() {} | ||||
58 | |||||
59 | private: | ||||
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 60 | DISALLOW_COPY_AND_ASSIGN(PrefStore); |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 61 | }; |
62 | |||||
[email protected] | 03b9b4e | 2012-10-22 20:01:52 | [diff] [blame] | 63 | #endif // BASE_PREFS_PREF_STORE_H_ |