deletes containers, and adds and deletes site assignments.

This commit is contained in:
Kendall Werts 2019-12-20 22:01:59 -06:00
parent 063b7509bd
commit 0e45f06338
2 changed files with 20 additions and 23 deletions

View file

@ -65,23 +65,27 @@ const assignManager = {
}); });
}, },
set(pageUrl, data, exemptedTabIds) { async set(pageUrl, data, exemptedTabIds) {
const siteStoreKey = this.getSiteStoreKey(pageUrl); const siteStoreKey = this.getSiteStoreKey(pageUrl);
if (exemptedTabIds) { if (exemptedTabIds) {
exemptedTabIds.forEach((tabId) => { exemptedTabIds.forEach((tabId) => {
this.setExempted(pageUrl, tabId); this.setExempted(pageUrl, tabId);
}); });
} }
return this.area.set({ await this.area.set({
[siteStoreKey]: data [siteStoreKey]: data
}); });
await backup();
return;
}, },
remove(pageUrl) { async remove(pageUrl) {
const siteStoreKey = this.getSiteStoreKey(pageUrl); const siteStoreKey = this.getSiteStoreKey(pageUrl);
// When we remove an assignment we should clear all the exemptions // When we remove an assignment we should clear all the exemptions
this.removeExempted(pageUrl); this.removeExempted(pageUrl);
return this.area.remove([siteStoreKey]); await this.area.remove([siteStoreKey]);
await backup();
return;
}, },
async deleteContainer(userContextId) { async deleteContainer(userContextId) {
@ -582,10 +586,7 @@ async function backup(options) {
await updateSyncIdentities(); await updateSyncIdentities();
await updateCookieStoreIdMap(); await updateCookieStoreIdMap();
await updateSyncSiteAssignments(); await updateSyncSiteAssignments();
if (options) { if (options && options.uuid) await updateDeletedIdentityList(options.uuid);
if (options.uuid) { updateDeletedIdentityList(options.uuid);}
if (options.siteURL) { updateDeletedSiteAssignmentList(options.siteURL);}
}
// for testing // for testing
const storage = await browser.storage.sync.get(); const storage = await browser.storage.sync.get();
console.log("in sync: ", storage); console.log("in sync: ", storage);
@ -613,19 +614,12 @@ async function updateSyncSiteAssignments() {
} }
async function updateDeletedIdentityList(deletedIdentityUUID) { async function updateDeletedIdentityList(deletedIdentityUUID) {
let deletedIdentityList = await browser.storage.sync.get("deletedIdentityList"); let { deletedIdentityList } = await browser.storage.sync.get("deletedIdentityList");
if (Object.entries(deletedIdentityList).length === 0) deletedIdentityList = []; if (!deletedIdentityList) deletedIdentityList = [];
deletedIdentityList.push(deletedIdentityUUID); deletedIdentityList.push(deletedIdentityUUID);
await browser.storage.sync.set({ deletedIdentityList }); await browser.storage.sync.set({ deletedIdentityList });
} }
async function updateDeletedSiteAssignmentList(deletedSiteURL) {
let deletedSiteAssignmentList = await browser.storage.sync.get("deletedSiteAssignmentList");
if (Object.entries(deletedSiteAssignmentList).length === 0) deletedSiteAssignmentList = [];
deletedSiteAssignmentList.push(deletedSiteURL);
await browser.storage.sync.set({ deletedSiteAssignmentList });
}
browser.resetMAC1 = async function () { browser.resetMAC1 = async function () {
// for debugging and testing: remove all containers except the default 4 and the first one created // for debugging and testing: remove all containers except the default 4 and the first one created
browser.storage.onChanged.removeListener(syncOnChangedListener); browser.storage.onChanged.removeListener(syncOnChangedListener);
@ -846,9 +840,9 @@ async function runSync() {
browser.storage.onChanged.removeListener(syncOnChangedListener); browser.storage.onChanged.removeListener(syncOnChangedListener);
removeContextualIdentityListeners(syncCIListenerList); removeContextualIdentityListeners(syncCIListenerList);
console.log("runSync"); console.log("runSync");
identityState.storageArea.cleanup(); await identityState.storageArea.cleanup();
const inSync = await browser.storage.sync.get(); const inSync = await browser.storage.sync.get();
cleanupSync(inSync); await cleanupSync(inSync);
if (Object.entries(inSync).length === 0){ if (Object.entries(inSync).length === 0){
console.log("no sync storage, backing up..."); console.log("no sync storage, backing up...");
await backup(); await backup();
@ -883,15 +877,15 @@ async function addToDeletedList(changeInfo) {
async function runFirstSync() { async function runFirstSync() {
console.log("runFirstSync"); console.log("runFirstSync");
identityState.storageArea.cleanup(); await identityState.storageArea.cleanup();
const localIdentities = await browser.contextualIdentities.query({}); const localIdentities = await browser.contextualIdentities.query({});
await addUUIDsToContainers(localIdentities); await addUUIDsToContainers(localIdentities);
const inSync = await browser.storage.sync.get(); const inSync = await browser.storage.sync.get();
cleanupSync(inSync);
if (Object.entries(inSync).length === 0){ if (Object.entries(inSync).length === 0){
console.log("no sync storage, backing up..."); console.log("no sync storage, backing up...");
await backup(); await backup();
} else { } else {
await cleanupSync(inSync);
console.log("storage found, attempting to restore ..."); console.log("storage found, attempting to restore ...");
await restoreFirstRun(inSync); await restoreFirstRun(inSync);
} }
@ -905,13 +899,16 @@ async function addUUIDsToContainers(localIdentities) {
} }
async function cleanupSync(inSync) { async function cleanupSync(inSync) {
console.log("cleanupSync")
const identitiesList = inSync.identities; const identitiesList = inSync.identities;
console.log(identitiesList)
const cookieStoreIDmap = inSync.cookieStoreIDmap; const cookieStoreIDmap = inSync.cookieStoreIDmap;
console.log(cookieStoreIDmap)
for(const cookieStoreId of Object.keys(cookieStoreIDmap)) { for(const cookieStoreId of Object.keys(cookieStoreIDmap)) {
const match = identitiesList.find(syncIdentity => syncIdentity.cookieStoreId === cookieStoreId); const match = identitiesList.find(syncIdentity => syncIdentity.cookieStoreId === cookieStoreId);
if (!match) { if (!match) {
delete inSync.cookieStoreIDmap[cookieStoreId]; delete inSync.cookieStoreIDmap[cookieStoreId];
browser.storage.sync.set({cookieStoreIDmap: inSync.cookieStoreIDmap}); await browser.storage.sync.set({cookieStoreIDmap: inSync.cookieStoreIDmap});
console.log("removed ", cookieStoreId, " from sync list"); console.log("removed ", cookieStoreId, " from sync list");
} }
} }

View file

@ -38,7 +38,7 @@ const identityState = {
if (configKey.includes("identitiesState@@_")) { if (configKey.includes("identitiesState@@_")) {
const cookieStoreId = String(configKey).replace(/^identitiesState@@_/, ""); const cookieStoreId = String(configKey).replace(/^identitiesState@@_/, "");
const match = identitiesList.find(localIdentity => localIdentity.cookieStoreId === cookieStoreId); const match = identitiesList.find(localIdentity => localIdentity.cookieStoreId === cookieStoreId);
if (!match) { if (!match && cookieStoreId !== "firefox-default") {
console.log("removed ", cookieStoreId, " from storage list"); console.log("removed ", cookieStoreId, " from storage list");
this.remove(cookieStoreId); this.remove(cookieStoreId);
} }