| Index: chrome/common/extensions/value_set.cc
|
| diff --git a/chrome/common/extensions/value_set.cc b/chrome/common/extensions/value_set.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..6a6c6ebcfe8e5045a736c66ca8f30bb7bb4ae548
|
| --- /dev/null
|
| +++ b/chrome/common/extensions/value_set.cc
|
| @@ -0,0 +1,64 @@
|
| +// Copyright (c) 2012 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/common/extensions/value_set.h"
|
| +
|
| +#include "base/values.h"
|
| +
|
| +namespace extensions {
|
| +
|
| +ValueSet::ValueSet() {
|
| +}
|
| +
|
| +ValueSet::~ValueSet() {
|
| +}
|
| +
|
| +ValueSet::Entry::Entry(const base::Value* value)
|
| + : value(value->DeepCopy()),
|
| + count(1) {
|
| +}
|
| +
|
| +ValueSet::Entry::~Entry() {
|
| +}
|
| +
|
| +int ValueSet::Entry::Increment() {
|
| + return ++count;
|
| +}
|
| +
|
| +int ValueSet::Entry::Decrement() {
|
| + return --count;
|
| +}
|
| +
|
| +int ValueSet::Add(const base::Value* value) {
|
| + return AddImpl(value, true);
|
| +}
|
| +
|
| +int ValueSet::Remove(const base::Value* value) {
|
| + for (EntryList::iterator it = entries_.begin(); it != entries_.end(); it++) {
|
| + (*it)->value->GetType();
|
| + if ((*it)->value->Equals(value)) {
|
| + int remaining = --(*it)->count;
|
| + if (remaining == 0) {
|
| + entries_.erase(it);
|
| + }
|
| + return remaining;
|
| + }
|
| + }
|
| + return 0;
|
| +}
|
| +
|
| +int ValueSet::AddIfMissing(const base::Value* value) {
|
| + return AddImpl(value, false);
|
| +}
|
| +
|
| +int ValueSet::AddImpl(const base::Value* value, bool increment) {
|
| + for (EntryList::iterator it = entries_.begin(); it != entries_.end(); it++) {
|
| + if ((*it)->value->Equals(value))
|
| + return increment ? (*it)->Increment() : (*it)->count;
|
| + }
|
| + entries_.push_back(linked_ptr<Entry>(new Entry(value->DeepCopy())));
|
| + return 1;
|
| +}
|
| +
|
| +} // namespace extensions
|
|
|