commit 304dffc6e7c0d15086051272fd01d757d60e14d5
parent c9c2eac140638278c40890696158332216abcd29
Author: Harshit <hsohaney@mozilla.com>
Date: Wed, 17 Dec 2025 02:02:21 +0000
Bug 1994875 - Only backup bookmarks separately if places is not being backed up. r=mak,places-reviewers,mconley
Differential Revision: https://phabricator.services.mozilla.com/D275668
Diffstat:
3 files changed, 75 insertions(+), 57 deletions(-)
diff --git a/browser/components/backup/resources/BackupResource.sys.mjs b/browser/components/backup/resources/BackupResource.sys.mjs
@@ -10,8 +10,44 @@ ChromeUtils.defineESModuleGetters(lazy, {
Sqlite: "resource://gre/modules/Sqlite.sys.mjs",
BackupError: "resource:///modules/backup/BackupError.mjs",
ERRORS: "chrome://browser/content/backup/backup-constants.mjs",
+ PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs",
});
+XPCOMUtils.defineLazyPreferenceGetter(
+ lazy,
+ "isBrowsingHistoryEnabled",
+ "places.history.enabled",
+ true
+);
+
+XPCOMUtils.defineLazyPreferenceGetter(
+ lazy,
+ "isSanitizeOnShutdownEnabled",
+ "privacy.sanitize.sanitizeOnShutdown",
+ false
+);
+
+XPCOMUtils.defineLazyPreferenceGetter(
+ lazy,
+ "isHistoryClearedOnShutdown2",
+ "privacy.clearOnShutdown_v2.browsingHistoryAndDownloads",
+ false
+);
+
+XPCOMUtils.defineLazyPreferenceGetter(
+ lazy,
+ "useOldClearHistoryDialog",
+ "privacy.sanitize.useOldClearHistoryDialog",
+ false
+);
+
+XPCOMUtils.defineLazyPreferenceGetter(
+ lazy,
+ "isHistoryClearedOnShutdown",
+ "privacy.clearOnShutdown.history",
+ false
+);
+
// Convert from bytes to kilobytes (not kibibytes).
export const BYTES_IN_KB = 1000;
@@ -243,6 +279,34 @@ export class BackupResource {
return true;
}
+ /**
+ * Helper function to see if we are going to be backing up and restoring places.sqlite
+ *
+ * @returns {boolean}
+ */
+ static get backingUpPlaces() {
+ if (
+ lazy.PrivateBrowsingUtils.permanentPrivateBrowsing ||
+ !lazy.isBrowsingHistoryEnabled
+ ) {
+ return false;
+ }
+
+ if (!lazy.isSanitizeOnShutdownEnabled) {
+ return true;
+ }
+
+ if (!lazy.useOldClearHistoryDialog) {
+ if (lazy.isHistoryClearedOnShutdown2) {
+ return false;
+ }
+ } else if (lazy.isHistoryClearedOnShutdown) {
+ return false;
+ }
+
+ return true;
+ }
+
constructor() {}
/**
diff --git a/browser/components/backup/resources/BookmarksBackupResource.sys.mjs b/browser/components/backup/resources/BookmarksBackupResource.sys.mjs
@@ -24,6 +24,16 @@ export class BookmarksBackupResource extends BackupResource {
return false;
}
+ static get canBackupResource() {
+ /**
+ * We don't need to backup bookmarks if places is being backed up
+ * since places.sqlite has bookmarks in it. This resource is to be used
+ * when places cannot be backed up, like in the case of sanitizeOnShutdown
+ * See Bug 1994875
+ */
+ return !BackupResource.backingUpPlaces;
+ }
+
static get priority() {
return 1;
}
diff --git a/browser/components/backup/resources/PlacesBackupResource.sys.mjs b/browser/components/backup/resources/PlacesBackupResource.sys.mjs
@@ -2,7 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
-import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
import { BackupResource } from "resource:///modules/backup/BackupResource.sys.mjs";
import { MeasurementUtils } from "resource:///modules/backup/MeasurementUtils.sys.mjs";
@@ -10,44 +9,8 @@ const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
PlacesDBUtils: "resource://gre/modules/PlacesDBUtils.sys.mjs",
- PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs",
});
-XPCOMUtils.defineLazyPreferenceGetter(
- lazy,
- "isBrowsingHistoryEnabled",
- "places.history.enabled",
- true
-);
-
-XPCOMUtils.defineLazyPreferenceGetter(
- lazy,
- "isSanitizeOnShutdownEnabled",
- "privacy.sanitize.sanitizeOnShutdown",
- false
-);
-
-XPCOMUtils.defineLazyPreferenceGetter(
- lazy,
- "isHistoryClearedOnShutdown2",
- "privacy.clearOnShutdown_v2.browsingHistoryAndDownloads",
- false
-);
-
-XPCOMUtils.defineLazyPreferenceGetter(
- lazy,
- "useOldClearHistoryDialog",
- "privacy.sanitize.useOldClearHistoryDialog",
- false
-);
-
-XPCOMUtils.defineLazyPreferenceGetter(
- lazy,
- "isHistoryClearedOnShutdown",
- "privacy.clearOnShutdown.history",
- false
-);
-
/**
* Class representing Places database related files within a user profile.
*/
@@ -65,26 +28,7 @@ export class PlacesBackupResource extends BackupResource {
}
static get canBackupResource() {
- if (
- lazy.PrivateBrowsingUtils.permanentPrivateBrowsing ||
- !lazy.isBrowsingHistoryEnabled
- ) {
- return false;
- }
-
- if (!lazy.isSanitizeOnShutdownEnabled) {
- return true;
- }
-
- if (!lazy.useOldClearHistoryDialog) {
- if (lazy.isHistoryClearedOnShutdown2) {
- return false;
- }
- } else if (lazy.isHistoryClearedOnShutdown) {
- return false;
- }
-
- return true;
+ return BackupResource.backingUpPlaces;
}
async backup(