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

Issue 2943583002: [extension SW] Support lazy events from extension service workers. (Closed)

Created:
3 years, 6 months ago by lazyboy
Modified:
3 years, 5 months ago
CC:
chromium-reviews, michaeln, jsbell+serviceworker_chromium.org, tzik, mlamouri+watch-content_chromium.org, extensions-reviews_chromium.org, serviceworker-reviews, jam, kinuko+serviceworker, nhiroki, darin-cc_chromium.org, chromium-apps-reviews_chromium.org, horo+watch_chromium.org, kinuko+watch, shimazu+serviceworker_chromium.org, blink-worker-reviews_chromium.org
Target Ref:
refs/heads/master
Project:
chromium
Visibility:
Public.

Description

[extension SW] Support lazy events from extension service workers. This CL adds support to register and dispatch lazy events from/to extension SW (a) To register, we use SW's (unique) scope url to identify a SW within an extension. Pass the information about scope url through ServiceWorkerContextClient. Initially EventListener::worker_thread_id_ was used to identify whether an event is for SW context or not. However, that is not enough for lazy service worker events, because we need to persist lazy events in the browser process and worker_thread_id_ is temporary for a running SW. Change SW EventListener by adding EventListener::is_for_service_worker() to support this. (b) To dispatch, we need to start a worker before dispatching the event. The content/ API: ServiceWorkerContext::GetWorkerInfoAfterStartWorker() was added to do that. Add ServiceWorkerTaskQueue (similar to LazyBackgroundTaskQueue for lazy background pages) to dispatch the event (a task) in extensions/ layer. IPC changes: In order to identify a (possibly stopped) SW, IPCs for lazy service worker events were changed to accept service worker scope urls. In order to not convolute existing lazy background page IPCs (ExtensionHostMsg_Add/RemoveLazyListener), new ones have been introduced: ExtensionHostMsg_Add/RemoveLazyServiceWorkerListener. Other notable changes: - LazyContextTaskQueue is introduced to express a lazy runnable context. Make the new ServiceWorkerTaskQueue and existing LazyBackgroundTaskQueue derived from that. One can post [1] PendingTasks to these contexts. Unfortunately becuase of many existing usages of LazyBackgroundTaskQueue::AddPendingTask, [1] was named AddPendingTaskToDispatchEvent to avoid collision. - LazyContextTaskQueue provides a contexual information expressed as LazyContextTaskQueue::ContextInfo. This was introduced to avoid ExtensionHost from LazyContextTaskQueue (See LazyBackgroundTaskQueue::AddPendingTask) BUG=721147 Test=After an extension service worker stops, it should still be possible to dispatch extension events to it. That will wake up the service worker. Review-Url: https://codereview.chromium.org/2943583002 Cr-Commit-Position: refs/heads/master@{#483820} Committed: https://chromium.googlesource.com/chromium/src/+/63b994a1d1026a4b992c74e10e1e7c826bb5f9ae

Patch Set 1 #

Total comments: 22

Patch Set 2 : address comments #

Patch Set 3 : address comments #

Total comments: 14

Patch Set 4 : Address comments #

Total comments: 10

Patch Set 5 : Address comments from falken@ #

Total comments: 6

Patch Set 6 : address nits #

Patch Set 7 : sync only #

Patch Set 8 : sync @tott #

