summaryrefslogtreecommitdiffstats
path: root/browser/components/backup/resources/MiscDataBackupResource.sys.mjs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:50 +0000
commitdef92d1b8e9d373e2f6f27c366d578d97d8960c6 (patch)
tree2ef34b9ad8bb9a9220e05d60352558b15f513894 /browser/components/backup/resources/MiscDataBackupResource.sys.mjs
parentAdding debian version 125.0.3-1. (diff)
downloadfirefox-def92d1b8e9d373e2f6f27c366d578d97d8960c6.tar.xz
firefox-def92d1b8e9d373e2f6f27c366d578d97d8960c6.zip
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/backup/resources/MiscDataBackupResource.sys.mjs')
-rw-r--r--browser/components/backup/resources/MiscDataBackupResource.sys.mjs101
1 files changed, 101 insertions, 0 deletions
diff --git a/browser/components/backup/resources/MiscDataBackupResource.sys.mjs b/browser/components/backup/resources/MiscDataBackupResource.sys.mjs
new file mode 100644
index 0000000000..97224f0e31
--- /dev/null
+++ b/browser/components/backup/resources/MiscDataBackupResource.sys.mjs
@@ -0,0 +1,101 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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 { BackupResource } from "resource:///modules/backup/BackupResource.sys.mjs";
+
+const lazy = {};
+
+ChromeUtils.defineESModuleGetters(lazy, {
+ Sqlite: "resource://gre/modules/Sqlite.sys.mjs",
+});
+
+/**
+ * Class representing miscellaneous files for telemetry, site storage,
+ * media device origin mapping, chrome privileged IndexedDB databases,
+ * and Mozilla Accounts within a user profile.
+ */
+export class MiscDataBackupResource extends BackupResource {
+ static get key() {
+ return "miscellaneous";
+ }
+
+ static get requiresEncryption() {
+ return false;
+ }
+
+ async backup(stagingPath, profilePath = PathUtils.profileDir) {
+ const files = [
+ "times.json",
+ "enumerate_devices.txt",
+ "SiteSecurityServiceState.bin",
+ ];
+
+ for (let fileName of files) {
+ let sourcePath = PathUtils.join(profilePath, fileName);
+ let destPath = PathUtils.join(stagingPath, fileName);
+ if (await IOUtils.exists(sourcePath)) {
+ await IOUtils.copy(sourcePath, destPath, { recursive: true });
+ }
+ }
+
+ const sqliteDatabases = ["protections.sqlite"];
+
+ for (let fileName of sqliteDatabases) {
+ let sourcePath = PathUtils.join(profilePath, fileName);
+ let destPath = PathUtils.join(stagingPath, fileName);
+ let connection;
+
+ try {
+ connection = await lazy.Sqlite.openConnection({
+ path: sourcePath,
+ readOnly: true,
+ });
+
+ await connection.backup(destPath);
+ } finally {
+ await connection.close();
+ }
+ }
+
+ // Bug 1890585 - we don't currently have the ability to copy the
+ // chrome-privileged IndexedDB databases under storage/permanent/chrome, so
+ // we'll just skip that for now.
+
+ return null;
+ }
+
+ async measure(profilePath = PathUtils.profileDir) {
+ const files = [
+ "times.json",
+ "enumerate_devices.txt",
+ "protections.sqlite",
+ "SiteSecurityServiceState.bin",
+ ];
+
+ let fullSize = 0;
+
+ for (let filePath of files) {
+ let resourcePath = PathUtils.join(profilePath, filePath);
+ let resourceSize = await BackupResource.getFileSize(resourcePath);
+ if (Number.isInteger(resourceSize)) {
+ fullSize += resourceSize;
+ }
+ }
+
+ let chromeIndexedDBDirPath = PathUtils.join(
+ profilePath,
+ "storage",
+ "permanent",
+ "chrome"
+ );
+ let chromeIndexedDBDirSize = await BackupResource.getDirectorySize(
+ chromeIndexedDBDirPath
+ );
+ if (Number.isInteger(chromeIndexedDBDirSize)) {
+ fullSize += chromeIndexedDBDirSize;
+ }
+
+ Glean.browserBackup.miscDataSize.set(fullSize);
+ }
+}