Multiprofile: switch to newly added user to the session

This CL remember pending user switch and do it as soon as profile
ready. From UI perspective this look very smooth because profile loading
is actually fast so previous desktop is not shown. But if it will be
a problem on slow device we may need to stay on add user screen a bit longer.

BUG=333879
TEST=manual
R=nkostylev@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266239 0039d316-1c4b-4281-b951-d872f2087c98
parent 9eabd003
......@@ -915,9 +915,6 @@ class MultiProfileFileManagerBrowserTest : public FileManagerBrowserTestBase {
const TestAccountInfo& info = kTestAccounts[PRIMARY_ACCOUNT_INDEX];
AddUser(info, true);
chromeos::UserManager* const user_manager = chromeos::UserManager::Get();
if (user_manager->GetActiveUser() != user_manager->FindUser(info.email))
chromeos::UserManager::Get()->SwitchActiveUser(info.email);
FileManagerBrowserTestBase::SetUpOnMainThread();
}
......
......@@ -424,9 +424,9 @@ void UserManagerImpl::UserLoggedIn(const std::string& user_id,
lru_logged_in_users_.push_back(user);
// Reset the new user flag if the user already exists.
is_current_user_new_ = false;
// Set active user wallpaper back.
WallpaperManager::Get()->SetUserWallpaperNow(active_user_->email());
NotifyUserAddedToSession(user);
// Remember that we need to switch to this user as soon as profile ready.
pending_user_switch_ = user_id;
return;
}
......@@ -971,7 +971,18 @@ void UserManagerImpl::Observe(int type,
User* user = GetUserByProfile(profile);
if (user != NULL)
user->set_profile_is_created();
// If there is pending user switch, do it now.
if (!pending_user_switch_.empty()) {
// Call SwitchActiveUser async because otherwise it may cause
// ProfileManager::GetProfile before the profile gets registered
// in ProfileManager. It happens in case of sync profile load when
// NOTIFICATION_PROFILE_CREATED is called synchronously.
base::MessageLoop::current()->PostTask(FROM_HERE,
base::Bind(&UserManagerImpl::SwitchActiveUser,
base::Unretained(this),
pending_user_switch_));
pending_user_switch_.clear();
}
break;
}
default:
......
......@@ -483,6 +483,10 @@ class UserManagerImpl
scoped_ptr<policy::CloudExternalDataPolicyObserver>
wallpaper_policy_observer_;
// ID of the user just added to the session that needs to be activated
// as soon as user's profile is loaded.
std::string pending_user_switch_;
DISALLOW_COPY_AND_ASSIGN(UserManagerImpl);
};
......
......@@ -153,19 +153,15 @@ IN_PROC_BROWSER_TEST_F(PreferencesTest, MultiProfiles) {
// Add second user and init its prefs with different values.
UserAddingScreen::Get()->Start();
content::RunAllPendingInMessageLoop();
DisableAnimations();
AddUser(kTestUsers[1]);
EXPECT_TRUE(user1->is_active());
content::RunAllPendingInMessageLoop();
const User* user2 = user_manager->FindUser(kTestUsers[1]);
EXPECT_TRUE(user2->is_active());
PrefService* prefs2 = user_manager->GetProfileByUser(user2)->GetPrefs();
SetPrefs(prefs2, true);
// First user is still active, so settings was not changed.
EXPECT_TRUE(user1->is_active());
CheckSettingsCorrespondToPrefs(prefs1);
// Switch user and check that settings was changed accordingly.
DisableAnimations();
user_manager->SwitchActiveUser(kTestUsers[1]);
// Check that settings were changed accordingly.
EXPECT_TRUE(user2->is_active());
CheckSettingsCorrespondToPrefs(prefs2);
......
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