Chromium Code Reviews| Index: chrome/browser/resources/settings/site_settings/site_data.js |
| diff --git a/chrome/browser/resources/settings/site_settings/site_data.js b/chrome/browser/resources/settings/site_settings/site_data.js |
| index e17c67bf4926b9f00c2b0cb57090bbaf1a5c7bef..180d462b519229bb9e7b32ecf6e77a94835757f7 100644 |
| --- a/chrome/browser/resources/settings/site_settings/site_data.js |
| +++ b/chrome/browser/resources/settings/site_settings/site_data.js |
| @@ -28,12 +28,6 @@ Polymer({ |
| treeNodes_: Object, |
| /** |
| - * Keeps track of how many outstanding requests for more data there are. |
| - * @private |
| - */ |
| - requests_: Number, |
| - |
| - /** |
| * The current filter applied to the cookie data list. |
| * @private |
| */ |
| @@ -108,37 +102,46 @@ Polymer({ |
| * @private |
| */ |
| loadChildren_: function(list) { |
| - var parentId = list.id; |
| + assert(list.id == null); |
| + // New root being added, clear the list and add the nodes. |
| + this.sites = []; |
| var data = list.children; |
| - |
| - if (parentId == null) { |
| - // New root being added, clear the list and add the nodes. |
| - this.sites = []; |
| - this.requests_ = 0; |
| - this.treeNodes_.addChildNodes(this.treeNodes_, data); |
| - } else { |
| - this.treeNodes_.populateChildNodes(parentId, this.treeNodes_, data); |
| + this.treeNodes_.addChildNodes(this.treeNodes_, data); |
| + var promiseList = []; |
|
dpapad
2016/10/21 22:03:08
Nit: s/promiseList/promises/. It's shorter, and co
dschuyler
2016/10/22 00:50:45
Done.
|
| + for (var i = 0; i < data.length; ++i) { |
|
dpapad
2016/10/21 22:03:07
Nit(optional): A more functional way to do this (a
dschuyler
2016/10/22 00:50:45
javascript map is often suggested as alternative t
dpapad
2016/10/22 01:05:57
forEach() and for() are usually compared in terms
dschuyler
2016/10/22 01:17:11
The poor performance of map, afaik, comes from the
|
| + if (data[i].hasChildren) { |
| + promiseList.push(this.browserProxy.loadCookieChildren( |
| + data[i].id).then(function(list) { |
|
dpapad
2016/10/21 22:03:07
Nit (optional): I think is more readable if you sk
dschuyler
2016/10/22 00:50:45
Thanks
Done.
|
| + return this.loadChildrenRecurse_(list); |
| + }.bind(this))); |
| + } |
| } |
| + Promise.all(promiseList).then(function() { |
| + this.sites = this.treeNodes_.getSummaryList(); |
| + }.bind(this)); |
| + }, |
| + /** |
| + * Called when the cookie list is ready to be shown. |
| + * @param {!CookieList} list The cookie list to show. |
| + * @private |
| + */ |
| + loadChildrenRecurse_: function(list) { |
|
dpapad
2016/10/21 22:03:07
loadChildrenRecurse_ and loadChildren_ seem almost
dschuyler
2016/10/22 00:50:45
Done.
|
| + assert(list.id != null); |
|
dpapad
2016/10/21 22:03:07
Do we need to assert, on top of relying on the com
dschuyler
2016/10/22 00:50:45
The assserts are testing whether id is null (rathe
|
| + var parentId = list.id; |
| + var data = list.children; |
| + this.treeNodes_.populateChildNodes(parentId, this.treeNodes_, data); |
| + var promiseList = []; |
| + var prefix = parentId + ', '; |
| for (var i = 0; i < data.length; ++i) { |
| - var prefix = parentId == null ? '' : parentId + ', '; |
| if (data[i].hasChildren) { |
| - ++this.requests_; |
| - this.browserProxy.loadCookieChildren( |
| + promiseList.push(this.browserProxy.loadCookieChildren( |
| prefix + data[i].id).then(function(list) { |
| - --this.requests_; |
| - this.loadChildren_(list); |
| - }.bind(this)); |
| + return this.loadChildrenRecurse_(list); |
| + }.bind(this))); |
| } |
| } |
| - |
| - if (this.requests_ == 0) |
| - this.sites = this.treeNodes_.getSummaryList(); |
| - |
| - // If this reaches below zero then we're forgetting to increase the |
| - // outstanding request count and the summary list won't be updated at the |
| - // end. |
| - assert(this.requests_ >= 0); |
| + return Promise.all(promiseList); |
| }, |
| /** |