OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 * @fileoverview The section of the history page that shows tabs from sessions | 6 * @fileoverview The section of the history page that shows tabs from sessions |
7 on other devices. | 7 on other devices. |
8 */ | 8 */ |
9 | 9 |
10 /////////////////////////////////////////////////////////////////////////////// | 10 /////////////////////////////////////////////////////////////////////////////// |
11 // Globals: | 11 // Globals: |
12 /** @const */ var MAX_NUM_COLUMNS = 3; | 12 /** @const */ var MAX_NUM_COLUMNS = 3; |
13 /** @const */ var NB_ENTRIES_FIRST_ROW_COLUMN = 6; | 13 /** @const */ var NB_ENTRIES_FIRST_ROW_COLUMN = 6; |
14 /** @const */ var NB_ENTRIES_OTHER_ROWS_COLUMN = 0; | 14 /** @const */ var NB_ENTRIES_OTHER_ROWS_COLUMN = 0; |
15 | 15 |
16 // Histogram buckets for UMA tracking of menu usage. | 16 // Histogram buckets for UMA tracking of menu usage. |
17 /** @const */ var HISTOGRAM_EVENT = { | 17 /** @const */ var HISTOGRAM_EVENT = { |
18 INITIALIZED: 0, | 18 INITIALIZED: 0, |
19 SHOW_MENU: 1, | 19 SHOW_MENU: 1, |
20 LINK_CLICKED: 2, | 20 LINK_CLICKED: 2, |
21 LINK_RIGHT_CLICKED: 3, | 21 LINK_RIGHT_CLICKED: 3, |
22 SESSION_NAME_RIGHT_CLICKED: 4, | 22 SESSION_NAME_RIGHT_CLICKED: 4, |
23 SHOW_SESSION_MENU: 5, | 23 SHOW_SESSION_MENU: 5, |
24 COLLAPSE_SESSION: 6, | 24 COLLAPSE_SESSION: 6, |
25 EXPAND_SESSION: 7, | 25 EXPAND_SESSION: 7, |
26 OPEN_ALL: 8, | 26 OPEN_ALL: 8, |
27 LIMIT: 9 // Should always be the last one. | 27 HAS_FOREIGN_DATA: 9, |
| 28 LIMIT: 10 // Should always be the last one. |
28 }; | 29 }; |
29 | 30 |
30 /** | 31 /** |
31 * Record an event in the UMA histogram. | 32 * Record an event in the UMA histogram. |
32 * @param {number} eventId The id of the event to be recorded. | 33 * @param {number} eventId The id of the event to be recorded. |
33 * @private | 34 * @private |
34 */ | 35 */ |
35 function recordUmaEvent_(eventId) { | 36 function recordUmaEvent_(eventId) { |
36 chrome.send('metricsHandler:recordInHistogram', | 37 chrome.send('metricsHandler:recordInHistogram', |
37 ['HistoryPage.OtherDevicesMenu', eventId, HISTOGRAM_EVENT.LIMIT]); | 38 ['HistoryPage.OtherDevicesMenu', eventId, HISTOGRAM_EVENT.LIMIT]); |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 * Functions and state for populating the page with HTML. | 347 * Functions and state for populating the page with HTML. |
347 * @constructor | 348 * @constructor |
348 */ | 349 */ |
349 function DevicesView() { | 350 function DevicesView() { |
350 this.devices_ = []; // List of individual devices. | 351 this.devices_ = []; // List of individual devices. |
351 this.resultDiv_ = $('other-devices'); | 352 this.resultDiv_ = $('other-devices'); |
352 this.searchText_ = ''; | 353 this.searchText_ = ''; |
353 this.rowHeights_ = [NB_ENTRIES_FIRST_ROW_COLUMN]; | 354 this.rowHeights_ = [NB_ENTRIES_FIRST_ROW_COLUMN]; |
354 this.focusGrids_ = []; | 355 this.focusGrids_ = []; |
355 this.updateSignInState(loadTimeData.getBoolean('isUserSignedIn')); | 356 this.updateSignInState(loadTimeData.getBoolean('isUserSignedIn')); |
| 357 this.hasSeenForeignData_ = false; |
356 recordUmaEvent_(HISTOGRAM_EVENT.INITIALIZED); | 358 recordUmaEvent_(HISTOGRAM_EVENT.INITIALIZED); |
357 } | 359 } |
358 | 360 |
359 // DevicesView, public: ------------------------------------------------------- | 361 // DevicesView, public: ------------------------------------------------------- |
360 | 362 |
361 /** | 363 /** |
362 * Updates our sign in state by clearing the view is not signed in or sending | 364 * Updates our sign in state by clearing the view is not signed in or sending |
363 * a request to get the data to display otherwise. | 365 * a request to get the data to display otherwise. |
364 * @param {boolean} signedIn Whether the user is signed in or not. | 366 * @param {boolean} signedIn Whether the user is signed in or not. |
365 */ | 367 */ |
366 DevicesView.prototype.updateSignInState = function(signedIn) { | 368 DevicesView.prototype.updateSignInState = function(signedIn) { |
367 if (signedIn) | 369 if (signedIn) |
368 chrome.send('getForeignSessions'); | 370 chrome.send('getForeignSessions'); |
369 else | 371 else |
370 this.clearDOM(); | 372 this.clearDOM(); |
371 }; | 373 }; |
372 | 374 |
373 /** | 375 /** |
374 * Resets the view sessions. | 376 * Resets the view sessions. |
375 * @param {Object} sessionList The sessions to add. | 377 * @param {Object} sessionList The sessions to add. |
376 */ | 378 */ |
377 DevicesView.prototype.setSessionList = function(sessionList) { | 379 DevicesView.prototype.setSessionList = function(sessionList) { |
378 this.devices_ = []; | 380 this.devices_ = []; |
379 for (var i = 0; i < sessionList.length; i++) | 381 for (var i = 0; i < sessionList.length; i++) |
380 this.devices_.push(new Device(sessionList[i], this)); | 382 this.devices_.push(new Device(sessionList[i], this)); |
381 this.displayResults_(); | 383 this.displayResults_(); |
| 384 |
| 385 // This metric should only be emitted if we see foreign data, and it should |
| 386 // only be emitted once per page refresh. Flip flag to remember because this |
| 387 // method is called upon any update. |
| 388 if (!this.hasSeenForeignData_ && sessionList.length > 0) { |
| 389 this.hasSeenForeignData_ = true; |
| 390 recordUmaEvent_(HISTOGRAM_EVENT.HAS_FOREIGN_DATA); |
| 391 } |
382 }; | 392 }; |
383 | 393 |
384 | 394 |
385 /** | 395 /** |
386 * Sets the current search text. | 396 * Sets the current search text. |
387 * @param {string} searchText The text to search. | 397 * @param {string} searchText The text to search. |
388 */ | 398 */ |
389 DevicesView.prototype.setSearchText = function(searchText) { | 399 DevicesView.prototype.setSearchText = function(searchText) { |
390 if (this.searchText_ != searchText) { | 400 if (this.searchText_ != searchText) { |
391 this.searchText_ = searchText; | 401 this.searchText_ = searchText; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 devicesView.setSearchText($('search-field').value); | 564 devicesView.setSearchText($('search-field').value); |
555 }; | 565 }; |
556 $('search-field').addEventListener('search', doSearch); | 566 $('search-field').addEventListener('search', doSearch); |
557 $('search-button').addEventListener('click', doSearch); | 567 $('search-button').addEventListener('click', doSearch); |
558 | 568 |
559 chrome.send('otherDevicesInitialized'); | 569 chrome.send('otherDevicesInitialized'); |
560 } | 570 } |
561 | 571 |
562 // Add handlers to HTML elements. | 572 // Add handlers to HTML elements. |
563 document.addEventListener('DOMContentLoaded', load); | 573 document.addEventListener('DOMContentLoaded', load); |
OLD | NEW |