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 CHROME_COMMON_EXTENSIONS_EVENT_FILTER_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_EVENT_FILTER_H_ |
6 #define CHROME_COMMON_EXTENSIONS_EVENT_FILTER_H_ | 6 #define CHROME_COMMON_EXTENSIONS_EVENT_FILTER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/memory/linked_ptr.h" | 9 #include "base/memory/linked_ptr.h" |
10 #include "chrome/common/extensions/event_matcher.h" | 10 #include "chrome/common/extensions/event_matcher.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
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 scoped_ptr<EventMatcher> matcher); |
32 | |
33 // Retrieve the EventMatcher with the given id. | |
34 EventMatcher* GetEventMatcher(MatcherID id); | |
35 | |
36 // Retrieve the name of the event that the EventMatcher specified by |id| is | |
37 // referring to. | |
38 const std::string& GetEventName(MatcherID id); | |
39 | |
32 // 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. |
33 std::string RemoveEventMatcher(MatcherID id); | 41 std::string RemoveEventMatcher(MatcherID id); |
34 | 42 |
35 // Match an event named |event_name| with filtering info |event_info| against | 43 // Match an event named |event_name| with filtering info |event_info| against |
36 // our set of event matchers. Returns a set of ids that correspond to the | 44 // our set of event matchers. Returns a set of ids that correspond to the |
37 // event matchers that matched the event. | 45 // event matchers that matched the event. |
38 // TODO(koz): Add a std::string* parameter for retrieving error messages. | 46 // TODO(koz): Add a std::string* parameter for retrieving error messages. |
39 std::set<MatcherID> MatchEvent(const std::string& event_name, | 47 std::set<MatcherID> MatchEvent(const std::string& event_name, |
40 const EventFilteringInfo& event_info); | 48 const EventFilteringInfo& event_info); |
41 | 49 |
(...skipping 15 matching lines...) Expand all Loading... | |
57 URLMatcher* url_matcher, | 65 URLMatcher* url_matcher, |
58 const URLMatcherConditionSet::Vector& condition_sets); | 66 const URLMatcherConditionSet::Vector& condition_sets); |
59 ~EventMatcherEntry(); | 67 ~EventMatcherEntry(); |
60 | 68 |
61 // Prevents the removal of condition sets when this class is destroyed. We | 69 // Prevents the removal of condition sets when this class is destroyed. We |
62 // call this in EventFilter's destructor so that we don't do the costly | 70 // call this in EventFilter's destructor so that we don't do the costly |
63 // removal of condition sets when the URLMatcher is going to be destroyed | 71 // removal of condition sets when the URLMatcher is going to be destroyed |
64 // and clean them up anyway. | 72 // and clean them up anyway. |
65 void DontRemoveConditionSetsInDestructor(); | 73 void DontRemoveConditionSetsInDestructor(); |
66 | 74 |
67 const EventMatcher& event_matcher() const { | 75 EventMatcher* event_matcher() { |
68 return *event_matcher_; | 76 return event_matcher_.get(); |
battre
2012/06/19 14:26:23
this is part of the other CL.
koz (OOO until 15th September)
2012/06/20 08:05:56
Oops, I must have uploaded the union. Sorry about
| |
69 } | 77 } |
70 | 78 |
71 private: | 79 private: |
72 scoped_ptr<EventMatcher> event_matcher_; | 80 scoped_ptr<EventMatcher> event_matcher_; |
73 // The id sets in url_matcher_ that this EventMatcher owns. | 81 // The id sets in url_matcher_ that this EventMatcher owns. |
74 std::vector<URLMatcherConditionSet::ID> condition_set_ids_; | 82 std::vector<URLMatcherConditionSet::ID> condition_set_ids_; |
75 URLMatcher* url_matcher_; | 83 URLMatcher* url_matcher_; |
76 | 84 |
77 DISALLOW_COPY_AND_ASSIGN(EventMatcherEntry); | 85 DISALLOW_COPY_AND_ASSIGN(EventMatcherEntry); |
78 }; | 86 }; |
79 | 87 |
80 // Maps from a matcher id to an event matcher entry. | 88 // Maps from a matcher id to an event matcher entry. |
81 typedef std::map<MatcherID, linked_ptr<EventMatcherEntry> > EventMatcherMap; | 89 typedef std::map<MatcherID, linked_ptr<EventMatcherEntry> > EventMatcherMap; |
82 | 90 |
83 // Maps from event name to the map of matchers that are registered for it. | 91 // Maps from event name to the map of matchers that are registered for it. |
84 typedef std::map<std::string, EventMatcherMap> EventMatcherMultiMap; | 92 typedef std::map<std::string, EventMatcherMap> EventMatcherMultiMap; |
85 | 93 |
86 // Adds the list of filters to the URL matcher, having matches for those URLs | 94 // Adds the list of filters to the URL matcher, having matches for those URLs |
87 // map to |id|. | 95 // map to |id|. |
88 bool CreateConditionSets(MatcherID id, | 96 bool CreateConditionSets(MatcherID id, |
89 base::ListValue* url_filters, | 97 EventMatcher* matcher, |
90 URLMatcherConditionSet::Vector* condition_sets); | 98 URLMatcherConditionSet::Vector* condition_sets); |
91 | 99 |
92 bool AddDictionaryAsConditionSet( | 100 bool AddDictionaryAsConditionSet( |
93 base::DictionaryValue* url_filter, | 101 base::DictionaryValue* url_filter, |
94 URLMatcherConditionSet::Vector* condition_sets); | 102 URLMatcherConditionSet::Vector* condition_sets); |
95 | 103 |
96 URLMatcher url_matcher_; | 104 URLMatcher url_matcher_; |
97 EventMatcherMultiMap event_matchers_; | 105 EventMatcherMultiMap event_matchers_; |
98 | 106 |
99 // The next id to assign to an EventMatcher. | 107 // The next id to assign to an EventMatcher. |
(...skipping 10 matching lines...) Expand all Loading... | |
110 | 118 |
111 // Maps from event matcher ids to the name of the event they match on. | 119 // Maps from event matcher ids to the name of the event they match on. |
112 std::map<MatcherID, std::string> id_to_event_name_; | 120 std::map<MatcherID, std::string> id_to_event_name_; |
113 | 121 |
114 DISALLOW_COPY_AND_ASSIGN(EventFilter); | 122 DISALLOW_COPY_AND_ASSIGN(EventFilter); |
115 }; | 123 }; |
116 | 124 |
117 } // namespace extensions | 125 } // namespace extensions |
118 | 126 |
119 #endif // CHROME_COMMON_EXTENSIONS_EVENT_FILTER_H_ | 127 #endif // CHROME_COMMON_EXTENSIONS_EVENT_FILTER_H_ |
OLD | NEW |