mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-25 14:17:22 +00:00
Bug 556721 - Close custom Places tests connection when it's used.
rs=places-team
This commit is contained in:
parent
cf4d0a80bd
commit
4374b1bcf6
@ -126,16 +126,27 @@ function uri(aSpec) NetUtil.newURI(aSpec);
|
||||
*
|
||||
* @return The database connection or null if unable to get one.
|
||||
*/
|
||||
let gDBConn;
|
||||
function DBConn() {
|
||||
let db = PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase)
|
||||
.DBConnection;
|
||||
if (db.connectionReady)
|
||||
return db;
|
||||
|
||||
// If the database has been closed, then we need to open a new connection.
|
||||
let file = Services.dirsvc.get('ProfD', Ci.nsIFile);
|
||||
file.append("places.sqlite");
|
||||
return Services.storage.openDatabase(file);
|
||||
// If the Places database connection has been closed, create a new connection.
|
||||
if (!gDBConn) {
|
||||
let file = Services.dirsvc.get('ProfD', Ci.nsIFile);
|
||||
file.append("places.sqlite");
|
||||
gDBConn = Services.storage.openDatabase(file);
|
||||
|
||||
// Be sure to cleanly close this connection.
|
||||
Services.obs.addObserver(function (aSubject, aTopic, aData) {
|
||||
Services.obs.removeObserver(arguments.callee, aTopic);
|
||||
gDBConn.asyncClose();
|
||||
}, "profile-before-change", false);
|
||||
}
|
||||
|
||||
return gDBConn.connectionReady ? gDBConn : null;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user