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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 /**
6 * @typedef {{device: string,
7 * lastUpdateTime: string,
8 * timestamp: number,
9 * tabs: !Array<!ForeignSessionTab>,
10 * tag: string}}
11 */
12 var ForeignDeviceInternal;
13
5 Polymer({ 14 Polymer({
6 is: 'history-synced-device-manager', 15 is: 'history-synced-device-manager',
7 16
8 properties: { 17 properties: {
9 /** 18 /**
10 * An array of synced devices with synced tab data. 19 * An array of synced devices with synced tab data.
11 * @type {!Array<!{device: string, 20 * @type {!Array<!ForeignDeviceInternal>}
12 * lastUpdateTime: string,
13 * tabs: !Array<!ForeignSessionTab>}>}
14 */ 21 */
15 syncedDevices: { 22 syncedDevices: {
16 type: Array, 23 type: Array,
17 value: function() { return []; } 24 value: function() { return []; }
18 } 25 }
19 }, 26 },
20 27
21 /** 28 /**
22 * Adds |sessionList| to the currently displayed synced tabs. 29 * @param {!ForeignSession} session
30 * @return {!ForeignDeviceInternal}
31 */
32 createInternalDevice_: function(session) {
33 var tabs = [];
34 for (var j = 0; j < session.windows.length; j++) {
35 var newTabs = session.windows[j].tabs;
36 if (newTabs.length == 0)
37 continue;
38
39 tabs = tabs.concat(newTabs);
40 tabs[tabs.length - 1].needsWindowSeparator = true;
41 }
42 return {
43 device: session.name,
44 lastUpdateTime: '– ' + session.modifiedTime,
45 timestamp: session.timestamp,
46 tabs: tabs,
47 tag: session.tag
48 };
49 },
50
51 /**
52 * Replaces the currently displayed synced tabs with |sessionList|. It is
53 * common for only a single session within the list to have changed, We try to
54 * avoid doing extra work in this case. The logic could be more intelligent
55 * about updating individual tabs rather than replacing whole sessions, but
56 * this approach seems to have acceptable performance.
23 * @param {!Array<!ForeignSession>} sessionList 57 * @param {!Array<!ForeignSession>} sessionList
24 */ 58 */
25 addSyncedHistory: function(sessionList) { 59 setSyncedHistory: function(sessionList) {
26 // TODO(calamity): Does not add more items onto the page when the 60 // First, update any existing devices that have changed.
27 // sessionList updates. Update the cards dynamically by refreshing the tab 61 var updateCount = Math.min(sessionList.length, this.syncedDevices.length);
28 // list and last update time for each synced tab card. 62 for (var i = 0; i < updateCount; i++) {
29 if (this.syncedDevices.length > 0) 63 var oldDevice = this.syncedDevices[i];
30 return; 64 if (oldDevice.tag != sessionList[i].tag ||
65 oldDevice.timestamp != sessionList[i].timestamp) {
66 this.splice(
67 'syncedDevices', i, 1, this.createInternalDevice_(sessionList[i]));
68 }
69 }
31 70
32 for (var i = 0; i < sessionList.length; i++) { 71 // Then, append any new devices.
33 var tabs = []; 72 for (var i = updateCount; i < sessionList.length; i++) {
34 for (var j = 0; j < sessionList[i].windows.length; j++) { 73 this.push('syncedDevices', this.createInternalDevice_(sessionList[i]));
35 var newTabs = sessionList[i].windows[j].tabs;
36 if (newTabs.length == 0)
37 continue;
38
39 tabs = tabs.concat(newTabs);
40 tabs[tabs.length - 1].needsWindowSeparator = true;
41 }
42
43 this.push('syncedDevices', {
44 device: sessionList[i].name,
45 lastUpdateTime: '– ' + sessionList[i].modifiedTime,
46 tabs: tabs,
47 });
48 } 74 }
49 } 75 }
50 }); 76 });
OLDNEW
« 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