OLD | NEW |
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 /** | 5 /** |
6 * @typedef {{device: string, | 6 * @typedef {{device: string, |
7 * lastUpdateTime: string, | 7 * lastUpdateTime: string, |
8 * separatorIndexes: !Array<number>, | 8 * separatorIndexes: !Array<number>, |
9 * timestamp: number, | 9 * timestamp: number, |
10 * tabs: !Array<!ForeignSessionTab>, | 10 * tabs: !Array<!ForeignSessionTab>, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 /** @private */ | 47 /** @private */ |
48 guestSession_: { | 48 guestSession_: { |
49 type: Boolean, | 49 type: Boolean, |
50 value: loadTimeData.getBoolean('isGuestSession'), | 50 value: loadTimeData.getBoolean('isGuestSession'), |
51 }, | 51 }, |
52 | 52 |
53 /** @private */ | 53 /** @private */ |
54 fetchingSyncedTabs_: { | 54 fetchingSyncedTabs_: { |
55 type: Boolean, | 55 type: Boolean, |
56 value: false, | 56 value: false, |
57 } | 57 }, |
| 58 |
| 59 hasSeenForeignData_: Boolean, |
58 }, | 60 }, |
59 | 61 |
60 listeners: { | 62 listeners: { |
61 'toggle-menu': 'onToggleMenu_', | 63 'toggle-menu': 'onToggleMenu_', |
62 }, | 64 }, |
63 | 65 |
64 /** @override */ | 66 /** @override */ |
65 attached: function() { | 67 attached: function() { |
66 // Update the sign in state. | 68 // Update the sign in state. |
67 chrome.send('otherDevicesInitialized'); | 69 chrome.send('otherDevicesInitialized'); |
| 70 md_history.BrowserService.getInstance().recordHistogram( |
| 71 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.INITIALIZED, |
| 72 SyncedTabsHistogram.LIMIT); |
68 }, | 73 }, |
69 | 74 |
70 /** | 75 /** |
71 * @param {!ForeignSession} session | 76 * @param {!ForeignSession} session |
72 * @return {!ForeignDeviceInternal} | 77 * @return {!ForeignDeviceInternal} |
73 */ | 78 */ |
74 createInternalDevice_: function(session) { | 79 createInternalDevice_: function(session) { |
75 var tabs = []; | 80 var tabs = []; |
76 var separatorIndexes = []; | 81 var separatorIndexes = []; |
77 for (var i = 0; i < session.windows.length; i++) { | 82 for (var i = 0; i < session.windows.length; i++) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 }, | 122 }, |
118 | 123 |
119 onToggleMenu_: function(e) { | 124 onToggleMenu_: function(e) { |
120 this.$.menu.get().then(function(menu) { | 125 this.$.menu.get().then(function(menu) { |
121 menu.toggleMenu(e.detail.target, e.detail.tag); | 126 menu.toggleMenu(e.detail.target, e.detail.tag); |
122 }); | 127 }); |
123 }, | 128 }, |
124 | 129 |
125 onOpenAllTap_: function() { | 130 onOpenAllTap_: function() { |
126 var menu = assert(this.$.menu.getIfExists()); | 131 var menu = assert(this.$.menu.getIfExists()); |
127 md_history.BrowserService.getInstance().openForeignSessionAllTabs( | 132 var browserService = md_history.BrowserService.getInstance(); |
| 133 browserService.recordHistogram( |
| 134 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.OPEN_ALL, |
| 135 SyncedTabsHistogram.LIMIT); |
| 136 browserService.openForeignSessionAllTabs( |
128 menu.itemData); | 137 menu.itemData); |
129 menu.closeMenu(); | 138 menu.closeMenu(); |
130 }, | 139 }, |
131 | 140 |
132 onDeleteSessionTap_: function() { | 141 onDeleteSessionTap_: function() { |
133 var menu = assert(this.$.menu.getIfExists()); | 142 var menu = assert(this.$.menu.getIfExists()); |
134 md_history.BrowserService.getInstance().deleteForeignSession( | 143 var browserService = md_history.BrowserService.getInstance(); |
135 menu.itemData); | 144 browserService.recordHistogram( |
| 145 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.HIDE_FOR_NOW, |
| 146 SyncedTabsHistogram.LIMIT); |
| 147 browserService.deleteForeignSession(menu.itemData); |
136 menu.closeMenu(); | 148 menu.closeMenu(); |
137 }, | 149 }, |
138 | 150 |
139 /** @private */ | 151 /** @private */ |
140 clearDisplayedSyncedDevices_: function() { | 152 clearDisplayedSyncedDevices_: function() { |
141 this.syncedDevices_ = []; | 153 this.syncedDevices_ = []; |
142 }, | 154 }, |
143 | 155 |
144 /** | 156 /** |
145 * Decide whether or not should display no synced tabs message. | 157 * Decide whether or not should display no synced tabs message. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 * about updating individual tabs rather than replacing whole sessions, but | 203 * about updating individual tabs rather than replacing whole sessions, but |
192 * this approach seems to have acceptable performance. | 204 * this approach seems to have acceptable performance. |
193 * @param {?Array<!ForeignSession>} sessionList | 205 * @param {?Array<!ForeignSession>} sessionList |
194 */ | 206 */ |
195 updateSyncedDevices: function(sessionList) { | 207 updateSyncedDevices: function(sessionList) { |
196 this.fetchingSyncedTabs_ = false; | 208 this.fetchingSyncedTabs_ = false; |
197 | 209 |
198 if (!sessionList) | 210 if (!sessionList) |
199 return; | 211 return; |
200 | 212 |
| 213 if (sessionList.length > 0 && !this.hasSeenForeignData_) { |
| 214 this.hasSeenForeignData_ = true; |
| 215 md_history.BrowserService.getInstance().recordHistogram( |
| 216 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.HAS_FOREIGN_DATA, |
| 217 SyncedTabsHistogram.LIMIT); |
| 218 } |
| 219 |
201 // First, update any existing devices that have changed. | 220 // First, update any existing devices that have changed. |
202 var updateCount = Math.min(sessionList.length, this.syncedDevices_.length); | 221 var updateCount = Math.min(sessionList.length, this.syncedDevices_.length); |
203 for (var i = 0; i < updateCount; i++) { | 222 for (var i = 0; i < updateCount; i++) { |
204 var oldDevice = this.syncedDevices_[i]; | 223 var oldDevice = this.syncedDevices_[i]; |
205 if (oldDevice.tag != sessionList[i].tag || | 224 if (oldDevice.tag != sessionList[i].tag || |
206 oldDevice.timestamp != sessionList[i].timestamp) { | 225 oldDevice.timestamp != sessionList[i].timestamp) { |
207 this.splice( | 226 this.splice( |
208 'syncedDevices_', i, 1, this.createInternalDevice_(sessionList[i])); | 227 'syncedDevices_', i, 1, this.createInternalDevice_(sessionList[i])); |
209 } | 228 } |
210 } | 229 } |
(...skipping 29 matching lines...) Expand all Loading... |
240 // User signed in, show the loading message when querying for synced | 259 // User signed in, show the loading message when querying for synced |
241 // devices. | 260 // devices. |
242 this.fetchingSyncedTabs_ = true; | 261 this.fetchingSyncedTabs_ = true; |
243 }, | 262 }, |
244 | 263 |
245 searchTermChanged: function(searchTerm) { | 264 searchTermChanged: function(searchTerm) { |
246 this.clearDisplayedSyncedDevices_(); | 265 this.clearDisplayedSyncedDevices_(); |
247 this.updateSyncedDevices(this.sessionList); | 266 this.updateSyncedDevices(this.sessionList); |
248 } | 267 } |
249 }); | 268 }); |
OLD | NEW |