OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 CHROME_BROWSER_PREFS_VALUE_MAP_PREF_STORE_H_ | 5 #ifndef CHROME_BROWSER_PREFS_VALUE_MAP_PREF_STORE_H_ |
6 #define CHROME_BROWSER_PREFS_VALUE_MAP_PREF_STORE_H_ | 6 #define CHROME_BROWSER_PREFS_VALUE_MAP_PREF_STORE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
13 #include "chrome/browser/prefs/pref_value_map.h" | 13 #include "chrome/browser/prefs/pref_value_map.h" |
14 #include "chrome/common/pref_store.h" | 14 #include "chrome/common/pref_store.h" |
15 | 15 |
16 // A basic PrefStore implementation that uses a simple name-value map for | 16 // A basic PrefStore implementation that uses a simple name-value map for |
17 // storing the preference values. | 17 // storing the preference values. |
18 class ValueMapPrefStore : public PrefStore { | 18 class ValueMapPrefStore : public PrefStore { |
19 public: | 19 public: |
20 ValueMapPrefStore() {} | 20 ValueMapPrefStore(); |
21 virtual ~ValueMapPrefStore() {} | 21 virtual ~ValueMapPrefStore(); |
22 | 22 |
23 // PrefStore overrides: | 23 // PrefStore overrides: |
24 virtual ReadResult GetValue(const std::string& key, Value** value) const; | 24 virtual ReadResult GetValue(const std::string& key, Value** value) const; |
25 virtual void AddObserver(PrefStore::Observer* observer); | 25 virtual void AddObserver(PrefStore::Observer* observer); |
26 virtual void RemoveObserver(PrefStore::Observer* observer); | 26 virtual void RemoveObserver(PrefStore::Observer* observer); |
27 | 27 |
28 protected: | 28 protected: |
29 // Store a |value| for |key| in the store. Also generates an notification if | 29 // Store a |value| for |key| in the store. Also generates an notification if |
30 // the value changed. Assumes ownership of |value|, which must be non-NULL. | 30 // the value changed. Assumes ownership of |value|, which must be non-NULL. |
31 void SetValue(const std::string& key, Value* value); | 31 void SetValue(const std::string& key, Value* value); |
32 | 32 |
33 // Remove the value for |key| from the store. Sends a notification if there | 33 // Remove the value for |key| from the store. Sends a notification if there |
34 // was a value to be removed. | 34 // was a value to be removed. |
35 void RemoveValue(const std::string& key); | 35 void RemoveValue(const std::string& key); |
36 | 36 |
37 // Notify observers about the initialization completed event. | 37 // Notify observers about the initialization completed event. |
38 void NotifyInitializationCompleted(); | 38 void NotifyInitializationCompleted(); |
39 | 39 |
40 private: | 40 private: |
41 PrefValueMap prefs_; | 41 PrefValueMap prefs_; |
42 | 42 |
43 ObserverList<PrefStore::Observer, true> observers_; | 43 ObserverList<PrefStore::Observer, true> observers_; |
44 | 44 |
45 DISALLOW_COPY_AND_ASSIGN(ValueMapPrefStore); | 45 DISALLOW_COPY_AND_ASSIGN(ValueMapPrefStore); |
46 }; | 46 }; |
47 | 47 |
48 #endif // CHROME_BROWSER_PREFS_VALUE_MAP_PREF_STORE_H_ | 48 #endif // CHROME_BROWSER_PREFS_VALUE_MAP_PREF_STORE_H_ |
OLD | NEW |