Bug 1449162 - Attach longstrings to NetworkEventActor directly instead of WebConsoleActor. r=jryans draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Thu, 29 Mar 2018 02:28:16 -0700
changeset 800605 cb48b9869f94a634de30085537c1baf6bfe7d576
parent 800604 6809cc23b7a4398c5c35e6af027e7bc118e07724
child 800606 9d4768658d802ac01166b7a0f5d217f553bcb41c
push id111423
push userbmo:poirot.alex@gmail.com
push dateMon, 28 May 2018 16:48:32 +0000
reviewersjryans
bugs1449162
milestone62.0a1
Bug 1449162 - Attach longstrings to NetworkEventActor directly instead of WebConsoleActor. r=jryans Now that NetworkEventActor uses protocol.js, it can manage child actors it uses. So instead of hosting the longstring it creates into WebConsoleActor pool, it can register them it internal pool managed by protocol.js. MozReview-Commit-ID: 9ekezmqWnME
devtools/server/actors/network-event.js
devtools/server/actors/stylesheets.js
--- a/devtools/server/actors/network-event.js
+++ b/devtools/server/actors/network-event.js
@@ -1,16 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 const protocol = require("devtools/shared/protocol");
 const { networkEventSpec } = require("devtools/shared/specs/network-event");
+const { LongStringActor } = require("devtools/server/actors/string");
 
 /**
  * Creates an actor for a network event.
  *
  * @constructor
  * @param object webConsoleActor
  *        The parent WebConsoleActor instance for this object.
  */
@@ -38,25 +39,21 @@ const NetworkEventActor = protocol.Actor
       content: {},
     };
 
     this._timings = {};
     this._stackTrace = {};
 
     this._discardRequestBody = false;
     this._discardResponseBody = false;
-
-    // Keep track of LongStringActors owned by this NetworkEventActor.
-    this._longStringActors = new Set();
   },
 
   _request: null,
   _response: null,
   _timings: null,
