| Index: chrome/browser/resources/ntp_search/most_visited_page.js
|
| diff --git a/chrome/browser/resources/ntp_search/most_visited_page.js b/chrome/browser/resources/ntp_search/most_visited_page.js
|
| index e3dae2bde32138bf869081f2f79006ab47e5b760..529519655ebc01486bf5dc78f6381aa2156f9e3b 100644
|
| --- a/chrome/browser/resources/ntp_search/most_visited_page.js
|
| +++ b/chrome/browser/resources/ntp_search/most_visited_page.js
|
| @@ -210,114 +210,91 @@ cr.define('ntp', function() {
|
| * TODO(pedrosimonetti): Move data handling related code to TilePage. Make
|
| * sure the new logic works with Apps without requiring duplicating code.
|
| * @param {Array} data The array of data.
|
| - * @type (Array}
|
| */
|
| - set data(data) {
|
| + setData: function(data) {
|
| var startTime = Date.now();
|
| - var maxTileCount = this.config_.maxTileCount;
|
| -
|
| - // The first time data is set, create the tiles.
|
| - if (!this.data_) {
|
| - this.data_ = data.slice(0, maxTileCount);
|
| - this.createTiles_(this.data_.length);
|
| - } else {
|
| - this.data_ = refreshData(this.data_, data, maxTileCount);
|
| - }
|
| -
|
| - this.updateTiles_();
|
| + ThumbnailPage.prototype.setData.apply(this, arguments);
|
| logEvent('mostVisited.layout: ' + (Date.now() - startTime));
|
| },
|
| - };
|
|
|
| - /**
|
| - * Executed once the NTP has loaded. Checks if the Most Visited pane is
|
| - * shown or not. If it is shown, the 'mostVisitedSelected' message is sent
|
| - * to the C++ code, to record the fact that the user has seen this pane.
|
| - */
|
| - MostVisitedPage.onLoaded = function() {
|
| - if (ntp.getCardSlider() &&
|
| - ntp.getCardSlider().currentCardValue &&
|
| - ntp.getCardSlider().currentCardValue.classList
|
| - .contains('most-visited-page')) {
|
| - chrome.send('mostVisitedSelected');
|
| - }
|
| - };
|
| + /**
|
| + * Merges new Most Visited data into the old while minimizing re-ordering.
|
| + * @param {Array} oldData The current page list.
|
| + * @param {Array} newData The new page list.
|
| + * @param {number} maxTileCount The maximum number of tiles to render.
|
| + * @return {Array} The merged page list that should replace the current page
|
| + * list.
|
| + * @private
|
| + */
|
| + refreshData_: function(oldData, newData, maxTileCount) {
|
| + oldData = oldData.slice(0, maxTileCount);
|
| + newData = newData.slice(0, maxTileCount);
|
| +
|
| + // Look through old pages; if they exist in the newData list, keep them
|
| + // where they are.
|
| + for (var i = 0; i < oldData.length; i++) {
|
| + if (!oldData[i] || oldData[i].updated)
|
| + continue;
|
|
|
| - /**
|
| - * We've gotten additional Most Visited data. Update our old data with the
|
| - * new data. The ordering of the new data is not important, except when a
|
| - * page is pinned. Thus we try to minimize re-ordering.
|
| - * @param {Array} oldData The current Most Visited page list.
|
| - * @param {Array} newData The new Most Visited page list.
|
| - * @return {Array} The merged page list that should replace the current page
|
| - * list.
|
| - */
|
| - function refreshData(oldData, newData, maxTileCount) {
|
| - oldData = oldData.slice(0, maxTileCount);
|
| - newData = newData.slice(0, maxTileCount);
|
| -
|
| - // Copy over pinned sites directly.
|
| - for (var j = 0; j < newData.length; j++) {
|
| - if (newData[j].pinned) {
|
| - oldData[j] = newData[j];
|
| - // Mark the entry as 'updated' so we don't try to update again.
|
| - oldData[j].updated = true;
|
| - // Mark the newData page as 'used' so we don't try to re-use it.
|
| - newData[j].used = true;
|
| + for (var j = 0; j < newData.length; j++) {
|
| + if (newData[j].used)
|
| + continue;
|
| +
|
| + if (newData[j].url == oldData[i].url) {
|
| + // The background image and other data may have changed.
|
| + oldData[i] = newData[j];
|
| + oldData[i].updated = true;
|
| + newData[j].used = true;
|
| + break;
|
| + }
|
| + }
|
| }
|
| - }
|
| -
|
| - // Look through old pages; if they exist in the newData list, keep them
|
| - // where they are.
|
| - for (var i = 0; i < oldData.length; i++) {
|
| - if (!oldData[i] || oldData[i].updated)
|
| - continue;
|
|
|
| - for (var j = 0; j < newData.length; j++) {
|
| - if (newData[j].used)
|
| + // Look through old pages that haven't been updated yet; replace them.
|
| + for (var i = 0; i < oldData.length; i++) {
|
| + if (oldData[i] && oldData[i].updated)
|
| continue;
|
|
|
| - if (newData[j].url == oldData[i].url) {
|
| - // The background image and other data may have changed.
|
| + for (var j = 0; j < newData.length; j++) {
|
| + if (newData[j].used)
|
| + continue;
|
| +
|
| oldData[i] = newData[j];
|
| oldData[i].updated = true;
|
| newData[j].used = true;
|
| break;
|
| }
|
| - }
|
| - }
|
| -
|
| - // Look through old pages that haven't been updated yet; replace them.
|
| - for (var i = 0; i < oldData.length; i++) {
|
| - if (oldData[i] && oldData[i].updated)
|
| - continue;
|
|
|
| - for (var j = 0; j < newData.length; j++) {
|
| - if (newData[j].used)
|
| - continue;
|
| + if (oldData[i] && !oldData[i].updated)
|
| + oldData[i] = null;
|
| + }
|
|
|
| - oldData[i] = newData[j];
|
| - oldData[i].updated = true;
|
| - newData[j].used = true;
|
| - break;
|
| + // Clear 'updated' flags so this function will work next time it's called.
|
| + for (var i = 0; i < maxTileCount; i++) {
|
| + if (oldData[i])
|
| + oldData[i].updated = false;
|
| }
|
|
|
| - if (oldData[i] && !oldData[i].updated)
|
| - oldData[i] = null;
|
| - }
|
| + return oldData;
|
| + },
|
| + };
|
|
|
| - // Clear 'updated' flags so this function will work next time it's called.
|
| - for (var i = 0; i < maxTileCount; i++) {
|
| - if (oldData[i])
|
| - oldData[i].updated = false;
|
| + /**
|
| + * Executed once the NTP has loaded. Checks if the Most Visited pane is
|
| + * shown or not. If it is shown, the 'mostVisitedSelected' message is sent
|
| + * to the C++ code, to record the fact that the user has seen this pane.
|
| + */
|
| + MostVisitedPage.onLoaded = function() {
|
| + if (ntp.getCardSlider() &&
|
| + ntp.getCardSlider().currentCardValue &&
|
| + ntp.getCardSlider().currentCardValue.classList
|
| + .contains('most-visited-page')) {
|
| + chrome.send('mostVisitedSelected');
|
| }
|
| -
|
| - return oldData;
|
| - }
|
| + };
|
|
|
| return {
|
| MostVisitedPage: MostVisitedPage,
|
| - refreshData: refreshData,
|
| };
|
| });
|
|
|
|
|