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_PREF_VALUE_MAP_H_ | 5 #ifndef CHROME_BROWSER_PREFS_PREF_VALUE_MAP_H_ |
6 #define CHROME_BROWSER_PREFS_PREF_VALUE_MAP_H_ | 6 #define CHROME_BROWSER_PREFS_PREF_VALUE_MAP_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 | 13 |
14 class Value; | 14 class Value; |
15 | 15 |
16 // A generic string to value map used by the PrefStore implementations. | 16 // A generic string to value map used by the PrefStore implementations. |
17 class PrefValueMap { | 17 class PrefValueMap { |
18 public: | 18 public: |
19 PrefValueMap() {} | 19 PrefValueMap(); |
20 virtual ~PrefValueMap(); | 20 virtual ~PrefValueMap(); |
21 | 21 |
22 // Gets the value for |key| and stores it in |value|. Ownership remains with | 22 // Gets the value for |key| and stores it in |value|. Ownership remains with |
23 // the map. Returns true if a value is present. If not, |value| is not | 23 // the map. Returns true if a value is present. If not, |value| is not |
24 // touched. | 24 // touched. |
25 bool GetValue(const std::string& key, Value** value) const; | 25 bool GetValue(const std::string& key, Value** value) const; |
26 | 26 |
27 // Sets a new |value| for |key|. Takes ownership of |value|, which must be | 27 // Sets a new |value| for |key|. Takes ownership of |value|, which must be |
28 // non-NULL. Returns true if the value changed. | 28 // non-NULL. Returns true if the value changed. |
29 bool SetValue(const std::string& key, Value* value); | 29 bool SetValue(const std::string& key, Value* value); |
30 | 30 |
31 // Removes the value for |key| from the map. Returns true if a value was | 31 // Removes the value for |key| from the map. Returns true if a value was |
32 // removed. | 32 // removed. |
33 bool RemoveValue(const std::string& key); | 33 bool RemoveValue(const std::string& key); |
34 | 34 |
35 // Clears the map. | 35 // Clears the map. |
36 void Clear(); | 36 void Clear(); |
37 | 37 |
38 private: | 38 private: |
39 typedef std::map<std::string, Value*> Map; | 39 typedef std::map<std::string, Value*> Map; |
40 | 40 |
41 Map prefs_; | 41 Map prefs_; |
42 | 42 |
43 DISALLOW_COPY_AND_ASSIGN(PrefValueMap); | 43 DISALLOW_COPY_AND_ASSIGN(PrefValueMap); |
44 }; | 44 }; |
45 | 45 |
46 #endif // CHROME_BROWSER_PREFS_PREF_VALUE_MAP_H_ | 46 #endif // CHROME_BROWSER_PREFS_PREF_VALUE_MAP_H_ |
OLD | NEW |