Commit 92625bc1 authored by Ryan Hansberry's avatar Ryan Hansberry Committed by Commit Bot

Smart Lock: Create a new user pref and make EasyUnlockService listen on it.

Use a new Smart Lock user pref to track if Smart Lock is fully enabled. This
removes the need to consider additional complexity when migrating to Unified
Setup.

Additionally, make EasyUnlockServiceRegular and ProximityAuthProfilePrefManager
now consult MultiDeviceSetupClient if Smart Lock is enabled (and listen on
feature state changes from it). To be clear, these two classes no longer
directly set the Smart Lock user pref, and instead only determine if Smart
Lock is enabled by asking MultiDeviceSetupClient.

R=jhawkins@chromium.org, jlklein@chromium.org

Bug: 881435
Change-Id: I0a8535c19789e826d277258f76ce384e27cc8652
Reviewed-on: https://chromium-review.googlesource.com/1211246Reviewed-by: default avatarJeremy Klein <jlklein@chromium.org>
Reviewed-by: default avatarJames Hawkins <jhawkins@chromium.org>
Reviewed-by: default avatarDan Erat <derat@chromium.org>
Commit-Queue: Ryan Hansberry <hansberry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589319}
parent fb043b0b
...@@ -66,7 +66,8 @@ class FakeEasyUnlockService : public EasyUnlockServiceRegular { ...@@ -66,7 +66,8 @@ class FakeEasyUnlockService : public EasyUnlockServiceRegular {
explicit FakeEasyUnlockService(Profile* profile) explicit FakeEasyUnlockService(Profile* profile)
: EasyUnlockServiceRegular(profile, : EasyUnlockServiceRegular(profile,
nullptr /* secure_channel_client */, nullptr /* secure_channel_client */,
nullptr /* device_sync_client */), nullptr /* device_sync_client */,
nullptr /* multidevice_setup_client */),
reauth_count_(0) {} reauth_count_(0) {}
~FakeEasyUnlockService() override {} ~FakeEasyUnlockService() override {}
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_service_regular.h" #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_service_regular.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_service_signin_chromeos.h" #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_service_signin_chromeos.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_factory.h" #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_factory.h"
#include "chrome/browser/chromeos/multidevice_setup/multidevice_setup_client_factory.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/chromeos/secure_channel/secure_channel_client_provider.h" #include "chrome/browser/chromeos/secure_channel/secure_channel_client_provider.h"
#include "chrome/browser/profiles/incognito_helpers.h" #include "chrome/browser/profiles/incognito_helpers.h"
...@@ -71,6 +72,7 @@ EasyUnlockServiceFactory::EasyUnlockServiceFactory() ...@@ -71,6 +72,7 @@ EasyUnlockServiceFactory::EasyUnlockServiceFactory()
extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
DependsOn(EasyUnlockTpmKeyManagerFactory::GetInstance()); DependsOn(EasyUnlockTpmKeyManagerFactory::GetInstance());
DependsOn(device_sync::DeviceSyncClientFactory::GetInstance()); DependsOn(device_sync::DeviceSyncClientFactory::GetInstance());
DependsOn(multidevice_setup::MultiDeviceSetupClientFactory::GetInstance());
} }
EasyUnlockServiceFactory::~EasyUnlockServiceFactory() {} EasyUnlockServiceFactory::~EasyUnlockServiceFactory() {}
...@@ -100,6 +102,8 @@ KeyedService* EasyUnlockServiceFactory::BuildServiceInstanceFor( ...@@ -100,6 +102,8 @@ KeyedService* EasyUnlockServiceFactory::BuildServiceInstanceFor(
Profile::FromBrowserContext(context), Profile::FromBrowserContext(context),
secure_channel::SecureChannelClientProvider::GetInstance()->GetClient(), secure_channel::SecureChannelClientProvider::GetInstance()->GetClient(),
device_sync::DeviceSyncClientFactory::GetForProfile( device_sync::DeviceSyncClientFactory::GetForProfile(
Profile::FromBrowserContext(context)),
multidevice_setup::MultiDeviceSetupClientFactory::GetForProfile(
Profile::FromBrowserContext(context))); Profile::FromBrowserContext(context)));
manifest_id = IDR_EASY_UNLOCK_MANIFEST; manifest_id = IDR_EASY_UNLOCK_MANIFEST;
} }
......
...@@ -106,18 +106,21 @@ void LogSmartLockEnabledState(SmartLockEnabledState state) { ...@@ -106,18 +106,21 @@ void LogSmartLockEnabledState(SmartLockEnabledState state) {
EasyUnlockServiceRegular::EasyUnlockServiceRegular( EasyUnlockServiceRegular::EasyUnlockServiceRegular(
Profile* profile, Profile* profile,
secure_channel::SecureChannelClient* secure_channel_client, secure_channel::SecureChannelClient* secure_channel_client,
device_sync::DeviceSyncClient* device_sync_client) device_sync::DeviceSyncClient* device_sync_client,
multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client)
: EasyUnlockServiceRegular( : EasyUnlockServiceRegular(
profile, profile,
secure_channel_client, secure_channel_client,
std::make_unique<EasyUnlockNotificationController>(profile), std::make_unique<EasyUnlockNotificationController>(profile),
device_sync_client) {} device_sync_client,
multidevice_setup_client) {}
EasyUnlockServiceRegular::EasyUnlockServiceRegular( EasyUnlockServiceRegular::EasyUnlockServiceRegular(
Profile* profile, Profile* profile,
secure_channel::SecureChannelClient* secure_channel_client, secure_channel::SecureChannelClient* secure_channel_client,
std::unique_ptr<EasyUnlockNotificationController> notification_controller, std::unique_ptr<EasyUnlockNotificationController> notification_controller,
device_sync::DeviceSyncClient* device_sync_client) device_sync::DeviceSyncClient* device_sync_client,
multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client)
: EasyUnlockService(profile, secure_channel_client), : EasyUnlockService(profile, secure_channel_client),
turn_off_flow_status_(EasyUnlockService::IDLE), turn_off_flow_status_(EasyUnlockService::IDLE),
scoped_crypt_auth_device_manager_observer_(this), scoped_crypt_auth_device_manager_observer_(this),
...@@ -126,6 +129,7 @@ EasyUnlockServiceRegular::EasyUnlockServiceRegular( ...@@ -126,6 +129,7 @@ EasyUnlockServiceRegular::EasyUnlockServiceRegular(
deferring_device_load_(false), deferring_device_load_(false),
notification_controller_(std::move(notification_controller)), notification_controller_(std::move(notification_controller)),
device_sync_client_(device_sync_client), device_sync_client_(device_sync_client),
multidevice_setup_client_(multidevice_setup_client),
shown_pairing_changed_notification_(false), shown_pairing_changed_notification_(false),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) { if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
...@@ -135,16 +139,18 @@ EasyUnlockServiceRegular::EasyUnlockServiceRegular( ...@@ -135,16 +139,18 @@ EasyUnlockServiceRegular::EasyUnlockServiceRegular(
OnReady(); OnReady();
device_sync_client_->AddObserver(this); device_sync_client_->AddObserver(this);
}
}
EasyUnlockServiceRegular::~EasyUnlockServiceRegular() { if (base::FeatureList::IsEnabled(
registrar_.RemoveAll(); chromeos::features::kEnableUnifiedMultiDeviceSetup)) {
OnFeatureStatesChanged(multidevice_setup_client_->GetFeatureStates());
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) multidevice_setup_client_->AddObserver(this);
device_sync_client_->RemoveObserver(this); }
}
} }
EasyUnlockServiceRegular::~EasyUnlockServiceRegular() = default;
// TODO(jhawkins): This method with |has_unlock_keys| == true is the only signal // TODO(jhawkins): This method with |has_unlock_keys| == true is the only signal
// that SmartLock setup has completed successfully. Make this signal more // that SmartLock setup has completed successfully. Make this signal more
// explicit. // explicit.
...@@ -158,6 +164,18 @@ void EasyUnlockServiceRegular::LoadRemoteDevices() { ...@@ -158,6 +164,18 @@ void EasyUnlockServiceRegular::LoadRemoteDevices() {
return; return;
} }
if (base::FeatureList::IsEnabled(
chromeos::features::kEnableUnifiedMultiDeviceSetup) &&
feature_state_ !=
multidevice_setup::mojom::FeatureState::kEnabledByUser) {
// OnFeatureStatesChanged() will call back on this method when feature state
// changes.
PA_LOG(INFO) << "Smart Lock is disabled; aborting.";
SetProximityAuthDevices(GetAccountId(), cryptauth::RemoteDeviceRefList(),
base::nullopt /* local_device */);
return;
}
bool has_unlock_keys; bool has_unlock_keys;
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) { if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
has_unlock_keys = !GetUnlockKeys().empty(); has_unlock_keys = !GetUnlockKeys().empty();
...@@ -504,7 +522,7 @@ void EasyUnlockServiceRegular::InitializeInternal() { ...@@ -504,7 +522,7 @@ void EasyUnlockServiceRegular::InitializeInternal() {
proximity_auth::ScreenlockBridge::Get()->AddObserver(this); proximity_auth::ScreenlockBridge::Get()->AddObserver(this);
pref_manager_.reset(new proximity_auth::ProximityAuthProfilePrefManager( pref_manager_.reset(new proximity_auth::ProximityAuthProfilePrefManager(
profile()->GetPrefs())); profile()->GetPrefs(), multidevice_setup_client_));
// TODO(tengs): Due to badly configured browser_tests, Chrome crashes during // TODO(tengs): Due to badly configured browser_tests, Chrome crashes during
// shutdown. Revisit this condition after migration is fully completed. // shutdown. Revisit this condition after migration is fully completed.
...@@ -538,10 +556,20 @@ void EasyUnlockServiceRegular::ShutdownInternal() { ...@@ -538,10 +556,20 @@ void EasyUnlockServiceRegular::ShutdownInternal() {
turn_off_flow_status_ = EasyUnlockService::IDLE; turn_off_flow_status_ = EasyUnlockService::IDLE;
proximity_auth::ScreenlockBridge::Get()->RemoveObserver(this); proximity_auth::ScreenlockBridge::Get()->RemoveObserver(this);
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) if (!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
device_sync_client_->RemoveObserver(this);
else
scoped_crypt_auth_device_manager_observer_.RemoveAll(); scoped_crypt_auth_device_manager_observer_.RemoveAll();
}
registrar_.RemoveAll();
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
device_sync_client_->RemoveObserver(this);
if (base::FeatureList::IsEnabled(
chromeos::features::kEnableUnifiedMultiDeviceSetup)) {
multidevice_setup_client_->RemoveObserver(this);
}
}
} }
bool EasyUnlockServiceRegular::IsAllowedInternal() const { bool EasyUnlockServiceRegular::IsAllowedInternal() const {
...@@ -558,6 +586,13 @@ bool EasyUnlockServiceRegular::IsAllowedInternal() const { ...@@ -558,6 +586,13 @@ bool EasyUnlockServiceRegular::IsAllowedInternal() const {
if (!ProfileHelper::IsPrimaryProfile(profile())) if (!ProfileHelper::IsPrimaryProfile(profile()))
return false; return false;
if (base::FeatureList::IsEnabled(
chromeos::features::kEnableUnifiedMultiDeviceSetup) &&
feature_state_ ==
multidevice_setup::mojom::FeatureState::kProhibitedByPolicy) {
return false;
}
if (!profile()->GetPrefs()->GetBoolean(prefs::kEasyUnlockAllowed)) if (!profile()->GetPrefs()->GetBoolean(prefs::kEasyUnlockAllowed))
return false; return false;
...@@ -565,6 +600,12 @@ bool EasyUnlockServiceRegular::IsAllowedInternal() const { ...@@ -565,6 +600,12 @@ bool EasyUnlockServiceRegular::IsAllowedInternal() const {
} }
bool EasyUnlockServiceRegular::IsEnabled() const { bool EasyUnlockServiceRegular::IsEnabled() const {
if (base::FeatureList::IsEnabled(
chromeos::features::kEnableUnifiedMultiDeviceSetup)) {
return feature_state_ ==
multidevice_setup::mojom::FeatureState::kEnabledByUser;
}
return pref_manager_ && pref_manager_->IsEasyUnlockEnabled(); return pref_manager_ && pref_manager_->IsEasyUnlockEnabled();
} }
...@@ -652,6 +693,21 @@ void EasyUnlockServiceRegular::OnNewDevicesSynced() { ...@@ -652,6 +693,21 @@ void EasyUnlockServiceRegular::OnNewDevicesSynced() {
remote_device_unlock_keys_before_sync_ = remote_device_unlock_keys_after_sync; remote_device_unlock_keys_before_sync_ = remote_device_unlock_keys_after_sync;
} }
void EasyUnlockServiceRegular::OnFeatureStatesChanged(
const multidevice_setup::MultiDeviceSetupClient::FeatureStatesMap&
feature_states_map) {
const auto it =
feature_states_map.find(multidevice_setup::mojom::Feature::kSmartLock);
if (it == feature_states_map.end()) {
feature_state_ =
multidevice_setup::mojom::FeatureState::kUnavailableNoVerifiedHost;
return;
}
feature_state_ = it->second;
LoadRemoteDevices();
}
void EasyUnlockServiceRegular::ShowNotificationIfNewDevicePresent( void EasyUnlockServiceRegular::ShowNotificationIfNewDevicePresent(
const std::set<std::string>& public_keys_before_sync, const std::set<std::string>& public_keys_before_sync,
const std::set<std::string>& public_keys_after_sync) { const std::set<std::string>& public_keys_after_sync) {
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "chrome/browser/chromeos/login/easy_unlock/short_lived_user_context.h" #include "chrome/browser/chromeos/login/easy_unlock/short_lived_user_context.h"
#include "chromeos/components/proximity_auth/screenlock_bridge.h" #include "chromeos/components/proximity_auth/screenlock_bridge.h"
#include "chromeos/services/device_sync/public/cpp/device_sync_client.h" #include "chromeos/services/device_sync/public/cpp/device_sync_client.h"
#include "chromeos/services/multidevice_setup/public/cpp/multidevice_setup_client.h"
#include "components/cryptauth/cryptauth_device_manager.h" #include "components/cryptauth/cryptauth_device_manager.h"
#include "components/cryptauth/network_request_error.h" #include "components/cryptauth/network_request_error.h"
#include "components/cryptauth/remote_device_ref.h" #include "components/cryptauth/remote_device_ref.h"
...@@ -56,19 +57,22 @@ class EasyUnlockServiceRegular ...@@ -56,19 +57,22 @@ class EasyUnlockServiceRegular
: public EasyUnlockService, : public EasyUnlockService,
public proximity_auth::ScreenlockBridge::Observer, public proximity_auth::ScreenlockBridge::Observer,
public cryptauth::CryptAuthDeviceManager::Observer, public cryptauth::CryptAuthDeviceManager::Observer,
public device_sync::DeviceSyncClient::Observer { public device_sync::DeviceSyncClient::Observer,
public multidevice_setup::MultiDeviceSetupClient::Observer {
public: public:
EasyUnlockServiceRegular( EasyUnlockServiceRegular(
Profile* profile, Profile* profile,
secure_channel::SecureChannelClient* secure_channel_client, secure_channel::SecureChannelClient* secure_channel_client,
device_sync::DeviceSyncClient* device_sync_client); device_sync::DeviceSyncClient* device_sync_client,
multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client);
// Constructor for tests. // Constructor for tests.
EasyUnlockServiceRegular( EasyUnlockServiceRegular(
Profile* profile, Profile* profile,
secure_channel::SecureChannelClient* secure_channel_client, secure_channel::SecureChannelClient* secure_channel_client,
std::unique_ptr<EasyUnlockNotificationController> notification_controller, std::unique_ptr<EasyUnlockNotificationController> notification_controller,
device_sync::DeviceSyncClient* device_sync_client); device_sync::DeviceSyncClient* device_sync_client,
multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client);
~EasyUnlockServiceRegular() override; ~EasyUnlockServiceRegular() override;
...@@ -120,6 +124,11 @@ class EasyUnlockServiceRegular ...@@ -120,6 +124,11 @@ class EasyUnlockServiceRegular
void OnEnrollmentFinished() override; void OnEnrollmentFinished() override;
void OnNewDevicesSynced() override; void OnNewDevicesSynced() override;
// multidevice_setup::MultiDeviceSetupClient::Observer:
void OnFeatureStatesChanged(
const multidevice_setup::MultiDeviceSetupClient::FeatureStatesMap&
feature_states_map) override;
void ShowNotificationIfNewDevicePresent( void ShowNotificationIfNewDevicePresent(
const std::set<std::string>& public_keys_before_sync, const std::set<std::string>& public_keys_before_sync,
const std::set<std::string>& public_keys_after_sync); const std::set<std::string>& public_keys_after_sync);
...@@ -210,13 +219,23 @@ class EasyUnlockServiceRegular ...@@ -210,13 +219,23 @@ class EasyUnlockServiceRegular
// Responsible for showing all the notifications used for EasyUnlock. // Responsible for showing all the notifications used for EasyUnlock.
std::unique_ptr<EasyUnlockNotificationController> notification_controller_; std::unique_ptr<EasyUnlockNotificationController> notification_controller_;
// Used to fetch local device and remote device data.
device_sync::DeviceSyncClient* device_sync_client_; device_sync::DeviceSyncClient* device_sync_client_;
// Used to determine the FeatureState of Smart Lock. See |feature_state_|.
multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client_;
// Stores the unlock keys for EasyUnlock before the current device sync, so we // Stores the unlock keys for EasyUnlock before the current device sync, so we
// can compare it to the unlock keys after syncing. // can compare it to the unlock keys after syncing.
std::vector<cryptauth::ExternalDeviceInfo> unlock_keys_before_sync_; std::vector<cryptauth::ExternalDeviceInfo> unlock_keys_before_sync_;
cryptauth::RemoteDeviceRefList remote_device_unlock_keys_before_sync_; cryptauth::RemoteDeviceRefList remote_device_unlock_keys_before_sync_;
// Caches feature state of Smart Lock. This service should only actively be
// running if its value is kEnabledByUser. Populated by using
// |multidevice_setup_client_|.
multidevice_setup::mojom::FeatureState feature_state_ =
multidevice_setup::mojom::FeatureState::kUnavailableNoVerifiedHost;
// True if the pairing changed notification was shown, so that the next time // True if the pairing changed notification was shown, so that the next time
// the Chromebook is unlocked, we can show the subsequent 'pairing applied' // the Chromebook is unlocked, we can show the subsequent 'pairing applied'
// notification. // notification.
......
...@@ -213,7 +213,7 @@ std::unique_ptr<KeyedService> CreateEasyUnlockServiceForTest( ...@@ -213,7 +213,7 @@ std::unique_ptr<KeyedService> CreateEasyUnlockServiceForTest(
Profile::FromBrowserContext(context), Profile::FromBrowserContext(context),
nullptr /* secure_channel_client */, nullptr /* secure_channel_client */,
std::make_unique<MockEasyUnlockNotificationController>(), std::make_unique<MockEasyUnlockNotificationController>(),
fake_device_sync_client)); fake_device_sync_client, nullptr /* multidevice_setup_client */));
service->Initialize(std::move(app_manager)); service->Initialize(std::move(app_manager));
return std::move(service); return std::move(service);
} }
......
...@@ -58,6 +58,7 @@ static_library("proximity_auth") { ...@@ -58,6 +58,7 @@ static_library("proximity_auth") {
# TODO(hansberry): Remove this dependency once https://crbug.com/870123 is # TODO(hansberry): Remove this dependency once https://crbug.com/870123 is
# fixed. # fixed.
"//chromeos/services/multidevice_setup/public/cpp",
"//chromeos/services/multidevice_setup/public/cpp:prefs", "//chromeos/services/multidevice_setup/public/cpp:prefs",
"//chromeos/services/secure_channel/public/cpp/client", "//chromeos/services/secure_channel/public/cpp/client",
"//chromeos/services/secure_channel/public/mojom", "//chromeos/services/secure_channel/public/mojom",
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/values.h" #include "base/values.h"
#include "chromeos/chromeos_features.h"
#include "chromeos/components/proximity_auth/logging/logging.h" #include "chromeos/components/proximity_auth/logging/logging.h"
#include "chromeos/components/proximity_auth/proximity_auth_pref_names.h" #include "chromeos/components/proximity_auth/proximity_auth_pref_names.h"
#include "chromeos/services/multidevice_setup/public/cpp/prefs.h" #include "chromeos/services/multidevice_setup/public/cpp/prefs.h"
...@@ -20,11 +21,27 @@ ...@@ -20,11 +21,27 @@
namespace proximity_auth { namespace proximity_auth {
ProximityAuthProfilePrefManager::ProximityAuthProfilePrefManager( ProximityAuthProfilePrefManager::ProximityAuthProfilePrefManager(
PrefService* pref_service) PrefService* pref_service,
: pref_service_(pref_service), weak_ptr_factory_(this) {} chromeos::multidevice_setup::MultiDeviceSetupClient*
multidevice_setup_client)
: pref_service_(pref_service),
multidevice_setup_client_(multidevice_setup_client),
weak_ptr_factory_(this) {
if (base::FeatureList::IsEnabled(
chromeos::features::kEnableUnifiedMultiDeviceSetup)) {
OnFeatureStatesChanged(multidevice_setup_client_->GetFeatureStates());
multidevice_setup_client_->AddObserver(this);
}
}
ProximityAuthProfilePrefManager::~ProximityAuthProfilePrefManager() { ProximityAuthProfilePrefManager::~ProximityAuthProfilePrefManager() {
registrar_.RemoveAll(); registrar_.RemoveAll();
if (base::FeatureList::IsEnabled(
chromeos::features::kEnableUnifiedMultiDeviceSetup)) {
multidevice_setup_client_->RemoveObserver(this);
}
} }
// static // static
...@@ -61,8 +78,9 @@ void ProximityAuthProfilePrefManager::StartSyncingToLocalState( ...@@ -61,8 +78,9 @@ void ProximityAuthProfilePrefManager::StartSyncingToLocalState(
registrar_.Init(pref_service_); registrar_.Init(pref_service_);
registrar_.Add(chromeos::multidevice_setup::kSmartLockAllowedPrefName, registrar_.Add(chromeos::multidevice_setup::kSmartLockAllowedPrefName,
on_pref_changed_callback); on_pref_changed_callback);
registrar_.Add(chromeos::multidevice_setup::kSmartLockEnabledPrefName, registrar_.Add(
on_pref_changed_callback); chromeos::multidevice_setup::kSmartLockEnabledDeprecatedPrefName,
on_pref_changed_callback);
registrar_.Add(proximity_auth::prefs::kEasyUnlockProximityThreshold, registrar_.Add(proximity_auth::prefs::kEasyUnlockProximityThreshold,
on_pref_changed_callback); on_pref_changed_callback);
registrar_.Add(proximity_auth::prefs::kProximityAuthIsChromeOSLoginEnabled, registrar_.Add(proximity_auth::prefs::kProximityAuthIsChromeOSLoginEnabled,
...@@ -100,13 +118,19 @@ bool ProximityAuthProfilePrefManager::IsEasyUnlockAllowed() const { ...@@ -100,13 +118,19 @@ bool ProximityAuthProfilePrefManager::IsEasyUnlockAllowed() const {
void ProximityAuthProfilePrefManager::SetIsEasyUnlockEnabled( void ProximityAuthProfilePrefManager::SetIsEasyUnlockEnabled(
bool is_easy_unlock_enabled) const { bool is_easy_unlock_enabled) const {
pref_service_->SetBoolean( pref_service_->SetBoolean(
chromeos::multidevice_setup::kSmartLockEnabledPrefName, chromeos::multidevice_setup::kSmartLockEnabledDeprecatedPrefName,
is_easy_unlock_enabled); is_easy_unlock_enabled);
} }
bool ProximityAuthProfilePrefManager::IsEasyUnlockEnabled() const { bool ProximityAuthProfilePrefManager::IsEasyUnlockEnabled() const {
if (base::FeatureList::IsEnabled(
chromeos::features::kEnableUnifiedMultiDeviceSetup)) {
return feature_state_ ==
chromeos::multidevice_setup::mojom::FeatureState::kEnabledByUser;
}
return pref_service_->GetBoolean( return pref_service_->GetBoolean(
chromeos::multidevice_setup::kSmartLockEnabledPrefName); chromeos::multidevice_setup::kSmartLockEnabledDeprecatedPrefName);
} }
void ProximityAuthProfilePrefManager::SetEasyUnlockEnabledStateSet() const { void ProximityAuthProfilePrefManager::SetEasyUnlockEnabledStateSet() const {
...@@ -159,4 +183,20 @@ bool ProximityAuthProfilePrefManager::IsChromeOSLoginEnabled() { ...@@ -159,4 +183,20 @@ bool ProximityAuthProfilePrefManager::IsChromeOSLoginEnabled() {
return pref_service_->GetBoolean(prefs::kProximityAuthIsChromeOSLoginEnabled); return pref_service_->GetBoolean(prefs::kProximityAuthIsChromeOSLoginEnabled);
} }
void ProximityAuthProfilePrefManager::OnFeatureStatesChanged(
const chromeos::multidevice_setup::MultiDeviceSetupClient::FeatureStatesMap&
feature_states_map) {
const auto it = feature_states_map.find(
chromeos::multidevice_setup::mojom::Feature::kSmartLock);
if (it == feature_states_map.end()) {
feature_state_ = chromeos::multidevice_setup::mojom::FeatureState::
kUnavailableNoVerifiedHost;
return;
}
feature_state_ = it->second;
if (local_state_)
SyncPrefsToLocalState();
}
} // namespace proximity_auth } // namespace proximity_auth
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "chromeos/components/proximity_auth/proximity_auth_pref_manager.h" #include "chromeos/components/proximity_auth/proximity_auth_pref_manager.h"
#include "chromeos/services/multidevice_setup/public/cpp/multidevice_setup_client.h"
#include "components/account_id/account_id.h" #include "components/account_id/account_id.h"
#include "components/prefs/pref_change_registrar.h" #include "components/prefs/pref_change_registrar.h"
...@@ -29,13 +30,18 @@ namespace proximity_auth { ...@@ -29,13 +30,18 @@ namespace proximity_auth {
// Implementation of ProximityAuthPrefManager for a logged in session with a // Implementation of ProximityAuthPrefManager for a logged in session with a
// user profile. // user profile.
class ProximityAuthProfilePrefManager : public ProximityAuthPrefManager { class ProximityAuthProfilePrefManager
: public ProximityAuthPrefManager,
public chromeos::multidevice_setup::MultiDeviceSetupClient::Observer {
public: public:
// Creates a pref manager backed by preferences registered in // Creates a pref manager backed by preferences registered in
// |pref_service| (persistent across browser restarts). |pref_service| should // |pref_service| (persistent across browser restarts). |pref_service| should
// have been registered using RegisterPrefs(). Not owned, must out live this // have been registered using RegisterPrefs(). Not owned, must out live this
// instance. // instance.
explicit ProximityAuthProfilePrefManager(PrefService* pref_service); ProximityAuthProfilePrefManager(
PrefService* pref_service,
chromeos::multidevice_setup::MultiDeviceSetupClient*
multidevice_setup_client);
~ProximityAuthProfilePrefManager() override; ~ProximityAuthProfilePrefManager() override;
// Initializes the manager to listen to pref changes and sync prefs to the // Initializes the manager to listen to pref changes and sync prefs to the
...@@ -61,6 +67,11 @@ class ProximityAuthProfilePrefManager : public ProximityAuthPrefManager { ...@@ -61,6 +67,11 @@ class ProximityAuthProfilePrefManager : public ProximityAuthPrefManager {
void SetIsChromeOSLoginEnabled(bool is_enabled) override; void SetIsChromeOSLoginEnabled(bool is_enabled) override;
bool IsChromeOSLoginEnabled() override; bool IsChromeOSLoginEnabled() override;
// chromeos::multidevice_setup::MultiDeviceSetupClient::Observer:
void OnFeatureStatesChanged(
const chromeos::multidevice_setup::MultiDeviceSetupClient::
FeatureStatesMap& feature_states_map) override;
private: private:
const base::DictionaryValue* GetRemoteBleDevices() const; const base::DictionaryValue* GetRemoteBleDevices() const;
...@@ -79,6 +90,15 @@ class ProximityAuthProfilePrefManager : public ProximityAuthPrefManager { ...@@ -79,6 +90,15 @@ class ProximityAuthProfilePrefManager : public ProximityAuthPrefManager {
// The account id of the current profile. // The account id of the current profile.
AccountId account_id_; AccountId account_id_;
// Used to determine the FeatureState of Smart Lock. See |feature_state_|.
chromeos::multidevice_setup::MultiDeviceSetupClient*
multidevice_setup_client_;
// Caches feature state of Smart Lock. Populated by using
// |multidevice_setup_client_|.
chromeos::multidevice_setup::mojom::FeatureState feature_state_ = chromeos::
multidevice_setup::mojom::FeatureState::kUnavailableNoVerifiedHost;
base::WeakPtrFactory<ProximityAuthProfilePrefManager> weak_ptr_factory_; base::WeakPtrFactory<ProximityAuthProfilePrefManager> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(ProximityAuthProfilePrefManager); DISALLOW_COPY_AND_ASSIGN(ProximityAuthProfilePrefManager);
......
...@@ -49,7 +49,8 @@ class ProximityAuthProfilePrefManagerTest : public testing::Test { ...@@ -49,7 +49,8 @@ class ProximityAuthProfilePrefManagerTest : public testing::Test {
}; };
TEST_F(ProximityAuthProfilePrefManagerTest, IsEasyUnlockAllowed) { TEST_F(ProximityAuthProfilePrefManagerTest, IsEasyUnlockAllowed) {
ProximityAuthProfilePrefManager pref_manager(&pref_service_); ProximityAuthProfilePrefManager pref_manager(
&pref_service_, nullptr /* multidevice_setup_service */);
EXPECT_TRUE(pref_manager.IsEasyUnlockAllowed()); EXPECT_TRUE(pref_manager.IsEasyUnlockAllowed());
// Simulating setting kEasyUnlockAllowed pref through enterprise policy. // Simulating setting kEasyUnlockAllowed pref through enterprise policy.
...@@ -59,7 +60,8 @@ TEST_F(ProximityAuthProfilePrefManagerTest, IsEasyUnlockAllowed) { ...@@ -59,7 +60,8 @@ TEST_F(ProximityAuthProfilePrefManagerTest, IsEasyUnlockAllowed) {
} }
TEST_F(ProximityAuthProfilePrefManagerTest, IsEasyUnlockEnabled) { TEST_F(ProximityAuthProfilePrefManagerTest, IsEasyUnlockEnabled) {
ProximityAuthProfilePrefManager pref_manager(&pref_service_); ProximityAuthProfilePrefManager pref_manager(
&pref_service_, nullptr /* multidevice_setup_service */);
EXPECT_TRUE(pref_manager.IsEasyUnlockEnabled()); EXPECT_TRUE(pref_manager.IsEasyUnlockEnabled());
pref_manager.SetIsEasyUnlockEnabled(true); pref_manager.SetIsEasyUnlockEnabled(true);
...@@ -70,7 +72,8 @@ TEST_F(ProximityAuthProfilePrefManagerTest, IsEasyUnlockEnabled) { ...@@ -70,7 +72,8 @@ TEST_F(ProximityAuthProfilePrefManagerTest, IsEasyUnlockEnabled) {
} }
TEST_F(ProximityAuthProfilePrefManagerTest, LastPromotionCheckTimestamp) { TEST_F(ProximityAuthProfilePrefManagerTest, LastPromotionCheckTimestamp) {
ProximityAuthProfilePrefManager pref_manager(&pref_service_); ProximityAuthProfilePrefManager pref_manager(
&pref_service_, nullptr /* multidevice_setup_service */);
EXPECT_EQ(0L, pref_manager.GetLastPromotionCheckTimestampMs()); EXPECT_EQ(0L, pref_manager.GetLastPromotionCheckTimestampMs());
pref_manager.SetLastPromotionCheckTimestampMs(kPromotionCheckTimestampMs1); pref_manager.SetLastPromotionCheckTimestampMs(kPromotionCheckTimestampMs1);
EXPECT_EQ(kPromotionCheckTimestampMs1, EXPECT_EQ(kPromotionCheckTimestampMs1,
...@@ -81,7 +84,8 @@ TEST_F(ProximityAuthProfilePrefManagerTest, LastPromotionCheckTimestamp) { ...@@ -81,7 +84,8 @@ TEST_F(ProximityAuthProfilePrefManagerTest, LastPromotionCheckTimestamp) {
} }
TEST_F(ProximityAuthProfilePrefManagerTest, PromotionShownCount) { TEST_F(ProximityAuthProfilePrefManagerTest, PromotionShownCount) {
ProximityAuthProfilePrefManager pref_manager(&pref_service_); ProximityAuthProfilePrefManager pref_manager(
&pref_service_, nullptr /* multidevice_setup_service */);
EXPECT_EQ(0, pref_manager.GetPromotionShownCount()); EXPECT_EQ(0, pref_manager.GetPromotionShownCount());
pref_manager.SetPromotionShownCount(1); pref_manager.SetPromotionShownCount(1);
EXPECT_EQ(1, pref_manager.GetPromotionShownCount()); EXPECT_EQ(1, pref_manager.GetPromotionShownCount());
...@@ -90,7 +94,8 @@ TEST_F(ProximityAuthProfilePrefManagerTest, PromotionShownCount) { ...@@ -90,7 +94,8 @@ TEST_F(ProximityAuthProfilePrefManagerTest, PromotionShownCount) {
} }
TEST_F(ProximityAuthProfilePrefManagerTest, ProximityThreshold) { TEST_F(ProximityAuthProfilePrefManagerTest, ProximityThreshold) {
ProximityAuthProfilePrefManager pref_manager(&pref_service_); ProximityAuthProfilePrefManager pref_manager(
&pref_service_, nullptr /* multidevice_setup_service */);
EXPECT_EQ(1, pref_manager.GetProximityThreshold()); EXPECT_EQ(1, pref_manager.GetProximityThreshold());
pref_manager.SetProximityThreshold(kProximityThreshold1); pref_manager.SetProximityThreshold(kProximityThreshold1);
EXPECT_EQ(kProximityThreshold1, pref_manager.GetProximityThreshold()); EXPECT_EQ(kProximityThreshold1, pref_manager.GetProximityThreshold());
...@@ -99,7 +104,8 @@ TEST_F(ProximityAuthProfilePrefManagerTest, ProximityThreshold) { ...@@ -99,7 +104,8 @@ TEST_F(ProximityAuthProfilePrefManagerTest, ProximityThreshold) {
} }
TEST_F(ProximityAuthProfilePrefManagerTest, IsChromeOSLoginEnabled) { TEST_F(ProximityAuthProfilePrefManagerTest, IsChromeOSLoginEnabled) {
ProximityAuthProfilePrefManager pref_manager(&pref_service_); ProximityAuthProfilePrefManager pref_manager(
&pref_service_, nullptr /* multidevice_setup_service */);
EXPECT_FALSE(pref_manager.IsChromeOSLoginEnabled()); EXPECT_FALSE(pref_manager.IsChromeOSLoginEnabled());
pref_manager.SetIsChromeOSLoginEnabled(true); pref_manager.SetIsChromeOSLoginEnabled(true);
...@@ -110,7 +116,8 @@ TEST_F(ProximityAuthProfilePrefManagerTest, IsChromeOSLoginEnabled) { ...@@ -110,7 +116,8 @@ TEST_F(ProximityAuthProfilePrefManagerTest, IsChromeOSLoginEnabled) {
} }
TEST_F(ProximityAuthProfilePrefManagerTest, SyncsToLocalPrefOnChange) { TEST_F(ProximityAuthProfilePrefManagerTest, SyncsToLocalPrefOnChange) {
ProximityAuthProfilePrefManager profile_pref_manager(&pref_service_); ProximityAuthProfilePrefManager profile_pref_manager(
&pref_service_, nullptr /* multidevice_setup_service */);
TestingPrefServiceSimple local_state; TestingPrefServiceSimple local_state;
AccountId account_id = AccountId::FromUserEmail(kUserEmail); AccountId account_id = AccountId::FromUserEmail(kUserEmail);
......
...@@ -77,7 +77,10 @@ class MockUnlockManager : public UnlockManager { ...@@ -77,7 +77,10 @@ class MockUnlockManager : public UnlockManager {
// Mock implementation of ProximityAuthProfilePrefManager. // Mock implementation of ProximityAuthProfilePrefManager.
class MockProximityAuthPrefManager : public ProximityAuthProfilePrefManager { class MockProximityAuthPrefManager : public ProximityAuthProfilePrefManager {
public: public:
MockProximityAuthPrefManager() : ProximityAuthProfilePrefManager(nullptr) {} MockProximityAuthPrefManager()
: ProximityAuthProfilePrefManager(
nullptr,
nullptr /* multidevice_setup_client */) {}
~MockProximityAuthPrefManager() override {} ~MockProximityAuthPrefManager() override {}
MOCK_CONST_METHOD0(GetLastPasswordEntryTimestampMs, int64_t()); MOCK_CONST_METHOD0(GetLastPasswordEntryTimestampMs, int64_t());
......
...@@ -61,7 +61,10 @@ class MockProximityMonitorObserver : public ProximityMonitorObserver { ...@@ -61,7 +61,10 @@ class MockProximityMonitorObserver : public ProximityMonitorObserver {
class MockProximityAuthPrefManager : public ProximityAuthProfilePrefManager { class MockProximityAuthPrefManager : public ProximityAuthProfilePrefManager {
public: public:
MockProximityAuthPrefManager() : ProximityAuthProfilePrefManager(nullptr) {} MockProximityAuthPrefManager()
: ProximityAuthProfilePrefManager(
nullptr,
nullptr /* multidevice_setup_client */) {}
~MockProximityAuthPrefManager() override {} ~MockProximityAuthPrefManager() override {}
MOCK_CONST_METHOD0(GetProximityThreshold, MOCK_CONST_METHOD0(GetProximityThreshold,
......
...@@ -24,7 +24,8 @@ const char kBetterTogetherSuiteEnabledPrefName[] = ...@@ -24,7 +24,8 @@ const char kBetterTogetherSuiteEnabledPrefName[] =
"multidevice_setup.suite_enabled"; "multidevice_setup.suite_enabled";
const char kInstantTetheringEnabledPrefName[] = "tether.enabled"; const char kInstantTetheringEnabledPrefName[] = "tether.enabled";
const char kMessagesEnabledPrefName[] = "multidevice.sms_connect_enabled"; const char kMessagesEnabledPrefName[] = "multidevice.sms_connect_enabled";
const char kSmartLockEnabledPrefName[] = "easy_unlock.enabled"; const char kSmartLockEnabledPrefName[] = "smart_lock.enabled";
const char kSmartLockEnabledDeprecatedPrefName[] = "easy_unlock.enabled";
void RegisterFeaturePrefs(PrefRegistrySimple* registry) { void RegisterFeaturePrefs(PrefRegistrySimple* registry) {
registry->RegisterBooleanPref(kInstantTetheringAllowedPrefName, true); registry->RegisterBooleanPref(kInstantTetheringAllowedPrefName, true);
...@@ -34,6 +35,7 @@ void RegisterFeaturePrefs(PrefRegistrySimple* registry) { ...@@ -34,6 +35,7 @@ void RegisterFeaturePrefs(PrefRegistrySimple* registry) {
registry->RegisterBooleanPref(kBetterTogetherSuiteEnabledPrefName, true); registry->RegisterBooleanPref(kBetterTogetherSuiteEnabledPrefName, true);
registry->RegisterBooleanPref(kInstantTetheringEnabledPrefName, true); registry->RegisterBooleanPref(kInstantTetheringEnabledPrefName, true);
registry->RegisterBooleanPref(kMessagesEnabledPrefName, true); registry->RegisterBooleanPref(kMessagesEnabledPrefName, true);
registry->RegisterBooleanPref(kSmartLockEnabledDeprecatedPrefName, true);
registry->RegisterBooleanPref(kSmartLockEnabledPrefName, true); registry->RegisterBooleanPref(kSmartLockEnabledPrefName, true);
} }
......
...@@ -27,6 +27,11 @@ extern const char kInstantTetheringEnabledPrefName[]; ...@@ -27,6 +27,11 @@ extern const char kInstantTetheringEnabledPrefName[];
extern const char kMessagesEnabledPrefName[]; extern const char kMessagesEnabledPrefName[];
extern const char kSmartLockEnabledPrefName[]; extern const char kSmartLockEnabledPrefName[];
// The old pref which controlled if Smart Lock was enabled, prior to the
// introduction of MultiDeviceSetupService. It will be removed once old Smart
// Lock code is fully deprecated.
extern const char kSmartLockEnabledDeprecatedPrefName[];
void RegisterFeaturePrefs(PrefRegistrySimple* registry); void RegisterFeaturePrefs(PrefRegistrySimple* registry);
bool AreAnyMultiDeviceFeaturesAllowed(PrefService* pref_service); bool AreAnyMultiDeviceFeaturesAllowed(PrefService* pref_service);
......
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