Chromium Code Reviews| Index: chrome/browser/ui/startup/startup_browser_creator.cc |
| diff --git a/chrome/browser/ui/startup/startup_browser_creator.cc b/chrome/browser/ui/startup/startup_browser_creator.cc |
| index 8cb76a7171ef019ee311ff43e2587668cccb3051..dfc48b10e470689b1408806dae5269869b61013a 100644 |
| --- a/chrome/browser/ui/startup/startup_browser_creator.cc |
| +++ b/chrome/browser/ui/startup/startup_browser_creator.cc |
| @@ -884,3 +884,80 @@ base::FilePath GetStartupProfilePath(const base::FilePath& user_data_dir, |
| return g_browser_process->profile_manager()->GetLastUsedProfileDir( |
| user_data_dir); |
| } |
| + |
| +#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| +Profile* GetStartupProfile(const base::FilePath& user_data_dir, |
| + const base::CommandLine& command_line) { |
| + ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| + |
| + base::FilePath profile_path = |
| + GetStartupProfilePath(user_data_dir, command_line); |
| + Profile* profile = profile_manager->GetProfile(profile_path); |
| + |
| + // If we're using the --new-profile-management flag and this profile is signed |
|
Mike Lerman
2016/06/20 01:09:36
it's not that the profile is signed out, it's that
WC Leung
2016/06/20 15:44:24
Acknowledged.
|
| + // out, then we should show the user manager instead. By switching the active |
| + // profile to the guest profile we ensure that no browser windows will be |
| + // opened for the guest profile. The initialization of guest profile is |
| + // possible to fail. |
| + if (switches::IsNewProfileManagement() && |
| + profile && !profile->IsGuestSession()) { |
| + auto& storage = profile_manager->GetProfileAttributesStorage(); |
| + ProfileAttributesEntry* entry; |
| + bool has_entry = storage.GetProfileAttributesWithPath(profile_path, &entry); |
| + |
| + if (has_entry && entry->IsSigninRequired()) { |
| + profile = |
| + profile_manager->GetProfile(ProfileManager::GetGuestProfilePath()); |
| + if (!profile_manager->GetProfile(ProfileManager::GetSystemProfilePath())) |
| + profile = nullptr; |
| + } |
| + } |
| + |
| + return profile; |
| +} |
| + |
| +Profile* GetFallbackStartupProfile() { |
| + ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| + // The only known reason for profiles to fail initialization is unable to |
| + // create the profile directory. This has already happened in the last used |
| + // profile before calling this function. Therefore, creation of all new |
| + // profiles is expected to fail. So only existing profiles are attempted for |
| + // fallback. |
| + |
| + // If the last used profile is unable to initialize, see if any of other last |
| + // opened profiles can initialize successfully. |
| + std::vector<Profile*> last_opened_profiles = |
| + ProfileManager::GetLastOpenedProfiles(); |
| + auto& storage = profile_manager->GetProfileAttributesStorage(); |
| + for (Profile* last_opened_profile : last_opened_profiles) { |
| + // Return any profile that is not signed out. |
| + ProfileAttributesEntry* entry; |
| + bool has_entry = storage.GetProfileAttributesWithPath( |
| + last_opened_profile->GetPath(), &entry); |
| + if (!has_entry || !entry->IsSigninRequired()) |
| + return last_opened_profile; |
| + } |
| + |
| + // If it still fails, try to initialize a guest profile and a system profile. |
| + // Show the user manager if this is successful. |
| + Profile* guest_profile = |
| + profile_manager->GetProfile(ProfileManager::GetGuestProfilePath()); |
| + Profile* system_profile = |
| + profile_manager->GetProfile(ProfileManager::GetSystemProfilePath()); |
| + if (guest_profile && system_profile) |
| + return guest_profile; |
| + |
| + // If still fails, try to open any profile that is not signed out. |
| + std::vector<ProfileAttributesEntry*> entries = |
| + storage.GetAllProfilesAttributes(); |
| + for (ProfileAttributesEntry* entry : entries) { |
| + if (!entry->IsSigninRequired()) { |
| + Profile* profile = profile_manager->GetProfile(entry->GetPath()); |
| + if (profile) |
| + return profile; |
| + } |
| + } |
| + |
| + return nullptr; |
| +} |
| +#endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |