Bug 1416468 - Share container data parsing instead of duplicating it. r=baku a=baku
authorIan Moody <moz-ian@perix.co.uk>
Tue, 14 Nov 2017 01:55:17 +0100
changeset 391597 e1d7427787f7a26983c92ea1a1ac99eb863edd6c
parent 391596 c9f889585dd884a692064b8c9a9e3ad1d1deb308
child 391598 9673bed1d07e7be03ddf96fe46e00667cdc76c63
push id32894
push userarchaeopteryx@coole-files.de
push dateTue, 14 Nov 2017 00:55:46 +0000
treeherdermozilla-central@e1d7427787f7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku, baku
bugs1416468
milestone59.0a1
first release with
nightly linux32
e1d7427787f7 / 59.0a1 / 20171114100042 / files
nightly linux64
e1d7427787f7 / 59.0a1 / 20171114100042 / files
nightly mac
e1d7427787f7 / 59.0a1 / 20171114100042 / files
nightly win32
e1d7427787f7 / 59.0a1 / 20171114100042 / files
nightly win64
e1d7427787f7 / 59.0a1 / 20171114100042 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1416468 - Share container data parsing instead of duplicating it. r=baku a=baku
toolkit/components/contextualidentity/ContextualIdentityService.jsm
--- a/toolkit/components/contextualidentity/ContextualIdentityService.jsm
+++ b/toolkit/components/contextualidentity/ContextualIdentityService.jsm
@@ -146,30 +146,17 @@ function _ContextualIdentityService(path
   load() {
     OS.File.read(this._path).then(bytes => {
       // If synchronous loading happened in the meantime, exit now.
       if (this._dataReady) {
         return;
       }
 
       try {
-        let data = JSON.parse(gTextDecoder.decode(bytes));
-        if (data.version == 1) {
-          this.resetDefault();
-        }
-        if (data.version != 2) {
-          dump("ERROR - ContextualIdentityService - Unknown version found in " + this._path + "\n");
-          this.loadError(null);
-          return;
-        }
-
-        this._identities = data.identities;
-        this._lastUserContextId = data.lastUserContextId;
-
-        this._dataReady = true;
+        this.parseData(bytes);
       } catch (error) {
         this.loadError(error);
       }
     }, (error) => {
       this.loadError(error);
     });
   },
 
@@ -300,34 +287,47 @@ function _ContextualIdentityService(path
       icon: identity.icon,
       color: identity.color,
       userContextId: identity.userContextId,
     };
 
     return {wrappedJSObject};
   },
 
+  parseData(bytes) {
+    let data = JSON.parse(gTextDecoder.decode(bytes));
+    if (data.version == 1) {
+      this.resetDefault();
+    }
+    if (data.version != 2) {
+      dump("ERROR - ContextualIdentityService - Unknown version found in " + this._path + "\n");
+      this.loadError(null);
+      return;
+    }
+
+    this._identities = data.identities;
+    this._lastUserContextId = data.lastUserContextId;
+
+    this._dataReady = true;
+  },
+
   ensureDataReady() {
     if (this._dataReady) {
       return;
     }
 
     try {
       // This reads the file and automatically detects the UTF-8 encoding.
       let inputStream = Cc["@mozilla.org/network/file-input-stream;1"]
                           .createInstance(Ci.nsIFileInputStream);
       inputStream.init(new FileUtils.File(this._path),
                        FileUtils.MODE_RDONLY, FileUtils.PERMS_FILE, 0);
       try {
-        let bytes = NetUtil.readInputStreamToString(inputStream, inputStream.available());
-        let data = JSON.parse(gTextDecoder.decode(bytes));
-        this._identities = data.identities;
-        this._lastUserContextId = data.lastUserContextId;
-
-        this._dataReady = true;
+        let bytes = NetUtil.readInputStream(inputStream, inputStream.available());
+        this.parseData(bytes);
       } finally {
         inputStream.close();
       }
     } catch (error) {
       this.loadError(error);
     }
   },