Chromium Code Reviews| Index: chrome/browser/prefs/pref_value_map.cc |
| diff --git a/chrome/browser/prefs/pref_value_map.cc b/chrome/browser/prefs/pref_value_map.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4f819fed1ec2f4a1469b8006d541674ae21da190 |
| --- /dev/null |
| +++ b/chrome/browser/prefs/pref_value_map.cc |
| @@ -0,0 +1,56 @@ |
| +// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/prefs/pref_value_map.h" |
| + |
| +#include "base/logging.h" |
| +#include "base/scoped_ptr.h" |
| +#include "base/stl_util-inl.h" |
| +#include "base/values.h" |
| + |
| +PrefValueMap::~PrefValueMap() { |
| + Clear(); |
| +} |
| + |
| +bool PrefValueMap::GetValue(const std::string& key, Value** value) const { |
|
battre (please use the other)
2010/12/08 12:24:15
DCHECK(value)?
or: if value == NULL, don't write b
Mattias Nissler (ping if slow)
2010/12/09 10:20:20
Done.
|
| + Map::const_iterator entry = prefs_.find(key); |
|
danno
2010/12/08 13:08:45
const
Mattias Nissler (ping if slow)
2010/12/09 10:20:20
Done.
|
| + if (entry != prefs_.end()) { |
| + *value = entry->second; |
| + return true; |
| + } |
| + |
| + return false; |
| +} |
| + |
| +bool PrefValueMap::SetValue(const std::string& key, Value* value) { |
| + DCHECK(value); |
| + scoped_ptr<Value> value_ptr(value); |
| + Map::iterator entry = prefs_.find(key); |
|
danno
2010/12/08 13:08:45
const
Mattias Nissler (ping if slow)
2010/12/09 10:20:20
Done.
|
| + if (entry != prefs_.end()) { |
| + if (Value::Equals(entry->second, value)) |
| + return false; |
| + delete entry->second; |
| + entry->second = value_ptr.release(); |
| + } else { |
| + prefs_[key] = value_ptr.release(); |
| + } |
| + |
| + return true; |
| +} |
| + |
| +bool PrefValueMap::RemoveValue(const std::string& key) { |
| + Map::iterator entry = prefs_.find(key); |
|
danno
2010/12/08 13:08:45
const
Mattias Nissler (ping if slow)
2010/12/09 10:20:20
Done.
|
| + if (entry != prefs_.end()) { |
| + delete entry->second; |
| + prefs_.erase(entry); |
| + return true; |
| + } |
| + |
| + return false; |
| +} |
| + |
| +void PrefValueMap::Clear() { |
| + STLDeleteValues(&prefs_); |
| + prefs_.clear(); |
| +} |