Bug 1523454 - Remove isActive and isRunning from worker details;r=daisuke
authorJulian Descottes <jdescottes@mozilla.com>
Fri, 08 Feb 2019 15:22:01 +0000
changeset 458863 1a88323932cb
parent 458862 1d79453b1f68
child 458864 96b6da57e237
push id35551
push usershindli@mozilla.com
push dateWed, 13 Feb 2019 21:34:09 +0000
treeherdermozilla-central@08f794a4928e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaisuke
bugs1523454
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1523454 - Remove isActive and isRunning from worker details;r=daisuke Depends on D18365. Not mandatory, but relying on the computed state seems better than duplicating the logic around isActive/isRunning. Differential Revision: https://phabricator.services.mozilla.com/D18366
devtools/client/aboutdebugging-new/src/components/debugtarget/ServiceWorkerAction.js
devtools/client/aboutdebugging-new/src/middleware/worker-component-data.js
devtools/client/aboutdebugging-new/src/types/debug-target.js
--- a/devtools/client/aboutdebugging-new/src/components/debugtarget/ServiceWorkerAction.js
+++ b/devtools/client/aboutdebugging-new/src/components/debugtarget/ServiceWorkerAction.js
@@ -13,16 +13,17 @@ const FluentReact = require("devtools/cl
 const Localized = createFactory(FluentReact.Localized);
 
 const { getCurrentRuntimeDetails } = require("../../modules/runtimes-state-helper");
 
 const InspectAction = createFactory(require("./InspectAction"));
 
 const Actions = require("../../actions/index");
 const Types = require("../../types/index");
+const { SERVICE_WORKER_STATUSES } = require("../../constants");
 
 /**
  * This component displays buttons for service worker.
  */
 class ServiceWorkerAction extends PureComponent {
   static get propTypes() {
     return {
       dispatch: PropTypes.func.isRequired,
@@ -100,35 +101,39 @@ class ServiceWorkerAction extends PureCo
       className: "default-button js-unregister-button",
       key: "service-worker-unregister-button",
       labelId: "about-debugging-worker-action-unregister",
       onClick: this.unregister.bind(this),
     });
   }
 
   _renderAction() {
-    const { isActive, isRunning } = this.props.target.details;
-
-    if (!isRunning) {
-      return [
-        this._renderUnregisterButton(),
-        this._renderStartButton(),
-      ];
-    }
+    const { status } = this.props.target.details;
 
-    if (!isActive) {
-      // Only inspect is available if the service worker is not active.
-      return [this._renderInspectAction()];
+    switch (status) {
+      case SERVICE_WORKER_STATUSES.RUNNING:
+        return [
+          this._renderUnregisterButton(),
+          this._renderPushButton(),
+          this._renderInspectAction(),
+        ];
+      case SERVICE_WORKER_STATUSES.REGISTERING:
+        // Only inspect is available if the service worker is not active.
+        return [
+          this._renderInspectAction(),
+        ];
+      case SERVICE_WORKER_STATUSES.STOPPED:
+        return [
+          this._renderUnregisterButton(),
+          this._renderStartButton(),
+        ];
+      default:
+        console.error("Unexpected service worker status: " + status);
+        return [];
     }
-
-    return [
-      this._renderUnregisterButton(),
-      this._renderPushButton(),
-      this._renderInspectAction(),
-    ];
   }
 
   render() {
     return dom.div(
       {
         className: "toolbar",
       },
       this._renderAction()
--- a/devtools/client/aboutdebugging-new/src/middleware/worker-component-data.js
+++ b/devtools/client/aboutdebugging-new/src/middleware/worker-component-data.js
@@ -23,17 +23,20 @@ const workerComponentDataMiddleware = st
       action.sharedWorkers = toComponentData(action.sharedWorkers);
       break;
     }
   }
 
   return next(action);
 };
 
-function getServiceWorkerStatus(isActive, isRunning) {
+function getServiceWorkerStatus(worker) {
+  const isActive = worker.active;
+  const isRunning = !!worker.workerTargetFront;
+
   if (isActive && isRunning) {
     return SERVICE_WORKER_STATUSES.RUNNING;
   } else if (isActive) {
     return SERVICE_WORKER_STATUSES.STOPPED;
   }
   // We cannot get service worker registrations unless the registration is in
   // ACTIVE state. Unable to know the actual state ("installing", "waiting"), we
   // display a custom state "registering" for now. See Bug 1153292.
@@ -54,35 +57,29 @@ function toComponentData(workers, isServ
       workerTargetFront,
     } = worker;
 
     // For registering service workers, workerTargetFront will not be available.
     // The only valid identifier we can use at that point is the actorID for the
     // service worker registration.
     const id = workerTargetFront ? workerTargetFront.actorID : registrationFront.actorID;
 
-    let isActive = false;
-    let isRunning = false;
     let pushServiceEndpoint = null;
     let status = null;
 
     if (isServiceWorker) {
       fetch = fetch ? SERVICE_WORKER_FETCH_STATES.LISTENING
                     : SERVICE_WORKER_FETCH_STATES.NOT_LISTENING;
-      isActive = worker.active;
-      isRunning = !!worker.workerTargetFront;
-      status = getServiceWorkerStatus(isActive, isRunning);
+      status = getServiceWorkerStatus(worker);
       pushServiceEndpoint = subscription ? subscription.endpoint : null;
     }
 
     return {
       details: {
         fetch,
-        isActive,
-        isRunning,
         pushServiceEndpoint,
         registrationFront,
         scope,
         status,
       },
       icon,
       id,
       name,
--- a/devtools/client/aboutdebugging-new/src/types/debug-target.js
+++ b/devtools/client/aboutdebugging-new/src/types/debug-target.js
@@ -22,20 +22,16 @@ const extensionTargetDetails = {
 const tabTargetDetails = {
   // the url of the tab.
   url: PropTypes.string.isRequired,
 };
 
 const workerTargetDetails = {
   // (service worker specific) one of "LISTENING", "NOT_LISTENING". undefined otherwise.
   fetch: PropTypes.string,
-  // (service worker specific) true if they reached the activated state.
-  isActive: PropTypes.bool,
-  // (service worker specific) true if they are currently running.
-  isRunning: PropTypes.bool,
   // front for the ServiceWorkerRegistration related to this service worker.
   registrationFront: PropTypes.object,
   // (service worker specific) scope of the service worker registration.
   scope: PropTypes.string,
   // (service worker specific) one of "RUNNING", "REGISTERING", "STOPPED".
   status: PropTypes.string,
 };