Unified diffs Side-by-side diffs Delta from patch set Stats (+1008 lines, -160 lines) Patch
M chrome/browser/extensions/service_worker_apitest.cc View 1 2 3 4 5 6 7 3 chunks +36 lines, -0 lines 0 comments Download
M chrome/renderer/chrome_content_renderer_client.h View 1 2 3 4 5 6 7 1 chunk +4 lines, -2 lines 0 comments Download
M chrome/renderer/chrome_content_renderer_client.cc View 1 2 3 4 5 6 7 1 chunk +6 lines, -4 lines 0 comments Download
A chrome/test/data/extensions/api_test/service_worker/events_to_stopped_worker/manifest.json View 1 chunk +6 lines, -0 lines 0 comments Download
A chrome/test/data/extensions/api_test/service_worker/events_to_stopped_worker/on_updated.html View 1 chunk +6 lines, -0 lines 0 comments Download
A chrome/test/data/extensions/api_test/service_worker/events_to_stopped_worker/on_updated.js View 1 chunk +13 lines, -0 lines 0 comments Download
A chrome/test/data/extensions/api_test/service_worker/events_to_stopped_worker/page.html View 1 chunk +1 line, -0 lines 0 comments Download
A chrome/test/data/extensions/api_test/service_worker/events_to_stopped_worker/page.js View 1 2 3 1 chunk +30 lines, -0 lines 0 comments Download
A chrome/test/data/extensions/api_test/service_worker/events_to_stopped_worker/sw.js View 1 chunk +55 lines, -0 lines 0 comments Download
M content/browser/service_worker/service_worker_context_wrapper.h View 1 2 3 4 5 6 1 chunk +3 lines, -0 lines 0 comments Download
M content/browser/service_worker/service_worker_context_wrapper.cc View 1 2 3 4 5 6 2 chunks +46 lines, -0 lines 0 comments Download
M content/public/browser/service_worker_context.h View 1 2 3 4 2 chunks +12 lines, -0 lines 0 comments Download
M content/public/renderer/content_renderer_client.h View 1 2 3 4 5 6 7 1 chunk +4 lines, -2 lines 0 comments Download
A content/public/test/service_worker_test_helpers.h View 1 2 3 4 5 1 chunk +25 lines, -0 lines 0 comments Download
A content/public/test/service_worker_test_helpers.cc View 1 2 3 4 1 chunk +106 lines, -0 lines 0 comments Download
M content/renderer/service_worker/service_worker_context_client.cc View 1 2 3 4 5 6 7 2 chunks +3 lines, -2 lines 0 comments Download
M content/test/BUILD.gn View 1 2 3 4 5 6 7 1 chunk +2 lines, -0 lines 0 comments Download
M extensions/browser/BUILD.gn View 1 2 3 4 5 6 2 chunks +5 lines, -0 lines 0 comments Download
M extensions/browser/event_listener_map.h View 1 4 chunks +13 lines, -3 lines 0 comments Download
M extensions/browser/event_listener_map.cc View 1 5 chunks +12 lines, -12 lines 0 comments Download
M extensions/browser/event_router.h View 1 7 chunks +12 lines, -11 lines 0 comments Download
M extensions/browser/event_router.cc View 1 2 3 8 chunks +61 lines, -50 lines 0 comments Download
M extensions/browser/events/lazy_event_dispatcher.h View 1 5 chunks +16 lines, -5 lines 0 comments Download
M extensions/browser/events/lazy_event_dispatcher.cc View 5 chunks +34 lines, -6 lines 0 comments Download
M extensions/browser/extension_message_filter.h View 1 chunk +10 lines, -4 lines 0 comments Download
M extensions/browser/extension_message_filter.cc View 7 chunks +50 lines, -24 lines 0 comments Download
M extensions/browser/lazy_background_task_queue.h View 4 chunks +10 lines, -1 line 0 comments Download
M extensions/browser/lazy_background_task_queue.cc View 3 chunks +25 lines, -0 lines 0 comments Download
M extensions/browser/lazy_context_id.h View 2 chunks +15 lines, -4 lines 0 comments Download
M extensions/browser/lazy_context_id.cc View 2 chunks +14 lines, -3 lines 0 comments Download
A extensions/browser/lazy_context_task_queue.h View 1 2 3 1 chunk +71 lines, -0 lines 0 comments Download
A extensions/browser/service_worker_task_queue.h View 1 chunk +46 lines, -0 lines 0 comments Download
A extensions/browser/service_worker_task_queue.cc View 1 2 3 4 1 chunk +98 lines, -0 lines 0 comments Download
A extensions/browser/service_worker_task_queue_factory.h View 1 chunk +39 lines, -0 lines 0 comments Download
A extensions/browser/service_worker_task_queue_factory.cc View 1 chunk +44 lines, -0 lines 0 comments Download
M extensions/common/extension_messages.h View 1 2 3 4 5 6 7 2 chunks +19 lines, -7 lines 0 comments Download
M extensions/renderer/dispatcher.h View 1 2 3 4 5 6 7 2 chunks +4 lines, -2 lines 0 comments Download
M extensions/renderer/dispatcher.cc View 1 2 3 4 5 6 7 5 chunks +15 lines, -12 lines 0 comments Download
M extensions/renderer/event_bindings.cc View 4 chunks +25 lines, -6 lines 0 comments Download
M extensions/renderer/script_context.h View 1 2 3 4 5 6 2 chunks +7 lines, -0 lines 0 comments Download
M extensions/renderer/script_context.cc View 1 2 3 4 5 6 1 chunk +5 lines, -0 lines 0 comments Download

Messages

