Commit aa6da7f1 authored by mlerman's avatar mlerman Committed by Commit bot

Profile unlock should always use session restore, regardless of system preference.

The UserManager will now set the ProfileInfoCache's "signin required" bit to false after the browser's opened rather than before, so that it can be read during startup.

BUG=420762

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

Cr-Commit-Position: refs/heads/master@{#302459}
parent 56957b6e
...@@ -4,11 +4,13 @@ ...@@ -4,11 +4,13 @@
#include "chrome/browser/ui/startup/session_crashed_infobar_delegate.h" #include "chrome/browser/ui/startup/session_crashed_infobar_delegate.h"
#include "base/files/scoped_temp_dir.h"
#include "base/prefs/pref_registry_simple.h" #include "base/prefs/pref_registry_simple.h"
#include "base/prefs/testing_pref_service.h" #include "base/prefs/testing_pref_service.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/prefs/browser_prefs.h" #include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/sessions/session_service_factory.h" #include "chrome/browser/sessions/session_service_factory.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
...@@ -27,15 +29,23 @@ class SessionCrashedInfoBarDelegateUnitTest : public BrowserWithTestWindowTest { ...@@ -27,15 +29,23 @@ class SessionCrashedInfoBarDelegateUnitTest : public BrowserWithTestWindowTest {
// This needs to be called after the local state is set, because it will // This needs to be called after the local state is set, because it will
// create a browser which will try to read from the local state. // create a browser which will try to read from the local state.
BrowserWithTestWindowTest::SetUp(); BrowserWithTestWindowTest::SetUp();
// Make sure we have a Profile Manager.
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
TestingBrowserProcess::GetGlobal()->SetProfileManager(
new ProfileManagerWithoutInit(temp_dir_.path()));
} }
void TearDown() override { void TearDown() override {
static_cast<TestingBrowserProcess*>(g_browser_process)->SetLocalState(NULL); static_cast<TestingBrowserProcess*>(g_browser_process)->SetLocalState(NULL);
BrowserWithTestWindowTest::TearDown(); BrowserWithTestWindowTest::TearDown();
TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL);
} }
private: private:
TestingPrefServiceSimple pref_service; TestingPrefServiceSimple pref_service;
base::ScopedTempDir temp_dir_;
}; };
TEST_F(SessionCrashedInfoBarDelegateUnitTest, DetachingTabWithCrashedInfoBar) { TEST_F(SessionCrashedInfoBarDelegateUnitTest, DetachingTabWithCrashedInfoBar) {
......
...@@ -388,6 +388,19 @@ SessionStartupPref StartupBrowserCreator::GetSessionStartupPref( ...@@ -388,6 +388,19 @@ SessionStartupPref StartupBrowserCreator::GetSessionStartupPref(
!profile->IsNewProfile()) { !profile->IsNewProfile()) {
pref.type = SessionStartupPref::LAST; pref.type = SessionStartupPref::LAST;
} }
// A browser starting for a profile being unlocked should always restore.
if (!profile->IsGuestSession()) {
ProfileInfoCache& info_cache =
g_browser_process->profile_manager()->GetProfileInfoCache();
size_t index = info_cache.GetIndexOfProfileWithPath(profile->GetPath());
if (index != std::string::npos &&
info_cache.ProfileIsSigninRequiredAtIndex(index)) {
pref.type = SessionStartupPref::LAST;
}
}
if (pref.type == SessionStartupPref::LAST && if (pref.type == SessionStartupPref::LAST &&
IncognitoModePrefs::ShouldLaunchIncognito(command_line, prefs)) { IncognitoModePrefs::ShouldLaunchIncognito(command_line, prefs)) {
// We don't store session information when incognito. If the user has // We don't store session information when incognito. If the user has
......
...@@ -697,8 +697,6 @@ void UserManagerScreenHandler::ReportAuthenticationResult( ...@@ -697,8 +697,6 @@ void UserManagerScreenHandler::ReportAuthenticationResult(
if (success) { if (success) {
ProfileInfoCache& info_cache = ProfileInfoCache& info_cache =
g_browser_process->profile_manager()->GetProfileInfoCache(); g_browser_process->profile_manager()->GetProfileInfoCache();
info_cache.SetProfileSigninRequiredAtIndex(
authenticating_profile_index_, false);
base::FilePath path = info_cache.GetPathOfProfileAtIndex( base::FilePath path = info_cache.GetPathOfProfileAtIndex(
authenticating_profile_index_); authenticating_profile_index_);
profiles::SwitchToProfile( profiles::SwitchToProfile(
...@@ -724,6 +722,15 @@ void UserManagerScreenHandler::ReportAuthenticationResult( ...@@ -724,6 +722,15 @@ void UserManagerScreenHandler::ReportAuthenticationResult(
void UserManagerScreenHandler::OnBrowserWindowReady(Browser* browser) { void UserManagerScreenHandler::OnBrowserWindowReady(Browser* browser) {
DCHECK(browser); DCHECK(browser);
DCHECK(browser->window()); DCHECK(browser->window());
// Unlock the profile after browser opens so startup can read the lock bit.
// Any necessary authentication must have been successful to reach this point.
ProfileInfoCache& info_cache =
g_browser_process->profile_manager()->GetProfileInfoCache();
size_t index = info_cache.GetIndexOfProfileWithPath(
browser->profile()->GetPath());
info_cache.SetProfileSigninRequiredAtIndex(index, false);
if (url_hash_ == profiles::kUserManagerSelectProfileTaskManager) { if (url_hash_ == profiles::kUserManagerSelectProfileTaskManager) {
base::MessageLoop::current()->PostTask( base::MessageLoop::current()->PostTask(
FROM_HERE, base::Bind(&chrome::OpenTaskManager, browser)); FROM_HERE, base::Bind(&chrome::OpenTaskManager, browser));
......
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