Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Unified Diff: extensions/common/value_counter.h

Issue 1227093008: Clear an extension's filtered events when a context is destroyed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: valuecounter Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: extensions/common/value_counter.h
diff --git a/extensions/common/value_counter.h b/extensions/common/value_counter.h
index 948cd30e587784ff2c581329d1745a8f7d15d01c..2182748a7246acc0dae8f9721f8080baa61101bc 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 IsEmpty() const;
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);
};

Powered by Google App Engine
This is Rietveld 408576698