Bug 878677 - Part 1: allow GUID updating in FormHistory.jsm. r=enndeakin
authorMark Hammond <mhammond@skippinet.com.au>
Mon, 17 Jun 2013 16:58:54 -0700
changeset 147622 9126675b827abfd7248ca3f713aaecd0f9eb7cae
parent 147621 1544dcd2f78a10f1fd5e35317838ed820be997dd
child 147623 31f1458c6a0b12caa9115da9de67d4853523781b
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersenndeakin
bugs878677
milestone24.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 878677 - Part 1: allow GUID updating in FormHistory.jsm. r=enndeakin
toolkit/components/satchel/FormHistory.jsm
--- a/toolkit/components/satchel/FormHistory.jsm
+++ b/toolkit/components/satchel/FormHistory.jsm
@@ -64,16 +64,21 @@
  *  value - form value
  *  timesUsed - the number of times the entry has been accessed
  *  firstUsed - the time the the entry was first created
  *  lastUsed - the time the entry was last accessed
  *  firstUsedStart - search for entries created after or at this time
  *  firstUsedEnd - search for entries created before or at this time
  *  lastUsedStart - search for entries last accessed after or at this time
  *  lastUsedEnd - search for entries last accessed before or at this time
+ *  newGuid - a special case valid only for 'update' and allows the guid for
+ *            an existing record to be updated. The 'guid' term is the only
+ *            other term which can be used (ie, you can not also specify a
+ *            fieldname, value etc) and indicates the guid of the existing
+ *            record that should be updated.
  *
  * In all of the above methods, the callback argument should be an object with
  * handleResult(result), handleFailure(error) and handleCompletion(reason) functions.
  * For search and getAutoCompeteResults, result is an object containing the desired
  * properties. For count, result is the integer count. For, update, handleResult is
  * not called. For handleCompletion, reason is either 0 if successful or 1 if
  * an error occurred.
  */
@@ -201,18 +206,24 @@ const validFields = [
 const searchFilters = [
   "firstUsedStart",
   "firstUsedEnd",
   "lastUsedStart",
   "lastUsedEnd",
 ];
 
 function validateOpData(aData, aDataType) {
+  let thisValidFields = validFields;
+  // A special case to update the GUID - in this case there can be a 'newGuid'
+  // field and of the normally valid fields, only 'guid' is accepted.
+  if (aDataType == "Update" && "newGuid" in aData) {
+    thisValidFields = ["guid", "newGuid"];
+  }
   for (let field in aData) {
-    if (field != "op" && validFields.indexOf(field) == -1) {
+    if (field != "op" && thisValidFields.indexOf(field) == -1) {
       throw Components.Exception(
         aDataType + " query contains an unrecognized field: " + field,
         Cr.NS_ERROR_ILLEGAL_VALUE);
     }
   }
   return aData;
 }
 
@@ -304,18 +315,18 @@ function makeUpdateStatement(aGuid, aNew
   let query = "UPDATE moz_formhistory SET ";
   let queryTerms = makeQueryPredicates(aNewData, ', ');
 
   if (!queryTerms) {
     throw Components.Exception("Update query must define fields to modify.",
                                Cr.NS_ERROR_ILLEGAL_VALUE);
   }
 
-  query += queryTerms + " WHERE guid = :guid";
-  aNewData["guid"] = aGuid;
+  query += queryTerms + " WHERE guid = :existing_guid";
+  aNewData["existing_guid"] = aGuid;
 
   return dbCreateAsyncStatement(query, aNewData, aBindingArrays);
 }
 
 function makeMoveToDeletedStatement(aGuid, aNow, aData, aBindingArrays) {
   if (supportsDeletedTable) {
     let query = "INSERT INTO moz_deleted_formhistory (guid, timeDeleted)";
     let queryTerms = makeQueryPredicates(aData);
@@ -627,22 +638,28 @@ function updateFormHistoryWrite(aChanges
       case "remove":
         log("Remove from form history  " + change);
         let delStmt = makeMoveToDeletedStatement(change.guid, now, change, bindingArrays);
         if (delStmt && stmts.indexOf(delStmt) == -1)
           stmts.push(delStmt);
         if ("timeDeleted" in change)
           delete change.timeDeleted;
         stmt = makeRemoveStatement(change, bindingArrays);
-        notifications.push([ "formhistory-remove", null ]);
+        notifications.push([ "formhistory-remove", change.guid ]);
         break;
       case "update":
         log("Update form history " + change);
         let guid = change.guid;
         delete change.guid;
+        // a special case for updating the GUID - the new value can be
+        // specified in newGuid.
+        if (change.newGuid) {
+          change.guid = change.newGuid
+          delete change.newGuid;
+        }
         stmt = makeUpdateStatement(guid, change, bindingArrays);
         notifications.push([ "formhistory-update", guid ]);
         break;
       case "bump":
         log("Bump form history " + change);
         if (change.guid) {
           stmt = makeBumpStatement(change.guid, now, bindingArrays);
           notifications.push([ "formhistory-update", change.guid ]);