Bug 1017433 (part 1) - Have the sync RecordManager return CryptoWrappers. r=rnewman
authorMark Hammond <mhammond@skippinet.com.au>
Wed, 10 Dec 2014 13:02:24 +1100
changeset 218979 961e53b507fe37ca2dc145a8e107253b0eac33f6
parent 218978 b3198f39b947bf936b2a7d62c58a4ecf4143aaba
child 218980 d90fa41d351ce1a020d61ccbb9aaece5fc44eccd
push id27950
push usercbook@mozilla.com
push dateWed, 10 Dec 2014 10:58:50 +0000
treeherderautoland@5b01216f97f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs1017433
milestone37.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 1017433 (part 1) - Have the sync RecordManager return CryptoWrappers. r=rnewman
services/sync/modules/record.js
--- a/services/sync/modules/record.js
+++ b/services/sync/modules/record.js
@@ -100,78 +100,16 @@ WBORecord.prototype = {
       "ttl: "      + this.ttl       + "  " +
       "payload: "  + JSON.stringify(this.payload) +
       " }";
   }
 };
 
 Utils.deferGetSet(WBORecord, "data", ["id", "modified", "sortindex", "payload"]);
 
-/**
- * An interface and caching layer for records.
- */
-this.RecordManager = function RecordManager(service) {
-  this.service = service;
-
-  this._log = Log.repository.getLogger(this._logName);
-  this._records = {};
-}
-RecordManager.prototype = {
-  _recordType: WBORecord,
-  _logName: "Sync.RecordManager",
-
-  import: function RecordMgr_import(url) {
-    this._log.trace("Importing record: " + (url.spec ? url.spec : url));
-    try {
-      // Clear out the last response with empty object if GET fails
-      this.response = {};
-      this.response = this.service.resource(url).get();
-
-      // Don't parse and save the record on failure
-      if (!this.response.success)
-        return null;
-
-      let record = new this._recordType(url);
-      record.deserialize(this.response);
-
-      return this.set(url, record);
-    } catch(ex) {
-      this._log.debug("Failed to import record: " + Utils.exceptionStr(ex));
-      return null;
-    }
-  },
-
-  get: function RecordMgr_get(url) {
-    // Use a url string as the key to the hash
-    let spec = url.spec ? url.spec : url;
-    if (spec in this._records)
-      return this._records[spec];
-    return this.import(url);
-  },
-
-  set: function RecordMgr_set(url, record) {
-    let spec = url.spec ? url.spec : url;
-    return this._records[spec] = record;
-  },
-
-  contains: function RecordMgr_contains(url) {
-    if ((url.spec || url) in this._records)
-      return true;
-    return false;
-  },
-
-  clearCache: function recordMgr_clearCache() {
-    this._records = {};
-  },
-
-  del: function RecordMgr_del(url) {
-    delete this._records[url];
-  }
-};
-
 this.CryptoWrapper = function CryptoWrapper(collection, id) {
   this.cleartext = {};
   WBORecord.call(this, collection, id);
   this.ciphertext = null;
   this.id = id;
 }
 CryptoWrapper.prototype = {
   __proto__: WBORecord.prototype,
@@ -264,16 +202,77 @@ CryptoWrapper.prototype = {
     WBORecord.prototype.__lookupSetter__("id").call(this, val);
     return this.cleartext.id = val;
   },
 };
 
 Utils.deferGetSet(CryptoWrapper, "payload", ["ciphertext", "IV", "hmac"]);
 Utils.deferGetSet(CryptoWrapper, "cleartext", "deleted");
 
+/**
+ * An interface and caching layer for records.
+ */
+this.RecordManager = function RecordManager(service) {
+  this.service = service;
+
+  this._log = Log.repository.getLogger(this._logName);
+  this._records = {};
+}
+RecordManager.prototype = {
+  _recordType: CryptoWrapper,
+  _logName: "Sync.RecordManager",
+
+  import: function RecordMgr_import(url) {
+    this._log.trace("Importing record: " + (url.spec ? url.spec : url));
+    try {
+      // Clear out the last response with empty object if GET fails
+      this.response = {};
+      this.response = this.service.resource(url).get();
+
+      // Don't parse and save the record on failure
+      if (!this.response.success)
+        return null;
+
+      let record = new this._recordType(url);
+      record.deserialize(this.response);
+
+      return this.set(url, record);
+    } catch(ex) {
+      this._log.debug("Failed to import record: " + Utils.exceptionStr(ex));
+      return null;
+    }
+  },
+
+  get: function RecordMgr_get(url) {
+    // Use a url string as the key to the hash
+    let spec = url.spec ? url.spec : url;
+    if (spec in this._records)
+      return this._records[spec];
+    return this.import(url);
+  },
+
+  set: function RecordMgr_set(url, record) {
+    let spec = url.spec ? url.spec : url;
+    return this._records[spec] = record;
+  },
+
+  contains: function RecordMgr_contains(url) {
+    if ((url.spec || url) in this._records)
+      return true;
+    return false;
+  },
+
+  clearCache: function recordMgr_clearCache() {
+    this._records = {};
+  },
+
+  del: function RecordMgr_del(url) {
+    delete this._records[url];
+  }
+};
 
 /**
  * Keeps track of mappings between collection names ('tabs') and KeyBundles.
  *
  * You can update this thing simply by giving it /info/collections. It'll
  * use the last modified time to bring itself up to date.
  */
 this.CollectionKeyManager = function CollectionKeyManager() {