| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/common/value_counter.h" | 5 #include "extensions/common/value_counter.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 ValueCounter::~ValueCounter() { | 27 ValueCounter::~ValueCounter() { |
| 28 } | 28 } |
| 29 | 29 |
| 30 bool ValueCounter::Add(const base::Value& value) { | 30 bool ValueCounter::Add(const base::Value& value) { |
| 31 for (const auto& entry : entries_) { | 31 for (const auto& entry : entries_) { |
| 32 if (entry->value->Equals(&value)) { | 32 if (entry->value->Equals(&value)) { |
| 33 ++entry->count; | 33 ++entry->count; |
| 34 return false; | 34 return false; |
| 35 } | 35 } |
| 36 } | 36 } |
| 37 entries_.push_back(base::WrapUnique(new Entry(value.CreateDeepCopy()))); | 37 entries_.push_back(base::MakeUnique<Entry>(value.CreateDeepCopy())); |
| 38 return true; | 38 return true; |
| 39 } | 39 } |
| 40 | 40 |
| 41 bool ValueCounter::Remove(const base::Value& value) { | 41 bool ValueCounter::Remove(const base::Value& value) { |
| 42 for (auto it = entries_.begin(); it != entries_.end(); ++it) { | 42 for (auto it = entries_.begin(); it != entries_.end(); ++it) { |
| 43 if ((*it)->value->Equals(&value)) { | 43 if ((*it)->value->Equals(&value)) { |
| 44 if (--(*it)->count == 0) { | 44 if (--(*it)->count == 0) { |
| 45 std::swap(*it, entries_.back()); | 45 std::swap(*it, entries_.back()); |
| 46 entries_.pop_back(); | 46 entries_.pop_back(); |
| 47 return true; // Removed the last entry. | 47 return true; // Removed the last entry. |
| 48 } | 48 } |
| 49 return false; // Removed, but no the last entry. | 49 return false; // Removed, but no the last entry. |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 return false; // Nothing to remove. | 52 return false; // Nothing to remove. |
| 53 } | 53 } |
| 54 | 54 |
| 55 } // namespace extensions | 55 } // namespace extensions |
| OLD | NEW |