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

Unified Diff: chrome/common/extensions/value_set.h

Issue 10514013: Filtered events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add API permission check to filtered events :-| Created 8 years, 6 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: chrome/common/extensions/value_set.h
diff --git a/chrome/common/extensions/value_set.h b/chrome/common/extensions/value_set.h
new file mode 100644
index 0000000000000000000000000000000000000000..ca696e240b91d367d8e39b1034c80e309826a628
--- /dev/null
+++ b/chrome/common/extensions/value_set.h
@@ -0,0 +1,68 @@
+// 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.
+
+#ifndef CHROME_COMMON_EXTENSIONS_VALUE_SET_H_
+#define CHROME_COMMON_EXTENSIONS_VALUE_SET_H_
+#pragma once
+
+#include "base/memory/linked_ptr.h"
+
+#include <vector>
+
+namespace base {
+class Value;
+}
+
+namespace extensions {
+
+// Keeps a running count of Values, like map<Value, int>. Adding / removing
Aaron Boodman 2012/06/15 07:34:51 Nit: The use of the term 'map' in this description
koz (OOO until 15th September) 2012/06/18 23:27:27 Good point. How about ValueCounter?
+// values increments / decrements the count associated with a given Value.
+//
+// Add() and Remove() are linear in the number of Values in the ValueSet,
+// because there is no operator<() defined on Value, so we must iterate to find
+// whether a Value is equal to an existing one.
+class ValueSet {
Aaron Boodman 2012/06/15 07:34:51 I guess maybe this is technically a MultiSet?
koz (OOO until 15th September) 2012/06/18 23:27:27 This is true, but I think ValueCounter captures th
+ public:
+ ValueSet();
+ ~ValueSet();
+
+ // 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);
Aaron Boodman 2012/06/15 07:34:51 Chrome style would typically be to make this const
koz (OOO until 15th September) 2012/06/18 23:27:27 Done.
+
+ // Removes |value| from the set and returns how many equal values are in
+ // the set after.
+ int 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);
+
+ private:
+ struct Entry {
+ explicit Entry(const base::Value* value);
+ ~Entry();
+
+ int Increment();
+ int Decrement();
+
+ linked_ptr<base::Value> value;
+ int count;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Entry);
+ };
+ typedef std::vector<linked_ptr<Entry> > EntryList;
+
+ int AddImpl(const base::Value* value, bool increment);
+
+ EntryList entries_;
+
+ DISALLOW_COPY_AND_ASSIGN(ValueSet);
+};
+
+} // namespace extensions
+
+#endif // CHROME_COMMON_EXTENSIONS_VALUE_SET_H_

Powered by Google App Engine
This is Rietveld 408576698