Commit e84f9035 authored by tengs's avatar tengs Committed by Commit bot

Copy Smart Lock user preferences to local state so we can access them on the sign-in screen.

The only preference right now is proximityRequired, which is now returned
through the chrome.easyUnlockPrivate.getUserInfo API.

BUG=403419

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

Cr-Commit-Position: refs/heads/master@{#313409}
parent f69037c6
......@@ -696,6 +696,10 @@ bool EasyUnlockPrivateGetUserInfoFunction::RunSync() {
users[0]->logged_in = service->GetType() == EasyUnlockService::TYPE_REGULAR;
users[0]->data_ready = users[0]->logged_in ||
service->GetRemoteDevices() != NULL;
EasyUnlockService::UserSettings user_settings =
EasyUnlockService::GetUserSettings(user_id);
users[0]->require_close_proximity = user_settings.require_close_proximity;
}
results_ = easy_unlock_private::GetUserInfo::Results::Create(users);
return true;
......
......@@ -65,6 +65,13 @@ PrefService* GetLocalState() {
} // namespace
EasyUnlockService::UserSettings::UserSettings()
: require_close_proximity(false) {
}
EasyUnlockService::UserSettings::~UserSettings() {
}
// static
EasyUnlockService* EasyUnlockService::Get(Profile* profile) {
return EasyUnlockServiceFactory::GetForProfile(profile);
......@@ -233,6 +240,7 @@ void EasyUnlockService::RegisterProfilePrefs(
// static
void EasyUnlockService::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterDictionaryPref(prefs::kEasyUnlockLocalStateUserPrefs);
registry->RegisterDictionaryPref(prefs::kEasyUnlockHardlockState);
#if defined(OS_CHROMEOS)
EasyUnlockTpmKeyManager::RegisterLocalStatePrefs(registry);
......@@ -255,6 +263,33 @@ void EasyUnlockService::ResetLocalStateForUser(const std::string& user_id) {
#endif
}
// static
EasyUnlockService::UserSettings EasyUnlockService::GetUserSettings(
const std::string& user_id) {
DCHECK(!user_id.empty());
UserSettings user_settings;
PrefService* local_state = GetLocalState();
if (!local_state)
return user_settings;
const base::DictionaryValue* all_user_prefs_dict =
local_state->GetDictionary(prefs::kEasyUnlockLocalStateUserPrefs);
if (!all_user_prefs_dict)
return user_settings;
const base::DictionaryValue* user_prefs_dict;
if (!all_user_prefs_dict->GetDictionaryWithoutPathExpansion(user_id,
&user_prefs_dict))
return user_settings;
user_prefs_dict->GetBooleanWithoutPathExpansion(
prefs::kEasyUnlockProximityRequired,
&user_settings.require_close_proximity);
return user_settings;
}
bool EasyUnlockService::IsAllowed() {
if (shut_down_)
return false;
......
......@@ -50,6 +50,16 @@ class EasyUnlockService : public KeyedService {
TYPE_SIGNIN
};
// Easy Unlock settings that the user can configure.
struct UserSettings {
UserSettings();
~UserSettings();
// Whether to require the remote device to be in very close proximity
// before allowing unlock (~1 feet).
bool require_close_proximity;
};
// Gets EasyUnlockService instance.
static EasyUnlockService* Get(Profile* profile);
......@@ -66,6 +76,9 @@ class EasyUnlockService : public KeyedService {
// Removes the hardlock state for the given user.
static void ResetLocalStateForUser(const std::string& user_id);
// Returns the user's preferences.
static UserSettings GetUserSettings(const std::string& user_id);
// Returns true if Easy sign-in is enabled.
static bool IsSignInEnabled();
......
......@@ -9,6 +9,7 @@
#include "base/prefs/pref_service.h"
#include "base/prefs/scoped_user_pref_update.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
......@@ -257,6 +258,9 @@ void EasyUnlockServiceRegular::InitializeInternal() {
prefs::kEasyUnlockAllowed,
base::Bind(&EasyUnlockServiceRegular::OnPrefsChanged,
base::Unretained(this)));
registrar_.Add(prefs::kEasyUnlockProximityRequired,
base::Bind(&EasyUnlockServiceRegular::OnPrefsChanged,
base::Unretained(this)));
OnPrefsChanged();
}
......@@ -288,6 +292,7 @@ bool EasyUnlockServiceRegular::IsAllowedInternal() {
}
void EasyUnlockServiceRegular::OnPrefsChanged() {
SyncProfilePrefsToLocalState();
UpdateAppState();
}
......@@ -310,3 +315,24 @@ void EasyUnlockServiceRegular::OnToggleEasyUnlockApiFailed(
LOG(WARNING) << "Failed to turn off Smart Lock: " << error_message;
SetTurnOffFlowStatus(FAIL);
}
void EasyUnlockServiceRegular::SyncProfilePrefsToLocalState() {
PrefService* local_state =
g_browser_process ? g_browser_process->local_state() : NULL;
PrefService* profile_prefs = profile()->GetPrefs();
if (!local_state || !profile_prefs)
return;
// Create the dictionary of Easy Unlock preferences for the current user. The
// items in the dictionary are the same profile prefs used for Easy Unlock.
scoped_ptr<base::DictionaryValue> user_prefs_dict(
new base::DictionaryValue());
user_prefs_dict->SetBooleanWithoutPathExpansion(
prefs::kEasyUnlockProximityRequired,
profile_prefs->GetBoolean(prefs::kEasyUnlockProximityRequired));
DictionaryPrefUpdate update(local_state,
prefs::kEasyUnlockLocalStateUserPrefs);
std::string user_email = GetUserEmail();
update->SetWithoutPathExpansion(user_email, user_prefs_dict.Pass());
}
......@@ -89,6 +89,10 @@ class EasyUnlockServiceRegular : public EasyUnlockService {
scoped_ptr<chromeos::ShortLivedUserContext> short_lived_user_context_;
#endif
// Updates local state with the preference from the user's profile, so they
// can be accessed on the sign-in screen.
void SyncProfilePrefsToLocalState();
PrefChangeRegistrar registrar_;
TurnOffFlowStatus turn_off_flow_status_;
......
......@@ -143,6 +143,10 @@ namespace easyUnlockPrivate {
// the signin screen.
boolean loggedIn;
// Whether to require the remote device to be in very close proximity before
// allowing unlock (~1 feet).
boolean requireCloseProximity;
// Whether all data needed to use Easy unlock service has been loaded for
// the user.
boolean dataReady;
......
......@@ -1214,6 +1214,12 @@ const char kEasyUnlockAllowed[] = "easy_unlock.allowed";
// Whether Easy Unlock is enabled.
const char kEasyUnlockEnabled[] = "easy_unlock.enabled";
// A dictionary in local state containing each user's Easy Unlock profile
// preferences, so they can be accessed outside of the user's profile. The value
// is a dictionary containing an entry for each user. Each user's entry mirrors
// their profile's Easy Unlock preferences.
const char kEasyUnlockLocalStateUserPrefs[] = "easy_unlock.user_prefs";
// Preference storing Easy Unlock pairing data.
const char kEasyUnlockPairing[] = "easy_unlock.pairing";
......
......@@ -406,6 +406,7 @@ extern const char kPushMessagingRegistrationCount[];
extern const char kEasyUnlockAllowed[];
extern const char kEasyUnlockEnabled[];
extern const char kEasyUnlockLocalStateUserPrefs[];
extern const char kEasyUnlockPairing[];
extern const char kEasyUnlockProximityRequired[];
extern const char kEasyUnlockShowTutorial[];
......
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