OLD | NEW |
---|---|
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({ |
11 is: 'site-data', | 11 is: 'site-data', |
12 | 12 |
13 behaviors: [SiteSettingsBehavior, WebUIListenerBehavior], | 13 behaviors: [SiteSettingsBehavior, WebUIListenerBehavior], |
14 | 14 |
15 properties: { | 15 properties: { |
16 /** | 16 /** |
17 * A summary list of all sites and how many entities each contain. | 17 * A summary list of all sites and how many entities each contain. |
18 * @type {Array<CookieDataSummaryItem>} | 18 * @type {Array<CookieDataSummaryItem>} |
19 */ | 19 */ |
20 sites: Array, | 20 sites: Array, |
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 |
dpapad
2016/10/21 22:03:08
Nit: @private {!settings.CookieTreeNode}
for consi
dschuyler
2016/10/22 00:50:45
Discussed this offline, leaving this out.
| |
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 isRemoveButtonVisible_: function(sites, renderedItemCount) { | 84 isRemoveButtonVisible_: function(sites, renderedItemCount) { |
91 return renderedItemCount != 0; | 85 return renderedItemCount != 0; |
92 }, | 86 }, |
93 | 87 |
94 /** | 88 /** |
95 * Returns the string to use for the Remove label. | 89 * Returns the string to use for the Remove label. |
96 * @return {string} filterString The current filter string. | 90 * @return {string} filterString The current filter string. |
97 * @private | 91 * @private |
98 */ | 92 */ |
99 computeRemoveLabel_: function(filterString) { | 93 computeRemoveLabel_: function(filterString) { |
100 if (filterString.length == 0) | 94 if (filterString.length == 0) |
dpapad
2016/10/21 22:03:07
Nit(optional): I know you are not touching this pa
dschuyler
2016/10/22 00:50:45
I'd rather put these in the html with $i18n
and no
| |
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 assert(list.id == null); |
106 // New root being added, clear the list and add the nodes. | |
107 this.sites = []; | |
112 var data = list.children; | 108 var data = list.children; |
113 | 109 this.treeNodes_.addChildNodes(this.treeNodes_, data); |
114 if (parentId == null) { | 110 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.
| |
115 // New root being added, clear the list and add the nodes. | |
116 this.sites = []; | |
117 this.requests_ = 0; | |
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) { | 111 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
| |
124 var prefix = parentId == null ? '' : parentId + ', '; | |
125 if (data[i].hasChildren) { | 112 if (data[i].hasChildren) { |
126 ++this.requests_; | 113 promiseList.push(this.browserProxy.loadCookieChildren( |
127 this.browserProxy.loadCookieChildren( | 114 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.
| |
128 prefix + data[i].id).then(function(list) { | 115 return this.loadChildrenRecurse_(list); |
129 --this.requests_; | 116 }.bind(this))); |
130 this.loadChildren_(list); | |
131 }.bind(this)); | |
132 } | 117 } |
133 } | 118 } |
134 | 119 Promise.all(promiseList).then(function() { |
135 if (this.requests_ == 0) | |
136 this.sites = this.treeNodes_.getSummaryList(); | 120 this.sites = this.treeNodes_.getSummaryList(); |
137 | 121 }.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 }, | 122 }, |
143 | 123 |
144 /** | 124 /** |
125 * Called when the cookie list is ready to be shown. | |
126 * @param {!CookieList} list The cookie list to show. | |
127 * @private | |
128 */ | |
129 loadChildrenRecurse_: function(list) { | |
dpapad
2016/10/21 22:03:07
loadChildrenRecurse_ and loadChildren_ seem almost
dschuyler
2016/10/22 00:50:45
Done.
| |
130 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
| |
131 var parentId = list.id; | |
132 var data = list.children; | |
133 this.treeNodes_.populateChildNodes(parentId, this.treeNodes_, data); | |
134 var promiseList = []; | |
135 var prefix = parentId + ', '; | |
136 for (var i = 0; i < data.length; ++i) { | |
137 if (data[i].hasChildren) { | |
138 promiseList.push(this.browserProxy.loadCookieChildren( | |
139 prefix + data[i].id).then(function(list) { | |
140 return this.loadChildrenRecurse_(list); | |
141 }.bind(this))); | |
142 } | |
143 } | |
144 return Promise.all(promiseList); | |
145 }, | |
146 | |
147 /** | |
145 * Called when a single item has been removed (not during delete all). | 148 * Called when a single item has been removed (not during delete all). |
146 * @param {!CookieRemovePacket} args The details about what to remove. | 149 * @param {!CookieRemovePacket} args The details about what to remove. |
147 * @private | 150 * @private |
148 */ | 151 */ |
149 onTreeItemRemoved_: function(args) { | 152 onTreeItemRemoved_: function(args) { |
150 this.treeNodes_.removeByParentId(args.id, args.start, args.count); | 153 this.treeNodes_.removeByParentId(args.id, args.start, args.count); |
151 this.sites = this.treeNodes_.getSummaryList(); | 154 this.sites = this.treeNodes_.getSummaryList(); |
152 }, | 155 }, |
153 | 156 |
154 /** @private */ | 157 /** @private */ |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 this.shadowRoot.appendChild(dialog); | 218 this.shadowRoot.appendChild(dialog); |
216 | 219 |
217 var node = this.treeNodes_.fetchNodeById(event.model.item.id, false); | 220 var node = this.treeNodes_.fetchNodeById(event.model.item.id, false); |
218 dialog.open(node); | 221 dialog.open(node); |
219 | 222 |
220 dialog.addEventListener('close', function(event) { | 223 dialog.addEventListener('close', function(event) { |
221 dialog.remove(); | 224 dialog.remove(); |
222 }); | 225 }); |
223 }, | 226 }, |
224 }); | 227 }); |
OLD | NEW |