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

Side by Side Diff: ui/login/account_picker/user_pod_row.js

Issue 1428973003: Utilize ProfileInfoCache to support data type counts in profile deletion flow (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added storing to ProfileInfoCache at startup after a non-normal shutdown Created 5 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 User pod row implementation. 6 * @fileoverview User pod row implementation.
7 */ 7 */
8 8
9 cr.define('login', function() { 9 cr.define('login', function() {
10 /** 10 /**
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 /** 969 /**
970 * Gets the custom icon. This icon is normally hidden, but can be shown 970 * Gets the custom icon. This icon is normally hidden, but can be shown
971 * using the chrome.screenlockPrivate API. 971 * using the chrome.screenlockPrivate API.
972 * @type {!HTMLDivElement} 972 * @type {!HTMLDivElement}
973 */ 973 */
974 get customIconElement() { 974 get customIconElement() {
975 return this.querySelector('.custom-icon-container'); 975 return this.querySelector('.custom-icon-container');
976 }, 976 },
977 977
978 /** 978 /**
979 * Get the elements used for statistics display.
980 * @type {Object.<string, !HTMLDivElement>}
981 */
982 get statsMapElements() {
983 return {
984 'browsing_history':
985 this.querySelector('.action-box-remove-user-warning-history'),
986 'passwords':
987 this.querySelector('.action-box-remove-user-warning-passwords'),
988 'bookmarks':
989 this.querySelector('.action-box-remove-user-warning-bookmarks'),
990 'settings':
991 this.querySelector('.action-box-remove-user-warning-settings')
992 }
993 },
994
995 /**
979 * Updates the user pod element. 996 * Updates the user pod element.
980 */ 997 */
981 update: function() { 998 update: function() {
982 this.imageElement.src = 'chrome://userimage/' + this.user.username + 999 this.imageElement.src = 'chrome://userimage/' + this.user.username +
983 '?id=' + UserPod.userImageSalt_[this.user.username]; 1000 '?id=' + UserPod.userImageSalt_[this.user.username];
984 1001
985 this.nameElement.textContent = this.user_.displayName; 1002 this.nameElement.textContent = this.user_.displayName;
986 this.reauthNameHintElement.textContent = this.user_.displayName; 1003 this.reauthNameHintElement.textContent = this.user_.displayName;
987 this.classList.toggle('signed-in', this.user_.signedIn); 1004 this.classList.toggle('signed-in', this.user_.signedIn);
988 1005
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
1396 1413
1397 // Move up the menu if it overlaps shelf. 1414 // Move up the menu if it overlaps shelf.
1398 var maxHeight = cr.ui.LoginUITools.getMaxHeightBeforeShelfOverlapping( 1415 var maxHeight = cr.ui.LoginUITools.getMaxHeightBeforeShelfOverlapping(
1399 this.actionBoxMenu, true); 1416 this.actionBoxMenu, true);
1400 var actualHeight = parseInt( 1417 var actualHeight = parseInt(
1401 window.getComputedStyle(this.actionBoxMenu).height); 1418 window.getComputedStyle(this.actionBoxMenu).height);
1402 if (maxHeight < actualHeight) { 1419 if (maxHeight < actualHeight) {
1403 this.actionBoxMenu.classList.add('menu-moved-up'); 1420 this.actionBoxMenu.classList.add('menu-moved-up');
1404 this.actionBoxAreaElement.classList.add('menu-moved-up'); 1421 this.actionBoxAreaElement.classList.add('menu-moved-up');
1405 } 1422 }
1406 chrome.send('logRemoveUserWarningShown');
1407 }, 1423 },
1408 1424
1409 /** 1425 /**
1410 * Shows remove user warning. Used for legacy supervised users on CrOS, and 1426 * Shows remove user warning. Used for legacy supervised users on CrOS, and
1411 * for all users on desktop. 1427 * for all users on desktop.
1412 */ 1428 */
1413 showRemoveWarning_: function() { 1429 showRemoveWarning_: function() {
1414 this.actionBoxMenuRemoveElement.hidden = true; 1430 this.actionBoxMenuRemoveElement.hidden = true;
1415 this.actionBoxRemoveUserWarningElement.hidden = false; 1431 this.actionBoxRemoveUserWarningElement.hidden = false;
1416 this.actionBoxRemoveUserWarningButtonElement.focus(); 1432 this.actionBoxRemoveUserWarningButtonElement.focus();
1417 1433
1418 // Show extra statistics information for desktop users 1434 // Show extra statistics information for desktop users
1419 var message; 1435 var message;
1420 if (this.user.isDesktopUser) { 1436 if (this.user.isLegacySupervisedUser) {
1421 this.classList.remove('has-errors'); 1437 this.moveActionMenuUpIfNeeded_();
1422 var isSyncedUser = this.user.emailAddress !== ""; 1438 } else {
1423 if (!this.user.isProfileLoaded) { 1439 this.RemoveWarningDialogSetMessage_(true, false);
1424 message = loadTimeData.getString(
1425 isSyncedUser ? 'removeUserWarningTextSyncNoStats' :
1426 'removeUserWarningTextNonSyncNoStats');
1427 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath,
1428 message);
1429 } else {
1430 message = loadTimeData.getString(
1431 isSyncedUser ? 'removeUserWarningTextSyncCalculating' :
1432 'removeUserWarningTextNonSyncCalculating');
1433 substitute = loadTimeData.getString(
1434 'removeUserWarningTextCalculating');
1435 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath,
1436 message, substitute);
1437 }
1438
1439 // set a global handler for the callback 1440 // set a global handler for the callback
1440 window.updateRemoveWarningDialog = 1441 window.updateRemoveWarningDialog =
1441 this.updateRemoveWarningDialog_.bind(this); 1442 this.updateRemoveWarningDialog_.bind(this);
1442 chrome.send('removeUserWarningLoadStats', [this.user.profilePath]); 1443 chrome.send('removeUserWarningLoadStats', [this.user.profilePath]);
1443 } 1444 }
1444 1445 chrome.send('logRemoveUserWarningShown');
1445 this.moveActionMenuUpIfNeeded_();
1446 }, 1446 },
1447 1447
1448 /** 1448 /**
1449 * Refresh the statistics in the remove user warning dialog. 1449 * Refresh the statistics in the remove user warning dialog.
1450 * @param {string} profilePath The filepath of the URL (must be verified). 1450 * @param {string} profilePath The filepath of the URL (must be verified).
1451 * @param {Object} profileStats Statistics associated with profileURL. 1451 * @param {Object} profileStats Statistics associated with profileURL.
1452 */ 1452 */
1453 updateRemoveWarningDialog_: function(profilePath, profileStats) { 1453 updateRemoveWarningDialog_: function(profilePath, profileStats) {
1454 if (profilePath !== this.user.profilePath) 1454 if (profilePath !== this.user.profilePath)
1455 return; 1455 return;
1456 // Converting profileStats into id attribute by an object. 1456
1457 var stats_id_map = { 1457 var stats_elements = this.statsMapElements;
1458 'BrowsingHistory': 'action-box-remove-user-warning-history', 1458 // Update individual statistics
1459 'Passwords': 'action-box-remove-user-warning-passwords',
1460 'Bookmarks': 'action-box-remove-user-warning-bookmarks',
1461 'Settings': 'action-box-remove-user-warning-settings',
1462 }
1463 // Load individual statistics
1464 var num_stats_loaded = 0; 1459 var num_stats_loaded = 0;
1465 var total_count = 0;
1466 var failed = false; 1460 var failed = false;
1467 for (var key in profileStats) { 1461 for (var key in profileStats) {
1468 if (stats_id_map.hasOwnProperty(key)) { 1462 if (stats_elements.hasOwnProperty(key)) {
1469 if (profileStats[key].success) { 1463 if (profileStats[key].success) {
1470 var count = profileStats[key].count; 1464 this.user.statistics[key] = profileStats[key].count;
1471 this.querySelector("." + stats_id_map[key]).textContent = count; 1465 } else if (!this.user.statistics.hasOwnProperty(key)) {
1472 total_count += count;
1473 } else {
1474 failed = true; 1466 failed = true;
1475 this.querySelector("." + stats_id_map[key]).textContent = ''; 1467 stats_elements[key].textContent = '';
1476 } 1468 }
1477 num_stats_loaded++; 1469 num_stats_loaded++;
1478 } 1470 }
1479 } 1471 }
1480 1472
1481 // this.classList is used for selecting the appropriate dialog. 1473 this.RemoveWarningDialogSetMessage_(
1482 this.classList.toggle('has-errors', failed); 1474 false, failed && num_stats_loaded === this.statsMapElements.count);
1483 if (total_count > 0) { 1475 },
1484 this.classList.remove('has-no-stats'); 1476
1477 /**
1478 * Set the new message in the dialog.
1479 * @param {boolean} Whether this statistics are not available due to errors.
1480 * Should be true only if there is an error and the corresponding statistic
1481 * is also unavailable in ProfileInfoCache.
1482 */
1483 RemoveWarningDialogSetMessage_: function(isInitial, isError) {
1484 var stats_elements = this.statsMapElements;
1485 var num_stats_loaded = 0;
1486 var total_count = 0;
1487 for (var key in stats_elements) {
1488 if (this.user.statistics.hasOwnProperty(key)) {
1489 var count = this.user.statistics[key];
1490 stats_elements[key].textContent = count;
1491 total_count += count;
1492 num_stats_loaded++;
1493 }
1485 } 1494 }
1486 1495
1496 // this.classList is used for selecting the appropriate dialog.
1497 if (total_count)
1498 this.classList.remove('has-no-stats');
1499
1500 var is_synced_user = this.user.emailAddress !== "";
1487 // Write total number if all statistics are loaded. 1501 // Write total number if all statistics are loaded.
1488 if (num_stats_loaded === Object.keys(stats_id_map).length) { 1502 if (num_stats_loaded === Object.keys(stats_elements).length || isError) {
1489 if (total_count === 0) { 1503 if (!total_count) {
1490 this.classList.add('has-no-stats'); 1504 this.classList.add('has-no-stats');
1491 var isSyncedUser = this.user.emailAddress !== "";
1492 var message = loadTimeData.getString( 1505 var message = loadTimeData.getString(
1493 isSyncedUser ? 'removeUserWarningTextSyncNoStats' : 1506 is_synced_user ? 'removeUserWarningTextSyncNoStats' :
1494 'removeUserWarningTextNonSyncNoStats'); 1507 'removeUserWarningTextNonSyncNoStats');
1495 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, 1508 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath,
1496 message); 1509 message);
1497 } else { 1510 } else {
1498 window.updateRemoveWarningDialogSetMessage = 1511 window.updateRemoveWarningDialogSetMessage =
1499 this.updateRemoveWarningDialogSetMessage_.bind(this); 1512 this.updateRemoveWarningDialogSetMessage_.bind(this);
1500 chrome.send('getRemoveWarningDialogMessage',[{ 1513 chrome.send('getRemoveWarningDialogMessage',[{
1501 profilePath: this.user.profilePath, 1514 profilePath: this.user.profilePath,
1502 isSyncedUser: this.user.emailAddress !== "", 1515 isSyncedUser: is_synced_user,
1503 hasErrors: failed, 1516 hasErrors: num_stats_loaded < Object.keys(stats_elements).length,
1504 totalCount: total_count 1517 totalCount: total_count
1505 }]); 1518 }]);
1506 } 1519 }
1520 } else if (isInitial) {
1521 if (!this.user.isProfileLoaded) {
1522 message = loadTimeData.getString(
1523 is_synced_user ? 'removeUserWarningTextSyncNoStats' :
1524 'removeUserWarningTextNonSyncNoStats');
1525 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath,
1526 message);
1527 } else {
1528 message = loadTimeData.getString(
1529 is_synced_user ? 'removeUserWarningTextSyncCalculating' :
1530 'removeUserWarningTextNonSyncCalculating');
1531 substitute = loadTimeData.getString(
1532 'removeUserWarningTextCalculating');
1533 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath,
1534 message, substitute);
1535 }
1507 } 1536 }
1508
1509 this.moveActionMenuUpIfNeeded_();
1510 }, 1537 },
1511 1538
1512 /** 1539 /**
1513 * Refresh the message in the remove user warning dialog. 1540 * Refresh the message in the remove user warning dialog.
1514 * @param {string} profilePath The filepath of the URL (must be verified). 1541 * @param {string} profilePath The filepath of the URL (must be verified).
1515 * @param {string} message The message to be written. 1542 * @param {string} message The message to be written.
1516 * @param {number|string=} count The number or string to replace $1 in 1543 * @param {number|string=} count The number or string to replace $1 in
1517 * |message|. Can be omitted if $1 is not present in |message|. 1544 * |message|. Can be omitted if $1 is not present in |message|.
1518 */ 1545 */
1519 updateRemoveWarningDialogSetMessage_: function(profilePath, message, 1546 updateRemoveWarningDialogSetMessage_: function(profilePath, message,
1520 count) { 1547 count) {
1521 if (profilePath !== this.user.profilePath) 1548 if (profilePath !== this.user.profilePath)
1522 return; 1549 return;
1523 // Add localized messages where $1 will be replaced with 1550 // Add localized messages where $1 will be replaced with
1524 // <span class="total-count"></span>. 1551 // <span class="total-count"></span>.
1525 var element = this.querySelector('.action-box-remove-user-warning-text'); 1552 var element = this.querySelector('.action-box-remove-user-warning-text');
1526 while (element.firstChild) 1553 element.textContent = '';
1527 element.removeChild(element.firstChild);
1528 1554
1529 messageParts = message.split('$1'); 1555 messageParts = message.split('$1');
1530 var numParts = messageParts.length; 1556 var numParts = messageParts.length;
1531 for (var j = 0; j < numParts; j++) { 1557 for (var j = 0; j < numParts; j++) {
1532 element.appendChild(document.createTextNode(messageParts[j])); 1558 element.appendChild(document.createTextNode(messageParts[j]));
1533 if (j < numParts - 1) { 1559 if (j < numParts - 1) {
1534 var elementToAdd = document.createElement('span'); 1560 var elementToAdd = document.createElement('span');
1535 elementToAdd.classList.add('total-count'); 1561 elementToAdd.classList.add('total-count');
1536 elementToAdd.textContent = count; 1562 elementToAdd.textContent = count;
1537 element.appendChild(elementToAdd); 1563 element.appendChild(elementToAdd);
1538 } 1564 }
1539 } 1565 }
1566 this.moveActionMenuUpIfNeeded_();
1540 }, 1567 },
1541 1568
1542 /** 1569 /**
1543 * Handles a click event on remove user confirmation button. 1570 * Handles a click event on remove user confirmation button.
1544 * @param {Event} e Click event. 1571 * @param {Event} e Click event.
1545 */ 1572 */
1546 handleRemoveUserConfirmationClick_: function(e) { 1573 handleRemoveUserConfirmationClick_: function(e) {
1547 if (this.isActionBoxMenuActive) { 1574 if (this.isActionBoxMenuActive) {
1548 this.isActionBoxMenuActive = false; 1575 this.isActionBoxMenuActive = false;
1549 this.removeUser(this.user); 1576 this.removeUser(this.user);
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
2069 2096
2070 var isLockedUser = this.user.needsSignin; 2097 var isLockedUser = this.user.needsSignin;
2071 var isLegacySupervisedUser = this.user.legacySupervisedUser; 2098 var isLegacySupervisedUser = this.user.legacySupervisedUser;
2072 var isChildUser = this.user.childUser; 2099 var isChildUser = this.user.childUser;
2073 var isSyncedUser = this.user.emailAddress !== ""; 2100 var isSyncedUser = this.user.emailAddress !== "";
2074 var isProfileLoaded = this.user.isProfileLoaded; 2101 var isProfileLoaded = this.user.isProfileLoaded;
2075 this.classList.toggle('locked', isLockedUser); 2102 this.classList.toggle('locked', isLockedUser);
2076 this.classList.toggle('legacy-supervised', isLegacySupervisedUser); 2103 this.classList.toggle('legacy-supervised', isLegacySupervisedUser);
2077 this.classList.toggle('child', isChildUser); 2104 this.classList.toggle('child', isChildUser);
2078 this.classList.toggle('synced', isSyncedUser); 2105 this.classList.toggle('synced', isSyncedUser);
2079 this.classList.toggle('has-no-stats', !isProfileLoaded); 2106 this.classList.toggle('has-no-stats',
2107 !isProfileLoaded && !this.user.statistics.length);
2080 2108
2081 if (this.isAuthTypeUserClick) 2109 if (this.isAuthTypeUserClick)
2082 this.passwordLabelElement.textContent = this.authValue; 2110 this.passwordLabelElement.textContent = this.authValue;
2083 2111
2084 this.passwordElement.setAttribute('aria-label', loadTimeData.getStringF( 2112 this.passwordElement.setAttribute('aria-label', loadTimeData.getStringF(
2085 'passwordFieldAccessibleName', this.user_.emailAddress)); 2113 'passwordFieldAccessibleName', this.user_.emailAddress));
2086 2114
2087 UserPod.prototype.updateActionBoxArea.call(this); 2115 UserPod.prototype.updateActionBoxArea.call(this);
2088 }, 2116 },
2089 2117
(...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after
3292 if (pod && pod.multiProfilesPolicyApplied) { 3320 if (pod && pod.multiProfilesPolicyApplied) {
3293 pod.userTypeBubbleElement.classList.remove('bubble-shown'); 3321 pod.userTypeBubbleElement.classList.remove('bubble-shown');
3294 } 3322 }
3295 } 3323 }
3296 }; 3324 };
3297 3325
3298 return { 3326 return {
3299 PodRow: PodRow 3327 PodRow: PodRow
3300 }; 3328 };
3301 }); 3329 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698