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