Bug 637576 - Part 0: Sync Form engine: tidying and cleanup. r=philikon
authorRichard Newman <rnewman@mozilla.com>
Mon, 22 Aug 2011 10:38:28 -0700
changeset 75733 7df9d5dfdb75c4c9b9aeab0c473cc0a55b24e741
parent 75732 2e842de9564da92b7ee384eccff37942b2eb7b07
child 75734 0b209890603fab79662900a3ea24c7b2f4a9b227
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersphilikon
bugs637576
milestone9.0a1
Bug 637576 - Part 0: Sync Form engine: tidying and cleanup. r=philikon
services/sync/modules/engines/forms.js
--- a/services/sync/modules/engines/forms.js
+++ b/services/sync/modules/engines/forms.js
@@ -59,17 +59,17 @@ FormRec.prototype = {
   ttl: FORMS_TTL
 };
 
 Utils.deferGetSet(FormRec, "cleartext", ["name", "value"]);
 
 
 let FormWrapper = {
   _log: Log4Moz.repository.getLogger("Sync.Engine.Forms"),
-    
+
   getAllEntries: function getAllEntries() {
     // Sort by (lastUsed - minLast) / (maxLast - minLast) * timesUsed / maxTimes
     let query = Svc.Form.DBConnection.createAsyncStatement(
       "SELECT fieldname name, value FROM moz_formhistory " +
       "ORDER BY 1.0 * (lastUsed - (SELECT lastUsed FROM moz_formhistory ORDER BY lastUsed ASC LIMIT 1)) / " +
         "((SELECT lastUsed FROM moz_formhistory ORDER BY lastUsed DESC LIMIT 1) - (SELECT lastUsed FROM moz_formhistory ORDER BY lastUsed ASC LIMIT 1)) * " +
         "timesUsed / (SELECT timesUsed FROM moz_formhistory ORDER BY timesUsed DESC LIMIT 1) DESC " +
       "LIMIT 500");
@@ -79,39 +79,40 @@ let FormWrapper = {
   getEntry: function getEntry(guid) {
     let query = Svc.Form.DBConnection.createAsyncStatement(
       "SELECT fieldname name, value FROM moz_formhistory WHERE guid = :guid");
     query.params.guid = guid;
     return Async.querySpinningly(query, ["name", "value"])[0];
   },
 
   getGUID: function getGUID(name, value) {
-    // Query for the provided entry
+    // Query for the provided entry.
     let getQuery = Svc.Form.DBConnection.createAsyncStatement(
       "SELECT guid FROM moz_formhistory " +
       "WHERE fieldname = :name AND value = :value");
     getQuery.params.name = name;
     getQuery.params.value = value;
 
-    // Give the guid if we found one
+    // Give the GUID if we found one.
     let item = Async.querySpinningly(getQuery, ["guid"])[0];
-    
+
     if (!item) {
       // Shouldn't happen, but Bug 597400...
       // Might as well just return.
       this._log.warn("GUID query returned " + item + "; turn on Trace logging for details.");
       this._log.trace("getGUID(" + JSON.stringify(name) + ", " +
                       JSON.stringify(value) + ") => " + item);
       return null;
     }
-    
-    if (item.guid != null)
+
+    if (item.guid != null) {
       return item.guid;
+    }
 
-    // We need to create a guid for this entry
+    // We need to create a GUID for this entry.
     let setQuery = Svc.Form.DBConnection.createAsyncStatement(
       "UPDATE moz_formhistory SET guid = :guid " +
       "WHERE fieldname = :name AND value = :value");
     let guid = Utils.makeGUID();
     setQuery.params.guid = guid;
     setQuery.params.name = name;
     setQuery.params.value = value;
     Async.querySpinningly(setQuery);
@@ -144,18 +145,19 @@ FormEngine.prototype = {
   _storeObj: FormStore,
   _trackerObj: FormTracker,
   _recordObj: FormRec,
   applyIncomingBatchSize: FORMS_STORE_BATCH_SIZE,
 
   get prefName() "history",
 
   _findDupe: function _findDupe(item) {
-    if (Svc.Form.entryExists(item.name, item.value))
+    if (Svc.Form.entryExists(item.name, item.value)) {
       return FormWrapper.getGUID(item.name, item.value);
+    }
   }
 };
 
 function FormStore(name) {
   Store.call(this, name);
 }
 FormStore.prototype = {
   __proto__: Store.prototype,
@@ -168,18 +170,19 @@ FormStore.prototype = {
 
   applyIncoming: function applyIncoming(record) {
     Store.prototype.applyIncoming.call(this, record);
     this._sleep(0); // Yield back to main thread after synchronous operation.
   },
 
   getAllIDs: function FormStore_getAllIDs() {
     let guids = {};
-    for each (let {name, value} in FormWrapper.getAllEntries())
+    for each (let {name, value} in FormWrapper.getAllEntries()) {
       guids[FormWrapper.getGUID(name, value)] = true;
+    }
     return guids;
   },
 
   changeItemID: function FormStore_changeItemID(oldID, newID) {
     FormWrapper.replaceGUID(oldID, newID);
   },
 
   itemExists: function FormStore_itemExists(id) {
@@ -187,34 +190,35 @@ FormStore.prototype = {
   },
 
   createRecord: function createRecord(id, collection) {
     let record = new FormRec(collection, id);
     let entry = FormWrapper.getEntry(id);
     if (entry != null) {
       record.name = entry.name;
       record.value = entry.value;
+    } else {
+      record.deleted = true;
     }
-    else
-      record.deleted = true;
     return record;
   },
 
   create: function FormStore_create(record) {
     this._log.trace("Adding form record for " + record.name);
     Svc.Form.addEntry(record.name, record.value);
   },
 
   remove: function FormStore_remove(record) {
     this._log.trace("Removing form record: " + record.id);
 
     // Just skip remove requests for things already gone
     let entry = FormWrapper.getEntry(record.id);
-    if (entry == null)
+    if (entry == null) {
       return;
+    }
 
     Svc.Form.removeEntry(entry.name, entry.value);
   },
 
   update: function FormStore_update(record) {
     this._log.trace("Ignoring form record update request!");
   },
 
@@ -276,18 +280,19 @@ FormTracker.prototype = {
                              .toString();
           this.trackEntry(name, value);
         }
         break;
     }
   },
 
   notify: function FormTracker_notify(formElement, aWindow, actionURI) {
-    if (this.ignoreAll)
+    if (this.ignoreAll) {
       return;
+    }
 
     this._log.trace("Form submission notification for " + actionURI.spec);
 
     // XXX Bug 487541 Copy the logic from nsFormHistory::Notify to avoid
     // divergent logic, which can lead to security issues, until there's a
     // better way to get satchel's results like with a notification.
 
     // Determine if a dom node has the autocomplete attribute set to "off"
@@ -304,18 +309,19 @@ FormTracker.prototype = {
     /* Get number of elements in form, add points and changedIDs */
     let len = formElement.length;
     let elements = formElement.elements;
     for (let i = 0; i < len; i++) {
       let el = elements.item(i);
 
       // Grab the name for debugging, but check if empty when satchel would
       let name = el.name;
-      if (name === "")
+      if (name === "") {
         name = el.id;
+      }
 
       if (!(el instanceof Ci.nsIDOMHTMLInputElement)) {
         this._log.trace(name + " is not a DOMHTMLInputElement: " + el);
         continue;
       }
 
       if (el.type.search(/^text$/i) != 0) {
         this._log.trace(name + "'s type is not 'text': " + el.type);