Index: extensions/browser/event_listener_map.cc |
diff --git a/extensions/browser/event_listener_map.cc b/extensions/browser/event_listener_map.cc |
index 89855e3f7305dd9b4e109b9704d023aa8857b83a..fa200e7dd2b462c0d74b5f9dffd48f2f58d2b273 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(), |
Devlin
2017/06/01 04:54:49
while we're here, prefer std::string()
lazyboy
2017/06/01 23:33:29
Done.
|
+ 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())); |
} |
@@ -64,16 +78,21 @@ std::unique_ptr<EventListener> EventListener::Copy() const { |
std::unique_ptr<DictionaryValue> filter_copy; |
if (filter_) |
filter_copy = filter_->CreateDeepCopy(); |
- return base::WrapUnique(new EventListener(event_name_, extension_id_, |
- listener_url_, process_, |
- std::move(filter_copy))); |
+ return base::WrapUnique( |
+ new EventListener(event_name_, extension_id_, listener_url_, process_, |
+ 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() { |
+ DCHECK_NE(worker_thread_id_, kNonWorkerThreadId); |
process_ = nullptr; |
} |
@@ -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) {} |
@@ -174,12 +195,15 @@ bool EventListenerMap::HasListener(const EventListener* listener) const { |
bool EventListenerMap::HasProcessListener( |
content::RenderProcessHost* process, |
+ int worker_thread_id, |
const std::string& extension_id) const { |
for (const auto& it : listeners_) { |
for (const auto& listener : it.second) { |
if (listener->process() == process && |
- listener->extension_id() == extension_id) |
+ listener->extension_id() == extension_id && |
+ listener->worker_thread_id() == worker_thread_id) { |
return true; |
+ } |
} |
} |
return false; |
@@ -224,6 +248,8 @@ void EventListenerMap::LoadFilteredLazyListeners( |
const DictionaryValue* filter = nullptr; |
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, nullptr, |
base::WrapUnique(filter->DeepCopy()))); |