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} */ | 12 /** @type {boolean} */ |
13 var resultsRendered = false; | 13 var resultsRendered = false; |
14 | 14 |
15 /** | 15 /** |
16 * @return {!Promise} Resolves once the history-app has been fully upgraded. | 16 * @return {!Promise<!HistoryAppElement>} Resolves once the history-app has been |
| 17 * fully upgraded. |
17 */ | 18 */ |
18 function waitForAppUpgrade() { | 19 function waitForHistoryApp() { |
19 if (!upgradePromise) { | 20 if (!upgradePromise) { |
20 upgradePromise = new Promise(function(resolve, reject) { | 21 upgradePromise = new Promise(function(resolve, reject) { |
21 if (window.Polymer && Polymer.isInstance && | 22 if (window.Polymer && Polymer.isInstance && |
22 Polymer.isInstance($('history-app'))) { | 23 Polymer.isInstance(document.querySelector('history-app'))) { |
23 resolve(); | 24 resolve(/** @type {!HistoryAppElement} */( |
| 25 document.querySelector('history-app'))); |
24 } else { | 26 } else { |
25 $('bundle').addEventListener('load', resolve); | 27 $('bundle').addEventListener('load', function() { |
| 28 resolve(/** @type {!HistoryAppElement} */( |
| 29 document.querySelector('history-app'))); |
| 30 }); |
26 } | 31 } |
27 }); | 32 }); |
28 } | 33 } |
29 return upgradePromise; | 34 return upgradePromise; |
30 } | 35 } |
31 | 36 |
32 // Chrome Callbacks------------------------------------------------------------- | 37 // Chrome Callbacks------------------------------------------------------------- |
33 | 38 |
34 /** | 39 /** |
35 * Our history system calls this function with results from searches. | 40 * Our history system calls this function with results from searches. |
36 * @param {HistoryQuery} info An object containing information about the query. | 41 * @param {HistoryQuery} info An object containing information about the query. |
37 * @param {!Array<HistoryEntry>} results A list of results. | 42 * @param {!Array<HistoryEntry>} results A list of results. |
38 */ | 43 */ |
39 function historyResult(info, results) { | 44 function historyResult(info, results) { |
40 waitForAppUpgrade().then(function() { | 45 waitForHistoryApp().then(function(historyApp) { |
41 /** @type {HistoryAppElement} */($('history-app')) | 46 historyApp.historyResult(info, results); |
42 .historyResult(info, results); | |
43 document.body.classList.remove('loading'); | 47 document.body.classList.remove('loading'); |
44 | 48 |
45 if (!resultsRendered) { | 49 if (!resultsRendered) { |
46 resultsRendered = true; | 50 resultsRendered = true; |
47 // requestAnimationFrame allows measurement immediately before the next | 51 // requestAnimationFrame allows measurement immediately before the next |
48 // repaint, but after the first page of <iron-list> items has stamped. | 52 // repaint, but after the first page of <iron-list> items has stamped. |
49 requestAnimationFrame(function() { | 53 requestAnimationFrame(function() { |
50 chrome.send( | 54 chrome.send( |
51 'metricsHandler:recordTime', | 55 'metricsHandler:recordTime', |
52 ['History.ResultsRenderedTime', window.performance.now()]); | 56 ['History.ResultsRenderedTime', window.performance.now()]); |
53 }); | 57 }); |
54 } | 58 } |
55 }); | 59 }); |
56 } | 60 } |
57 | 61 |
58 /** | 62 /** |
59 * Called by the history backend after receiving results and after discovering | 63 * Called by the history backend after receiving results and after discovering |
60 * the existence of other forms of browsing history. | 64 * the existence of other forms of browsing history. |
61 * @param {boolean} hasSyncedResults Whether there are synced results. | 65 * @param {boolean} hasSyncedResults Whether there are synced results. |
62 * @param {boolean} includeOtherFormsOfBrowsingHistory Whether to include | 66 * @param {boolean} includeOtherFormsOfBrowsingHistory Whether to include |
63 * a sentence about the existence of other forms of browsing history. | 67 * a sentence about the existence of other forms of browsing history. |
64 */ | 68 */ |
65 function showNotification( | 69 function showNotification( |
66 hasSyncedResults, includeOtherFormsOfBrowsingHistory) { | 70 hasSyncedResults, includeOtherFormsOfBrowsingHistory) { |
67 // TODO(msramek): |hasSyncedResults| was used in the old WebUI to show | 71 // TODO(msramek): |hasSyncedResults| was used in the old WebUI to show |
68 // the message about other signed-in devices. This message does not exist | 72 // the message about other signed-in devices. This message does not exist |
69 // in the MD history anymore, so the parameter is not needed. Remove it | 73 // in the MD history anymore, so the parameter is not needed. Remove it |
70 // when WebUI is removed and this becomes the only client of | 74 // when WebUI is removed and this becomes the only client of |
71 // BrowsingHistoryHandler. | 75 // BrowsingHistoryHandler. |
72 waitForAppUpgrade().then(function() { | 76 waitForHistoryApp().then(function(historyApp) { |
73 /** @type {HistoryAppElement} */ ($('history-app')).showSidebarFooter = | 77 historyApp.showSidebarFooter = includeOtherFormsOfBrowsingHistory; |
74 includeOtherFormsOfBrowsingHistory; | |
75 }); | 78 }); |
76 } | 79 } |
77 | 80 |
78 /** | 81 /** |
79 * Receives the synced history data. An empty list means that either there are | 82 * Receives the synced history data. An empty list means that either there are |
80 * no foreign sessions, or tab sync is disabled for this profile. | 83 * no foreign sessions, or tab sync is disabled for this profile. |
81 * |isTabSyncEnabled| makes it possible to distinguish between the cases. | 84 * |isTabSyncEnabled| makes it possible to distinguish between the cases. |
82 * | 85 * |
83 * @param {!Array<!ForeignSession>} sessionList Array of objects describing the | 86 * @param {!Array<!ForeignSession>} sessionList Array of objects describing the |
84 * sessions from other devices. | 87 * sessions from other devices. |
85 * @param {boolean} isTabSyncEnabled Is tab sync enabled for this profile? | 88 * @param {boolean} isTabSyncEnabled Is tab sync enabled for this profile? |
86 */ | 89 */ |
87 function setForeignSessions(sessionList, isTabSyncEnabled) { | 90 function setForeignSessions(sessionList, isTabSyncEnabled) { |
88 waitForAppUpgrade().then(function() { | 91 waitForHistoryApp().then(function(historyApp) { |
89 /** @type {HistoryAppElement} */($('history-app')) | 92 historyApp.setForeignSessions(sessionList, isTabSyncEnabled); |
90 .setForeignSessions(sessionList, isTabSyncEnabled); | |
91 }); | 93 }); |
92 } | 94 } |
93 | 95 |
94 /** | 96 /** |
95 * Called when the history is deleted by someone else. | 97 * Called when the history is deleted by someone else. |
96 */ | 98 */ |
97 function historyDeleted() { | 99 function historyDeleted() { |
98 } | 100 } |
99 | 101 |
100 /** | 102 /** |
101 * Called by the history backend after user's sign in state changes. | 103 * Called by the history backend after user's sign in state changes. |
102 * @param {boolean} isUserSignedIn Whether user is signed in or not now. | 104 * @param {boolean} isUserSignedIn Whether user is signed in or not now. |
103 */ | 105 */ |
104 function updateSignInState(isUserSignedIn) { | 106 function updateSignInState(isUserSignedIn) { |
105 waitForAppUpgrade().then(function() { | 107 waitForHistoryApp().then(function(historyApp) { |
106 /** @type {HistoryAppElement} */($('history-app')) | 108 historyApp.updateSignInState(isUserSignedIn); |
107 .updateSignInState(isUserSignedIn); | |
108 }); | 109 }); |
109 } | 110 } |
OLD | NEW |