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..ef19f63a1b926915a4eff5235a599d3ab7928f4d 100644 |
--- a/chrome/browser/resources/md_history/history.js |
+++ b/chrome/browser/resources/md_history/history.js |
@@ -7,17 +7,23 @@ |
chrome.send('queryHistory', ['', 0, 0, 0, RESULTS_PER_PAGE]); |
chrome.send('getForeignSessions'); |
+var upgradePromise = null; |
tsergeant
2016/07/21 07:25:27
Nit: /** @type {Promise} */
calamity
2016/07/25 03:43:30
Done.
|
+ |
/** |
- * @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 +34,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 +58,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 +74,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 +91,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); |
}); |
} |