Bug 1597358 - Create a backup of logins.json to use when logins.json is missing or corrupt. r=MattN

Depends on D78477

Differential Revision: https://phabricator.services.mozilla.com/D79688
This commit is contained in:
prathiksha 2020-06-25 16:30:42 +00:00
Родитель a7eff183d5
Коммит bc85d62d8c
4 изменённых файлов: 20 добавлений и 2 удалений

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

@ -3748,6 +3748,7 @@ pref("signon.autologin.proxy", false);
pref("signon.capture.inputChanges.enabled", true);
pref("signon.formlessCapture.enabled", true);
pref("signon.generation.available", true);
pref("signon.backup.enabled", false);
// A value of "-1" disables new-password heuristics. Can be updated once Bug 1618058 is resolved.
pref("signon.generation.confidenceThreshold", "-1");
pref("signon.generation.enabled", true);

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

@ -77,10 +77,11 @@ const MAX_DATE_MS = 8640000000000000;
* @param aPath
* String containing the file path where data should be saved.
*/
function LoginStore(aPath) {
function LoginStore(aPath, aBackupPath = "") {
JSONFile.call(this, {
path: aPath,
dataPostProcessor: this._dataPostProcessor.bind(this),
backupTo: aBackupPath,
});
}

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

@ -89,7 +89,17 @@ class LoginManagerStorage_json {
// Set the reference to LoginStore synchronously.
let jsonPath = OS.Path.join(OS.Constants.Path.profileDir, "logins.json");
this._store = new LoginStore(jsonPath);
let backupPath = "";
let loginsBackupEnabled = Services.prefs.getBoolPref(
"signon.backup.enabled"
);
if (loginsBackupEnabled) {
backupPath = OS.Path.join(
OS.Constants.Path.profileDir,
"logins-backup.json"
);
}
this._store = new LoginStore(jsonPath, backupPath);
return (async () => {
// Load the data asynchronously.

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

@ -109,6 +109,8 @@ const kSaveDelayMs = 1500;
* testing.
* - compression: A compression algorithm to use when reading and
* writing the data.
* - backupTo: A boolean value indicating whether writeAtomic should create
* a backup before writing to json files.
*/
function JSONFile(config) {
this.path = config.path;
@ -130,6 +132,10 @@ function JSONFile(config) {
this._options.compression = config.compression;
}
if (config.backupTo) {
this._options.backupTo = config.backupTo;
}
this._finalizeAt = config.finalizeAt || AsyncShutdown.profileBeforeChange;
this._finalizeInternalBound = this._finalizeInternal.bind(this);
this._finalizeAt.addBlocker(