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

Unified Diff: content/browser/resources/service_worker/serviceworker_internals.js

Issue 304543002: Show the unregistered workers in chrome://serviceworker-internals and chrome://inspect (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Pass live_registrations to chrome://inspect. Created 6 years, 7 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/browser/resources/service_worker/serviceworker_internals.js
diff --git a/content/browser/resources/service_worker/serviceworker_internals.js b/content/browser/resources/service_worker/serviceworker_internals.js
index fa23e7f9eb7415d8478d47b39abd626da9b82b52..c232c2a7bf0164d2fca26dcce6cdec4c9e0a4680 100644
--- a/content/browser/resources/service_worker/serviceworker_internals.js
+++ b/content/browser/resources/service_worker/serviceworker_internals.js
@@ -17,8 +17,7 @@ cr.define('serviceworker', function() {
if (event.origin != 'chrome://inspect') {
return;
}
- chrome.send(event.data.action,
- [event.data.partition_path, event.data.scope]);
+ sendCommand(event.data.action, event.data.worker);
}
function update() {
@@ -31,70 +30,144 @@ cr.define('serviceworker', function() {
// All commands are sent with the partition_path and scope, and
falken 2014/05/28 16:26:06 Is the "partition_path and scope" part of the comm
horo 2014/05/29 01:31:25 Done.
// are all completed with 'onOperationComplete'.
- var COMMANDS = ['unregister', 'start', 'stop', 'sync', 'inspect'];
+ var COMMANDS = ['stop', 'sync', 'inspect', 'unregister', 'start'];
function commandHandler(command) {
return function(event) {
var link = event.target;
progressNodeFor(link).style.display = 'inline';
- chrome.send(command, [link.partition_path,
- link.scope]);
+ sendCommand(command, link.cmdArgs, (function(status){
+ progressNodeFor(link).style.display = 'none';
+ }).bind(null, link));
return false;
};
};
- function withNode(selector, partition_path, scope, callback) {
- var links = document.querySelectorAll(selector);
- for (var i = 0; i < links.length; ++i) {
- var link = links[i];
- if (partition_path == link.partition_path &&
- scope == link.scope) {
- callback(link);
- }
+ var commandCallbacks = [];
+ function sendCommand(command, args, callback) {
+ var callbackId = 0;
+ while (callbackId in commandCallbacks) {
+ callbackId++;
}
+ commandCallbacks[callbackId] = callback;
+ chrome.send(command, [callbackId, args]);
}
- // Fired from the backend after the start call has completed
- function onOperationComplete(status, path, scope) {
- // refreshes the ui, displaying any relevant buttons
- withNode('button', path, scope, function(link) {
- progressNodeFor(link).style.display = 'none';
- });
+ // Fired from the backend after the command call has completed.
+ function onOperationComplete(status, callbackId) {
+ var callback = commandCallbacks[callbackId];
+ delete commandCallbacks[callbackId];
+ if (callback) {
+ callback(status);
+ }
update();
}
- var allLogMessages = {};
-
// Send the active ServiceWorker information to chrome://inspect.
- function sendToInspectPage(registrations, partition_id, partition_path) {
+ function sendToInspectPage(live_registrations,
+ partition_id) {
var workers = [];
- for (var i = 0; i < registrations.length; i++) {
- var registration = registrations[i];
- if (!registration.active ||
- registration.active.running_status != 'RUNNING') {
- continue;
- }
- workers.push({
- 'partition_path': partition_path,
- 'scope': registration.scope,
- 'url': registration.script_url
- })
- }
+ live_registrations.forEach(function (registration) {
falken 2014/05/28 08:21:40 should be no space after "function"? (and througho
horo 2014/05/28 09:06:39 Done.
+ [registration.active,
+ registration.pending].forEach(function (version){
falken 2014/05/28 08:21:40 should be a space before "{"? (and throughout)
horo 2014/05/28 09:06:39 Done.
+ if (!version || version.running_status != 'RUNNING') {
+ return;
+ }
+ workers.push({
+ 'scope': registration.scope,
+ 'url': registration.script_url,
+ 'partition_id': partition_id,
+ 'version_id': version.version_id,
+ 'process_id': version.process_id,
+ 'devtools_agent_route_id':
+ version.devtools_agent_route_id
+ });
+ });
+ });
window.parent.postMessage({
'partition_id': partition_id,
'workers': workers,
}, 'chrome://inspect')
}
+ var allLogMessages = {};
+ // Set log for each worker versions.
falken 2014/05/28 08:21:40 This function is really filling the log for one ve
horo 2014/05/28 09:06:39 Done.
+ function fillLogForVersion(partition_id, version) {
+ if (!version) {
+ return;
+ }
+ if (!(partition_id in allLogMessages)) {
+ allLogMessages[partition_id] = {};
+ }
+ var logMessages = allLogMessages[partition_id];
+ if (version.version_id in logMessages) {
+ version.log = logMessages[version.version_id];
+ } else {
+ version.log = '';
+ }
+ }
+
+ // Get the unregistered workers.
+ // |unregistered_registrations| will be filled with the registrations which
+ // are in |live_registrations| but not in |stored_registrations|.
+ // |unregistered_versions| will be filled with the versions which
+ // are in |live_versions| but not in |stored_registrations| nor in
+ // |live_registrations|.
+ function getUnregisteredWorkers(stored_registrations,
+ live_registrations,
+ live_versions,
+ unregistered_registrations,
+ unregistered_versions) {
+ var registration_id_set = {};
+ var version_id_set = {};
+ stored_registrations.forEach(function (registration) {
falken 2014/05/28 08:21:40 should be no space after "function"?
horo 2014/05/28 09:06:39 Done.
+ registration_id_set[registration.registration_id] = true;
+ });
+ [stored_registrations, live_registrations].forEach(
+ function (registrations) {
+ registrations.forEach(function (registration) {
+ [registration.active,
+ registration.pending].forEach(
+ function (version){
+ if (version) {
+ version_id_set[version.version_id] = true;
+ }
+ });
falken 2014/05/28 08:21:40 this close paren should be aligned with its open p
horo 2014/05/28 09:06:39 Done.
+ });
+ });
+ live_registrations.forEach(function (registration) {
+ if (!registration_id_set[registration.registration_id]) {
+ registration.unregistered = true;
+ unregistered_registrations.push(registration);
+ }
+ });
+ live_versions.forEach(function (version) {
+ if (!version_id_set[version.version_id]) {
+ unregistered_versions.push(version);
+ }
+ });
+ }
+
// Fired once per partition from the backend.
- function onPartitionData(registrations, partition_id, partition_path) {
+ function onPartitionData(live_registrations,
+ live_versions,
+ stored_registrations,
+ partition_id,
+ partition_path) {
if (window.location.hash == "#iframe") {
// This page is loaded from chrome://inspect.
- sendToInspectPage(registrations, partition_id, partition_path);
+ sendToInspectPage(live_registrations,
+ partition_id);
return;
}
+ var unregistered_registrations = [];
+ var unregistered_versions = [];
+ getUnregisteredWorkers(stored_registrations,
+ live_registrations,
+ live_versions,
+ unregistered_registrations,
+ unregistered_versions);
var template;
var container = $('serviceworker-list');
-
// Existing templates are keyed by partition_path. This allows
// the UI to be updated in-place rather than refreshing the
// whole page.
@@ -103,33 +176,25 @@ cr.define('serviceworker', function() {
template = container.childNodes[i];
}
}
-
// This is probably the first time we're loading.
if (!template) {
template = jstGetTemplate('serviceworker-list-template');
container.appendChild(template);
}
-
- // Set log for each worker versions.
- if (!(partition_id in allLogMessages)) {
- allLogMessages[partition_id] = {};
- }
- var logMessages = allLogMessages[partition_id];
- registrations.forEach(function (worker) {
- [worker.active, worker.pending].forEach(function (version) {
- if (version) {
- if (version.version_id in logMessages) {
- version.log = logMessages[version.version_id];
- } else {
- version.log = '';
- }
- }
- });
+ var fillLogFunc = fillLogForVersion.bind(this, partition_id);
+ stored_registrations.forEach(function (registration) {
+ [registration.active, registration.pending].forEach(fillLogFunc);
});
-
- jstProcess(new JsEvalContext({ registrations: registrations,
- partition_id: partition_id,
- partition_path: partition_path}),
+ unregistered_registrations.forEach(function (registration) {
+ [registration.active, registration.pending].forEach(fillLogFunc);
+ });
+ unregistered_versions.forEach(fillLogFunc);
+ jstProcess(new JsEvalContext({
+ stored_registrations: stored_registrations,
+ unregistered_registrations: unregistered_registrations,
+ unregistered_versions: unregistered_versions,
+ partition_id: partition_id,
+ partition_path: partition_path}),
template);
for (var i = 0; i < COMMANDS.length; ++i) {
var handler = commandHandler(COMMANDS[i]);
@@ -207,7 +272,6 @@ cr.define('serviceworker', function() {
return {
initialize: initialize,
- update: update,
onOperationComplete: onOperationComplete,
onPartitionData: onPartitionData,
onWorkerStarted: onWorkerStarted,

Powered by Google App Engine
This is Rietveld 408576698