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

Side by Side Diff: chrome/browser/resources/md_history/synced_device_manager.js

Issue 2360193002: [MD History] Hide empty synced device cards. (Closed)
Patch Set: Created 4 years, 3 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 /** 5 /**
6 * @typedef {{device: string, 6 * @typedef {{device: string,
7 * lastUpdateTime: string, 7 * lastUpdateTime: string,
8 * opened: boolean, 8 * opened: boolean,
9 * separatorIndexes: !Array<number>, 9 * separatorIndexes: !Array<number>,
10 * timestamp: number, 10 * timestamp: number,
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 md_history.BrowserService.getInstance().recordAction( 197 md_history.BrowserService.getInstance().recordAction(
198 'Signin_Impression_FromRecentTabs'); 198 'Signin_Impression_FromRecentTabs');
199 } 199 }
200 200
201 return show; 201 return show;
202 }, 202 },
203 203
204 /** 204 /**
205 * Decide what message should be displayed when user is logged in and there 205 * Decide what message should be displayed when user is logged in and there
206 * are no synced tabs. 206 * are no synced tabs.
207 * @param {boolean} fetchingSyncedTabs
208 * @return {string} 207 * @return {string}
209 */ 208 */
210 noSyncedTabsMessage: function(fetchingSyncedTabs) { 209 noSyncedTabsMessage: function() {
211 return loadTimeData.getString( 210 var stringName = this.fetchingSyncedTabs_ ? 'loading' : 'noSyncedResults';
212 fetchingSyncedTabs ? 'loading' : 'noSyncedResults'); 211 if (this.searchTerm !== '')
212 stringName = 'noSearchResults';
213 return loadTimeData.getString(stringName);
213 }, 214 },
214 215
215 /** 216 /**
216 * Replaces the currently displayed synced tabs with |sessionList|. It is 217 * Replaces the currently displayed synced tabs with |sessionList|. It is
217 * common for only a single session within the list to have changed, We try to 218 * common for only a single session within the list to have changed, We try to
218 * avoid doing extra work in this case. The logic could be more intelligent 219 * avoid doing extra work in this case. The logic could be more intelligent
219 * about updating individual tabs rather than replacing whole sessions, but 220 * about updating individual tabs rather than replacing whole sessions, but
220 * this approach seems to have acceptable performance. 221 * this approach seems to have acceptable performance.
221 * @param {?Array<!ForeignSession>} sessionList 222 * @param {?Array<!ForeignSession>} sessionList
222 */ 223 */
223 updateSyncedDevices: function(sessionList) { 224 updateSyncedDevices: function(sessionList) {
224 this.fetchingSyncedTabs_ = false; 225 this.fetchingSyncedTabs_ = false;
225 226
226 if (!sessionList) 227 if (!sessionList)
227 return; 228 return;
228 229
229 if (sessionList.length > 0 && !this.hasSeenForeignData_) { 230 if (sessionList.length > 0 && !this.hasSeenForeignData_) {
230 this.hasSeenForeignData_ = true; 231 this.hasSeenForeignData_ = true;
231 md_history.BrowserService.getInstance().recordHistogram( 232 md_history.BrowserService.getInstance().recordHistogram(
232 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.HAS_FOREIGN_DATA, 233 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.HAS_FOREIGN_DATA,
233 SyncedTabsHistogram.LIMIT); 234 SyncedTabsHistogram.LIMIT);
234 } 235 }
235 236
236 // First, update any existing devices that have changed. 237 // First, update any existing devices that have changed.
237 var updateCount = Math.min(sessionList.length, this.syncedDevices_.length); 238 var updateCount = Math.min(sessionList.length, this.syncedDevices_.length);
238 for (var i = 0; i < updateCount; i++) { 239 for (var i = 0; i < updateCount; i++) {
239 var oldDevice = this.syncedDevices_[i]; 240 var oldDevice = this.syncedDevices_[i];
240 if (oldDevice.tag != sessionList[i].tag || 241 if (oldDevice.tag != sessionList[i].tag ||
241 oldDevice.timestamp != sessionList[i].timestamp) { 242 oldDevice.timestamp != sessionList[i].timestamp) {
242 this.splice( 243 device = this.createInternalDevice_(sessionList[i]);
tsergeant 2016/09/22 06:58:50 Nit: Add `var`
calamity 2016/09/22 07:52:53 Done.
243 'syncedDevices_', i, 1, this.createInternalDevice_(sessionList[i])); 244 if (device.tabs.length != 0)
245 this.splice('syncedDevices_', i, 1, device);
244 } 246 }
245 } 247 }
246 248
247 if (sessionList.length >= this.syncedDevices_.length) { 249 if (sessionList.length >= this.syncedDevices_.length) {
248 // The list grew; append new items. 250 // The list grew; append new items.
249 for (var i = updateCount; i < sessionList.length; i++) { 251 for (var i = updateCount; i < sessionList.length; i++) {
250 this.push('syncedDevices_', this.createInternalDevice_(sessionList[i])); 252 device = this.createInternalDevice_(sessionList[i]);
tsergeant 2016/09/22 06:58:50 Nit: Here too (or declare `var device;` at the to
calamity 2016/09/22 07:52:53 Done.
253 if (device.tabs.length != 0)
254 this.push('syncedDevices_', device);
251 } 255 }
252 } else { 256 } else {
253 // The list shrank; remove deleted items. 257 // The list shrank; remove deleted items.
254 this.splice( 258 this.splice(
255 'syncedDevices_', updateCount, 259 'syncedDevices_', updateCount,
256 this.syncedDevices_.length - updateCount); 260 this.syncedDevices_.length - updateCount);
257 } 261 }
258 }, 262 },
259 263
260 /** 264 /**
(...skipping 20 matching lines...) Expand all
281 // User signed in, show the loading message when querying for synced 285 // User signed in, show the loading message when querying for synced
282 // devices. 286 // devices.
283 this.fetchingSyncedTabs_ = true; 287 this.fetchingSyncedTabs_ = true;
284 }, 288 },
285 289
286 searchTermChanged: function(searchTerm) { 290 searchTermChanged: function(searchTerm) {
287 this.clearDisplayedSyncedDevices_(); 291 this.clearDisplayedSyncedDevices_();
288 this.updateSyncedDevices(this.sessionList); 292 this.updateSyncedDevices(this.sessionList);
289 } 293 }
290 }); 294 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698