Bug 1415433 - cleanup unnecessary update in firefox-data-provider draft
authorFred Lin <gasolin@gmail.com>
Mon, 06 Nov 2017 16:42:47 +0800
changeset 694740 400b1f764263fc92e54de742190b8d08c07427f3
parent 694565 40df5dd35fdb7ce3652fe4448ac8961c075c928e
child 739416 4d5f1da126844b60ae6cab15081c77921d5227ad
push id88222
push userbmo:gasolin@mozilla.com
push dateWed, 08 Nov 2017 06:25:56 +0000
bugs1415433
milestone58.0a1
Bug 1415433 - cleanup unnecessary update in firefox-data-provider MozReview-Commit-ID: CmRe8NunlHL
devtools/client/netmonitor/src/connector/firefox-data-provider.js
--- a/devtools/client/netmonitor/src/connector/firefox-data-provider.js
+++ b/devtools/client/netmonitor/src/connector/firefox-data-provider.js
@@ -68,22 +68,22 @@ class FirefoxDataProvider {
         true,
       );
     }
 
     emit(EVENTS.REQUEST_ADDED, id);
   }
 
   /**
-   * Update a network request if it already exists in application state.
+   * Update a network request and push to a request queue.
    *
    * @param {string} id request id
    * @param {object} data data payload will be updated to application state
    */
