add a generic WBO record manager
authorDan Mills <thunder@mozilla.com>
Wed, 11 Feb 2009 23:53:37 -0800
changeset 45261 4e379046d01d7a8473ca17455af60ccec043e818
parent 45260 6325083b0f3b1382e73835c2c5f9680a7909f1d2
child 45262 1824d663526415aeee41f8dc6f0151f9577c53e5
push idunknown
push userunknown
push dateunknown
add a generic WBO record manager
services/sync/modules/base_records/wbo.js
--- a/services/sync/modules/base_records/wbo.js
+++ b/services/sync/modules/base_records/wbo.js
@@ -29,17 +29,17 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-const EXPORTED_SYMBOLS = ['WBORecord', 'RecordManager'];
+const EXPORTED_SYMBOLS = ['WBORecord', 'RecordManager', 'Records'];
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cr = Components.results;
 const Cu = Components.utils;
 
 Cu.import("resource://weave/log4moz.js");
 Cu.import("resource://weave/resource.js");
@@ -133,16 +133,18 @@ WBORecord.prototype = {
     return "{ id: " + this.id + "\n" +
       "  parent: " + this.parentid + "\n" +
       "  depth: " + this.depth + ", index: " + this.sortindex + "\n" +
       "  modified: " + this.modified + "\n" +
       "  payload: " + Svc.Json.encode(this.payload) + " }";
   }
 };
 
+Utils.lazy(this, 'Records', RecordManager);
+
 function RecordManager() {
   this._init();
 }
 RecordManager.prototype = {
   _recordType: WBORecord,
   _logName: "RecordMgr",
 
   _init: function RegordMgr__init() {
@@ -154,22 +156,22 @@ RecordManager.prototype = {
   import: function RegordMgr_import(onComplete, url) {
     let fn = function RegordMgr__import(url) {
       let self = yield;
       let record;
 
       this._log.trace("Importing record: " + (url.spec? url.spec : url));
 
       try {
-        let rsrc = new Resource(url);
-        yield rsrc.get(self.cb);
+        this.lastResource = new Resource(url);
+        yield this.lastResource.get(self.cb);
 
         record = new this._recordType();
-	record.deserialize(rsrc.data);
-	record.uri = url; // NOTE: may override id in rsrc.data
+	record.deserialize(this.lastResource.data);
+	record.uri = url; // NOTE: may override id in this.lastResource.data
 
         this.set(url, record);
       } catch (e) {
         this._log.debug("Failed to import record: " + e);
         record = null;
       }
       self.done(record);
     };