BookmarksBackupResource.sys.mjs (2193B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ 4 5 import { BackupResource } from "resource:///modules/backup/BackupResource.sys.mjs"; 6 7 const lazy = {}; 8 9 ChromeUtils.defineESModuleGetters(lazy, { 10 BookmarkJSONUtils: "resource://gre/modules/BookmarkJSONUtils.sys.mjs", 11 }); 12 13 const BOOKMARKS_BACKUP_FILENAME = "bookmarks.jsonlz4"; 14 15 /** 16 * Class representing Bookmarks database related files within a user profile. 17 */ 18 export class BookmarksBackupResource extends BackupResource { 19 static get key() { 20 return "bookmarks"; 21 } 22 23 static get requiresEncryption() { 24 return false; 25 } 26 27 static get canBackupResource() { 28 /** 29 * We don't need to backup bookmarks if places is being backed up 30 * since places.sqlite has bookmarks in it. This resource is to be used 31 * when places cannot be backed up, like in the case of sanitizeOnShutdown 32 * See Bug 1994875 33 */ 34 return !BackupResource.backingUpPlaces; 35 } 36 37 static get priority() { 38 return 1; 39 } 40 41 async backup( 42 stagingPath, 43 _profilePath = PathUtils.profileDir, 44 _isEncrypting = false 45 ) { 46 let bookmarksBackupFile = PathUtils.join( 47 stagingPath, 48 BOOKMARKS_BACKUP_FILENAME 49 ); 50 await lazy.BookmarkJSONUtils.exportToFile(bookmarksBackupFile, { 51 compress: true, 52 }); 53 return null; 54 } 55 56 async recover(_manifestEntry, recoveryPath, _destProfilePath) { 57 /** 58 * pass the file path to postRecovery() so that we can import all bookmarks into the new 59 * profile once it's been launched and restored. 60 */ 61 let bookmarksBackupPath = PathUtils.join( 62 recoveryPath, 63 BOOKMARKS_BACKUP_FILENAME 64 ); 65 return { bookmarksBackupPath }; 66 } 67 68 async postRecovery(postRecoveryEntry) { 69 if (postRecoveryEntry?.bookmarksBackupPath) { 70 await lazy.BookmarkJSONUtils.importFromFile( 71 postRecoveryEntry.bookmarksBackupPath, 72 { 73 replace: true, 74 } 75 ); 76 } 77 } 78 79 async measure(_profilePath = PathUtils.profileDir) { 80 // Unsure how to measure this!! 81 } 82 }