OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_BROWSER_EVENT_LISTENER_MAP_H_ | 5 #ifndef EXTENSIONS_BROWSER_EVENT_LISTENER_MAP_H_ |
6 #define EXTENSIONS_BROWSER_EVENT_LISTENER_MAP_H_ | 6 #define EXTENSIONS_BROWSER_EVENT_LISTENER_MAP_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 content::RenderProcessHost* process, | 60 content::RenderProcessHost* process, |
61 std::unique_ptr<base::DictionaryValue> filter); | 61 std::unique_ptr<base::DictionaryValue> filter); |
62 // Constructs EventListener for an Extension service worker. | 62 // Constructs EventListener for an Extension service worker. |
63 // Similar to ForExtension above with the only difference that | 63 // Similar to ForExtension above with the only difference that |
64 // |worker_thread_id_| contains a valid worker thread, as opposed to | 64 // |worker_thread_id_| contains a valid worker thread, as opposed to |
65 // kNonWorkerThreadId. | 65 // kNonWorkerThreadId. |
66 static std::unique_ptr<EventListener> ForExtensionServiceWorker( | 66 static std::unique_ptr<EventListener> ForExtensionServiceWorker( |
67 const std::string& event_name, | 67 const std::string& event_name, |
68 const std::string& extension_id, | 68 const std::string& extension_id, |
69 content::RenderProcessHost* process, | 69 content::RenderProcessHost* process, |
70 const GURL& service_worker_scope, | |
70 int worker_thread_id, | 71 int worker_thread_id, |
71 std::unique_ptr<base::DictionaryValue> filter); | 72 std::unique_ptr<base::DictionaryValue> filter); |
72 | 73 |
73 ~EventListener(); | 74 ~EventListener(); |
74 | 75 |
75 bool Equals(const EventListener* other) const; | 76 bool Equals(const EventListener* other) const; |
76 | 77 |
77 std::unique_ptr<EventListener> Copy() const; | 78 std::unique_ptr<EventListener> Copy() const; |
78 | 79 |
79 // Returns true if the listener is for a lazy context: e.g. a background page | 80 // Returns true if the listener is for a lazy context: e.g. a background page |
80 // or an extension service worker. This listener does not have |process_|. | 81 // or an extension service worker. This listener does not have |process_|. |
81 bool IsLazy() const; | 82 bool IsLazy() const; |
82 | 83 |
83 // Returns true if this listener was registered for an extension service | 84 // Returns true if this listener was registered for an extension service |
84 // worker. | 85 // worker. |
85 bool IsForServiceWorker() const; | 86 bool IsForServiceWorker() const; |
Devlin
2017/06/16 02:34:42
We probably shouldn't have two "IsForServiceWorker
lazyboy
2017/06/16 18:48:05
Aha, I kept the new one close to the one so I don'
| |
87 bool is_for_service_worker() const { return is_for_service_worker_; } | |
86 | 88 |
87 // Modifies this listener to be a lazy listener, clearing process references. | 89 // Modifies this listener to be a lazy listener, clearing process references. |
88 void MakeLazy(); | 90 void MakeLazy(); |
89 | 91 |
90 // Returns the browser context associated with the listener, or NULL if | 92 // Returns the browser context associated with the listener, or NULL if |
91 // IsLazy. | 93 // IsLazy. |
92 content::BrowserContext* GetBrowserContext() const; | 94 content::BrowserContext* GetBrowserContext() const; |
93 | 95 |
94 const std::string& event_name() const { return event_name_; } | 96 const std::string& event_name() const { return event_name_; } |
95 const std::string& extension_id() const { return extension_id_; } | 97 const std::string& extension_id() const { return extension_id_; } |
96 const GURL& listener_url() const { return listener_url_; } | 98 const GURL& listener_url() const { return listener_url_; } |
97 content::RenderProcessHost* process() const { return process_; } | 99 content::RenderProcessHost* process() const { return process_; } |
98 base::DictionaryValue* filter() const { return filter_.get(); } | 100 base::DictionaryValue* filter() const { return filter_.get(); } |
99 EventFilter::MatcherID matcher_id() const { return matcher_id_; } | 101 EventFilter::MatcherID matcher_id() const { return matcher_id_; } |
100 void set_matcher_id(EventFilter::MatcherID id) { matcher_id_ = id; } | 102 void set_matcher_id(EventFilter::MatcherID id) { matcher_id_ = id; } |
101 int worker_thread_id() const { return worker_thread_id_; } | 103 int worker_thread_id() const { return worker_thread_id_; } |
102 | 104 |
103 private: | 105 private: |
104 EventListener(const std::string& event_name, | 106 EventListener(const std::string& event_name, |
105 const std::string& extension_id, | 107 const std::string& extension_id, |
106 const GURL& listener_url, | 108 const GURL& listener_url, |
107 content::RenderProcessHost* process, | 109 content::RenderProcessHost* process, |
110 bool is_for_service_worker, | |
108 int worker_thread_id, | 111 int worker_thread_id, |
109 std::unique_ptr<base::DictionaryValue> filter); | 112 std::unique_ptr<base::DictionaryValue> filter); |
110 | 113 |
111 const std::string event_name_; | 114 const std::string event_name_; |
112 const std::string extension_id_; | 115 const std::string extension_id_; |
113 const GURL listener_url_; | 116 const GURL listener_url_; |
114 content::RenderProcessHost* process_; | 117 content::RenderProcessHost* process_; |
118 const bool is_for_service_worker_ = false; | |
Devlin
2017/06/16 02:34:42
Do we need this + worker_thread_id? If so, worth
lazyboy
2017/06/16 18:48:05
Yes we need both.
is_for_service_worker implies th
| |
115 const int worker_thread_id_; | 119 const int worker_thread_id_; |
116 std::unique_ptr<base::DictionaryValue> filter_; | 120 std::unique_ptr<base::DictionaryValue> filter_; |
117 EventFilter::MatcherID matcher_id_; // -1 if unset. | 121 EventFilter::MatcherID matcher_id_; // -1 if unset. |
118 | 122 |
119 DISALLOW_COPY_AND_ASSIGN(EventListener); | 123 DISALLOW_COPY_AND_ASSIGN(EventListener); |
120 }; | 124 }; |
121 | 125 |
122 // Holds listeners for extension events and can answer questions about which | 126 // Holds listeners for extension events and can answer questions about which |
123 // listeners are interested in what events. | 127 // listeners are interested in what events. |
124 class EventListenerMap { | 128 class EventListenerMap { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 std::map<EventFilter::MatcherID, EventListener*> listeners_by_matcher_id_; | 214 std::map<EventFilter::MatcherID, EventListener*> listeners_by_matcher_id_; |
211 | 215 |
212 EventFilter event_filter_; | 216 EventFilter event_filter_; |
213 | 217 |
214 DISALLOW_COPY_AND_ASSIGN(EventListenerMap); | 218 DISALLOW_COPY_AND_ASSIGN(EventListenerMap); |
215 }; | 219 }; |
216 | 220 |
217 } // namespace extensions | 221 } // namespace extensions |
218 | 222 |
219 #endif // EXTENSIONS_BROWSER_EVENT_LISTENER_MAP_H_ | 223 #endif // EXTENSIONS_BROWSER_EVENT_LISTENER_MAP_H_ |
OLD | NEW |