-  async updateRequest(id, data) {
+  async updateRequestInQueue(id, data) {
     let {
       mimeType,
       responseContent,
       responseCookies,
       responseHeaders,
       requestCookies,
       requestHeaders,
       requestPostData,
@@ -311,16 +311,17 @@ class FirefoxDataProvider {
       request: {
         method,
         url,
       },
       startedDateTime,
     } = networkInfo;
 
     // Create tracking record for this request.
+    // Untracked events are optional events
     this.rdpRequestMap.set(actor, {
       requestHeaders: false,
       requestCookies: false,
       eventTimings: false,
       responseContent: false,
     });
 
     this.addRequest(actor, {
@@ -366,24 +367,25 @@ class FirefoxDataProvider {
       case "requestPostData":
         this.requestData(actor, updateType).then(response => {
           this.onRequestPostData(response)
             .then(() => this.onDataReceived(actor, updateType));
           emit(EVENTS.UPDATING_REQUEST_POST_DATA, actor);
         });
         break;
       case "securityInfo":
-        this.updateRequest(actor, {
-          securityState: networkInfo.securityInfo,
-        }).then(() => {
-          this.requestData(actor, updateType).then(response => {
-            this.onSecurityInfo(response)
-              .then(() => this.onDataReceived(actor, updateType));
-            emit(EVENTS.UPDATING_SECURITY_INFO, actor);
-          });
+        this.requestData(actor, updateType).then(response => {
+          this.onSecurityInfo(response)
+            .then(() => {
+              this.pushRequestToQueue(actor, {
+                securityState: networkInfo.securityInfo,
+              });
+              this.onDataReceived(actor, updateType);
+            });
+          emit(EVENTS.UPDATING_SECURITY_INFO, actor);
         });
         break;
       case "responseHeaders":
         this.requestData(actor, updateType).then(response => {
           this.onResponseHeaders(response)
             .then(() => this.onDataReceived(actor, updateType));
           emit(EVENTS.UPDATING_RESPONSE_HEADERS, actor);
         });
@@ -391,17 +393,17 @@ class FirefoxDataProvider {
       case "responseCookies":
         this.requestData(actor, updateType).then(response => {
           this.onResponseCookies(response)
             .then(() => this.onDataReceived(actor, updateType));
           emit(EVENTS.UPDATING_RESPONSE_COOKIES, actor);
         });
         break;
       case "responseStart":
-        this.updateRequest(actor, {
+        this.updateRequestInQueue(actor, {
           httpVersion: networkInfo.response.httpVersion,
           remoteAddress: networkInfo.response.remoteAddress,
           remotePort: networkInfo.response.remotePort,
           status: networkInfo.response.status,
           statusText: networkInfo.response.statusText,
           headersSize: networkInfo.response.headersSize
         }).then(() => {
           emit(EVENTS.STARTED_RECEIVING_RESPONSE, actor);
@@ -413,24 +415,26 @@ class FirefoxDataProvider {
             contentSize: networkInfo.response.bodySize,
             transferredSize: networkInfo.response.transferredSize,
             mimeType: networkInfo.response.content.mimeType
           }, response).then(() => this.onDataReceived(actor, updateType));
           emit(EVENTS.UPDATING_RESPONSE_CONTENT, actor);
         });
         break;
       case "eventTimings":
-        this.updateRequest(actor, { totalTime: networkInfo.totalTime })
-          .then(() => {
-            this.requestData(actor, updateType).then(response => {
-              this.onEventTimings(response)
-                .then(() => this.onDataReceived(actor, updateType));
-              emit(EVENTS.UPDATING_EVENT_TIMINGS, actor);
+        this.requestData(actor, updateType).then(response => {
+          this.onEventTimings(response)
+            .then(() => {
+              this.pushRequestToQueue(actor, {
+                totalTime: networkInfo.totalTime,
+              });
+              this.onDataReceived(actor, updateType);
             });
-          });
+          emit(EVENTS.UPDATING_EVENT_TIMINGS, actor);
+        });
         break;
     }
 
     emit(EVENTS.NETWORK_EVENT_UPDATED, actor);
   }
 
   /**
    * Wrapper method for requesting HTTP details data from the backend.
@@ -509,108 +513,108 @@ class FirefoxDataProvider {
   }
 
   /**
    * Handles additional information received for a "requestHeaders" packet.
    *
    * @param {object} response the message received from the server.
    */
   onRequestHeaders(response) {
-    return this.updateRequest(response.from, {
+    return this.updateRequestInQueue(response.from, {
       requestHeaders: response
     }).then(() => {
       emit(EVENTS.RECEIVED_REQUEST_HEADERS, response.from);
     });
   }
 
   /**
    * Handles additional information received for a "requestCookies" packet.
    *
    * @param {object} response the message received from the server.
    */
   onRequestCookies(response) {
-    return this.updateRequest(response.from, {
+    return this.updateRequestInQueue(response.from, {
       requestCookies: response
     }).then(() => {
       emit(EVENTS.RECEIVED_REQUEST_COOKIES, response.from);
     });
   }
 
   /**
    * Handles additional information received for a "requestPostData" packet.
    *
    * @param {object} response the message received from the server.
    */
   onRequestPostData(response) {
-    return this.updateRequest(response.from, {
+    return this.updateRequestInQueue(response.from, {
       requestPostData: response
     }).then(() => {
       emit(EVENTS.RECEIVED_REQUEST_POST_DATA, response.from);
     });
   }
 
   /**
    * Handles additional information received for a "securityInfo" packet.
    *
    * @param {object} response the message received from the server.
    */
   onSecurityInfo(response) {
-    return this.updateRequest(response.from, {
+    return this.updateRequestInQueue(response.from, {
       securityInfo: response.securityInfo
     }).then(() => {
       emit(EVENTS.RECEIVED_SECURITY_INFO, response.from);
     });
   }
 
   /**
    * Handles additional information received for a "responseHeaders" packet.
    *
    * @param {object} response the message received from the server.
    */
   onResponseHeaders(response) {
-    return this.updateRequest(response.from, {
+    return this.updateRequestInQueue(response.from, {
       responseHeaders: response
     }).then(() => {
       emit(EVENTS.RECEIVED_RESPONSE_HEADERS, response.from);
     });
   }
 
   /**
    * Handles additional information received for a "responseCookies" packet.
    *
    * @param {object} response the message received from the server.
    */
   onResponseCookies(response) {
-    return this.updateRequest(response.from, {
+    return this.updateRequestInQueue(response.from, {
       responseCookies: response
     }).then(() => {
       emit(EVENTS.RECEIVED_RESPONSE_COOKIES, response.from);
     });
   }
 
   /**
    * Handles additional information received for a "responseContent" packet.
    *
    * @param {object} data the message received from the server event.
    * @param {object} response the message received from the server.
    */
   onResponseContent(data, response) {
     let payload = Object.assign({ responseContent: response }, data);
-    return this.updateRequest(response.from, payload).then(() => {
+    return this.updateRequestInQueue(response.from, payload).then(() => {
       emit(EVENTS.RECEIVED_RESPONSE_CONTENT, response.from);
     });
   }
 
   /**
    * Handles additional information received for a "eventTimings" packet.
    *
    * @param {object} response the message received from the server.
    */
   onEventTimings(response) {
-    return this.updateRequest(response.from, {
+    return this.updateRequestInQueue(response.from, {
       eventTimings: response
     }).then(() => {
       emit(EVENTS.RECEIVED_EVENT_TIMINGS, response.from);
     });
   }
 }
 
 /**