Index: chrome/browser/resources/md_history/history.js |
diff --git a/chrome/browser/resources/md_history/history.js b/chrome/browser/resources/md_history/history.js |
index 8f248b966dfa747c29fc5efed33c3e0c95e7fdc3..e9d55e7fcc4c472ad73af8e852956ae4c82dc886 100644 |
--- a/chrome/browser/resources/md_history/history.js |
+++ b/chrome/browser/resources/md_history/history.js |
@@ -7,17 +7,24 @@ |
chrome.send('queryHistory', ['', 0, 0, 0, RESULTS_PER_PAGE]); |
chrome.send('getForeignSessions'); |
+/** @type {Promise} */ |
+var upgradePromise = null; |
+ |
/** |
- * @param {HTMLElement} element |
- * @return {!Promise} Resolves once a Polymer element has been fully upgraded. |
+ * @return {!Promise} Resolves once the history-app has been fully upgraded. |
*/ |
-function waitForUpgrade(element) { |
- return new Promise(function(resolve, reject) { |
- if (window.Polymer && Polymer.isInstance && Polymer.isInstance(element)) |
- resolve(); |
- else |
- $('bundle').addEventListener('load', resolve); |
- }); |
+function waitForAppUpgrade() { |
+ if (!upgradePromise) { |
+ upgradePromise = new Promise(function(resolve, reject) { |
+ if (window.Polymer && Polymer.isInstance && |
+ Polymer.isInstance($('history-app'))) { |
+ resolve(); |
+ } else { |
+ $('bundle').addEventListener('load', resolve); |
+ } |
+ }); |
+ } |
+ return upgradePromise; |
} |
// Chrome Callbacks------------------------------------------------------------- |
@@ -28,9 +35,9 @@ function waitForUpgrade(element) { |
* @param {!Array<HistoryEntry>} results A list of results. |
*/ |
function historyResult(info, results) { |
- var appElem = $('history-app'); |
- waitForUpgrade(appElem).then(function() { |
- /** @type {HistoryAppElement} */(appElem).historyResult(info, results); |
+ waitForAppUpgrade().then(function() { |
+ /** @type {HistoryAppElement} */($('history-app')) |
+ .historyResult(info, results); |
// TODO(tsergeant): Showing everything as soon as the list is ready is not |
// ideal, as the sidebar can still pop in after. Fix this to show everything |
// at once. |
@@ -52,9 +59,8 @@ function showNotification( |
// in the MD history anymore, so the parameter is not needed. Remove it |
// when WebUI is removed and this becomes the only client of |
// BrowsingHistoryHandler. |
- var appElem = $('history-app'); |
- waitForUpgrade(appElem).then(function() { |
- /** @type {HistoryAppElement} */(appElem) |
+ waitForAppUpgrade().then(function() { |
+ /** @type {HistoryAppElement} */($('history-app')) |
.getSideBar().showFooter = includeOtherFormsOfBrowsingHistory; |
}); |
} |
@@ -69,9 +75,8 @@ function showNotification( |
* @param {boolean} isTabSyncEnabled Is tab sync enabled for this profile? |
*/ |
function setForeignSessions(sessionList, isTabSyncEnabled) { |
- var appElem = $('history-app'); |
- waitForUpgrade(appElem).then(function() { |
- /** @type {HistoryAppElement} */(appElem) |
+ waitForAppUpgrade().then(function() { |
+ /** @type {HistoryAppElement} */($('history-app')) |
.setForeignSessions(sessionList, isTabSyncEnabled); |
}); |
} |
@@ -87,9 +92,8 @@ function historyDeleted() { |
* @param {boolean} isUserSignedIn Whether user is signed in or not now. |
*/ |
function updateSignInState(isUserSignedIn) { |
- var appElem = $('history-app'); |
- waitForUpgrade(appElem).then(function() { |
- /** @type {HistoryAppElement} */(appElem) |
+ waitForAppUpgrade().then(function() { |
+ /** @type {HistoryAppElement} */($('history-app')) |
.updateSignInState(isUserSignedIn); |
}); |
} |