-  _longStringActors: null,
 
   /**
    * Returns a grip for this actor for returning in a protocol message.
    */
   form() {
     return {
       actor: this.actorID,
       startedDateTime: this._startedDateTime,
@@ -70,24 +67,16 @@ const NetworkEventActor = protocol.Actor
       private: this._private,
     };
   },
 
   /**
    * Releases this actor from the pool.
    */
   destroy(conn) {
-    for (let grip of this._longStringActors) {
-      let actor = this.webConsoleActor.getActorByID(grip.actor);
-      if (actor) {
-        this.webConsoleActor.releaseActor(actor);
-      }
-    }
-    this._longStringActors = new Set();
-
     if (!this.webConsoleActor) {
       return;
     }
     if (this._request.url) {
       this.webConsoleActor._networkEventActorsByURL.delete(this._request.url);
     }
     if (this.channel) {
       this.webConsoleActor._netEvents.delete(this.channel);
@@ -279,19 +268,18 @@ const NetworkEventActor = protocol.Actor
    *        The request headers array.
    * @param string rawHeaders
    *        The raw headers source.
    */
   addRequestHeaders(headers, rawHeaders) {
     this._request.headers = headers;
     this._prepareHeaders(headers);
 
-    rawHeaders = this.webConsoleActor._createStringGrip(rawHeaders);
-    if (typeof rawHeaders == "object") {
-      this._longStringActors.add(rawHeaders);
+    if (rawHeaders) {
+      rawHeaders = new LongStringActor(this.conn, rawHeaders);
     }
     this._request.rawHeaders = rawHeaders;
 
     this.emit("network-event-update:headers", "requestHeaders", {
       headers: headers.length,
       headersSize: this._request.headersSize,
     });
   },
@@ -314,40 +302,34 @@ const NetworkEventActor = protocol.Actor
   /**
    * Add network request POST data.
    *
    * @param object postData
    *        The request POST data.
    */
   addRequestPostData(postData) {
     this._request.postData = postData;
-    postData.text = this.webConsoleActor._createStringGrip(postData.text);
-    if (typeof postData.text == "object") {
-      this._longStringActors.add(postData.text);
-    }
+    postData.text = new LongStringActor(this.conn, postData.text);
 
     this.emit("network-event-update:post-data", "requestPostData", {
-      dataSize: postData.text.length,
+      dataSize: postData.text.str.length,
       discardRequestBody: this._discardRequestBody,
     });
   },
 
   /**
    * Add the initial network response information.
    *
    * @param object info
    *        The response information.
    * @param string rawHeaders
    *        The raw headers source.
    */
   addResponseStart(info, rawHeaders) {
-    rawHeaders = this.webConsoleActor._createStringGrip(rawHeaders);
-    if (typeof rawHeaders == "object") {
-      this._longStringActors.add(rawHeaders);
-    }
+    rawHeaders = new LongStringActor(this.conn, rawHeaders);
     this._response.rawHeaders = rawHeaders;
 
     this._response.httpVersion = info.httpVersion;
     this._response.status = info.status;
     this._response.statusText = info.statusText;
     this._response.headersSize = info.headersSize;
     // Consider as not discarded if info.discardResponseBody is undefined
     this._discardResponseBody = !!info.discardResponseBody;
@@ -411,20 +393,17 @@ const NetworkEventActor = protocol.Actor
    *        - boolean discardedResponseBody
    *          Tells if the response content was recorded or not.
    *        - boolean truncated
    *          Tells if the some of the response content is missing.
    */
   addResponseContent(content, {discardResponseBody, truncated}) {
     this._truncated = truncated;
     this._response.content = content;
-    content.text = this.webConsoleActor._createStringGrip(content.text);
-    if (typeof content.text == "object") {
-      this._longStringActors.add(content.text);
-    }
+    content.text = new LongStringActor(this.conn, content.text);
 
     this.emit("network-event-update:response-content", "responseContent", {
       mimeType: content.mimeType,
       contentSize: content.size,
       encoding: content.encoding,
       transferredSize: content.transferredSize,
       discardResponseBody,
     });
@@ -457,17 +436,14 @@ const NetworkEventActor = protocol.Actor
    * Prepare the headers array to be sent to the client by using the
    * LongStringActor for the header values, when needed.
    *
    * @private
    * @param array aHeaders
    */
   _prepareHeaders(headers) {
     for (let header of headers) {
-      header.value = this.webConsoleActor._createStringGrip(header.value);
-      if (typeof header.value == "object") {
-        this._longStringActors.add(header.value);
-      }
+      header.value = new LongStringActor(this.conn, header.value);
     }
   },
 });
 
 exports.NetworkEventActor = NetworkEventActor;
--- a/devtools/server/actors/stylesheets.js
+++ b/devtools/server/actors/stylesheets.js
@@ -156,30 +156,20 @@ function fetchStylesheetFromNetworkMonit
   let request = consoleActor.getNetworkEventActorForURL(href);
   if (!request) {
     return null;
   }
   let content = request._response.content;
   if (request._discardResponseBody || request._truncated || !content) {
     return null;
   }
-  if (content.text.type != "longString") {
-    // For short strings, the text is available directly.
-    return {
-      content: content.text,
-      contentType: content.mimeType,
-    };
-  }
-  // For long strings, look up the actor that holds the full text.
-  let longStringActor = consoleActor.conn._getOrCreateActor(content.text.actor);
-  if (!longStringActor) {
-    return null;
-  }
+  // `content.text` is a LongStringActor instance
+  // Get a reference to the raw string via `str` property
   return {
-    content: longStringActor.rawValue(),
+    content: content.text.str,
     contentType: content.mimeType,
   };
 }
 
 /**
  * Get the charset of the stylesheet.
  */
 function getCSSCharset(sheet) {