Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3411)

Unified Diff: chrome/browser/resources/md_history/synced_device_manager.js

Issue 1874473004: MD History: Support dynamically updating synced tab data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix indent Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/md_history/history.js ('k') | chrome/browser/ui/webui/foreign_session_handler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/md_history/synced_device_manager.js
diff --git a/chrome/browser/resources/md_history/synced_device_manager.js b/chrome/browser/resources/md_history/synced_device_manager.js
index 6ed8058ca0bf64fe9ff95a88d164d880c36b0b80..aab4aefccf81017e250682d75aca46d2796adee2 100644
--- a/chrome/browser/resources/md_history/synced_device_manager.js
+++ b/chrome/browser/resources/md_history/synced_device_manager.js
@@ -2,15 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+/**
+ * @typedef {{device: string,
+ * lastUpdateTime: string,
+ * timestamp: number,
+ * tabs: !Array<!ForeignSessionTab>,
+ * tag: string}}
+ */
+var ForeignDeviceInternal;
+
Polymer({
is: 'history-synced-device-manager',
properties: {
/**
* An array of synced devices with synced tab data.
- * @type {!Array<!{device: string,
- * lastUpdateTime: string,
- * tabs: !Array<!ForeignSessionTab>}>}
+ * @type {!Array<!ForeignDeviceInternal>}
*/
syncedDevices: {
type: Array,
@@ -19,32 +26,51 @@ Polymer({
},
/**
- * Adds |sessionList| to the currently displayed synced tabs.
- * @param {!Array<!ForeignSession>} sessionList
+ * @param {!ForeignSession} session
+ * @return {!ForeignDeviceInternal}
*/
- addSyncedHistory: function(sessionList) {
- // TODO(calamity): Does not add more items onto the page when the
- // sessionList updates. Update the cards dynamically by refreshing the tab
- // list and last update time for each synced tab card.
- if (this.syncedDevices.length > 0)
- return;
+ createInternalDevice_: function(session) {
+ var tabs = [];
+ for (var j = 0; j < session.windows.length; j++) {
+ var newTabs = session.windows[j].tabs;
+ if (newTabs.length == 0)
+ continue;
- for (var i = 0; i < sessionList.length; i++) {
- var tabs = [];
- for (var j = 0; j < sessionList[i].windows.length; j++) {
- var newTabs = sessionList[i].windows[j].tabs;
- if (newTabs.length == 0)
- continue;
+ tabs = tabs.concat(newTabs);
+ tabs[tabs.length - 1].needsWindowSeparator = true;
+ }
+ return {
+ device: session.name,
+ lastUpdateTime: '– ' + session.modifiedTime,
+ timestamp: session.timestamp,
+ tabs: tabs,
+ tag: session.tag
+ };
+ },
- tabs = tabs.concat(newTabs);
- tabs[tabs.length - 1].needsWindowSeparator = true;
+ /**
+ * Replaces the currently displayed synced tabs with |sessionList|. It is
+ * common for only a single session within the list to have changed, We try to
+ * avoid doing extra work in this case. The logic could be more intelligent
+ * about updating individual tabs rather than replacing whole sessions, but
+ * this approach seems to have acceptable performance.
+ * @param {!Array<!ForeignSession>} sessionList
+ */
+ setSyncedHistory: function(sessionList) {
+ // First, update any existing devices that have changed.
+ var updateCount = Math.min(sessionList.length, this.syncedDevices.length);
+ for (var i = 0; i < updateCount; i++) {
+ var oldDevice = this.syncedDevices[i];
+ if (oldDevice.tag != sessionList[i].tag ||
+ oldDevice.timestamp != sessionList[i].timestamp) {
+ this.splice(
+ 'syncedDevices', i, 1, this.createInternalDevice_(sessionList[i]));
}
+ }
- this.push('syncedDevices', {
- device: sessionList[i].name,
- lastUpdateTime: '– ' + sessionList[i].modifiedTime,
- tabs: tabs,
- });
+ // Then, append any new devices.
+ for (var i = updateCount; i < sessionList.length; i++) {
+ this.push('syncedDevices', this.createInternalDevice_(sessionList[i]));
}
}
});
« no previous file with comments | « chrome/browser/resources/md_history/history.js ('k') | chrome/browser/ui/webui/foreign_session_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698