Commit 8787ad84 authored by isherman's avatar isherman Committed by Commit bot

[Cleanup] Clean up Easy Unlock code a bit.

Add an IsEnabled() method to the EasyUnlockService, and other minor cleanup.

BUG=none
TEST=none
R=xiyuan@chromium.org

Review URL: https://codereview.chromium.org/889153004

Cr-Commit-Position: refs/heads/master@{#314758}
parent 2cb36e7c
......@@ -574,7 +574,7 @@
<section id="easy-unlock-section" guest-visibility="hidden" hidden>
<h3 i18n-content="easyUnlockSectionTitle"></h3>
<!-- Options shown when the user has not set up Easy Unlock -->
<div id="easy-unlock-setup" hidden>
<div id="easy-unlock-disabled" hidden>
<div class="settings-row">
<span i18n-content="easyUnlockSetupIntro"></span>
<a target="_blank" i18n-content="learnMore"
......@@ -584,7 +584,7 @@
i18n-content="easyUnlockSetupButton"></button>
</div>
<!-- Options shown when the user has set up Easy Unlock -->
<div id="easy-unlock-enable" hidden>
<div id="easy-unlock-enabled" hidden>
<div class="settings-row">
<span i18n-content="easyUnlockDescription"></span>
<a target="_blank" i18n-content="learnMore"
......
......@@ -1097,14 +1097,15 @@ cr.define('options', function() {
},
/**
* Update the UI depending on whether the current profile has a pairing for
* Easy Unlock.
* @param {boolean} hasPairing True if the current profile has a pairing.
*/
updateEasyUnlock_: function(hasPairing) {
$('easy-unlock-setup').hidden = hasPairing;
$('easy-unlock-enable').hidden = !hasPairing;
if (!hasPairing && EasyUnlockTurnOffOverlay.getInstance().visible) {
* Update the UI depending on whether Easy Unlock is enabled for the current
* profile.
* @param {boolean} isEnabled True if the feature is enabled for the current
* profile.
*/
updateEasyUnlock_: function(isEnabled) {
$('easy-unlock-disabled').hidden = isEnabled;
$('easy-unlock-enabled').hidden = !isEnabled;
if (!isEnabled && EasyUnlockTurnOffOverlay.getInstance().visible) {
EasyUnlockTurnOffOverlay.dismiss();
}
},
......
......@@ -313,6 +313,12 @@ bool EasyUnlockService::IsAllowed() {
#endif
}
bool EasyUnlockService::IsEnabled() const {
// The feature is enabled iff there are any paired devices.
const base::ListValue* devices = GetRemoteDevices();
return devices && !devices->empty();
}
void EasyUnlockService::SetHardlockState(
EasyUnlockScreenlockStateHandler::HardlockState state) {
const std::string user_id = GetUserEmail();
......
......@@ -131,6 +131,9 @@ class EasyUnlockService : public KeyedService {
// permitted either the flag is enabled or its field trial is enabled.
bool IsAllowed();
// Whether Easy Unlock is currently enabled for this user.
bool IsEnabled() const;
// Sets the hardlock state for the associated user.
void SetHardlockState(EasyUnlockScreenlockStateHandler::HardlockState state);
......@@ -192,7 +195,7 @@ class EasyUnlockService : public KeyedService {
// Service type specific tests for whether the service is allowed. Returns
// false if service is not allowed. If true is returned, the service may still
// not be allowed if common tests fail (e.g. if Bluetooth is not available).
virtual bool IsAllowedInternal() = 0;
virtual bool IsAllowedInternal() const = 0;
// KeyedService override:
void Shutdown() override;
......
......@@ -273,7 +273,7 @@ void EasyUnlockServiceRegular::ShutdownInternal() {
registrar_.RemoveAll();
}
bool EasyUnlockServiceRegular::IsAllowedInternal() {
bool EasyUnlockServiceRegular::IsAllowedInternal() const {
#if defined(OS_CHROMEOS)
if (!user_manager::UserManager::Get()->IsLoggedInAsUserWithGaiaAccount())
return false;
......
......@@ -59,7 +59,7 @@ class EasyUnlockServiceRegular : public EasyUnlockService {
void RecordPasswordLoginEvent(const std::string& user_id) const override;
void InitializeInternal() override;
void ShutdownInternal() override;
bool IsAllowedInternal() override;
bool IsAllowedInternal() const override;
// Opens the component packaged app responsible for setting up Smart Lock.
void OpenSetupApp();
......
......@@ -284,7 +284,7 @@ void EasyUnlockServiceSignin::ShutdownInternal() {
user_data_.clear();
}
bool EasyUnlockServiceSignin::IsAllowedInternal() {
bool EasyUnlockServiceSignin::IsAllowedInternal() const {
return service_active_ &&
!user_id_.empty() &&
!chromeos::LoginState::Get()->IsUserLoggedIn();
......
......@@ -74,7 +74,7 @@ class EasyUnlockServiceSignin : public EasyUnlockService,
void RecordPasswordLoginEvent(const std::string& user_id) const override;
void InitializeInternal() override;
void ShutdownInternal() override;
bool IsAllowedInternal() override;
bool IsAllowedInternal() const override;
// ScreenlockBridge::Observer implementation:
void OnScreenDidLock() override;
......
......@@ -2035,14 +2035,11 @@ void BrowserOptionsHandler::SetupManagingSupervisedUsers() {
}
void BrowserOptionsHandler::SetupEasyUnlock() {
// TODO(xiyuan): Update when pairing data is really availble.
const base::ListValue* devices =
EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->GetRemoteDevices();
bool has_pairing = devices && !devices->empty();
base::FundamentalValue has_pairing_value(has_pairing);
base::FundamentalValue is_enabled(
EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->IsEnabled());
web_ui()->CallJavascriptFunction(
"BrowserOptions.updateEasyUnlock",
has_pairing_value);
is_enabled);
}
void BrowserOptionsHandler::SetupExtensionControlledIndicators() {
......
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