Bug 696404 - Finalize statements in profile-before-change; r=mak

This commit is contained in:
Rafael Avila de Espindola 2011-11-20 11:13:40 +00:00
parent d2a6b6d8eb
commit b4f153aee8
2 changed files with 26 additions and 9 deletions

View File

@ -84,9 +84,9 @@ FormAutoComplete.prototype = {
this._timeGroupingSize = this._prefBranch.getIntPref("timeGroupingSize") * 1000 * 1000; this._timeGroupingSize = this._prefBranch.getIntPref("timeGroupingSize") * 1000 * 1000;
this._expireDays = this._prefBranch.getIntPref("expire_days"); this._expireDays = this._prefBranch.getIntPref("expire_days");
this._dbStmts = []; this._dbStmts = {};
Services.obs.addObserver(this.observer, "xpcom-shutdown", true); Services.obs.addObserver(this.observer, "profile-before-change", true);
}, },
observer : { observer : {
@ -129,8 +129,11 @@ FormAutoComplete.prototype = {
default: default:
self.log("Oops! Pref not handled, change ignored."); self.log("Oops! Pref not handled, change ignored.");
} }
} else if (topic == "xpcom-shutdown") { } else if (topic == "profile-before-change") {
self._dbStmts = null; for each (let stmt in self._dbStmts) {
stmt.finalize();
}
self._dbStmts = {};
self.__formHistory = null; self.__formHistory = null;
} }
} }

View File

@ -137,6 +137,7 @@ FormHistory.prototype = {
this.messageManager.addMessageListener("FormHistory:FormSubmitEntries", this); this.messageManager.addMessageListener("FormHistory:FormSubmitEntries", this);
// Add observers // Add observers
Services.obs.addObserver(this, "profile-before-change", true);
Services.obs.addObserver(this, "idle-daily", true); Services.obs.addObserver(this, "idle-daily", true);
Services.obs.addObserver(this, "formhistory-expire-now", true); Services.obs.addObserver(this, "formhistory-expire-now", true);
}, },
@ -402,6 +403,9 @@ FormHistory.prototype = {
case "formhistory-expire-now": case "formhistory-expire-now":
this.expireOldEntries(); this.expireOldEntries();
break; break;
case "profile-before-change":
this._dbFinalize();
break;
default: default:
this.log("Oops! Unexpected notification: " + topic); this.log("Oops! Unexpected notification: " + topic);
break; break;
@ -862,6 +866,18 @@ 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 * dbCleanup
@ -881,13 +897,11 @@ FormHistory.prototype = {
storage.backupDatabaseFile(this.dbFile, backupFile); storage.backupDatabaseFile(this.dbFile, backupFile);
} }
// Finalize all statements to free memory, avoid errors later this._dbFinalize();
for each (let stmt in this.dbStmts)
stmt.finalize();
this.dbStmts = [];
// Close the connection, ignore 'already closed' error // Close the connection, ignore 'already closed' error
try { this.dbConnection.close() } catch(e) {} // FIXME (bug 696483): we should reportError in here.
try { this.dbConnection.close(); } catch(e) {}
this.dbFile.remove(false); this.dbFile.remove(false);
} }
}; };