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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_COMMON_EXTENSIONS_VALUE_SET_H_
6 #define CHROME_COMMON_EXTENSIONS_VALUE_SET_H_
7 #pragma once
8
9 #include "base/memory/linked_ptr.h"
10
11 #include <vector>
12
13 namespace base {
14 class Value;
15 }
16
17 namespace extensions {
18
19 // 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?
20 // values increments / decrements the count associated with a given Value.
21 //
22 // Add() and Remove() are linear in the number of Values in the ValueSet,
23 // because there is no operator<() defined on Value, so we must iterate to find
24 // whether a Value is equal to an existing one.
25 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
26 public:
27 ValueSet();
28 ~ValueSet();
29
30 // Adds |value| to the set and returns how many equal values are in the set
31 // after. Does not take ownership of |value|. In the case where a Value equal
32 // to |value| doesn't already exist in this map, this function makes a
33 // DeepCopy() of |value|.
34 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.
35
36 // Removes |value| from the set and returns how many equal values are in
37 // the set after.
38 int Remove(const base::Value* value);
39
40 // Same as Add() but only performs the add if the value isn't present.
41 int AddIfMissing(const base::Value* value);
42
43 private:
44 struct Entry {
45 explicit Entry(const base::Value* value);
46 ~Entry();
47
48 int Increment();
49 int Decrement();
50
51 linked_ptr<base::Value> value;
52 int count;
53
54 private:
55 DISALLOW_COPY_AND_ASSIGN(Entry);
56 };
57 typedef std::vector<linked_ptr<Entry> > EntryList;
58
59 int AddImpl(const base::Value* value, bool increment);
60
61 EntryList entries_;
62
63 DISALLOW_COPY_AND_ASSIGN(ValueSet);
64 };
65
66 } // namespace extensions
67
68 #endif // CHROME_COMMON_EXTENSIONS_VALUE_SET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698