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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * 'site-data' handles showing the local storage summary list for all sites. 7 * 'site-data' handles showing the local storage summary list for all sites.
8 */ 8 */
9 9
10 Polymer({ 10 Polymer({
(...skipping 10 matching lines...) Expand all
21 21
22 /** 22 /**
23 * The cookie tree with the details needed to display individual sites and 23 * The cookie tree with the details needed to display individual sites and
24 * their contained data. 24 * their contained data.
25 * @type {!settings.CookieTreeNode} 25 * @type {!settings.CookieTreeNode}
26 * @private 26 * @private
27 */ 27 */
28 treeNodes_: Object, 28 treeNodes_: Object,
29 29
30 /** 30 /**
31 * Keeps track of how many outstanding requests for more data there are.
32 * @private
33 */
34 requests_: Number,
35
36 /**
37 * The current filter applied to the cookie data list. 31 * The current filter applied to the cookie data list.
38 * @private 32 * @private
39 */ 33 */
40 filterString_: { 34 filterString_: {
41 type: String, 35 type: String,
42 value: '', 36 value: '',
43 }, 37 },
44 38
45 /** @private */ 39 /** @private */
46 confirmationDeleteMsg_: String, 40 confirmationDeleteMsg_: String,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 return loadTimeData.getString('siteSettingsCookieRemoveAll'); 95 return loadTimeData.getString('siteSettingsCookieRemoveAll');
102 return loadTimeData.getString('siteSettingsCookieRemoveAllShown'); 96 return loadTimeData.getString('siteSettingsCookieRemoveAllShown');
103 }, 97 },
104 98
105 /** 99 /**
106 * Called when the cookie list is ready to be shown. 100 * Called when the cookie list is ready to be shown.
107 * @param {!CookieList} list The cookie list to show. 101 * @param {!CookieList} list The cookie list to show.
108 * @private 102 * @private
109 */ 103 */
110 loadChildren_: function(list) { 104 loadChildren_: function(list) {
111 var parentId = list.id; 105 var loadChildrenRecurse = function(list) {
112 var data = list.children; 106 var parentId = list.id;
113 107 var data = list.children;
114 if (parentId == null) { 108 var prefix = '';
115 // New root being added, clear the list and add the nodes. 109 if (parentId !== null) {
116 this.sites = []; 110 this.treeNodes_.populateChildNodes(parentId, this.treeNodes_, data);
117 this.requests_ = 0; 111 prefix = parentId + ', ';
118 this.treeNodes_.addChildNodes(this.treeNodes_, data);
119 } else {
120 this.treeNodes_.populateChildNodes(parentId, this.treeNodes_, data);
121 }
122
123 for (var i = 0; i < data.length; ++i) {
124 var prefix = parentId == null ? '' : parentId + ', ';
125 if (data[i].hasChildren) {
126 ++this.requests_;
127 this.browserProxy.loadCookieChildren(
128 prefix + data[i].id).then(function(list) {
129 --this.requests_;
130 this.loadChildren_(list);
131 }.bind(this));
132 } 112 }
133 } 113 var promises = [];
134 114 for (var i = 0; i < data.length; ++i) {
135 if (this.requests_ == 0) 115 assert(data[i].id != null);
116 if (data[i].hasChildren) {
117 promises.push(this.browserProxy.loadCookieChildren(
118 prefix + data[i].id).then(loadChildrenRecurse.bind(this)));
119 }
120 }
121 return Promise.all(promises);
122 }.bind(this);
dpapad 2016/10/22 01:05:57 Perhaps add a \n here?
dschuyler 2016/10/22 01:17:11 Done.
123 // New root being added, clear the list and add the nodes.
124 this.sites = [];
125 this.treeNodes_.addChildNodes(this.treeNodes_, list.children);
126 loadChildrenRecurse(list).then(function() {
136 this.sites = this.treeNodes_.getSummaryList(); 127 this.sites = this.treeNodes_.getSummaryList();
137 128 }.bind(this));
138 // If this reaches below zero then we're forgetting to increase the
139 // outstanding request count and the summary list won't be updated at the
140 // end.
141 assert(this.requests_ >= 0);
142 }, 129 },
143 130
144 /** 131 /**
145 * Called when a single item has been removed (not during delete all). 132 * Called when a single item has been removed (not during delete all).
146 * @param {!CookieRemovePacket} args The details about what to remove. 133 * @param {!CookieRemovePacket} args The details about what to remove.
147 * @private 134 * @private
148 */ 135 */
149 onTreeItemRemoved_: function(args) { 136 onTreeItemRemoved_: function(args) {
150 this.treeNodes_.removeByParentId(args.id, args.start, args.count); 137 this.treeNodes_.removeByParentId(args.id, args.start, args.count);
151 this.sites = this.treeNodes_.getSummaryList(); 138 this.sites = this.treeNodes_.getSummaryList();
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 this.shadowRoot.appendChild(dialog); 202 this.shadowRoot.appendChild(dialog);
216 203
217 var node = this.treeNodes_.fetchNodeById(event.model.item.id, false); 204 var node = this.treeNodes_.fetchNodeById(event.model.item.id, false);
218 dialog.open(node); 205 dialog.open(node);
219 206
220 dialog.addEventListener('close', function(event) { 207 dialog.addEventListener('close', function(event) {
221 dialog.remove(); 208 dialog.remove();
222 }); 209 });
223 }, 210 },
224 }); 211 });
OLDNEW
« 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