mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 23:35:34 +00:00
Bug 1266339 - Part 2 - Delete outdated sessionstore.bak files when restoring tabs automatically. r=margaret
sessionstore.bak, which powers the "tabs from last time" display, is only updated with the data of the previous session if the user chooses to "never restore" tabs, or if we've temporarily disabled session restoring because of too many successive crashes in a row. In all other cases, we restore tabs automatically so sessionstore.bak is never updated with fresh data, meaning its contents get stale pretty soon. With this patch, we clean up old copies of sessionstore.bak when doing an automatic restore, so they don't linger indefinitely in the "tabs from last time" section of the recent tabs panel. MozReview-Commit-ID: DrOx5TNwYMv --HG-- extra : transplant_source : %2Ac%83%F40i%1Ah%3F%B1QI%D6%84%FF%7B%E8%157%F1 extra : histedit_source : 61cc196e844b26e00cf47363c69e6f1672d90f14
This commit is contained in:
parent
fa27d7a370
commit
be9ba0fd90
@ -1536,11 +1536,8 @@ public abstract class GeckoApp
|
||||
processTabQueue();
|
||||
}
|
||||
|
||||
// If we're not restoring, move the session file so it can be read for
|
||||
// the last tabs section.
|
||||
if (!mShouldRestore) {
|
||||
getProfile().moveSessionFile();
|
||||
}
|
||||
// Make sure sessionstore.bak is either updated or deleted as necessary.
|
||||
getProfile().updateSessionFile(mShouldRestore);
|
||||
|
||||
recordStartupActionTelemetry(passedUri, action);
|
||||
|
||||
|
@ -76,6 +76,7 @@ public final class GeckoProfile {
|
||||
// Session store
|
||||
private static final String SESSION_FILE = "sessionstore.js";
|
||||
private static final String SESSION_FILE_BACKUP = "sessionstore.bak";
|
||||
private static final long MAX_BACKUP_FILE_AGE = 1000 * 3600 * 24; // 24 hours
|
||||
|
||||
private static final HashMap<String, GeckoProfile> sProfileCache = new HashMap<String, GeckoProfile>();
|
||||
private static String sDefaultProfileName;
|
||||
@ -761,20 +762,29 @@ public final class GeckoProfile {
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the session file to the backup session file.
|
||||
* Updates the state of the old session data file.
|
||||
*
|
||||
* sessionstore.js should hold the current session, and sessionstore.bak
|
||||
* should hold the previous session (where it is used to read the "tabs
|
||||
* from last time"). Normally, sessionstore.js is moved to sessionstore.bak
|
||||
* on a clean quit, but this doesn't happen if Fennec crashed. Thus, this
|
||||
* method should be called after a crash so sessionstore.bak correctly
|
||||
* holds the previous session.
|
||||
* sessionstore.js should hold the current session, and sessionstore.bak should
|
||||
* hold the previous session (where it is used to read the "tabs from last time").
|
||||
* If we're not restoring tabs automatically, sessionstore.js needs to be moved to
|
||||
* sessionstore.bak, so we can display the correct "tabs from last time".
|
||||
* If we *are* restoring tabs, we need to delete outdated copies of sessionstore.bak,
|
||||
* so we don't continue showing stale "tabs from last time" indefinitely.
|
||||
*
|
||||
* @param shouldRestore Pass true if we are automatically restoring last session's tabs.
|
||||
*/
|
||||
public void moveSessionFile() {
|
||||
File sessionFile = getFile(SESSION_FILE);
|
||||
if (sessionFile != null && sessionFile.exists()) {
|
||||
File sessionFileBackup = getFile(SESSION_FILE_BACKUP);
|
||||
sessionFile.renameTo(sessionFileBackup);
|
||||
public void updateSessionFile(boolean shouldRestore) {
|
||||
File sessionFileBackup = getFile(SESSION_FILE_BACKUP);
|
||||
if (!shouldRestore) {
|
||||
File sessionFile = getFile(SESSION_FILE);
|
||||
if (sessionFile != null && sessionFile.exists()) {
|
||||
sessionFile.renameTo(sessionFileBackup);
|
||||
}
|
||||
} else {
|
||||
if (sessionFileBackup != null && sessionFileBackup.exists() &&
|
||||
System.currentTimeMillis() - sessionFileBackup.lastModified() > MAX_BACKUP_FILE_AGE) {
|
||||
sessionFileBackup.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user