| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // Send the history query immediately. This allows the query to process during | 5 // Send the history query immediately. This allows the query to process during |
| 6 // the initial page startup. | 6 // the initial page startup. |
| 7 chrome.send('queryHistory', ['', 0, 0, 0, RESULTS_PER_PAGE]); | 7 chrome.send('queryHistory', ['', 0, 0, 0, RESULTS_PER_PAGE]); |
| 8 chrome.send('getForeignSessions'); | 8 chrome.send('getForeignSessions'); |
| 9 | 9 |
| 10 /** @type {Promise} */ | 10 /** @type {Promise} */ |
| 11 var upgradePromise = null; | 11 var upgradePromise = null; |
| 12 /** @type {boolean} */ |
| 13 var resultsRendered = false; |
| 12 | 14 |
| 13 /** | 15 /** |
| 14 * @return {!Promise} Resolves once the history-app has been fully upgraded. | 16 * @return {!Promise} Resolves once the history-app has been fully upgraded. |
| 15 */ | 17 */ |
| 16 function waitForAppUpgrade() { | 18 function waitForAppUpgrade() { |
| 17 if (!upgradePromise) { | 19 if (!upgradePromise) { |
| 18 upgradePromise = new Promise(function(resolve, reject) { | 20 upgradePromise = new Promise(function(resolve, reject) { |
| 19 if (window.Polymer && Polymer.isInstance && | 21 if (window.Polymer && Polymer.isInstance && |
| 20 Polymer.isInstance($('history-app'))) { | 22 Polymer.isInstance($('history-app'))) { |
| 21 resolve(); | 23 resolve(); |
| 22 } else { | 24 } else { |
| 23 $('bundle').addEventListener('load', resolve); | 25 $('bundle').addEventListener('load', resolve); |
| 24 } | 26 } |
| 25 }); | 27 }); |
| 26 } | 28 } |
| 27 return upgradePromise; | 29 return upgradePromise; |
| 28 } | 30 } |
| 29 | 31 |
| 30 // Chrome Callbacks------------------------------------------------------------- | 32 // Chrome Callbacks------------------------------------------------------------- |
| 31 | 33 |
| 32 /** | 34 /** |
| 33 * Our history system calls this function with results from searches. | 35 * Our history system calls this function with results from searches. |
| 34 * @param {HistoryQuery} info An object containing information about the query. | 36 * @param {HistoryQuery} info An object containing information about the query. |
| 35 * @param {!Array<HistoryEntry>} results A list of results. | 37 * @param {!Array<HistoryEntry>} results A list of results. |
| 36 */ | 38 */ |
| 37 function historyResult(info, results) { | 39 function historyResult(info, results) { |
| 38 waitForAppUpgrade().then(function() { | 40 waitForAppUpgrade().then(function() { |
| 39 /** @type {HistoryAppElement} */($('history-app')) | 41 /** @type {HistoryAppElement} */($('history-app')) |
| 40 .historyResult(info, results); | 42 .historyResult(info, results); |
| 41 // TODO(tsergeant): Showing everything as soon as the list is ready is not | |
| 42 // ideal, as the sidebar can still pop in after. Fix this to show everything | |
| 43 // at once. | |
| 44 document.body.classList.remove('loading'); | 43 document.body.classList.remove('loading'); |
| 44 |
| 45 if (!resultsRendered) { |
| 46 resultsRendered = true; |
| 47 // requestAnimationFrame allows measurement immediately before the next |
| 48 // repaint, but after the first page of <iron-list> items has stamped. |
| 49 requestAnimationFrame(function() { |
| 50 chrome.send( |
| 51 'metricsHandler:recordTime', |
| 52 ['History.ResultsRenderedTime', window.performance.now()]); |
| 53 }); |
| 54 } |
| 45 }); | 55 }); |
| 46 } | 56 } |
| 47 | 57 |
| 48 /** | 58 /** |
| 49 * Called by the history backend after receiving results and after discovering | 59 * Called by the history backend after receiving results and after discovering |
| 50 * the existence of other forms of browsing history. | 60 * the existence of other forms of browsing history. |
| 51 * @param {boolean} hasSyncedResults Whether there are synced results. | 61 * @param {boolean} hasSyncedResults Whether there are synced results. |
| 52 * @param {boolean} includeOtherFormsOfBrowsingHistory Whether to include | 62 * @param {boolean} includeOtherFormsOfBrowsingHistory Whether to include |
| 53 * a sentence about the existence of other forms of browsing history. | 63 * a sentence about the existence of other forms of browsing history. |
| 54 */ | 64 */ |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 /** | 100 /** |
| 91 * Called by the history backend after user's sign in state changes. | 101 * Called by the history backend after user's sign in state changes. |
| 92 * @param {boolean} isUserSignedIn Whether user is signed in or not now. | 102 * @param {boolean} isUserSignedIn Whether user is signed in or not now. |
| 93 */ | 103 */ |
| 94 function updateSignInState(isUserSignedIn) { | 104 function updateSignInState(isUserSignedIn) { |
| 95 waitForAppUpgrade().then(function() { | 105 waitForAppUpgrade().then(function() { |
| 96 /** @type {HistoryAppElement} */($('history-app')) | 106 /** @type {HistoryAppElement} */($('history-app')) |
| 97 .updateSignInState(isUserSignedIn); | 107 .updateSignInState(isUserSignedIn); |
| 98 }); | 108 }); |
| 99 } | 109 } |
| OLD | NEW |