OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef EXTENSIONS_COMMON_EVENT_FILTER_H_ | 5 #ifndef EXTENSIONS_COMMON_EVENT_FILTER_H_ |
6 #define EXTENSIONS_COMMON_EVENT_FILTER_H_ | 6 #define EXTENSIONS_COMMON_EVENT_FILTER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 // passed a matching event. | 21 // passed a matching event. |
22 class EventFilter { | 22 class EventFilter { |
23 public: | 23 public: |
24 typedef int MatcherID; | 24 typedef int MatcherID; |
25 EventFilter(); | 25 EventFilter(); |
26 ~EventFilter(); | 26 ~EventFilter(); |
27 | 27 |
28 // Adds an event matcher that will be used in calls to MatchEvent(). Returns | 28 // Adds an event matcher that will be used in calls to MatchEvent(). Returns |
29 // the id of the matcher, or -1 if there was an error. | 29 // the id of the matcher, or -1 if there was an error. |
30 MatcherID AddEventMatcher(const std::string& event_name, | 30 MatcherID AddEventMatcher(const std::string& event_name, |
31 scoped_ptr<EventMatcher> matcher); | 31 std::unique_ptr<EventMatcher> matcher); |
32 | 32 |
33 // Retrieve the EventMatcher with the given id. | 33 // Retrieve the EventMatcher with the given id. |
34 EventMatcher* GetEventMatcher(MatcherID id); | 34 EventMatcher* GetEventMatcher(MatcherID id); |
35 | 35 |
36 // Retrieve the name of the event that the EventMatcher specified by |id| is | 36 // Retrieve the name of the event that the EventMatcher specified by |id| is |
37 // referring to. | 37 // referring to. |
38 const std::string& GetEventName(MatcherID id); | 38 const std::string& GetEventName(MatcherID id); |
39 | 39 |
40 // Removes an event matcher, returning the name of the event that it was for. | 40 // Removes an event matcher, returning the name of the event that it was for. |
41 std::string RemoveEventMatcher(MatcherID id); | 41 std::string RemoveEventMatcher(MatcherID id); |
(...skipping 14 matching lines...) Expand all Loading... |
56 } | 56 } |
57 | 57 |
58 private: | 58 private: |
59 class EventMatcherEntry { | 59 class EventMatcherEntry { |
60 public: | 60 public: |
61 // Adds |condition_sets| to |url_matcher| on construction and removes them | 61 // Adds |condition_sets| to |url_matcher| on construction and removes them |
62 // again on destruction. |condition_sets| should be the | 62 // again on destruction. |condition_sets| should be the |
63 // URLMatcherConditionSets that match the URL constraints specified by | 63 // URLMatcherConditionSets that match the URL constraints specified by |
64 // |event_matcher|. | 64 // |event_matcher|. |
65 EventMatcherEntry( | 65 EventMatcherEntry( |
66 scoped_ptr<EventMatcher> event_matcher, | 66 std::unique_ptr<EventMatcher> event_matcher, |
67 url_matcher::URLMatcher* url_matcher, | 67 url_matcher::URLMatcher* url_matcher, |
68 const url_matcher::URLMatcherConditionSet::Vector& condition_sets); | 68 const url_matcher::URLMatcherConditionSet::Vector& condition_sets); |
69 ~EventMatcherEntry(); | 69 ~EventMatcherEntry(); |
70 | 70 |
71 // Prevents the removal of condition sets when this class is destroyed. We | 71 // Prevents the removal of condition sets when this class is destroyed. We |
72 // call this in EventFilter's destructor so that we don't do the costly | 72 // call this in EventFilter's destructor so that we don't do the costly |
73 // removal of condition sets when the URLMatcher is going to be destroyed | 73 // removal of condition sets when the URLMatcher is going to be destroyed |
74 // and clean them up anyway. | 74 // and clean them up anyway. |
75 void DontRemoveConditionSetsInDestructor(); | 75 void DontRemoveConditionSetsInDestructor(); |
76 | 76 |
77 EventMatcher* event_matcher() { | 77 EventMatcher* event_matcher() { |
78 return event_matcher_.get(); | 78 return event_matcher_.get(); |
79 } | 79 } |
80 | 80 |
81 private: | 81 private: |
82 scoped_ptr<EventMatcher> event_matcher_; | 82 std::unique_ptr<EventMatcher> event_matcher_; |
83 // The id sets in url_matcher_ that this EventMatcher owns. | 83 // The id sets in url_matcher_ that this EventMatcher owns. |
84 std::vector<url_matcher::URLMatcherConditionSet::ID> condition_set_ids_; | 84 std::vector<url_matcher::URLMatcherConditionSet::ID> condition_set_ids_; |
85 url_matcher::URLMatcher* url_matcher_; | 85 url_matcher::URLMatcher* url_matcher_; |
86 | 86 |
87 DISALLOW_COPY_AND_ASSIGN(EventMatcherEntry); | 87 DISALLOW_COPY_AND_ASSIGN(EventMatcherEntry); |
88 }; | 88 }; |
89 | 89 |
90 // Maps from a matcher id to an event matcher entry. | 90 // Maps from a matcher id to an event matcher entry. |
91 typedef std::map<MatcherID, linked_ptr<EventMatcherEntry> > EventMatcherMap; | 91 typedef std::map<MatcherID, linked_ptr<EventMatcherEntry> > EventMatcherMap; |
92 | 92 |
(...skipping 28 matching lines...) Expand all Loading... |
121 | 121 |
122 // Maps from event matcher ids to the name of the event they match on. | 122 // Maps from event matcher ids to the name of the event they match on. |
123 std::map<MatcherID, std::string> id_to_event_name_; | 123 std::map<MatcherID, std::string> id_to_event_name_; |
124 | 124 |
125 DISALLOW_COPY_AND_ASSIGN(EventFilter); | 125 DISALLOW_COPY_AND_ASSIGN(EventFilter); |
126 }; | 126 }; |
127 | 127 |
128 } // namespace extensions | 128 } // namespace extensions |
129 | 129 |
130 #endif // EXTENSIONS_COMMON_EVENT_FILTER_H_ | 130 #endif // EXTENSIONS_COMMON_EVENT_FILTER_H_ |
OLD | NEW |