Commit 9d3e646a authored by ginkage's avatar ginkage Committed by Commit bot

Always load signin profile on Chrome OS startup.

Starting a Chrome OS session (e.g. on Linux build) using "--login-profile=" and then pressing Ctrl+Shift+L triggers some nasty behavior, as the sign-in profile was not loaded yet (which is not the case during normal boot-up, as this profile is usually the first thing that loads). This patch aims to force its loading for such cases.
This affects not only stub login, but also any session that was restored.
Current patch reiterates CL from https://codereview.chromium.org/240333011/

BUG=346763

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

Cr-Commit-Position: refs/heads/master@{#318220}
parent 758b7e1c
...@@ -532,6 +532,12 @@ void ChromeBrowserMainPartsChromeos::PostProfileInit() { ...@@ -532,6 +532,12 @@ void ChromeBrowserMainPartsChromeos::PostProfileInit() {
// -- This used to be in ChromeBrowserMainParts::PreMainMessageLoopRun() // -- This used to be in ChromeBrowserMainParts::PreMainMessageLoopRun()
// -- just after CreateProfile(). // -- just after CreateProfile().
// Force loading of signin profile if it was not loaded before. It is possible
// when we are restoring session or skipping login screen for some other
// reason.
if (!chromeos::ProfileHelper::IsSigninProfile(profile()))
chromeos::ProfileHelper::GetSigninProfile();
BootTimesRecorder::Get()->OnChromeProcessStart(); BootTimesRecorder::Get()->OnChromeProcessStart();
// Initialize the network portal detector for Chrome OS. The network // Initialize the network portal detector for Chrome OS. The network
......
...@@ -529,6 +529,13 @@ class DriveFileSystemExtensionApiTest : public FileSystemExtensionApiTestBase { ...@@ -529,6 +529,13 @@ class DriveFileSystemExtensionApiTest : public FileSystemExtensionApiTestBase {
// DriveIntegrationService factory function for this test. // DriveIntegrationService factory function for this test.
drive::DriveIntegrationService* CreateDriveIntegrationService( drive::DriveIntegrationService* CreateDriveIntegrationService(
Profile* profile) { Profile* profile) {
// Ignore signin profile.
if (profile->GetPath() == chromeos::ProfileHelper::GetSigninProfileDir())
return NULL;
// DriveFileSystemExtensionApiTest doesn't expect that several user profiles
// could exist simultaneously.
DCHECK(fake_drive_service_ == NULL);
fake_drive_service_ = new drive::FakeDriveService; fake_drive_service_ = new drive::FakeDriveService;
fake_drive_service_->LoadAppListForDriveApi("drive/applist.json"); fake_drive_service_->LoadAppListForDriveApi("drive/applist.json");
......
...@@ -141,7 +141,8 @@ base::FilePath ProfileHelper::GetUserProfileDir( ...@@ -141,7 +141,8 @@ base::FilePath ProfileHelper::GetUserProfileDir(
// static // static
bool ProfileHelper::IsSigninProfile(const Profile* profile) { bool ProfileHelper::IsSigninProfile(const Profile* profile) {
return profile->GetPath().BaseName().value() == chrome::kInitialProfile; return profile &&
profile->GetPath().BaseName().value() == chrome::kInitialProfile;
} }
// static // static
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "chrome/browser/chromeos/drive/drive_integration_service.h" #include "chrome/browser/chromeos/drive/drive_integration_service.h"
#include "chrome/browser/chromeos/drive/file_system_interface.h" #include "chrome/browser/chromeos/drive/file_system_interface.h"
#include "chrome/browser/chromeos/drive/file_system_util.h" #include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/drive/fake_drive_service.h" #include "chrome/browser/drive/fake_drive_service.h"
#include "chrome/browser/extensions/api/file_system/file_system_api.h" #include "chrome/browser/extensions/api/file_system/file_system_api.h"
#include "chrome/browser/extensions/component_loader.h" #include "chrome/browser/extensions/component_loader.h"
...@@ -64,6 +65,13 @@ class FileSystemApiTestForDrive : public PlatformAppBrowserTest { ...@@ -64,6 +65,13 @@ class FileSystemApiTestForDrive : public PlatformAppBrowserTest {
private: private:
drive::DriveIntegrationService* CreateDriveIntegrationService( drive::DriveIntegrationService* CreateDriveIntegrationService(
Profile* profile) { Profile* profile) {
// Ignore signin profile.
if (profile->GetPath() == chromeos::ProfileHelper::GetSigninProfileDir())
return NULL;
// FileSystemApiTestForDrive doesn't expect that several user profiles could
// exist simultaneously.
DCHECK(fake_drive_service_ == NULL);
fake_drive_service_ = new drive::FakeDriveService; fake_drive_service_ = new drive::FakeDriveService;
fake_drive_service_->LoadAppListForDriveApi("drive/applist.json"); fake_drive_service_->LoadAppListForDriveApi("drive/applist.json");
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chromeos/chromeos_switches.h" #include "chromeos/chromeos_switches.h"
#endif #endif
...@@ -359,6 +360,15 @@ IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, ...@@ -359,6 +360,15 @@ IN_PROC_BROWSER_TEST_F(ProfileBrowserTest,
ASSERT_NE(loaded_profiles.size(), 0UL); ASSERT_NE(loaded_profiles.size(), 0UL);
Profile* profile = loaded_profiles[0]; Profile* profile = loaded_profiles[0];
#if defined(OS_CHROMEOS)
for (const auto& loaded_profile : loaded_profiles) {
if (!chromeos::ProfileHelper::IsSigninProfile(loaded_profile)) {
profile = loaded_profile;
break;
}
}
#endif
// This retry loop reduces flakiness due to the fact that this ultimately // This retry loop reduces flakiness due to the fact that this ultimately
// tests whether or not a code path hits a timed wait. // tests whether or not a code path hits a timed wait.
bool succeeded = false; bool succeeded = false;
......
...@@ -808,6 +808,11 @@ void ProfileManager::InitProfileUserPrefs(Profile* profile) { ...@@ -808,6 +808,11 @@ void ProfileManager::InitProfileUserPrefs(Profile* profile) {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
bool force_supervised_user_id = bool force_supervised_user_id =
#if defined(OS_CHROMEOS)
g_browser_process->platform_part()
->profile_helper()
->GetSigninProfileDir() != profile->GetPath() &&
#endif
command_line->HasSwitch(switches::kSupervisedUserId); command_line->HasSwitch(switches::kSupervisedUserId);
if (force_supervised_user_id) { if (force_supervised_user_id) {
supervised_user_id = supervised_user_id =
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "base/path_service.h" #include "base/path_service.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "chromeos/chromeos_switches.h" #include "chromeos/chromeos_switches.h"
...@@ -112,6 +113,22 @@ class PasswordStoreConsumerVerifier : ...@@ -112,6 +113,22 @@ class PasswordStoreConsumerVerifier :
bool called_; bool called_;
}; };
static base::FilePath GetFirstNonSigninProfile(const ProfileInfoCache& cache) {
#if defined(OS_CHROMEOS)
const base::FilePath signin_path =
chromeos::ProfileHelper::GetSigninProfileDir();
size_t i, profile_num = cache.GetNumberOfProfiles();
for (i = 0; i != profile_num; ++i) {
base::FilePath profile_path = cache.GetPathOfProfileAtIndex(i);
if (profile_path != signin_path)
return profile_path;
}
return base::FilePath();
#else
return cache.GetPathOfProfileAtIndex(0);
#endif
}
} // namespace } // namespace
// This file contains tests for the ProfileManager that require a heavyweight // This file contains tests for the ProfileManager that require a heavyweight
...@@ -280,10 +297,11 @@ IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, ...@@ -280,10 +297,11 @@ IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest,
ProfileManager* profile_manager = g_browser_process->profile_manager(); ProfileManager* profile_manager = g_browser_process->profile_manager();
ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
base::FilePath path_profile1 = cache.GetPathOfProfileAtIndex(0); size_t initial_profile_count = profile_manager->GetNumberOfProfiles();
base::FilePath path_profile1 = GetFirstNonSigninProfile(cache);
ASSERT_EQ(profile_manager->GetNumberOfProfiles(), 1U); ASSERT_NE(0U, initial_profile_count);
EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U); EXPECT_EQ(1U, chrome::GetTotalBrowserCount());
// Create an additional profile. // Create an additional profile.
base::FilePath path_profile2 = base::FilePath path_profile2 =
...@@ -299,14 +317,14 @@ IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, ...@@ -299,14 +317,14 @@ IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest,
chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop();
BrowserList* browser_list = BrowserList::GetInstance(desktop_type); BrowserList* browser_list = BrowserList::GetInstance(desktop_type);
ASSERT_EQ(cache.GetNumberOfProfiles(), 2U); ASSERT_EQ(initial_profile_count + 1, cache.GetNumberOfProfiles());
EXPECT_EQ(1U, browser_list->size()); EXPECT_EQ(1U, browser_list->size());
// Open a browser window for the first profile. // Open a browser window for the first profile.
profiles::SwitchToProfile(path_profile1, desktop_type, false, profiles::SwitchToProfile(path_profile1, desktop_type, false,
kOnProfileSwitchDoNothing, kOnProfileSwitchDoNothing,
ProfileMetrics::SWITCH_PROFILE_ICON); ProfileMetrics::SWITCH_PROFILE_ICON);
EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U); EXPECT_EQ(1U, chrome::GetTotalBrowserCount());
EXPECT_EQ(1U, browser_list->size()); EXPECT_EQ(1U, browser_list->size());
EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath());
...@@ -314,7 +332,7 @@ IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, ...@@ -314,7 +332,7 @@ IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest,
profiles::SwitchToProfile(path_profile2, desktop_type, false, profiles::SwitchToProfile(path_profile2, desktop_type, false,
kOnProfileSwitchDoNothing, kOnProfileSwitchDoNothing,
ProfileMetrics::SWITCH_PROFILE_ICON); ProfileMetrics::SWITCH_PROFILE_ICON);
EXPECT_EQ(chrome::GetTotalBrowserCount(), 2U); EXPECT_EQ(2U, chrome::GetTotalBrowserCount());
EXPECT_EQ(2U, browser_list->size()); EXPECT_EQ(2U, browser_list->size());
EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath());
...@@ -322,7 +340,7 @@ IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, ...@@ -322,7 +340,7 @@ IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest,
profiles::SwitchToProfile(path_profile1, desktop_type, false, profiles::SwitchToProfile(path_profile1, desktop_type, false,
kOnProfileSwitchDoNothing, kOnProfileSwitchDoNothing,
ProfileMetrics::SWITCH_PROFILE_ICON); ProfileMetrics::SWITCH_PROFILE_ICON);
EXPECT_EQ(chrome::GetTotalBrowserCount(), 2U); EXPECT_EQ(2U, chrome::GetTotalBrowserCount());
EXPECT_EQ(2U, browser_list->size()); EXPECT_EQ(2U, browser_list->size());
EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath());
...@@ -349,9 +367,10 @@ IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, MAYBE_EphemeralProfile) { ...@@ -349,9 +367,10 @@ IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, MAYBE_EphemeralProfile) {
ProfileManager* profile_manager = g_browser_process->profile_manager(); ProfileManager* profile_manager = g_browser_process->profile_manager();
ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
base::FilePath path_profile1 = cache.GetPathOfProfileAtIndex(0); size_t initial_profile_count = profile_manager->GetNumberOfProfiles();
base::FilePath path_profile1 = GetFirstNonSigninProfile(cache);
ASSERT_EQ(1U, profile_manager->GetNumberOfProfiles()); ASSERT_NE(0U, initial_profile_count);
EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); EXPECT_EQ(1U, chrome::GetTotalBrowserCount());
// Create an ephemeral profile. // Create an ephemeral profile.
...@@ -367,7 +386,7 @@ IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, MAYBE_EphemeralProfile) { ...@@ -367,7 +386,7 @@ IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, MAYBE_EphemeralProfile) {
chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop();
BrowserList* browser_list = BrowserList::GetInstance(desktop_type); BrowserList* browser_list = BrowserList::GetInstance(desktop_type);
ASSERT_EQ(2U, cache.GetNumberOfProfiles()); ASSERT_EQ(initial_profile_count + 1, cache.GetNumberOfProfiles());
EXPECT_EQ(1U, browser_list->size()); EXPECT_EQ(1U, browser_list->size());
// Open a browser window for the second profile. // Open a browser window for the second profile.
...@@ -393,13 +412,13 @@ IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, MAYBE_EphemeralProfile) { ...@@ -393,13 +412,13 @@ IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, MAYBE_EphemeralProfile) {
browser_list->get(2)->window()->Close(); browser_list->get(2)->window()->Close();
content::RunAllPendingInMessageLoop(); content::RunAllPendingInMessageLoop();
EXPECT_EQ(2U, browser_list->size()); EXPECT_EQ(2U, browser_list->size());
ASSERT_EQ(2U, cache.GetNumberOfProfiles()); EXPECT_EQ(initial_profile_count + 1, cache.GetNumberOfProfiles());
// The second should though. // The second should though.
browser_list->get(1)->window()->Close(); browser_list->get(1)->window()->Close();
content::RunAllPendingInMessageLoop(); content::RunAllPendingInMessageLoop();
EXPECT_EQ(1U, browser_list->size()); EXPECT_EQ(1U, browser_list->size());
ASSERT_EQ(1U, cache.GetNumberOfProfiles()); EXPECT_EQ(initial_profile_count, cache.GetNumberOfProfiles());
} }
// The test makes sense on those platforms where the keychain exists. // The test makes sense on those platforms where the keychain exists.
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chromeos/chromeos_switches.h" #include "chromeos/chromeos_switches.h"
#endif #endif
...@@ -1028,6 +1029,18 @@ IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, StartAndStop) { ...@@ -1028,6 +1029,18 @@ IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, StartAndStop) {
// Change the other pref. SBS should stop now. // Change the other pref. SBS should stop now.
pref_service2->SetBoolean(prefs::kSafeBrowsingEnabled, false); pref_service2->SetBoolean(prefs::kSafeBrowsingEnabled, false);
WaitForIOThread(); WaitForIOThread();
// TODO(mattm): Remove this when crbug.com/461493 is fixed.
#if defined(OS_CHROMEOS)
// On Chrome OS we should disable safe browsing for signin profile.
EXPECT_TRUE(sb_service->enabled());
EXPECT_TRUE(csd_service->enabled());
chromeos::ProfileHelper::GetSigninProfile()
->GetOriginalProfile()
->GetPrefs()
->SetBoolean(prefs::kSafeBrowsingEnabled, false);
WaitForIOThread();
#endif
EXPECT_FALSE(sb_service->enabled()); EXPECT_FALSE(sb_service->enabled());
EXPECT_FALSE(csd_service->enabled()); EXPECT_FALSE(csd_service->enabled());
......
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