Chromium Code Reviews| 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({ |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 */ | 26 */ |
| 27 treeNodes_: Object, | 27 treeNodes_: Object, |
| 28 | 28 |
| 29 /** | 29 /** |
| 30 * Keeps track of how many outstanding requests for more data there are. | 30 * Keeps track of how many outstanding requests for more data there are. |
| 31 */ | 31 */ |
| 32 requests_: Number, | 32 requests_: Number, |
| 33 }, | 33 }, |
| 34 | 34 |
| 35 ready: function() { | 35 ready: function() { |
| 36 this.addWebUIListener('loadChildren', this.loadChildren_.bind(this)); | |
| 37 this.addWebUIListener('onTreeItemRemoved', | 36 this.addWebUIListener('onTreeItemRemoved', |
| 38 this.onTreeItemRemoved_.bind(this)); | 37 this.onTreeItemRemoved_.bind(this)); |
| 39 this.treeNodes_ = new settings.CookieTreeNode(null); | 38 this.treeNodes_ = new settings.CookieTreeNode(null); |
| 40 // Start the initial request. | 39 // Start the initial request. |
| 41 this.browserProxy.reloadCookies(); | 40 this.reloadCookies_(); |
| 42 this.requests_ = 1; | |
| 43 }, | 41 }, |
| 44 | 42 |
| 43 /** | |
| 44 * Reloads the whole cookie list. | |
| 45 * @private | |
| 46 */ | |
| 47 reloadCookies_: function() { | |
| 48 this.browserProxy.reloadCookies().then(function(list) { | |
| 49 this.loadChildren_(list); | |
| 50 }.bind(this)); | |
| 51 }, | |
| 52 | |
| 53 /** | |
| 54 * Returns whether remove all should be shown. | |
| 55 * @param {Array<CookieDataSummaryItem>} sites The sites list to use to | |
| 56 * determine whether the button should be visible. | |
|
dschuyler
2016/08/18 22:51:10
nit: indent 'determine...'
Finnur
2016/08/19 12:18:32
Done.
| |
| 57 * @private | |
| 58 */ | |
| 59 removeAllIsVisible_: function(sites) { | |
| 60 return sites.length > 0; | |
| 61 }, | |
| 62 | |
| 63 /** | |
| 64 * Called when the cookie list is ready to be shown. | |
| 65 * @private | |
| 66 */ | |
| 45 loadChildren_: function(list) { | 67 loadChildren_: function(list) { |
|
dschuyler
2016/08/18 22:51:10
@param for list.
| |
| 46 var parentId = list[0]; | 68 var parentId = list[0]; |
| 47 var data = list[1]; | 69 var data = list[1]; |
| 48 | 70 |
| 49 if (parentId == null) { | 71 if (parentId == null) { |
| 72 // New root being added, clear the list and add the nodes. | |
| 73 this.sites = []; | |
| 74 this.requests_ = 0; | |
| 50 this.treeNodes_.addChildNodes(this.treeNodes_, data); | 75 this.treeNodes_.addChildNodes(this.treeNodes_, data); |
| 51 } else { | 76 } else { |
| 52 this.treeNodes_.populateChildNodes(parentId, this.treeNodes_, data); | 77 this.treeNodes_.populateChildNodes(parentId, this.treeNodes_, data); |
| 53 } | 78 } |
| 54 | 79 |
| 55 for (var i = 0; i < data.length; ++i) { | 80 for (var i = 0; i < data.length; ++i) { |
| 56 var prefix = parentId == null ? '' : parentId + ', '; | 81 var prefix = parentId == null ? '' : parentId + ', '; |
| 57 if (data[i].hasChildren) { | 82 if (data[i].hasChildren) { |
| 58 this.requests_ += 1; | 83 ++this.requests_; |
| 59 this.browserProxy.loadCookieChildren(prefix + data[i].id); | 84 this.browserProxy.loadCookieChildren( |
| 85 prefix + data[i].id).then(function(list) { | |
| 86 --this.requests_; | |
| 87 this.loadChildren_(list); | |
| 88 }.bind(this)); | |
| 60 } | 89 } |
| 61 } | 90 } |
| 62 | 91 |
| 63 if (--this.requests_ == 0) | 92 if (this.requests_ == 0) |
| 64 this.sites = this.treeNodes_.getSummaryList(); | 93 this.sites = this.treeNodes_.getSummaryList(); |
|
dschuyler
2016/08/18 22:51:10
It looks like this may be called more often
than o
Finnur
2016/08/18 23:27:38
I don't think this is an issue, but will check tom
Finnur
2016/08/19 12:18:32
I verified this again and getSummaryList is called
| |
| 94 | |
| 95 // If this reaches below zero then we're forgetting to increase the | |
| 96 // outstanding request count and the summary list won't be updated at the | |
| 97 // end. | |
| 98 assert(this.requests_ >= 0); | |
| 65 }, | 99 }, |
| 66 | 100 |
| 67 /** | 101 /** |
| 68 * Called when an item is removed. | 102 * Called when a single item has been removed (not during delete all). |
| 69 */ | 103 */ |
| 70 onTreeItemRemoved_: function(args) { | 104 onTreeItemRemoved_: function(args) { |
|
dschuyler
2016/08/18 22:51:10
Can we @param the args?
Finnur
2016/08/18 23:27:38
Umm, yeah -- |we| probably can. :) I, however, alr
Finnur
2016/08/19 12:18:32
Actually, scratch that...
Coming in this morning
| |
| 71 this.treeNodes_.removeByParentId(args[0], args[1], args[2]); | 105 this.treeNodes_.removeByParentId(args[0], args[1], args[2]); |
| 72 this.sites = this.treeNodes_.getSummaryList(); | 106 this.sites = this.treeNodes_.getSummaryList(); |
| 73 }, | 107 }, |
| 74 | 108 |
| 75 /** | 109 /** |
| 76 * @param {!{model: !{item: !{title: string, id: string}}}} event | 110 * Deletes all site data for a given site. |
| 111 * @param {!{model: !{item: CookieDataSummaryItem}}} event | |
| 112 * @private | |
| 113 */ | |
| 114 onDeleteSite_: function(event) { | |
| 115 this.browserProxy.removeCookie(event.model.item.id); | |
| 116 }, | |
| 117 | |
| 118 /** | |
| 119 * Deletes site data for all sites. | |
| 120 * @private | |
| 121 */ | |
| 122 onDeleteAllSites_: function() { | |
| 123 this.browserProxy.removeAllCookies().then(function(list) { | |
| 124 this.loadChildren_(list); | |
| 125 }.bind(this)); | |
| 126 }, | |
| 127 | |
| 128 /** | |
| 129 * @param {!{model: !{item: CookieDataSummaryItem}}} event | |
| 77 * @private | 130 * @private |
| 78 */ | 131 */ |
| 79 onSiteTap_: function(event) { | 132 onSiteTap_: function(event) { |
| 80 var dialog = document.createElement('site-data-details-dialog'); | 133 var dialog = document.createElement('site-data-details-dialog'); |
| 81 dialog.category = this.category; | 134 dialog.category = this.category; |
| 82 this.shadowRoot.appendChild(dialog); | 135 this.shadowRoot.appendChild(dialog); |
| 83 | 136 |
| 84 var node = this.treeNodes_.fetchNodeById(event.model.item.id, false); | 137 var node = this.treeNodes_.fetchNodeById(event.model.item.id, false); |
| 85 dialog.open(node); | 138 dialog.open(node); |
| 86 | 139 |
| 87 dialog.addEventListener('close', function(event) { | 140 dialog.addEventListener('close', function(event) { |
| 88 dialog.remove(); | 141 dialog.remove(); |
| 89 }); | 142 }); |
| 90 }, | 143 }, |
| 91 }); | 144 }); |
| OLD | NEW |