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 @@ ...@@ -135,7 +135,7 @@
</h2> </h2>
<template is="dom-if" <template is="dom-if"
if="[[showImportOrExportPasswords_( if="[[showImportOrExportPasswords_(
showExportPasswords_, showImportPasswords_)]]"> hasSavedPasswords_, showImportPasswords_)]]">
<cr-icon-button class="icon-more-vert header-aligned-button" <cr-icon-button class="icon-more-vert header-aligned-button"
id="exportImportMenuButton" id="exportImportMenuButton"
on-click="onImportExportMenuTap_" title="$i18n{moreActions}" on-click="onImportExportMenuTap_" title="$i18n{moreActions}"
...@@ -151,8 +151,7 @@ ...@@ -151,8 +151,7 @@
should-show-storage-details="[[shouldShowStorageDetails_]]"> should-show-storage-details="[[shouldShowStorageDetails_]]">
<div slot="body" class="list-frame"> <div slot="body" class="list-frame">
<div id="savedPasswordsHeaders" class="list-item column-header" <div id="savedPasswordsHeaders" class="list-item column-header"
hidden$="[[!hasSome_(savedPasswords, savedPasswords.splices)]]" hidden$="[[!hasSavedPasswords_]]" aria-hidden="true">
aria-hidden="true">
<div class="website-column">$i18n{editPasswordWebsiteLabel}</div> <div class="website-column">$i18n{editPasswordWebsiteLabel}</div>
<div class="username-column"> <div class="username-column">
$i18n{editPasswordUsernameLabel} $i18n{editPasswordUsernameLabel}
...@@ -180,7 +179,7 @@ ...@@ -180,7 +179,7 @@
</template> </template>
</iron-list> </iron-list>
<div id="noPasswordsLabel" class="list-item" <div id="noPasswordsLabel" class="list-item"
hidden$="[[hasSome_(savedPasswords, savedPasswords.splices)]]"> hidden$="[[hasSavedPasswords_]]">
$i18n{noPasswordsFound} $i18n{noPasswordsFound}
</div> </div>
</div> </div>
...@@ -191,7 +190,7 @@ ...@@ -191,7 +190,7 @@
$i18n{import} $i18n{import}
</button> </button>
<button id="menuExportPassword" class="dropdown-item" <button id="menuExportPassword" class="dropdown-item"
on-click="onExportTap_" hidden="[[!showExportPasswords_]]"> on-click="onExportTap_" hidden="[[!hasSavedPasswords_]]">
$i18n{exportMenuItem} $i18n{exportMenuItem}
</button> </button>
</cr-action-menu> </cr-action-menu>
...@@ -229,7 +228,7 @@ ...@@ -229,7 +228,7 @@
</div> </div>
</template> </template>
<div id="noExceptionsLabel" class="list-item" <div id="noExceptionsLabel" class="list-item"
hidden$="[[hasSome_(passwordExceptions)]]"> hidden$="[[hasPasswordExceptions_]]">
$i18n{noExceptionsFound} $i18n{noExceptionsFound}
</div> </div>
</div> </div>
...@@ -153,16 +153,23 @@ Polymer({ ...@@ -153,16 +153,23 @@ Polymer({
}, },
/** @private */ /** @private */
hasStoredPasswords_: { hasSavedPasswords_: {
type: Boolean, type: Boolean,
value: false, computed:
'computeHasSavedPasswords_(savedPasswords, savedPasswords.splices)',
},
/** @private */
hasPasswordExceptions_: {
type: Boolean,
computed: 'computeHasPasswordExceptions_(passwordExceptions)',
}, },
shouldShowBanner_: { shouldShowBanner_: {
type: Boolean, type: Boolean,
value: true, value: true,
computed: 'computeShouldShowBanner_(hasLeakedCredentials_,' + computed: 'computeShouldShowBanner_(hasLeakedCredentials_,' +
'signedIn_, hasNeverCheckedPasswords_, hasStoredPasswords_)', 'signedIn_, hasNeverCheckedPasswords_, hasSavedPasswords_)',
}, },
/** /**
...@@ -188,12 +195,6 @@ Polymer({ ...@@ -188,12 +195,6 @@ Polymer({
computed: 'computeHidePasswordsLink_(syncPrefs_, syncStatus_)', computed: 'computeHidePasswordsLink_(syncPrefs_, syncStatus_)',
}, },
/** @private */
showExportPasswords_: {
type: Boolean,
computed: 'hasPasswords_(savedPasswords.splices)',
},
/** @private */ /** @private */
showImportPasswords_: { showImportPasswords_: {
type: Boolean, type: Boolean,
...@@ -460,12 +461,28 @@ Polymer({ ...@@ -460,12 +461,28 @@ Polymer({
(!!this.syncStatus_ && !this.syncStatus_.signedIn) && this.signedIn_; (!!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} * @return {boolean}
* @private * @private
*/ */
computeShouldShowBanner_() { computeShouldShowBanner_() {
return this.signedIn_ && this.hasStoredPasswords_ && return this.signedIn_ && this.hasSavedPasswords_ &&
this.hasNeverCheckedPasswords_ && !this.hasLeakedCredentials_; this.hasNeverCheckedPasswords_ && !this.hasLeakedCredentials_;
}, },
...@@ -587,29 +604,12 @@ Polymer({ ...@@ -587,29 +604,12 @@ Polymer({
this.passwordManager_.optInForAccountStorage(false); 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 * @private
* @param {boolean} showExportPasswords
* @param {boolean} showImportPasswords
* @return {boolean} * @return {boolean}
*/ */
showImportOrExportPasswords_(showExportPasswords, showImportPasswords) { showImportOrExportPasswords_() {
return showExportPasswords || showImportPasswords; 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