Bug 696486 - Close dbConnection. r=mak.
authorRafael Ávila de Espíndola <respindola@mozilla.com>
Wed, 28 Dec 2011 13:04:37 -0500
changeset 84694 3aeba1dee83676a197f65cf7be26f55decbd01b4
parent 84693 cc8c5e6dad1e2c4698c4c338254e7e39aae6afae
child 84695 6034efd8c0bbf2b27e8d35b02ab4332a524d6488
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)
reviewersmak
bugs696486
milestone12.0a1
Bug 696486 - Close dbConnection. r=mak.
toolkit/components/satchel/nsFormHistory.js
--- a/toolkit/components/satchel/nsFormHistory.js
+++ b/toolkit/components/satchel/nsFormHistory.js
@@ -132,17 +132,16 @@ 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 ---- */
 
 
@@ -398,20 +397,17 @@ 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();
+            this._dbClose();
             break;
         default:
             this.log("Oops! Unexpected notification: " + topic);
             break;
         }
     },
 
 
@@ -864,25 +860,32 @@ FormHistory.prototype = {
             stmt.finalize();
             return true;
         } catch (e) {
             return false;
         }
     },
 
     /**
-     * _dbFinalize
+     * _dbClose
      *
-     * Finalize all statements to allow closing the connection correctly.
+     * Finalize all statements and close the connection.
      */
-    _dbFinalize : function FH__dbFinalize() {
+    _dbClose : function FH__dbClose() {
         for each (let stmt in this.dbStmts) {
             stmt.finalize();
         }
         this.dbStmts = {};
+        if (this.dbConnection !== undefined) {
+            try {
+                this.dbConnection.close();
+            } catch (e) {
+                Components.utils.reportError(e);
+            }
+        }
     },
 
     /*
      * dbCleanup
      *
      * Called when database creation fails. Finalizes database statements,
      * closes the database connection, deletes the database file.
      */
@@ -890,24 +893,15 @@ FormHistory.prototype = {
         this.log("Cleaning up DB file - close & remove & backup")
 
         // Create backup file
         let storage = Cc["@mozilla.org/storage/service;1"].
                       getService(Ci.mozIStorageService);
         let backupFile = this.dbFile.leafName + ".corrupt";
         storage.backupDatabaseFile(this.dbFile, backupFile);
 
-        this._dbFinalize();
-
-        if (this.dbConnection !== undefined) {
-            try {
-                this.dbConnection.close();
-            } catch (e) {
-                Components.utils.reportError(e);
-            }
-        }
-
+        this._dbClose();
         this.dbFile.remove(false);
     }
 };
 
 let component = [FormHistory];
 var NSGetFactory = XPCOMUtils.generateNSGetFactory(component);