Index: extensions/browser/event_listener_map.cc |
diff --git a/extensions/browser/event_listener_map.cc b/extensions/browser/event_listener_map.cc |
index 12dd5b4499da1f744e97585ba8f6ce54251d50d4..4b21df25b0392511d1484649e5952f666d76dc4e 100644 |
--- a/extensions/browser/event_listener_map.cc |
+++ b/extensions/browser/event_listener_map.cc |
@@ -12,6 +12,7 @@ |
#include "base/values.h" |
#include "content/public/browser/render_process_host.h" |
#include "extensions/browser/event_router.h" |
+#include "extensions/common/constants.h" |
#include "ipc/ipc_message.h" |
#include "url/gurl.h" |
#include "url/origin.h" |
@@ -29,7 +30,8 @@ std::unique_ptr<EventListener> EventListener::ForExtension( |
content::RenderProcessHost* process, |
std::unique_ptr<base::DictionaryValue> filter) { |
return base::WrapUnique(new EventListener(event_name, extension_id, GURL(), |
- process, std::move(filter))); |
+ process, kNonWorkerThreadId, |
+ std::move(filter))); |
} |
// static |
@@ -42,9 +44,20 @@ std::unique_ptr<EventListener> EventListener::ForURL( |
// for chrome://settings/accounts, to avoid multiple events being triggered |
// for the same process. See crbug.com/536858 for details. // TODO(devlin): If |
// we dispatched events to processes more intelligently this could be avoided. |
- return base::WrapUnique(new EventListener(event_name, "", |
- url::Origin(listener_url).GetURL(), |
- process, std::move(filter))); |
+ return base::WrapUnique( |
+ new EventListener(event_name, "", url::Origin(listener_url).GetURL(), |
+ process, kNonWorkerThreadId, std::move(filter))); |
+} |
+ |
+std::unique_ptr<EventListener> EventListener::ForExtensionServiceWorker( |
+ const std::string& event_name, |
+ const std::string& extension_id, |
+ content::RenderProcessHost* process, |
+ int worker_thread_id, |
+ std::unique_ptr<base::DictionaryValue> filter) { |
+ return base::WrapUnique(new EventListener(event_name, extension_id, GURL(), |
+ process, worker_thread_id, |
+ std::move(filter))); |
} |
EventListener::~EventListener() {} |
@@ -56,6 +69,7 @@ bool EventListener::Equals(const EventListener* other) const { |
return event_name_ == other->event_name_ && |
extension_id_ == other->extension_id_ && |
listener_url_ == other->listener_url_ && process_ == other->process_ && |
+ worker_thread_id_ == other->worker_thread_id_ && |
((!!filter_.get()) == (!!other->filter_.get())) && |
(!filter_.get() || filter_->Equals(other->filter_.get())); |
} |
@@ -66,15 +80,20 @@ std::unique_ptr<EventListener> EventListener::Copy() const { |
filter_copy.reset(filter_->DeepCopy()); |
return std::unique_ptr<EventListener>( |
new EventListener(event_name_, extension_id_, listener_url_, process_, |
- std::move(filter_copy))); |
+ worker_thread_id_, std::move(filter_copy))); |
} |
bool EventListener::IsLazy() const { |
return !process_; |
} |
+bool EventListener::IsForServiceWorker() const { |
+ return worker_thread_id_ != kNonWorkerThreadId; |
+} |
+ |
void EventListener::MakeLazy() { |
- process_ = NULL; |
+ DCHECK(worker_thread_id_ == kNonWorkerThreadId); |
Devlin
2017/05/24 17:58:25
nit: DCHECK_EQ
lazyboy
2017/05/25 01:33:43
Done.
|
+ process_ = nullptr; |
} |
content::BrowserContext* EventListener::GetBrowserContext() const { |
@@ -85,11 +104,13 @@ EventListener::EventListener(const std::string& event_name, |
const std::string& extension_id, |
const GURL& listener_url, |
content::RenderProcessHost* process, |
+ int worker_thread_id, |
std::unique_ptr<DictionaryValue> filter) |
: event_name_(event_name), |
extension_id_(extension_id), |
listener_url_(listener_url), |
process_(process), |
+ worker_thread_id_(worker_thread_id), |
filter_(std::move(filter)), |
matcher_id_(-1) {} |
@@ -175,14 +196,17 @@ bool EventListenerMap::HasListener(const EventListener* listener) { |
} |
bool EventListenerMap::HasProcessListener(content::RenderProcessHost* process, |
+ int worker_thread_id, |
const std::string& extension_id) { |
for (ListenerMap::iterator it = listeners_.begin(); it != listeners_.end(); |
it++) { |
for (ListenerList::iterator it2 = it->second.begin(); |
it2 != it->second.end(); it2++) { |
if ((*it2)->process() == process && |
- (*it2)->extension_id() == extension_id) |
+ (*it2)->extension_id() == extension_id && |
+ (*it2)->worker_thread_id() == worker_thread_id) { |
return true; |
+ } |
} |
} |
return false; |
@@ -212,7 +236,7 @@ void EventListenerMap::LoadUnfilteredLazyListeners( |
for (std::set<std::string>::const_iterator it = event_names.begin(); |
it != event_names.end(); ++it) { |
AddListener(EventListener::ForExtension( |
- *it, extension_id, NULL, std::unique_ptr<DictionaryValue>())); |
+ *it, extension_id, nullptr, std::unique_ptr<DictionaryValue>())); |
} |
} |
@@ -228,6 +252,8 @@ void EventListenerMap::LoadFilteredLazyListeners( |
const DictionaryValue* filter = NULL; |
if (!filter_list->GetDictionary(i, &filter)) |
continue; |
+ // Currently this is only used for lazy background page events. |
+ // TODO(lazyboy): Add extension SW lazy events. |
AddListener(EventListener::ForExtension( |
it.key(), extension_id, NULL, base::WrapUnique(filter->DeepCopy()))); |
} |