Commit e728aee5 authored by Victor Hugo Vianna Silva's avatar Victor Hugo Vianna Silva Committed by Commit Bot

[Passwords/Settings] Avoid duplicated checks in PasswordsSection

It seems over time, different features added to passwords settings
ended up implementing the check of whether there are saved passwords
resulting in hasSome_, hasStoredPasswords_ and hasPasswords_ (e.g.
crrev.com/c/1047867, crrev.com/2107524). This CL summarizes these in
a single hasSavedPasswords_ property, reflecting the name of the
corresponding array. The same is done for the array of exceptions.

The motivations here are: a) Keep simplifying the PasswordsSection code;
b) Avoid the use of hasStoredPasswords_ in setSavedPasswordsListener,
allowing to extract that code into a new behavior in the next CL.

Bug: None
Change-Id: Ib39c29f3cc5fd90bde3313971eb95d17b3ed9fe1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2225905
Commit-Queue: Victor Vianna <victorvianna@google.com>
Reviewed-by: default avatarFriedrich [CET] <fhorschig@chromium.org>
Reviewed-by: default avatarJan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774589}
parent 202466fa
......@@ -135,7 +135,7 @@
</h2>
<template is="dom-if"
if="[[showImportOrExportPasswords_(
showExportPasswords_, showImportPasswords_)]]">
hasSavedPasswords_, showImportPasswords_)]]">
<cr-icon-button class="icon-more-vert header-aligned-button"
id="exportImportMenuButton"
on-click="onImportExportMenuTap_" title="$i18n{moreActions}"
......@@ -151,8 +151,7 @@
should-show-storage-details="[[shouldShowStorageDetails_]]">
<div slot="body" class="list-frame">
<div id="savedPasswordsHeaders" class="list-item column-header"
hidden$="[[!hasSome_(savedPasswords, savedPasswords.splices)]]"
aria-hidden="true">
hidden$="[[!hasSavedPasswords_]]" aria-hidden="true">
<div class="website-column">$i18n{editPasswordWebsiteLabel}</div>
<div class="username-column">
$i18n{editPasswordUsernameLabel}
......@@ -180,7 +179,7 @@
</template>
</iron-list>
<div id="noPasswordsLabel" class="list-item"
hidden$="[[hasSome_(savedPasswords, savedPasswords.splices)]]">
hidden$="[[hasSavedPasswords_]]">
$i18n{noPasswordsFound}
</div>
</div>
......@@ -191,7 +190,7 @@
$i18n{import}
</button>
<button id="menuExportPassword" class="dropdown-item"
on-click="onExportTap_" hidden="[[!showExportPasswords_]]">
on-click="onExportTap_" hidden="[[!hasSavedPasswords_]]">
$i18n{exportMenuItem}
</button>
</cr-action-menu>
......@@ -229,7 +228,7 @@
</div>
</template>
<div id="noExceptionsLabel" class="list-item"
hidden$="[[hasSome_(passwordExceptions)]]">
hidden$="[[hasPasswordExceptions_]]">
$i18n{noExceptionsFound}
</div>
</div>
......@@ -153,16 +153,23 @@ Polymer({
},
/** @private */
hasStoredPasswords_: {
hasSavedPasswords_: {
type: Boolean,
value: false,
computed:
'computeHasSavedPasswords_(savedPasswords, savedPasswords.splices)',
},
/** @private */
hasPasswordExceptions_: {
type: Boolean,
computed: 'computeHasPasswordExceptions_(passwordExceptions)',
},
shouldShowBanner_: {
type: Boolean,
value: true,
computed: 'computeShouldShowBanner_(hasLeakedCredentials_,' +
'signedIn_, hasNeverCheckedPasswords_, hasStoredPasswords_)',
'signedIn_, hasNeverCheckedPasswords_, hasSavedPasswords_)',
},
/**
......@@ -188,12 +195,6 @@ Polymer({
computed: 'computeHidePasswordsLink_(syncPrefs_, syncStatus_)',
},
/** @private */
showExportPasswords_: {
type: Boolean,
computed: 'hasPasswords_(savedPasswords.splices)',
},
/** @private */
showImportPasswords_: {
type: Boolean,
......@@ -460,12 +461,28 @@ Polymer({
(!!this.syncStatus_ && !this.syncStatus_.signedIn) && this.signedIn_;
},
/**
* @return {boolean}
* @private
*/
computeHasSavedPasswords_() {
return this.savedPasswords.length > 0;
},
/**
* @return {boolean}
* @private
*/
computeHasPasswordExceptions_() {
return this.passwordExceptions.length > 0;
},
/**
* @return {boolean}
* @private
*/
computeShouldShowBanner_() {
return this.signedIn_ && this.hasStoredPasswords_ &&
return this.signedIn_ && this.hasSavedPasswords_ &&
this.hasNeverCheckedPasswords_ && !this.hasLeakedCredentials_;
},
......@@ -587,29 +604,12 @@ Polymer({
this.passwordManager_.optInForAccountStorage(false);
},
/**
* Returns true if the list exists and is not empty.
* @param {Array<Object>} list
* @return {boolean}
* @private
*/
hasSome_(list) {
return !!(list && list.length);
},
/** @private */
hasPasswords_() {
return this.savedPasswords.length > 0;
},
/**
* @private
* @param {boolean} showExportPasswords
* @param {boolean} showImportPasswords
* @return {boolean}
*/
showImportOrExportPasswords_(showExportPasswords, showImportPasswords) {
return showExportPasswords || showImportPasswords;
showImportOrExportPasswords_() {
return this.hasSavedPasswords_ || this.showImportPasswords_;
},
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment