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

Unified Diff: chrome/browser/extensions/event_listener_map.h

Issue 10514013: Filtered events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: split out event_filter changes 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/event_listener_map.h
diff --git a/chrome/browser/extensions/event_listener_map.h b/chrome/browser/extensions/event_listener_map.h
new file mode 100644
index 0000000000000000000000000000000000000000..9521b52b2858aa0c6e91f6aae077a539225ae904
--- /dev/null
+++ b/chrome/browser/extensions/event_listener_map.h
@@ -0,0 +1,99 @@
+// 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_BROWSER_EXTENSIONS_EVENT_LISTENER_MAP_H_
+#define CHROME_BROWSER_EXTENSIONS_EVENT_LISTENER_MAP_H_
+#pragma once
+
+#include "base/memory/scoped_ptr.h"
+#include "chrome/common/extensions/event_filter.h"
+
+#include <map>
+#include <set>
+#include <string>
+#include <vector>
+
+namespace base {
+class DictionaryValue;
+}
+
+struct ExtensionEvent;
+
+namespace content {
+class RenderProcessHost;
+}
+
+using base::DictionaryValue;
+using extensions::EventFilter;
+using extensions::EventFilteringInfo;
+using extensions::EventMatcher;
+
+// A listener for an extension event. A listener is essentially an endpoint
+// that an event can be dispatched to. This is a lazy listener if |process| is
battre 2012/06/13 09:21:54 what is a lazy listener?
koz (OOO until 15th September) 2012/06/14 02:15:55 I've added a comment.
+// NULL and a filtered listener if |filter| is defined.
+class EventListener {
Matt Perry 2012/06/13 01:24:27 put all new extensions code in the extensions name
koz (OOO until 15th September) 2012/06/14 02:15:55 Done.
+ public:
+ EventListener(const std::string& event_name,
+ const std::string& extension_id,
+ content::RenderProcessHost* process,
+ scoped_ptr<DictionaryValue> filter);
battre 2012/06/13 09:21:54 what goes into |filter|?
koz (OOO until 15th September) 2012/06/14 02:15:55 Done.
+ ~EventListener();
+
+ bool Equals(const EventListener* other);
+
+ scoped_ptr<EventListener> Copy() const;
+
+ const std::string event_name;
battre 2012/06/13 09:21:54 I think according to our style guide, these should
koz (OOO until 15th September) 2012/06/14 02:15:55 Cool, I've changed this class to a struct.
+ const std::string extension_id;
+ content::RenderProcessHost* process;
+ scoped_ptr<DictionaryValue> filter;
+ int matcher_id;
battre 2012/06/13 09:21:54 private: DISALLOW_COPY_AND_ASSIGN(EventListener)
koz (OOO until 15th September) 2012/06/14 02:15:55 Done.
+};
+
+// Holds listeners for extension events and can answer questions about which
+// listeners are interested in what events.
+class EventListenerMap {
+ public:
+ typedef std::vector<linked_ptr<EventListener> > ListenerList;
+ EventListenerMap();
+ ~EventListenerMap();
Matt Perry 2012/06/13 01:24:27 nit: newline before and after constructor/destruct
koz (OOO until 15th September) 2012/06/14 02:15:55 Done.
+ bool AddListener(scoped_ptr<EventListener> listener);
Matt Perry 2012/06/13 01:24:27 comment all these methods
koz (OOO until 15th September) 2012/06/14 02:15:55 Done.
+ bool RemoveListener(scoped_ptr<EventListener> listener);
Matt Perry 2012/06/13 01:24:27 use scoped_ptr in params only when the function ne
battre 2012/06/13 09:21:54 or a pointer?
koz (OOO until 15th September) 2012/06/14 02:15:55 Done.
+
+ scoped_ptr<std::set<const EventListener*> > GetEventTargets(
Matt Perry 2012/06/13 01:24:27 why not just return a bare std::set?
koz (OOO until 15th September) 2012/06/14 02:15:55 Done.
+ const ExtensionEvent& event);
+
+ ListenerList RemoveListenersForProcess(
+ const content::RenderProcessHost* process);
+
+ bool AnyListenersForEvent(const std::string& event_name);
battre 2012/06/13 09:21:54 HasListenersForEvent? (see "HasListener(const Even
koz (OOO until 15th September) 2012/06/14 02:15:55 Done.
+ bool AnyListenersForExtension(const std::string& extension_id,
battre 2012/06/13 09:21:54 HasListenersForExtension?
koz (OOO until 15th September) 2012/06/14 02:15:55 Done.
+ const std::string& event_name);
+
+ bool HasListener(const EventListener* listener);
+ void RemoveLazyListenersFor(const std::string extension_id);
battre 2012/06/13 09:21:54 const std::string&
koz (OOO until 15th September) 2012/06/14 02:15:55 Done.
+
+ void AddLazyListenersFromPreferences(
+ const std::string& extension_id,
+ std::set<std::string>& unfiltered,
battre 2012/06/13 09:21:54 const std::set<...>&
koz (OOO until 15th September) 2012/06/14 02:15:55 Done.
+ const DictionaryValue& filtered);
+
+ private:
+ typedef std::map<std::string, ListenerList> ListenerMap;
+
+ void CleanupListener(EventListener* listener);
+ bool IsFilteredEvent(const ExtensionEvent& event) const;
+ scoped_ptr<EventMatcher> ParseEventMatcer(DictionaryValue* filter_dict);
+
+ std::set<std::string> filtered_events_;
+ ListenerMap listeners_;
+
+ std::map<int, EventListener*> listeners_by_matcher_id_;
+
+ EventFilter event_filter_;
+
+ DISALLOW_COPY_AND_ASSIGN(EventListenerMap);
+};
+
+#endif // CHROME_BROWSER_EXTENSIONS_EVENT_LISTENER_MAP_H_

Powered by Google App Engine
This is Rietveld 408576698