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

Unified Diff: chrome/common/extensions/filtered_event_router.h

Issue 10388135: Add common code for extensions event filtering. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: self review Created 8 years, 7 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 side-by-side diff with in-line comments
Download patch
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..e4a63176ceeb67b68b795886d6308e99aa3c295a
--- /dev/null
+++ b/chrome/common/extensions/filtered_event_router.h
@@ -0,0 +1,64 @@
+// 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 {
battre 2012/05/15 13:12:32 Given that we are dealing with so many IDs, could
Matt Perry 2012/05/15 20:42:59 How will this work in the multiprocess world of ev
koz (OOO until 15th September) 2012/05/16 00:14:00 Done.
koz (OOO until 15th September) 2012/05/16 00:14:00 The idea is that each process will maintain their
Matt Perry 2012/05/16 00:37:32 If I understand correctly, you're saying the event
koz (OOO until 15th September) 2012/05/16 01:01:21 Actually I was more thinking about the cost of add
Matt Perry 2012/05/16 01:17:07 What about: chrome.filteredEvent.addListener(cb1,
+ public:
+ FilteredEventRouter();
+ ~FilteredEventRouter();
+
+ int AddEventMatcher(const std::string& event_name,
battre 2012/05/15 13:12:32 Please document return values
koz (OOO until 15th September) 2012/05/16 00:14:00 Done.
+ scoped_ptr<EventMatcher> matcher);
+ std::string RemoveEventMatcher(int id);
+
+ std::set<int> MatchEvent(const std::string& event_name,
+ const EventFilteringInfo& event_info);
+
+ int GetMatcherCountForEvent(const std::string& event_name);
+
+ private:
+ typedef std::map<int, linked_ptr<EventMatcher> > EventMatcherMap;
+ typedef std::map<std::string, EventMatcherMap> EventMatcherMultiMap;
+
+ // Adds the list of filters to the URL matcher, having matches for those URLs
+ // map to |id|.
+ void AddURLConditionsToURLMatcher(int id, base::ListValue* url_filters);
+
+ URLMatcher url_matcher_;
+ EventMatcherMultiMap event_matchers_;
+
+ // The next id to assign to an EventMatcher.
+ int next_id_;
+
+ // The next id to assign to a condition set passed to URLMatcher.
+ int 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<int, int> condition_set_id_to_event_matcher_id_;
+
+ // Maps from event matcher ids to the name of the event they match on.
+ std::map<int, std::string> id_to_event_name_;
battre 2012/05/15 13:12:32 DISALLOW_COPY_AND_ASSIGN
battre 2012/05/15 13:12:32 this class has a lot of maps. I wonder whether we
koz (OOO until 15th September) 2012/05/16 00:14:00 Done.
koz (OOO until 15th September) 2012/05/16 00:14:00 We could, but wouldn't that just make the callers
+};
+
+} // namespace extensions
+
+#endif // CHROME_COMMON_EXTENSIONS_FILTERED_EVENT_ROUTER_H_

Powered by Google App Engine
This is Rietveld 408576698