Total messages: 48 (32 generated)
lazyboy
Hi Devlin, can you do an initial review of extensions/ bits and the one content/ ...
3 years, 6 months ago (2017-06-16 01:08:23 UTC) #5
Devlin
I was able to take a quick look tonight, but I need to go back ...
3 years, 6 months ago (2017-06-16 02:34:42 UTC) #6
lazyboy
Thanks for the initial look, comments addressed below. https://codereview.chromium.org/2943583002/diff/1/chrome/browser/extensions/service_worker_apitest.cc File chrome/browser/extensions/service_worker_apitest.cc (right): https://codereview.chromium.org/2943583002/diff/1/chrome/browser/extensions/service_worker_apitest.cc#newcode70 chrome/browser/extensions/service_worker_apitest.cc:70: GURL ...
3 years, 6 months ago (2017-06-16 18:48:05 UTC) #10
Devlin
a bunch of nits and a UAF concern, but otherwise I think this is good. ...
3 years, 6 months ago (2017-06-20 20:31:20 UTC) #15
lazyboy
+falken for content.*service_worker review: The primary change is adding: ServiceWorkerContext::GetWorkerInfoAfterStartWorker(). Also added a test method ...
3 years, 6 months ago (2017-06-22 02:46:57 UTC) #21
falken
https://codereview.chromium.org/2943583002/diff/80001/content/browser/service_worker/service_worker_context_wrapper.cc File content/browser/service_worker/service_worker_context_wrapper.cc (right): https://codereview.chromium.org/2943583002/diff/80001/content/browser/service_worker/service_worker_context_wrapper.cc#newcode89 content/browser/service_worker/service_worker_context_wrapper.cc:89: service_worker_registration->active_version()->embedded_worker(); It'd be safer to pass the active_version directly ...
3 years, 6 months ago (2017-06-22 03:35:58 UTC) #22
lazyboy
Thanks for the review, addressed comments in patch set #5 https://codereview.chromium.org/2943583002/diff/80001/content/browser/service_worker/service_worker_context_wrapper.cc File content/browser/service_worker/service_worker_context_wrapper.cc (right): https://codereview.chromium.org/2943583002/diff/80001/content/browser/service_worker/service_worker_context_wrapper.cc#newcode89 ...
3 years, 6 months ago (2017-06-23 02:18:30 UTC) #24
falken
content.*service_worker lgtm, thanks https://codereview.chromium.org/2943583002/diff/120001/content/browser/service_worker/service_worker_context_wrapper.cc File content/browser/service_worker/service_worker_context_wrapper.cc (right): https://codereview.chromium.org/2943583002/diff/120001/content/browser/service_worker/service_worker_context_wrapper.cc#newcode89 content/browser/service_worker/service_worker_context_wrapper.cc:89: EmbeddedWorkerInstance* instance = active_version->embedded_worker(); nit: Since ...
3 years, 6 months ago (2017-06-23 03:45:46 UTC) #27
lazyboy
Thanks Matt for looking. +Kinuko for service worker related content/public changes in: content/public/browser/service_worker_context.h content/public/renderer/content_renderer_client.h content/public/test/service_worker_test_helpers.h ...
3 years, 6 months ago (2017-06-23 07:44:57 UTC) #31
kinuko
Sorry for slow turn-around, lgtm
3 years, 5 months ago (2017-06-27 07:52:10 UTC) #32
lazyboy
+thestig for chrome/ OWNERS chrome_content_renderer_client.h/cc: a) Added service worker scope url param to (DidInitialize/WillDestroy)ServiceWorkerContextOnWorkerThread +meacer ...
3 years, 5 months ago (2017-06-27 23:02:05 UTC) #34
Lei Zhang
On 2017/06/27 23:02:05, lazyboy wrote: > +thestig for chrome/ OWNERS > chrome_content_renderer_client.h/cc: > a) Added ...
3 years, 5 months ago (2017-06-27 23:07:41 UTC) #35
meacer
IPC lgtm
3 years, 5 months ago (2017-06-30 00:42:29 UTC) #36
lazyboy
Thanks everyone for the reviews, going to CQ it soon!
3 years, 5 months ago (2017-06-30 21:01:36 UTC) #41
commit-bot: I haz the power
CQ is trying da patch. Follow status at: https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2943583002/180001
3 years, 5 months ago (2017-06-30 21:02:18 UTC) #44
commit-bot: I haz the power
3 years, 5 months ago (2017-06-30 21:20:59 UTC) #48
Message was sent while issue was closed.
Committed patchset #8 (id:180001) as
https://chromium.googlesource.com/chromium/src/+/63b994a1d1026a4b992c74e10e1e...

Powered by Google App Engine
This is Rietveld 408576698