Bug 702848 - Finalize the statements in services sync/modules/engines/forms.js. r=dolske.
authorRafael Ávila de Espíndola <respindola@mozilla.com>
Thu, 22 Dec 2011 11:21:37 -0500
changeset 84486 13a57f89f8cc91f584d7653c85b5d6acab3952cc
parent 84485 6707b24155987811ad405d6158f19ad0f2910b45
child 84487 9ed956b9a3b11cffb38e8061cba661655dfec891
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdolske
bugs702848
milestone12.0a1
Bug 702848 - Finalize the statements in services sync/modules/engines/forms.js. r=dolske.
services/sync/modules/engines/forms.js
toolkit/components/satchel/nsFormHistory.js
--- a/services/sync/modules/engines/forms.js
+++ b/services/sync/modules/engines/forms.js
@@ -74,16 +74,23 @@ let FormWrapper = {
       return this._stmts[query];
     }
 
     this._log.trace("Creating SQL statement: " + query);
     let db = Svc.Form.DBConnection;
     return this._stmts[query] = db.createAsyncStatement(query);
   },
 
+  _finalize : function () {
+    for each (let stmt in FormWrapper._stmts) {
+      stmt.finalize();
+    }
+    FormWrapper._stmts = {};
+  },
+
   get _getAllEntriesStmt() {
     const query =
       "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";
     return this._getStmt(query);
@@ -265,16 +272,17 @@ FormStore.prototype = {
     Svc.Form.removeAllEntries();
   }
 };
 
 function FormTracker(name) {
   Tracker.call(this, name);
   Svc.Obs.add("weave:engine:start-tracking", this);
   Svc.Obs.add("weave:engine:stop-tracking", this);
+  Svc.Obs.add("profile-change-teardown", this);
 }
 FormTracker.prototype = {
   __proto__: Tracker.prototype,
 
   QueryInterface: XPCOMUtils.generateQI([
     Ci.nsIFormSubmitObserver,
     Ci.nsIObserver,
     Ci.nsISupportsWeakReference]),
@@ -315,16 +323,19 @@ FormTracker.prototype = {
           subject = subject.QueryInterface(Ci.nsIArray);
           let name = subject.queryElementAt(0, Ci.nsISupportsString)
                             .toString();
           let value = subject.queryElementAt(1, Ci.nsISupportsString)
                              .toString();
           this.trackEntry(name, value);
         }
         break;
+    case "profile-change-teardown":
+      FormWrapper._finalize();
+      break;
     }
   },
 
   notify: function FormTracker_notify(formElement, aWindow, actionURI) {
     if (this.ignoreAll) {
       return;
     }
 
--- a/toolkit/components/satchel/nsFormHistory.js
+++ b/toolkit/components/satchel/nsFormHistory.js
@@ -132,16 +132,17 @@ FormHistory.prototype = {
         this.dbStmts = {};
 
         this.messageManager = Cc["@mozilla.org/globalmessagemanager;1"].
                               getService(Ci.nsIChromeFrameMessageManager);
         this.messageManager.loadFrameScript("chrome://satchel/content/formSubmitListener.js", true);
         this.messageManager.addMessageListener("FormHistory:FormSubmitEntries", this);
 
         // Add observers
+        Services.obs.addObserver(this, "profile-change-teardown", true);
         Services.obs.addObserver(this, "profile-before-change", true);
         Services.obs.addObserver(this, "idle-daily", true);
         Services.obs.addObserver(this, "formhistory-expire-now", true);
     },
 
     /* ---- message listener ---- */
 
 
@@ -397,16 +398,19 @@ FormHistory.prototype = {
         case "nsPref:changed":
             this.updatePrefs();
             break;
         case "idle-daily":
         case "formhistory-expire-now":
             this.expireOldEntries();
             break;
         case "profile-before-change":
+            // FIXME (bug 696486): close the connection in here.
+            break;
+        case "profile-change-teardown":
             this._dbFinalize();
             break;
         default:
             this.log("Oops! Unexpected notification: " + topic);
             break;
         }
     },
 
@@ -865,17 +869,16 @@ FormHistory.prototype = {
     },
 
     /**
      * _dbFinalize
      *
      * Finalize all statements to allow closing the connection correctly.
      */
     _dbFinalize : function FH__dbFinalize() {
-        // FIXME (bug 696486): close the connection in here.
         for each (let stmt in this.dbStmts) {
             stmt.finalize();
         }
         this.dbStmts = {};
     },
 
     /*
      * dbCleanup