Index: chrome/common/extensions/filtered_event_router.h |
diff --git a/chrome/common/extensions/filtered_event_router.h b/chrome/common/extensions/filtered_event_router.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2b85236d2dc45a6042df8f8f72417bcc0bcb2c6e |
--- /dev/null |
+++ b/chrome/common/extensions/filtered_event_router.h |
@@ -0,0 +1,74 @@ |
+// 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_FILTERED_EVENT_ROUTER_H_ |
+#define CHROME_COMMON_EXTENSIONS_FILTERED_EVENT_ROUTER_H_ |
+#pragma once |
+ |
+#include "base/memory/linked_ptr.h" |
+#include "chrome/common/extensions/event_matcher.h" |
+#include "chrome/common/extensions/event_filtering_info.h" |
+#include "chrome/common/extensions/matcher/url_matcher.h" |
+ |
+#include <map> |
+#include <set> |
+ |
+namespace extensions { |
+ |
+// Matches incoming events against a collection of EventMatchers. Each added |
+// EventMatcher is given an id which is returned by MatchEvent() when it is |
+// passed a matching event. |
+class FilteredEventRouter { |
+ public: |
+ typedef int MatcherID; |
+ FilteredEventRouter(); |
+ ~FilteredEventRouter(); |
+ |
+ // Adds an event matcher that will be used in calls to MatchEvent(). Returns |
+ // the id of the matcher, or -1 if there was an error. |
+ MatcherID AddEventMatcher(const std::string& event_name, |
+ scoped_ptr<EventMatcher> matcher); |
battre
2012/05/16 13:35:12
As the event filters will come from extension code
koz (OOO until 15th September)
2012/05/17 05:08:42
Cool, I've added a TODO.
|
+ // Removes an event matcher, returning the name of the event that it was for. |
+ std::string RemoveEventMatcher(MatcherID id); |
+ |
+ // Match an event named |event_name| with filtering info |event_info| against |
+ // our set of event matchers. Returns a set of ids that correspond to the |
+ // event matchers that matched the event. |
+ std::set<MatcherID> MatchEvent(const std::string& event_name, |
+ const EventFilteringInfo& event_info); |
+ |
+ int GetMatcherCountForEvent(const std::string& event_name); |
+ |
+ private: |
+ typedef std::map<MatcherID, linked_ptr<EventMatcher> > EventMatcherMap; |
+ typedef std::map<std::string, EventMatcherMap> EventMatcherMultiMap; |
battre
2012/05/16 13:35:12
optional:
typedef std::string EventName;
typedef s
koz (OOO until 15th September)
2012/05/17 05:08:42
I added comments here.
|
+ |
+ // Adds the list of filters to the URL matcher, having matches for those URLs |
+ // map to |id|. |
+ bool AddURLConditionsToURLMatcher(MatcherID id, base::ListValue* url_filters); |
+ |
+ URLMatcher url_matcher_; |
+ EventMatcherMultiMap event_matchers_; |
+ |
+ // The next id to assign to an EventMatcher. |
+ MatcherID next_id_; |
+ |
+ // The next id to assign to a condition set passed to URLMatcher. |
+ URLMatcherConditionSet::ID next_condition_set_id_; |
+ |
+ // Maps condition set ids, which URLMatcher operates in, to event matcher |
+ // ids, which the interface to this class operates in. As each EventFilter |
+ // can specify many condition sets this is a many to one relationship. |
+ std::map<URLMatcherConditionSet::ID, MatcherID> |
+ condition_set_id_to_event_matcher_id_; |
+ |
+ // Maps from event matcher ids to the name of the event they match on. |
+ std::map<MatcherID, std::string> id_to_event_name_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(FilteredEventRouter); |
+}; |
+ |
+} // namespace extensions |
+ |
+#endif // CHROME_COMMON_EXTENSIONS_FILTERED_EVENT_ROUTER_H_ |