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

Unified Diff: content/test/data/background_sync/service_worker.js

Issue 1344843003: [BackgroundSync] Add browser side support for SyncRegistration.done (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ncn_max
Patch Set: Rebase Created 5 years, 3 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: content/test/data/background_sync/service_worker.js
diff --git a/content/test/data/background_sync/service_worker.js b/content/test/data/background_sync/service_worker.js
index 56be354933bffe02d4021c9b75ea32e6948e7641..08b910d219fc7f65fb4b90b5a7f410c659f0e639 100644
--- a/content/test/data/background_sync/service_worker.js
+++ b/content/test/data/background_sync/service_worker.js
@@ -17,7 +17,7 @@ var resolveCallback = null;
var rejectCallback = null;
this.onmessage = function(event) {
- if (event.data === 'completeDelayedOneShot') {
+ if (event.data['action'] === 'completeDelayedOneShot') {
if (resolveCallback === null) {
sendMessageToClients('sync', 'error - resolveCallback is null');
return;
@@ -28,7 +28,7 @@ this.onmessage = function(event) {
return;
}
- if (event.data === 'rejectDelayedOneShot') {
+ if (event.data['action'] === 'rejectDelayedOneShot') {
if (rejectCallback === null) {
sendMessageToClients('sync', 'error - rejectCallback is null');
return;
@@ -37,6 +37,21 @@ this.onmessage = function(event) {
rejectCallback();
sendMessageToClients('sync', 'ok - delay rejected');
}
+
+ if (event.data['action'] === 'notifyWhenDone') {
+ var tag = event.data['tag'];
+ registration.sync.getRegistration(tag)
+ .then(function (syncRegistration) {
michaeln 2015/09/17 21:44:12 nit: indent two more spaces?
jkarlin 2015/09/18 12:03:20 Done.
+ sendMessageToClients('sync', 'ok - ' + tag + ' done');
+ return syncRegistration.done;
+ })
+ .then(function(success) {
+ sendMessageToClients('sync', tag + " done result: " + success);
+ }, function(error) {
+ sendMessageToClients('sync', tag + " done result: error");
+ })
+ .catch(sendSyncErrorToClients);
+ }
}
this.onsync = function(event) {
@@ -96,3 +111,7 @@ function sendMessageToClients(type, data) {
console.log(error);
});
}
+
+function sendSyncErrorToClients(error) {
+ sendMessageToClients('sync', error.name + ' - ' + error.message);
+}

Powered by Google App Engine
This is Rietveld 408576698