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

Side by Side Diff: chrome/common/extensions/value_counter.h

Issue 10514013: Filtered events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix 80 char 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_COUNTER_H_
6 #define CHROME_COMMON_EXTENSIONS_VALUE_COUNTER_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
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 ValueCounter,
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 ValueCounter {
26 public:
27 ValueCounter();
28 ~ValueCounter();
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);
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 class Entry {
45 public:
46 explicit Entry(const base::Value& value);
47 ~Entry();
48
49 int Increment();
50 int Decrement();
51
52 const base::Value* value() const { return value_.get(); }
53 int count() const { return count_; }
54
55 linked_ptr<base::Value> value_;
battre 2012/06/20 09:50:46 please move private: before this line
koz (OOO until 15th September) 2012/06/21 02:23:11 Done.
56 int count_;
57
58 private:
59 DISALLOW_COPY_AND_ASSIGN(Entry);
60 };
61 typedef std::vector<linked_ptr<Entry> > EntryList;
62
63 int AddImpl(const base::Value& value, bool increment);
64
65 EntryList entries_;
66
67 DISALLOW_COPY_AND_ASSIGN(ValueCounter);
68 };
69
70 } // namespace extensions
71
72 #endif // CHROME_COMMON_EXTENSIONS_VALUE_COUNTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698