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

Unified Diff: third_party/WebKit/LayoutTests/http/tests/serviceworker/chromium/resources/usecounter-worker.js

Issue 2658603003: ServiceWorker: Enable UseCounter for ServiceWorkerGlobalScope (Closed)
Patch Set: ready to review Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/http/tests/serviceworker/chromium/resources/usecounter-worker.js
diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/chromium/resources/usecounter-worker.js b/third_party/WebKit/LayoutTests/http/tests/serviceworker/chromium/resources/usecounter-worker.js
new file mode 100644
index 0000000000000000000000000000000000000000..34bee090f502cf9fe7cccbed8ad5cdef792d1d5d
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/chromium/resources/usecounter-worker.js
@@ -0,0 +1,30 @@
+// This should be accessed only in the install event or the message event. When
+// this is false, it implies that this service worker is restarted after the
+// install event.
+let run_install_event = false;
falken 2017/02/08 05:01:54 nit: maybe did_install or did_run_install_event is
nhiroki 2017/02/09 05:11:32 Done.
+
+self.addEventListener('install', e => {
+ var scope = new URL(self.registration.scope);
+ if (scope.searchParams.get('type') == 'features-during-install') {
+ internals.countFeature(scope.searchParams.get('feature'));
+ internals.countDeprecation(scope.searchParams.get('deprecated'));
+ } else if (scope.searchParams.get('type') == 'skip-waiting') {
+ e.waitUntil(self.skipWaiting());
+ }
+ run_install_event = true;
+});
+
+onmessage = e => {
+ if (e.data.type == 'COUNT_FEATURE') {
+ internals.countFeature(e.data.feature);
+ e.source.postMessage({type: 'COUNTED'});
+ } else if (e.data.type == 'COUNT_DEPRECATION') {
+ internals.countDeprecation(e.data.feature);
+ e.source.postMessage({type: 'COUNTED'});
+ } else if (e.data.type == 'CLAIM') {
+ let promise = self.clients.claim()
+ .then(() => e.source.postMessage(
+ {type: 'CLAIMED', restarted: !run_install_event}));
+ e.waitUntil(promise);
+ }
+};

Powered by Google App Engine
This is Rietveld 408576698