Commit cfddc360 authored by xiyuan's avatar xiyuan Committed by Commit bot

easy-signin: Defer chrome restart until key ops finish.

BUG=412006

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

Cr-Commit-Position: refs/heads/master@{#296983}
parent ff80a901
......@@ -164,6 +164,10 @@ bool CanPerformEarlyRestart() {
if (controller->auth_mode() != LoginPerformer::AUTH_MODE_INTERNAL)
return false;
// No early restart if Easy unlock key needs to be updated.
if (UserSessionManager::GetInstance()->NeedsToUpdateEasyUnlockKeys())
return false;
return true;
}
......@@ -453,6 +457,14 @@ void LoginUtilsImpl::OnRlzInitialized() {
#endif
void LoginUtilsImpl::AttemptRestart(Profile* profile) {
if (UserSessionManager::GetInstance()
->CheckEasyUnlockKeyOps(
base::Bind(&LoginUtilsImpl::AttemptRestart,
base::Unretained(this),
profile))) {
return;
}
if (UserSessionManager::GetInstance()->GetSigninSessionRestoreStrategy() !=
OAuth2LoginManager::RESTORE_FROM_COOKIE_JAR) {
chrome::AttemptRestart();
......
......@@ -223,7 +223,8 @@ UserSessionManager::UserSessionManager()
user_sessions_restore_in_progress_(false),
exit_after_session_restore_(false),
session_restore_strategy_(
OAuth2LoginManager::RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN) {
OAuth2LoginManager::RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN),
running_easy_unlock_key_ops_(false) {
net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
user_manager::UserManager::Get()->AddSessionStateObserver(this);
}
......@@ -449,6 +450,25 @@ bool UserSessionManager::RespectLocalePreference(
return true;
}
bool UserSessionManager::NeedsToUpdateEasyUnlockKeys() const {
return CommandLine::ForCurrentProcess()->HasSwitch(
chromeos::switches::kEnableEasySignin) &&
!user_context_.GetUserID().empty() &&
user_context_.GetUserType() == user_manager::USER_TYPE_REGULAR &&
user_context_.GetKey() && !user_context_.GetKey()->GetSecret().empty();
}
bool UserSessionManager::CheckEasyUnlockKeyOps(const base::Closure& callback) {
if (!running_easy_unlock_key_ops_)
return false;
// Assumes only one deferred callback is needed.
DCHECK(easy_unlock_key_ops_finished_callback_.is_null());
easy_unlock_key_ops_finished_callback_ = callback;
return true;
}
void UserSessionManager::AddSessionStateObserver(
chromeos::UserSessionStateObserver* observer) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
......@@ -793,6 +813,9 @@ void UserSessionManager::FinalizePrepareProfile(Profile* profile) {
InitializeCRLSetFetcher(user);
}
UpdateEasyUnlockKeys(profile);
user_context_.ClearSecrets();
// TODO(nkostylev): This pointer should probably never be NULL, but it looks
// like LoginUtilsImpl::OnProfileCreated() may be getting called before
// UserSessionManager::PrepareProfile() has set |delegate_| when Chrome is
......@@ -801,9 +824,6 @@ void UserSessionManager::FinalizePrepareProfile(Profile* profile) {
// resolved.
if (delegate_)
delegate_->OnProfilePrepared(profile);
UpdateEasyUnlockKeys(profile);
user_context_.ClearSecrets();
}
void UserSessionManager::InitSessionRestoreStrategy() {
......@@ -1029,17 +1049,28 @@ void UserSessionManager::UpdateEasyUnlockKeys(Profile* user_profile) {
if (EasyUnlockService::Get(user_profile))
device_list = EasyUnlockService::Get(user_profile)->GetRemoteDevices();
running_easy_unlock_key_ops_ = true;
if (device_list) {
easy_unlock_key_manager_->RefreshKeys(
user_context_,
*device_list,
EasyUnlockKeyManager::RefreshKeysCallback());
base::Bind(&UserSessionManager::OnEasyUnlockKeyOpsFinished,
AsWeakPtr()));
} else {
easy_unlock_key_manager_->RemoveKeys(
user_context_, 0, EasyUnlockKeyManager::RemoveKeysCallback());
user_context_,
0,
base::Bind(&UserSessionManager::OnEasyUnlockKeyOpsFinished,
AsWeakPtr()));
}
}
void UserSessionManager::OnEasyUnlockKeyOpsFinished(bool success) {
running_easy_unlock_key_ops_ = false;
if (!easy_unlock_key_ops_finished_callback_.is_null())
easy_unlock_key_ops_finished_callback_.Run();
}
void UserSessionManager::ActiveUserChanged(
const user_manager::User* active_user) {
Profile* profile = ProfileHelper::Get()->GetProfileByUser(active_user);
......
......@@ -8,6 +8,7 @@
#include <string>
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
#include "base/memory/weak_ptr.h"
......@@ -143,12 +144,18 @@ class UserSessionManager
// Changes browser locale (selects best suitable locale from different
// user settings). Returns true if callback will be called.
// Returns true if callback will be called.
bool RespectLocalePreference(
Profile* profile,
const user_manager::User* user,
scoped_ptr<locale_util::SwitchLanguageCallback> callback) const;
// Returns true if Easy unlock keys needs to be updated.
bool NeedsToUpdateEasyUnlockKeys() const;
// Returns true if there are pending Easy unlock key operations and
// |callback| will be invoked when it is done.
bool CheckEasyUnlockKeyOps(const base::Closure& callback);
void AddSessionStateObserver(chromeos::UserSessionStateObserver* observer);
void RemoveSessionStateObserver(chromeos::UserSessionStateObserver* observer);
......@@ -248,6 +255,9 @@ class UserSessionManager
// Update Easy unlock cryptohome keys using the pairing data in user prefs.
void UpdateEasyUnlockKeys(Profile* user_profile);
// Callback invoked when Easy unlock key operations are finished.
void OnEasyUnlockKeyOpsFinished(bool success);
UserSessionManagerDelegate* delegate_;
// Authentication/user context.
......@@ -299,6 +309,8 @@ class UserSessionManager
// Manages Easy unlock cryptohome keys.
scoped_ptr<EasyUnlockKeyManager> easy_unlock_key_manager_;
bool running_easy_unlock_key_ops_;
base::Closure easy_unlock_key_ops_finished_callback_;
DISALLOW_COPY_AND_ASSIGN(UserSessionManager);
};
......
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