Bug 735697 - Close the old connection when switching to/from private mode. r=mak.

This commit is contained in:
Marco Bonardo 2012-03-22 13:02:28 -04:00
Родитель 98c50b2bfb
Коммит 6d9b1228fa
4 изменённых файлов: 29 добавлений и 5 удалений

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

@ -319,9 +319,23 @@ nsDownloadManager::GetMemoryDBConnection() const
return conn.forget();
}
void
nsDownloadManager::CloseDB()
{
DebugOnly<nsresult> rv = mGetIdsForURIStatement->Finalize();
MOZ_ASSERT(NS_SUCCEEDED(rv));
rv = mUpdateDownloadStatement->Finalize();
MOZ_ASSERT(NS_SUCCEEDED(rv));
rv = mDBConn->Close();
MOZ_ASSERT(NS_SUCCEEDED(rv));
}
nsresult
nsDownloadManager::InitMemoryDB()
{
bool ready = false;
if (mDBConn && NS_SUCCEEDED(mDBConn->GetConnectionReady(&ready)) && ready)
CloseDB();
mDBConn = GetMemoryDBConnection();
if (!mDBConn)
return NS_ERROR_NOT_AVAILABLE;
@ -345,6 +359,9 @@ nsDownloadManager::InitFileDB()
rv = dbFile->Append(DM_DB_NAME);
NS_ENSURE_SUCCESS(rv, rv);
bool ready = false;
if (mDBConn && NS_SUCCEEDED(mDBConn->GetConnectionReady(&ready)) && ready)
CloseDB();
mDBConn = GetFileDBConnection(dbFile);
NS_ENSURE_TRUE(mDBConn, NS_ERROR_NOT_AVAILABLE);
@ -1940,10 +1957,7 @@ nsDownloadManager::Observe(nsISupports *aSubject,
if (dl2)
return CancelDownload(id);
} else if (strcmp(aTopic, "profile-before-change") == 0) {
mGetIdsForURIStatement->Finalize();
mUpdateDownloadStatement->Finalize();
mozilla::DebugOnly<nsresult> rv = mDBConn->Close();
MOZ_ASSERT(NS_SUCCEEDED(rv));
CloseDB();
} else if (strcmp(aTopic, "quit-application") == 0) {
// Try to pause all downloads and, if appropriate, mark them as auto-resume
// unless user has specified that downloads should be canceled

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

@ -109,6 +109,7 @@ protected:
nsresult InitDB();
nsresult InitFileDB();
void CloseDB();
nsresult InitMemoryDB();
already_AddRefed<mozIStorageConnection> GetFileDBConnection(nsIFile *dbFile) const;
already_AddRefed<mozIStorageConnection> GetMemoryDBConnection() const;

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

@ -56,6 +56,7 @@ function run_test() {
do_check_neq(dm.DBConnection.databaseFile, null);
do_check_true(connDisk.databaseFile.equals(dm.DBConnection.databaseFile));
connDisk = dm.DBConnection;
let oldFile = connDisk.databaseFile;
// switch to a memory DB
observer.observe(null, "dlmgr-switchdb", "memory");
@ -79,5 +80,5 @@ function run_test() {
// make sure that the disk database is initialized correctly
do_check_true(dm.DBConnection.connectionReady);
do_check_neq(dm.DBConnection.databaseFile, null);
do_check_true(connDisk.databaseFile.equals(dm.DBConnection.databaseFile));
do_check_true(oldFile.equals(dm.DBConnection.databaseFile));
}

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

@ -477,6 +477,7 @@ function Startup()
getService(Ci.nsIObserverService);
obs.addObserver(gDownloadObserver, "download-manager-remove-download", false);
obs.addObserver(gDownloadObserver, "private-browsing", false);
obs.addObserver(gDownloadObserver, "private-browsing-change-granted", false);
obs.addObserver(gDownloadObserver, "browser-lastwindow-close-granted", false);
// Clear the search box and move focus to the list on escape from the box
@ -502,6 +503,7 @@ function Shutdown()
let obs = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
obs.removeObserver(gDownloadObserver, "private-browsing");
obs.removeObserver(gDownloadObserver, "private-browsing-change-granted");
obs.removeObserver(gDownloadObserver, "download-manager-remove-download");
obs.removeObserver(gDownloadObserver, "browser-lastwindow-close-granted");
@ -526,6 +528,12 @@ let gDownloadObserver = {
let dl = getDownload(id.data);
removeFromView(dl);
break;
case "private-browsing-change-granted":
// Finalize our statements cause the connection will be closed by the
// service during the private browsing transition.
gStmt.finalize();
gStmt = null;
break;
case "private-browsing":
if (aData == "enter" || aData == "exit") {
// We need to reset the title here, because otherwise the title of