Index: ui/login/account_picker/user_pod_row.js |
diff --git a/ui/login/account_picker/user_pod_row.js b/ui/login/account_picker/user_pod_row.js |
index 05412649da72a2480b268b0ef6d05bff3bf8d0ec..7118e156770140eedd608db8235f51faf45618a5 100644 |
--- a/ui/login/account_picker/user_pod_row.js |
+++ b/ui/login/account_picker/user_pod_row.js |
@@ -976,6 +976,23 @@ cr.define('login', function() { |
}, |
/** |
+ * Get the elements used for statistics display. |
+ * @type {Object.<string, !HTMLDivElement>} |
+ */ |
+ get statsMapElements() { |
+ return { |
+ 'BrowsingHistory': |
+ this.querySelector('.action-box-remove-user-warning-history'), |
+ 'Passwords': |
+ this.querySelector('.action-box-remove-user-warning-passwords'), |
+ 'Bookmarks': |
+ this.querySelector('.action-box-remove-user-warning-bookmarks'), |
+ 'Settings': |
+ this.querySelector('.action-box-remove-user-warning-settings') |
+ } |
+ }, |
+ |
+ /** |
* Updates the user pod element. |
*/ |
update: function() { |
@@ -1403,7 +1420,6 @@ cr.define('login', function() { |
this.actionBoxMenu.classList.add('menu-moved-up'); |
this.actionBoxAreaElement.classList.add('menu-moved-up'); |
} |
- chrome.send('logRemoveUserWarningShown'); |
}, |
/** |
@@ -1417,32 +1433,16 @@ cr.define('login', function() { |
// Show extra statistics information for desktop users |
var message; |
- if (this.user.isDesktopUser) { |
- this.classList.remove('has-errors'); |
- var isSyncedUser = this.user.emailAddress !== ""; |
- if (!this.user.isProfileLoaded) { |
- message = loadTimeData.getString( |
- isSyncedUser ? 'removeUserWarningTextSyncNoStats' : |
- 'removeUserWarningTextNonSyncNoStats'); |
- this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, |
- message); |
- } else { |
- message = loadTimeData.getString( |
- isSyncedUser ? 'removeUserWarningTextSyncCalculating' : |
- 'removeUserWarningTextNonSyncCalculating'); |
- substitute = loadTimeData.getString( |
- 'removeUserWarningTextCalculating'); |
- this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, |
- message, substitute); |
- } |
- |
+ if (this.user.isLegacySupervisedUser) { |
+ this.moveActionMenuUpIfNeeded_(); |
+ } else { |
+ this.RemoveWarningDialogSetMessage_(true, false); |
// set a global handler for the callback |
window.updateRemoveWarningDialog = |
this.updateRemoveWarningDialog_.bind(this); |
chrome.send('removeUserWarningLoadStats', [this.user.profilePath]); |
} |
- |
- this.moveActionMenuUpIfNeeded_(); |
+ chrome.send('logRemoveUserWarningShown'); |
}, |
/** |
@@ -1453,45 +1453,58 @@ cr.define('login', function() { |
updateRemoveWarningDialog_: function(profilePath, profileStats) { |
if (profilePath !== this.user.profilePath) |
return; |
- // Converting profileStats into id attribute by an object. |
- var stats_id_map = { |
- 'BrowsingHistory': 'action-box-remove-user-warning-history', |
- 'Passwords': 'action-box-remove-user-warning-passwords', |
- 'Bookmarks': 'action-box-remove-user-warning-bookmarks', |
- 'Settings': 'action-box-remove-user-warning-settings', |
- } |
- // Load individual statistics |
+ |
+ var stats_elements = this.statsMapElements; |
+ // Update individual statistics |
var num_stats_loaded = 0; |
- var total_count = 0; |
var failed = false; |
for (var key in profileStats) { |
- if (stats_id_map.hasOwnProperty(key)) { |
+ if (stats_elements.hasOwnProperty(key)) { |
if (profileStats[key].success) { |
- var count = profileStats[key].count; |
- this.querySelector("." + stats_id_map[key]).textContent = count; |
- total_count += count; |
- } else { |
+ this.user.statistics[key] = profileStats[key].count; |
+ } else if (!this.user.statistics.hasOwnProperty(key)) { |
failed = true; |
- this.querySelector("." + stats_id_map[key]).textContent = ''; |
+ stats_elements[key].textContent = ''; |
} |
num_stats_loaded++; |
} |
} |
+ this.RemoveWarningDialogSetMessage_( |
+ false, failed && num_stats_loaded === this.statsMapElements.count); |
+ }, |
+ |
+ /** |
+ * Set the new message in the dialog. |
+ * @param {boolean} Whether this statistics are not available due to errors. |
+ * Should be true only if there is an error and the corresponding statistic |
+ * is also unavailable in ProfileInfoCache. |
+ */ |
+ RemoveWarningDialogSetMessage_: function(isInitial, isError) { |
+ var stats_elements = this.statsMapElements; |
+ var num_stats_loaded = 0; |
+ var total_count = 0; |
+ for (var key in stats_elements) { |
+ if (this.user.statistics.hasOwnProperty(key)) { |
+ var count = this.user.statistics[key]; |
+ stats_elements[key].textContent = count; |
+ total_count += count; |
+ num_stats_loaded++; |
+ } |
+ } |
+ |
// this.classList is used for selecting the appropriate dialog. |
- this.classList.toggle('has-errors', failed); |
- if (total_count > 0) { |
+ if (total_count) |
this.classList.remove('has-no-stats'); |
- } |
+ var is_synced_user = this.user.emailAddress !== ""; |
// Write total number if all statistics are loaded. |
- if (num_stats_loaded === Object.keys(stats_id_map).length) { |
- if (total_count === 0) { |
+ if (num_stats_loaded === Object.keys(stats_elements).length || isError) { |
+ if (!total_count) { |
this.classList.add('has-no-stats'); |
- var isSyncedUser = this.user.emailAddress !== ""; |
var message = loadTimeData.getString( |
- isSyncedUser ? 'removeUserWarningTextSyncNoStats' : |
- 'removeUserWarningTextNonSyncNoStats'); |
+ is_synced_user ? 'removeUserWarningTextSyncNoStats' : |
+ 'removeUserWarningTextNonSyncNoStats'); |
this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, |
message); |
} else { |
@@ -1499,14 +1512,28 @@ cr.define('login', function() { |
this.updateRemoveWarningDialogSetMessage_.bind(this); |
chrome.send('getRemoveWarningDialogMessage',[{ |
profilePath: this.user.profilePath, |
- isSyncedUser: this.user.emailAddress !== "", |
- hasErrors: failed, |
+ isSyncedUser: is_synced_user, |
+ hasErrors: num_stats_loaded < Object.keys(stats_elements).length, |
totalCount: total_count |
}]); |
} |
+ } else if (isInitial) { |
+ if (!this.user.isProfileLoaded) { |
+ message = loadTimeData.getString( |
+ is_synced_user ? 'removeUserWarningTextSyncNoStats' : |
+ 'removeUserWarningTextNonSyncNoStats'); |
+ this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, |
+ message); |
+ } else { |
+ message = loadTimeData.getString( |
+ is_synced_user ? 'removeUserWarningTextSyncCalculating' : |
+ 'removeUserWarningTextNonSyncCalculating'); |
+ substitute = loadTimeData.getString( |
+ 'removeUserWarningTextCalculating'); |
+ this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, |
+ message, substitute); |
+ } |
} |
- |
- this.moveActionMenuUpIfNeeded_(); |
}, |
/** |
@@ -1523,8 +1550,7 @@ cr.define('login', function() { |
// Add localized messages where $1 will be replaced with |
// <span class="total-count"></span>. |
var element = this.querySelector('.action-box-remove-user-warning-text'); |
- while (element.firstChild) |
- element.removeChild(element.firstChild); |
+ element.textContent = ''; |
messageParts = message.split('$1'); |
var numParts = messageParts.length; |
@@ -1537,6 +1563,7 @@ cr.define('login', function() { |
element.appendChild(elementToAdd); |
} |
} |
+ this.moveActionMenuUpIfNeeded_(); |
}, |
/** |
@@ -2076,7 +2103,8 @@ cr.define('login', function() { |
this.classList.toggle('legacy-supervised', isLegacySupervisedUser); |
this.classList.toggle('child', isChildUser); |
this.classList.toggle('synced', isSyncedUser); |
- this.classList.toggle('has-no-stats', !isProfileLoaded); |
+ this.classList.toggle('has-no-stats', |
+ !isProfileLoaded && !this.user.statistics.length); |
if (this.isAuthTypeUserClick) |
this.passwordLabelElement.textContent = this.authValue; |