updated with comments fixes from review

This commit is contained in:
Kendall Werts 2019-12-18 22:26:55 -06:00
parent 27225df281
commit e65c88cde2
2 changed files with 32 additions and 32 deletions

View file

@ -92,17 +92,17 @@ const assignManager = {
async getAssignedSites(userContextId = null) { async getAssignedSites(userContextId = null) {
const sites = {}; const sites = {};
const siteConfigs = await this.area.get(); const siteConfigs = await this.area.get();
for(const key of Object.keys(siteConfigs)) { for(const urlKey of Object.keys(siteConfigs)) {
if (key.includes("siteContainerMap@@_")) { if (urlKey.includes("siteContainerMap@@_")) {
// For some reason this is stored as string... lets check them both as that // For some reason this is stored as string... lets check them both as that
if (!!userContextId && String(siteConfigs[key].userContextId) !== String(userContextId)) { if (!!userContextId && String(siteConfigs[urlKey].userContextId) !== String(userContextId)) {
continue; continue;
} }
const site = siteConfigs[key]; const site = siteConfigs[urlKey];
// In hindsight we should have stored this // In hindsight we should have stored this
// TODO file a follow up to clean the storage onLoad // TODO file a follow up to clean the storage onLoad
site.hostname = key.replace(/^siteContainerMap@@_/, ""); site.hostname = urlKey.replace(/^siteContainerMap@@_/, "");
sites[key] = site; sites[urlKey] = site;
} }
}; };
return sites; return sites;
@ -564,10 +564,10 @@ const assignManager = {
console.log("inLocal: ", localInfo); console.log("inLocal: ", localInfo);
const beenSynced = await assignManager.storageArea.getSynced(); const beenSynced = await assignManager.storageArea.getSynced();
if (beenSynced){ if (beenSynced){
runSync(); await runSync();
return; return;
} }
runFirstSync(); await runFirstSync();
}, },
}; };
@ -741,12 +741,12 @@ async function reconcileIdentitiesByName(inSync){
async function reconcileSiteAssignments(inSync, firstSync = false) { async function reconcileSiteAssignments(inSync, firstSync = false) {
console.log("reconcileSiteAssignments"); console.log("reconcileSiteAssignments");
const assignedSitesLocal = await assignManager.storageArea.getAssignedSites(); const assignedSitesLocal = await assignManager.storageArea.getAssignedSites();
const syncAssignedSites = inSync.assignedSites; const assignedSitesFromSync = inSync.assignedSites;
for(const key of Object.keys(syncAssignedSites)) { for(const urlKey of Object.keys(assignedSitesFromSync)) {
if (assignedSitesLocal.hasOwnProperty(key)) { if (assignedSitesLocal.hasOwnProperty(urlKey)) {
const syncCookieStoreId = "firefox-container-" + syncAssignedSites[key].userContextId; const syncCookieStoreId = "firefox-container-" + assignedSitesFromSync[urlKey].userContextId;
const syncUUID = await inSync.cookieStoreIDmap[syncCookieStoreId]; const syncUUID = await inSync.cookieStoreIDmap[syncCookieStoreId];
const assignedSite = assignedSitesLocal[key]; const assignedSite = assignedSitesLocal[urlKey];
const localCookieStoreId = "firefox-container-" + assignedSite.userContextId; const localCookieStoreId = "firefox-container-" + assignedSite.userContextId;
const localIdentityUUID = await identityState.storageArea.get(localCookieStoreId).macAddonUUID const localIdentityUUID = await identityState.storageArea.get(localCookieStoreId).macAddonUUID
if (syncUUID === localIdentityUUID) { if (syncUUID === localIdentityUUID) {
@ -754,25 +754,25 @@ async function reconcileSiteAssignments(inSync, firstSync = false) {
} }
if (!firstSync) { if (!firstSync) {
// overwrite with Sync data // overwrite with Sync data
await setAsignmentWithUUID(syncUUID, assignedSite, key); await setAsignmentWithUUID(syncUUID, assignedSite, urlKey);
continue; continue;
} }
// TODO: on First Sync only, if uuids are not the same, // TODO: on First Sync only, if uuids are not the same,
// ask user where to assign the site. // ask user where to assign the site.
continue; continue;
} }
const assignedSite = syncAssignedSites[key]; const assignedSite = assignedSitesFromSync[urlKey];
console.log("new assignment ", assignedSite, ": ", assignedSite.userContextId) console.log("new assignment ", assignedSite, ": ", assignedSite.userContextId)
const newUUID = await inSync.cookieStoreIDmap["firefox-container-" + assignedSite.userContextId]; const newUUID = await inSync.cookieStoreIDmap["firefox-container-" + assignedSite.userContextId];
await setAsignmentWithUUID(newUUID, assignedSite, key); await setAsignmentWithUUID(newUUID, assignedSite, urlKey);
} }
} }
async function setAsignmentWithUUID (newUUID, assignedSite, key) { async function setAsignmentWithUUID (newUUID, assignedSite, urlKey) {
const cookieStoreId = await identityState.lookupCookieStoreId(newUUID); const cookieStoreId = await identityState.lookupCookieStoreId(newUUID);
assignedSite.userContextId = cookieStoreId.replace(/^firefox-container-/, ""); assignedSite.userContextId = cookieStoreId.replace(/^firefox-container-/, "");
await assignManager.storageArea.set( await assignManager.storageArea.set(
key.replace(/^siteContainerMap@@_/, "https://"), urlKey.replace(/^siteContainerMap@@_/, "https://"),
assignedSite assignedSite
); );
} }
@ -788,7 +788,7 @@ async function runSync() {
return; return;
} }
console.log("storage found, attempting to restore ..."); console.log("storage found, attempting to restore ...");
restore(inSync); await restore(inSync);
} }
function addContextualIdentityListeners(listener) { function addContextualIdentityListeners(listener) {
@ -810,7 +810,7 @@ async function runFirstSync() {
const inSync = await browser.storage.sync.get(); const inSync = await browser.storage.sync.get();
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...");
backup(); await backup();
} else { } else {
console.log("storage found, attempting to restore ..."); console.log("storage found, attempting to restore ...");
await restoreFirstRun(inSync); await restoreFirstRun(inSync);

View file

@ -40,10 +40,10 @@ const identityState = {
async getCookieStoreIDuuidMap() { async getCookieStoreIDuuidMap() {
const containers = {}; const containers = {};
const containerInfo = await identityState.storageArea.area.get(); const containerInfo = await identityState.storageArea.area.get();
for(const key of Object.keys(containerInfo)) { for(const configKey of Object.keys(containerInfo)) {
if (key.includes("identitiesState@@_")) { if (configKey.includes("identitiesState@@_")) {
const container = containerInfo[key]; const container = containerInfo[configKey];
const cookieStoreId = key.replace(/^identitiesState@@_/, ""); const cookieStoreId = configKey.replace(/^identitiesState@@_/, "");
containers[cookieStoreId] = container.macAddonUUID; containers[cookieStoreId] = container.macAddonUUID;
} }
} }
@ -79,10 +79,10 @@ const identityState = {
async lookupMACaddonUUID(cookieStoreId) { async lookupMACaddonUUID(cookieStoreId) {
const macConfigs = await this.storageArea.area.get(); const macConfigs = await this.storageArea.area.get();
for(const key of Object.keys(macConfigs)) { for(const configKey of Object.keys(macConfigs)) {
if (key.includes("identitiesState@@_")) { if (configKey.includes("identitiesState@@_")) {
if(macConfigs[key] === cookieStoreId) { if(macConfigs[configKey] === cookieStoreId) {
return macConfigs[key].macAddonUUID; return macConfigs[configKey].macAddonUUID;
} }
} }
} }
@ -91,10 +91,10 @@ const identityState = {
async lookupCookieStoreId(macAddonUUID) { async lookupCookieStoreId(macAddonUUID) {
const macConfigs = await this.storageArea.area.get(); const macConfigs = await this.storageArea.area.get();
for(const key of Object.keys(macConfigs)) { for(const configKey of Object.keys(macConfigs)) {
if (key.includes("identitiesState@@_")) { if (configKey.includes("identitiesState@@_")) {
if(macConfigs[key].macAddonUUID === macAddonUUID) { if(macConfigs[configKey].macAddonUUID === macAddonUUID) {
return String(key).replace(/^identitiesState@@_/, ""); return String(configKey).replace(/^identitiesState@@_/, "");
} }
} }
} }