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 777374 9cf8d7ece10d5c2a58e76016249e021ae0b9c098
parent 777358 724c5ab10e7371f85496d0ba0e682a2c61cc14ce
push id105190
push userbmo:poirot.alex@gmail.com
push dateWed, 04 Apr 2018 18:06:20 +0000
reviewersjryans
bugs1449162
milestone61.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);
@@ -267,19 +256,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.parent._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", "requestHeaders", {
       headers: headers.length,
       headersSize: this._request.headersSize,
     });
   },
@@ -302,40 +290,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.parent._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", "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.parent._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;
@@ -399,20 +381,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.parent._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", "responseContent", {
       mimeType: content.mimeType,
       contentSize: content.size,
       encoding: content.encoding,
       transferredSize: content.transferredSize,
       discardResponseBody,
     });
@@ -440,17 +419,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.parent._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
@@ -470,30 +470,20 @@ var StyleSheetActor = protocol.ActorClas
     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 = this.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,
     };
   },
 
   /**
    * Protocol method to get the media rules for the stylesheet.
    */
   getMediaRules: function() {