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

Side by Side Diff: extensions/browser/event_listener_map.h

Issue 2943583002: [extension SW] Support lazy events from extension service workers. (Closed)
Patch Set: Address comments from falken@ Created 3 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 unified diff | Download patch
OLDNEW
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
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 (lazy or not) was registered for an extension
84 // worker. 85 // service worker.
85 bool IsForServiceWorker() const; 86 bool is_for_service_worker() const { return is_for_service_worker_; }
86 87
87 // Modifies this listener to be a lazy listener, clearing process references. 88 // Modifies this listener to be a lazy listener, clearing process references.
88 void MakeLazy(); 89 void MakeLazy();
89 90
90 // Returns the browser context associated with the listener, or NULL if 91 // Returns the browser context associated with the listener, or NULL if
91 // IsLazy. 92 // IsLazy.
92 content::BrowserContext* GetBrowserContext() const; 93 content::BrowserContext* GetBrowserContext() const;
93 94
94 const std::string& event_name() const { return event_name_; } 95 const std::string& event_name() const { return event_name_; }
95 const std::string& extension_id() const { return extension_id_; } 96 const std::string& extension_id() const { return extension_id_; }
96 const GURL& listener_url() const { return listener_url_; } 97 const GURL& listener_url() const { return listener_url_; }
97 content::RenderProcessHost* process() const { return process_; } 98 content::RenderProcessHost* process() const { return process_; }
98 base::DictionaryValue* filter() const { return filter_.get(); } 99 base::DictionaryValue* filter() const { return filter_.get(); }
99 EventFilter::MatcherID matcher_id() const { return matcher_id_; } 100 EventFilter::MatcherID matcher_id() const { return matcher_id_; }
100 void set_matcher_id(EventFilter::MatcherID id) { matcher_id_ = id; } 101 void set_matcher_id(EventFilter::MatcherID id) { matcher_id_ = id; }
101 int worker_thread_id() const { return worker_thread_id_; } 102 int worker_thread_id() const { return worker_thread_id_; }
102 103
103 private: 104 private:
104 EventListener(const std::string& event_name, 105 EventListener(const std::string& event_name,
105 const std::string& extension_id, 106 const std::string& extension_id,
106 const GURL& listener_url, 107 const GURL& listener_url,
107 content::RenderProcessHost* process, 108 content::RenderProcessHost* process,
109 bool is_for_service_worker,
108 int worker_thread_id, 110 int worker_thread_id,
109 std::unique_ptr<base::DictionaryValue> filter); 111 std::unique_ptr<base::DictionaryValue> filter);
110 112
111 const std::string event_name_; 113 const std::string event_name_;
112 const std::string extension_id_; 114 const std::string extension_id_;
113 const GURL listener_url_; 115 const GURL listener_url_;
114 content::RenderProcessHost* process_; 116 content::RenderProcessHost* process_;
117
118 const bool is_for_service_worker_ = false;
119
120 // If this listener is for a service worker (i.e.
121 // is_for_service_worker_ = true) and the worker is in running state, then
122 // this is the worker's thread id in the worker |process_|. For lazy service
123 // worker events, this will be kNonWorkerThreadId.
115 const int worker_thread_id_; 124 const int worker_thread_id_;
125
116 std::unique_ptr<base::DictionaryValue> filter_; 126 std::unique_ptr<base::DictionaryValue> filter_;
117 EventFilter::MatcherID matcher_id_; // -1 if unset. 127 EventFilter::MatcherID matcher_id_; // -1 if unset.
118 128
119 DISALLOW_COPY_AND_ASSIGN(EventListener); 129 DISALLOW_COPY_AND_ASSIGN(EventListener);
120 }; 130 };
121 131
122 // Holds listeners for extension events and can answer questions about which 132 // Holds listeners for extension events and can answer questions about which
123 // listeners are interested in what events. 133 // listeners are interested in what events.
124 class EventListenerMap { 134 class EventListenerMap {
125 public: 135 public:
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 std::map<EventFilter::MatcherID, EventListener*> listeners_by_matcher_id_; 220 std::map<EventFilter::MatcherID, EventListener*> listeners_by_matcher_id_;
211 221
212 EventFilter event_filter_; 222 EventFilter event_filter_;
213 223
214 DISALLOW_COPY_AND_ASSIGN(EventListenerMap); 224 DISALLOW_COPY_AND_ASSIGN(EventListenerMap);
215 }; 225 };
216 226
217 } // namespace extensions 227 } // namespace extensions
218 228
219 #endif // EXTENSIONS_BROWSER_EVENT_LISTENER_MAP_H_ 229 #endif // EXTENSIONS_BROWSER_EVENT_LISTENER_MAP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698