OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/prefs/pref_value_map.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/scoped_ptr.h" |
| 9 #include "base/stl_util-inl.h" |
| 10 #include "base/values.h" |
| 11 |
| 12 PrefValueMap::~PrefValueMap() { |
| 13 Clear(); |
| 14 } |
| 15 |
| 16 bool PrefValueMap::GetValue(const std::string& key, Value** value) const { |
| 17 const Map::const_iterator entry = prefs_.find(key); |
| 18 if (entry != prefs_.end()) { |
| 19 if (value) |
| 20 *value = entry->second; |
| 21 return true; |
| 22 } |
| 23 |
| 24 return false; |
| 25 } |
| 26 |
| 27 bool PrefValueMap::SetValue(const std::string& key, Value* value) { |
| 28 DCHECK(value); |
| 29 scoped_ptr<Value> value_ptr(value); |
| 30 const Map::iterator entry = prefs_.find(key); |
| 31 if (entry != prefs_.end()) { |
| 32 if (Value::Equals(entry->second, value)) |
| 33 return false; |
| 34 delete entry->second; |
| 35 entry->second = value_ptr.release(); |
| 36 } else { |
| 37 prefs_[key] = value_ptr.release(); |
| 38 } |
| 39 |
| 40 return true; |
| 41 } |
| 42 |
| 43 bool PrefValueMap::RemoveValue(const std::string& key) { |
| 44 const Map::iterator entry = prefs_.find(key); |
| 45 if (entry != prefs_.end()) { |
| 46 delete entry->second; |
| 47 prefs_.erase(entry); |
| 48 return true; |
| 49 } |
| 50 |
| 51 return false; |
| 52 } |
| 53 |
| 54 void PrefValueMap::Clear() { |
| 55 STLDeleteValues(&prefs_); |
| 56 prefs_.clear(); |
| 57 } |
OLD | NEW |