Index: extensions/common/value_counter.h |
diff --git a/extensions/common/value_counter.h b/extensions/common/value_counter.h |
index 948cd30e587784ff2c581329d1745a8f7d15d01c..03f7907f8353caf964f70694c1bfb1c8e7e35ef6 100644 |
--- a/extensions/common/value_counter.h |
+++ b/extensions/common/value_counter.h |
@@ -5,9 +5,7 @@ |
#ifndef EXTENSIONS_COMMON_VALUE_COUNTER_H_ |
#define EXTENSIONS_COMMON_VALUE_COUNTER_H_ |
-#include <vector> |
- |
-#include "base/memory/linked_ptr.h" |
+#include "base/memory/scoped_vector.h" |
namespace base { |
class Value; |
@@ -15,8 +13,8 @@ class Value; |
namespace extensions { |
-// Keeps a running count of Values, like map<Value, int>. Adding / removing |
-// values increments / decrements the count associated with a given Value. |
+// Keeps a running count of Values, like map<Value, int>. Adding/removing |
+// values increments/decrements the count associated with a given Value. |
// |
// Add() and Remove() are linear in the number of Values in the ValueCounter, |
// because there is no operator<() defined on Value, so we must iterate to find |
@@ -26,42 +24,22 @@ class ValueCounter { |
ValueCounter(); |
~ValueCounter(); |
- // Adds |value| to the set and returns how many equal values are in the set |
- // after. Does not take ownership of |value|. In the case where a Value equal |
- // to |value| doesn't already exist in this map, this function makes a |
- // DeepCopy() of |value|. |
- int Add(const base::Value& value); |
+ // Adds |value| to the set. In the case where a Value equal to |value| |
+ // doesn't already exist in this map, this function makes a copy of |value| |
+ // and returns true. Otherwise, it returns false. |
+ bool Add(const base::Value& value); |
- // Removes |value| from the set and returns how many equal values are in |
- // the set after. |
- int Remove(const base::Value& value); |
+ // Removes |value| from the set, and returns true if it removed the last |
+ // value equal to |value|. If there are more equal values, or if there |
+ // weren't any in the first place, returns false. |
+ bool Remove(const base::Value& value); |
- // Same as Add() but only performs the add if the value isn't present. |
- int AddIfMissing(const base::Value& value); |
+ // Returns true if there are no values of any type being counted. |
+ bool is_empty() const { return entries_.empty(); } |
private: |
- class Entry { |
- public: |
- explicit Entry(const base::Value& value); |
- ~Entry(); |
- |
- int Increment(); |
- int Decrement(); |
- |
- const base::Value* value() const { return value_.get(); } |
- int count() const { return count_; } |
- |
- private: |
- linked_ptr<base::Value> value_; |
- int count_; |
- |
- DISALLOW_COPY_AND_ASSIGN(Entry); |
- }; |
- typedef std::vector<linked_ptr<Entry> > EntryList; |
- |
- int AddImpl(const base::Value& value, bool increment); |
- |
- EntryList entries_; |
+ struct Entry; |
+ ScopedVector<Entry> entries_; |
DISALLOW_COPY_AND_ASSIGN(ValueCounter); |
}; |