Commit ec4d95c5 authored by Maggie Cai's avatar Maggie Cai Committed by Commit Bot

Settings: Refresh All Sites data after returning from Site Details.

Currently the All Sites page |siteGroupMap| will not repopulate when we
click the back button from the Site Details page. This CL populates the
site list data whenever the All Sites route is navigated.

This CL also simplifies the |siteGroupMap| updating mechanism. Since the
site list sent from the backend will always include permissions and
storage, we can simply in-place update the |siteGroupMap| when a new list
is fetched.

BUG=835712

Change-Id: If8c6d8ae5092cfaa7b85dd49527c478243cddf86
Reviewed-on: https://chromium-review.googlesource.com/c/1428622Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarPatti <patricialor@chromium.org>
Commit-Queue: Maggie Cai <mxcai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#625427}
parent 8224d406
...@@ -139,7 +139,6 @@ Polymer({ ...@@ -139,7 +139,6 @@ Polymer({
} }
}, 500); }, 500);
}); });
this.populateList_();
}, },
/** @override */ /** @override */
...@@ -151,6 +150,21 @@ Polymer({ ...@@ -151,6 +150,21 @@ Polymer({
}); });
}, },
/**
* Reload the site list when the all sites page is visited.
*
* settings.RouteObserverBehavior
* @param {!settings.Route} currentRoute
* @protected
*/
currentRouteChanged: function(currentRoute) {
settings.GlobalScrollTargetBehaviorImpl.currentRouteChanged.call(
this, currentRoute);
if (currentRoute == settings.routes.SITE_SETTINGS_ALL) {
this.populateList_();
}
},
/** /**
* Retrieves a list of all known sites with site details. * Retrieves a list of all known sites with site details.
* @private * @private
...@@ -185,30 +199,7 @@ Polymer({ ...@@ -185,30 +199,7 @@ Polymer({
const newMap = /** @type {!Map<string, !SiteGroup>} */ const newMap = /** @type {!Map<string, !SiteGroup>} */
(new Map(this.siteGroupMap)); (new Map(this.siteGroupMap));
list.forEach(storageSiteGroup => { list.forEach(storageSiteGroup => {
if (newMap.has(storageSiteGroup.etldPlus1)) { newMap.set(storageSiteGroup.etldPlus1, storageSiteGroup);
const siteGroup = newMap.get(storageSiteGroup.etldPlus1);
const storageOriginInfoMap = new Map();
siteGroup.numCookies = storageSiteGroup.numCookies;
storageSiteGroup.origins.forEach(
originInfo =>
storageOriginInfoMap.set(originInfo.origin, originInfo));
// If there is an overlapping origin, update the original
// |originInfo|.
siteGroup.origins.forEach(originInfo => {
if (storageOriginInfoMap.has(originInfo.origin)) {
Object.assign(
originInfo, storageOriginInfoMap.get(originInfo.origin));
storageOriginInfoMap.delete(originInfo.origin);
}
});
// Otherwise, add it to the list.
storageOriginInfoMap.forEach(
originInfo => siteGroup.origins.push(originInfo));
} else {
newMap.set(storageSiteGroup.etldPlus1, storageSiteGroup);
}
}); });
this.siteGroupMap = newMap; this.siteGroupMap = newMap;
}, },
......
...@@ -323,9 +323,9 @@ suite('AllSites', function() { ...@@ -323,9 +323,9 @@ suite('AllSites', function() {
assertEquals(fooEtldPlus1, siteEntries[0].siteGroup.etldPlus1); assertEquals(fooEtldPlus1, siteEntries[0].siteGroup.etldPlus1);
assertEquals(2, siteEntries[0].siteGroup.origins.length); assertEquals(2, siteEntries[0].siteGroup.origins.length);
assertEquals(fooOrigin, siteEntries[0].siteGroup.origins[0].origin);
assertEquals( assertEquals(
'https://foo.com', siteEntries[0].siteGroup.origins[0].origin); 'https://foo.com', siteEntries[0].siteGroup.origins[1].origin);
assertEquals(fooOrigin, siteEntries[0].siteGroup.origins[1].origin);
assertEquals(addEtldPlus1, siteEntries[3].siteGroup.etldPlus1); assertEquals(addEtldPlus1, siteEntries[3].siteGroup.etldPlus1);
assertEquals(1, siteEntries[3].siteGroup.origins.length); assertEquals(1, siteEntries[3].siteGroup.origins.length);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment