Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2297)

Unified Diff: chrome/browser/resources/settings/site_settings/site_data.js

Issue 2439233002: [MD settings] use promises rather than a counter var to fetch cookie data (Closed)
Patch Set: review changes Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..7540cf012fc400a4d34935b14f89820c37d7f798 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,30 @@ Polymer({
* @private
*/
loadChildren_: function(list) {
- var parentId = list.id;
- 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);
- }
-
- 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 loadChildrenRecurse = function(list) {
+ var parentId = list.id;
+ var data = list.children;
+ var prefix = '';
+ if (parentId !== null) {
+ this.treeNodes_.populateChildNodes(parentId, this.treeNodes_, data);
+ prefix = parentId + ', ';
}
- }
-
- if (this.requests_ == 0)
+ var promises = [];
+ for (var i = 0; i < data.length; ++i) {
+ assert(data[i].id != null);
+ if (data[i].hasChildren) {
+ promises.push(this.browserProxy.loadCookieChildren(
+ prefix + data[i].id).then(loadChildrenRecurse.bind(this)));
+ }
+ }
+ return Promise.all(promises);
+ }.bind(this);
dpapad 2016/10/22 01:05:57 Perhaps add a \n here?
dschuyler 2016/10/22 01:17:11 Done.
+ // 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();
-
- // 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);
+ }.bind(this));
},
/**
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698