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
Родитель d2a6b6d8eb
Коммит b4f153aee8
2 изменённых файлов: 26 добавлений и 9 удалений

Просмотреть файл

@ -84,9 +84,9 @@ FormAutoComplete.prototype = {
this._timeGroupingSize = this._prefBranch.getIntPref("timeGroupingSize") * 1000 * 1000;
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 : {
@ -129,8 +129,11 @@ FormAutoComplete.prototype = {
default:
self.log("Oops! Pref not handled, change ignored.");
}
} else if (topic == "xpcom-shutdown") {
self._dbStmts = null;
} else if (topic == "profile-before-change") {
for each (let stmt in self._dbStmts) {
stmt.finalize();
}
self._dbStmts = {};
self.__formHistory = null;
}
}

Просмотреть файл

@ -137,6 +137,7 @@ FormHistory.prototype = {
this.messageManager.addMessageListener("FormHistory:FormSubmitEntries", this);
// Add observers
Services.obs.addObserver(this, "profile-before-change", true);
Services.obs.addObserver(this, "idle-daily", true);
Services.obs.addObserver(this, "formhistory-expire-now", true);
},
@ -402,6 +403,9 @@ FormHistory.prototype = {
case "formhistory-expire-now":
this.expireOldEntries();
break;
case "profile-before-change":
this._dbFinalize();
break;
default:
this.log("Oops! Unexpected notification: " + topic);
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
@ -881,13 +897,11 @@ FormHistory.prototype = {
storage.backupDatabaseFile(this.dbFile, backupFile);
}
// Finalize all statements to free memory, avoid errors later
for each (let stmt in this.dbStmts)
stmt.finalize();
this.dbStmts = [];
this._dbFinalize();
// 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);
}
};