OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // TODO(brettw) remove this forwarding header when prefs is completely moved to | 5 #ifndef BASE_PREFS_PREF_VALUE_MAP_H_ |
6 // components. | 6 #define BASE_PREFS_PREF_VALUE_MAP_H_ |
7 #include "components/prefs/pref_value_map.h" | 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/containers/scoped_ptr_hash_map.h" |
| 12 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/prefs/base_prefs_export.h" |
| 15 |
| 16 namespace base { |
| 17 class Value; |
| 18 } |
| 19 |
| 20 // A generic string to value map used by the PrefStore implementations. |
| 21 class BASE_PREFS_EXPORT PrefValueMap { |
| 22 public: |
| 23 using Map = base::ScopedPtrHashMap<std::string, scoped_ptr<base::Value>>; |
| 24 using iterator = Map::iterator; |
| 25 using const_iterator = Map::const_iterator; |
| 26 |
| 27 PrefValueMap(); |
| 28 virtual ~PrefValueMap(); |
| 29 |
| 30 // Gets the value for |key| and stores it in |value|. Ownership remains with |
| 31 // the map. Returns true if a value is present. If not, |value| is not |
| 32 // touched. |
| 33 bool GetValue(const std::string& key, const base::Value** value) const; |
| 34 bool GetValue(const std::string& key, base::Value** value); |
| 35 |
| 36 // Sets a new |value| for |key|. |value| must be non-null. Returns true if the |
| 37 // value changed. |
| 38 bool SetValue(const std::string& key, scoped_ptr<base::Value> value); |
| 39 |
| 40 // Removes the value for |key| from the map. Returns true if a value was |
| 41 // removed. |
| 42 bool RemoveValue(const std::string& key); |
| 43 |
| 44 // Clears the map. |
| 45 void Clear(); |
| 46 |
| 47 // Swaps the contents of two maps. |
| 48 void Swap(PrefValueMap* other); |
| 49 |
| 50 iterator begin(); |
| 51 iterator end(); |
| 52 const_iterator begin() const; |
| 53 const_iterator end() const; |
| 54 |
| 55 // Gets a boolean value for |key| and stores it in |value|. Returns true if |
| 56 // the value was found and of the proper type. |
| 57 bool GetBoolean(const std::string& key, bool* value) const; |
| 58 |
| 59 // Sets the value for |key| to the boolean |value|. |
| 60 void SetBoolean(const std::string& key, bool value); |
| 61 |
| 62 // Gets a string value for |key| and stores it in |value|. Returns true if |
| 63 // the value was found and of the proper type. |
| 64 bool GetString(const std::string& key, std::string* value) const; |
| 65 |
| 66 // Sets the value for |key| to the string |value|. |
| 67 void SetString(const std::string& key, const std::string& value); |
| 68 |
| 69 // Gets an int value for |key| and stores it in |value|. Returns true if |
| 70 // the value was found and of the proper type. |
| 71 bool GetInteger(const std::string& key, int* value) const; |
| 72 |
| 73 // Sets the value for |key| to the int |value|. |
| 74 void SetInteger(const std::string& key, const int value); |
| 75 |
| 76 // Sets the value for |key| to the double |value|. |
| 77 void SetDouble(const std::string& key, const double value); |
| 78 |
| 79 // Compares this value map against |other| and stores all key names that have |
| 80 // different values in |differing_keys|. This includes keys that are present |
| 81 // only in one of the maps. |
| 82 void GetDifferingKeys(const PrefValueMap* other, |
| 83 std::vector<std::string>* differing_keys) const; |
| 84 |
| 85 private: |
| 86 Map prefs_; |
| 87 |
| 88 DISALLOW_COPY_AND_ASSIGN(PrefValueMap); |
| 89 }; |
| 90 |
| 91 #endif // BASE_PREFS_PREF_VALUE_MAP_H_ |
OLD | NEW |