Commit 3c14e795 authored by dschuyler's avatar dschuyler Committed by Commit bot

[MD settings] use promises rather than a counter var to fetch cookie data

This CL replaces a var counter for fetching cookie data with javascript
promises. The counter had issues with reentrancy, while promise arrays
are more robust.

BUG=None
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2439233002
Cr-Commit-Position: refs/heads/master@{#427130}
parent e7518061
...@@ -27,12 +27,6 @@ Polymer({ ...@@ -27,12 +27,6 @@ Polymer({
*/ */
treeNodes_: Object, 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. * The current filter applied to the cookie data list.
* @private * @private
...@@ -108,37 +102,30 @@ Polymer({ ...@@ -108,37 +102,30 @@ Polymer({
* @private * @private
*/ */
loadChildren_: function(list) { loadChildren_: function(list) {
var parentId = list.id; var loadChildrenRecurse = function(list) {
var data = list.children; var parentId = list.id;
var children = list.children;
if (parentId == null) { var prefix = '';
// New root being added, clear the list and add the nodes. if (parentId !== null) {
this.sites = []; this.treeNodes_.populateChildNodes(parentId, this.treeNodes_, children);
this.requests_ = 0; prefix = parentId + ', ';
this.treeNodes_.addChildNodes(this.treeNodes_, data);
} else {
this.treeNodes_.populateChildNodes(parentId, this.treeNodes_, data);
}
for (var i = 0; i < data.length; ++i) {
var prefix = parentId == null ? '' : parentId + ', ';
if (data[i].hasChildren) {
++this.requests_;
this.browserProxy.loadCookieChildren(
prefix + data[i].id).then(function(list) {
--this.requests_;
this.loadChildren_(list);
}.bind(this));
} }
} var promises = [];
for (let child of children) {
if (child.hasChildren) {
promises.push(this.browserProxy.loadCookieChildren(
prefix + child.id).then(loadChildrenRecurse.bind(this)));
}
}
return Promise.all(promises);
}.bind(this);
if (this.requests_ == 0) // New root being added, clear the list and add the nodes.
this.sites = [];
this.treeNodes_.addChildNodes(this.treeNodes_, list.children);
loadChildrenRecurse(list).then(function() {
this.sites = this.treeNodes_.getSummaryList(); this.sites = this.treeNodes_.getSummaryList();
}.bind(this));
// 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);
}, },
/** /**
......
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