| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var activatedServiceWorkerPromise = null; | 5 var activatedServiceWorkerPromise = null; |
| 6 var messagePort = null; |
| 6 | 7 |
| 7 // Returns a promise that will be resolved with an activated Service | 8 // Returns a promise that will be resolved with an activated Service |
| 8 // Worker, or rejects when the Service Worker could not be started. There | 9 // Worker, or rejects when the Service Worker could not be started. There |
| 9 // will be a message port to and from the worker in |messagePort|. | 10 // will be a message port to and from the worker in |messagePort|. |
| 10 function GetActivatedServiceWorker(script, scope) { | 11 function GetActivatedServiceWorker(script, scope) { |
| 11 if (activatedServiceWorkerPromise == null) { | 12 if (activatedServiceWorkerPromise == null) { |
| 12 activatedServiceWorkerPromise = | 13 activatedServiceWorkerPromise = |
| 13 navigator.serviceWorker.getRegistration(scope) | 14 navigator.serviceWorker.getRegistration(scope) |
| 14 .then(function(registration) { | 15 .then(function(registration) { |
| 15 // Unregister any existing Service Worker. | 16 // Unregister any existing Service Worker. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 44 [ channel.port2 ]); | 45 [ channel.port2 ]); |
| 45 | 46 |
| 46 messagePort = channel.port1; | 47 messagePort = channel.port1; |
| 47 messagePort.start(); | 48 messagePort.start(); |
| 48 }); | 49 }); |
| 49 }); | 50 }); |
| 50 } | 51 } |
| 51 | 52 |
| 52 return activatedServiceWorkerPromise; | 53 return activatedServiceWorkerPromise; |
| 53 } | 54 } |
| OLD | NEW |