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 #include "chrome/browser/prefs/pref_value_map.h" | 5 #include "chrome/browser/prefs/pref_value_map.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 return true; | 50 return true; |
51 } | 51 } |
52 | 52 |
53 return false; | 53 return false; |
54 } | 54 } |
55 | 55 |
56 void PrefValueMap::Clear() { | 56 void PrefValueMap::Clear() { |
57 STLDeleteValues(&prefs_); | 57 STLDeleteValues(&prefs_); |
58 prefs_.clear(); | 58 prefs_.clear(); |
59 } | 59 } |
| 60 |
| 61 bool PrefValueMap::GetBoolean(const std::string& key, |
| 62 bool* value) const { |
| 63 Value* stored_value = NULL; |
| 64 return GetValue(key, &stored_value) && stored_value->GetAsBoolean(value); |
| 65 } |
| 66 |
| 67 bool PrefValueMap::GetString(const std::string& key, |
| 68 std::string* value) const { |
| 69 Value* stored_value = NULL; |
| 70 return GetValue(key, &stored_value) && stored_value->GetAsString(value); |
| 71 } |
| 72 |
| 73 void PrefValueMap::SetString(const std::string& key, |
| 74 const std::string& value) { |
| 75 SetValue(key, Value::CreateStringValue(value)); |
| 76 } |
| 77 |
| 78 void PrefValueMap::GetDifferingKeys( |
| 79 const PrefValueMap* other, |
| 80 std::vector<std::string>* differing_keys) const { |
| 81 differing_keys->clear(); |
| 82 |
| 83 // Walk over the maps in lockstep, adding everything that is different. |
| 84 Map::const_iterator this_pref(prefs_.begin()); |
| 85 Map::const_iterator other_pref(other->prefs_.begin()); |
| 86 while (this_pref != prefs_.end() && other_pref != other->prefs_.end()) { |
| 87 const int diff = this_pref->first.compare(other_pref->first); |
| 88 if (diff == 0) { |
| 89 if (!this_pref->second->Equals(other_pref->second)) |
| 90 differing_keys->push_back(this_pref->first); |
| 91 ++this_pref; |
| 92 ++other_pref; |
| 93 } else if (diff < 0) { |
| 94 differing_keys->push_back(this_pref->first); |
| 95 ++this_pref; |
| 96 } else if (diff > 0) { |
| 97 differing_keys->push_back(other_pref->first); |
| 98 ++other_pref; |
| 99 } |
| 100 } |
| 101 |
| 102 // Add the remaining entries. |
| 103 for ( ; this_pref != prefs_.end(); ++this_pref) |
| 104 differing_keys->push_back(this_pref->first); |
| 105 for ( ; other_pref != other->prefs_.end(); ++other_pref) |
| 106 differing_keys->push_back(other_pref->first); |
| 107 } |
OLD | NEW |