| 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 #ifndef BASE_PREFS_PREF_VALUE_MAP_H_ | 5 #ifndef BASE_PREFS_PREF_VALUE_MAP_H_ |
| 6 #define BASE_PREFS_PREF_VALUE_MAP_H_ | 6 #define BASE_PREFS_PREF_VALUE_MAP_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/containers/hash_tables.h" | 12 #include "base/containers/scoped_ptr_hash_map.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/prefs/base_prefs_export.h" | 14 #include "base/prefs/base_prefs_export.h" |
| 14 | 15 |
| 15 namespace base { | 16 namespace base { |
| 16 class Value; | 17 class Value; |
| 17 } | 18 } |
| 18 | 19 |
| 19 // A generic string to value map used by the PrefStore implementations. | 20 // A generic string to value map used by the PrefStore implementations. |
| 20 class BASE_PREFS_EXPORT PrefValueMap { | 21 class BASE_PREFS_EXPORT PrefValueMap { |
| 21 public: | 22 public: |
| 22 using Map = base::hash_map<std::string, base::Value*>; | 23 using Map = base::ScopedPtrHashMap<std::string, scoped_ptr<base::Value>>; |
| 23 using iterator = Map::iterator; | 24 using iterator = Map::iterator; |
| 24 using const_iterator = Map::const_iterator; | 25 using const_iterator = Map::const_iterator; |
| 25 | 26 |
| 26 PrefValueMap(); | 27 PrefValueMap(); |
| 27 virtual ~PrefValueMap(); | 28 virtual ~PrefValueMap(); |
| 28 | 29 |
| 29 // Gets the value for |key| and stores it in |value|. Ownership remains with | 30 // Gets the value for |key| and stores it in |value|. Ownership remains with |
| 30 // the map. Returns true if a value is present. If not, |value| is not | 31 // the map. Returns true if a value is present. If not, |value| is not |
| 31 // touched. | 32 // touched. |
| 32 bool GetValue(const std::string& key, const base::Value** value) const; | 33 bool GetValue(const std::string& key, const base::Value** value) const; |
| 33 bool GetValue(const std::string& key, base::Value** value); | 34 bool GetValue(const std::string& key, base::Value** value); |
| 34 | 35 |
| 35 // Sets a new |value| for |key|. Takes ownership of |value|, which must be | 36 // Sets a new |value| for |key|. |value| must be non-null. Returns true if the |
| 36 // non-NULL. Returns true if the value changed. | 37 // value changed. |
| 37 bool SetValue(const std::string& key, base::Value* value); | 38 bool SetValue(const std::string& key, scoped_ptr<base::Value> value); |
| 38 | 39 |
| 39 // Removes the value for |key| from the map. Returns true if a value was | 40 // Removes the value for |key| from the map. Returns true if a value was |
| 40 // removed. | 41 // removed. |
| 41 bool RemoveValue(const std::string& key); | 42 bool RemoveValue(const std::string& key); |
| 42 | 43 |
| 43 // Clears the map. | 44 // Clears the map. |
| 44 void Clear(); | 45 void Clear(); |
| 45 | 46 |
| 46 // Swaps the contents of two maps. | 47 // Swaps the contents of two maps. |
| 47 void Swap(PrefValueMap* other); | 48 void Swap(PrefValueMap* other); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 void GetDifferingKeys(const PrefValueMap* other, | 82 void GetDifferingKeys(const PrefValueMap* other, |
| 82 std::vector<std::string>* differing_keys) const; | 83 std::vector<std::string>* differing_keys) const; |
| 83 | 84 |
| 84 private: | 85 private: |
| 85 Map prefs_; | 86 Map prefs_; |
| 86 | 87 |
| 87 DISALLOW_COPY_AND_ASSIGN(PrefValueMap); | 88 DISALLOW_COPY_AND_ASSIGN(PrefValueMap); |
| 88 }; | 89 }; |
| 89 | 90 |
| 90 #endif // BASE_PREFS_PREF_VALUE_MAP_H_ | 91 #endif // BASE_PREFS_PREF_VALUE_MAP_H_ |
| OLD | NEW |