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..7f7a64a36b806098bdc1941b8f7f71bebb99a1fd 100644 |
| --- a/chrome/browser/ui/startup/startup_browser_creator.cc |
| +++ b/chrome/browser/ui/startup/startup_browser_creator.cc |
| @@ -884,3 +884,79 @@ 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 there is no entry in profile attributes storage, the profile is deleted, |
| + // and we should show the user manager. Also, when using |
| + // --new-profile-management, if the profile is locked we should show the user |
| + // manager as well. When neither of these is true, we can safely start up with |
| + // |profile|. |
| + auto* storage = &profile_manager->GetProfileAttributesStorage(); |
| + ProfileAttributesEntry* entry; |
| + bool has_entry = storage->GetProfileAttributesWithPath(profile_path, &entry); |
| + if (has_entry && (!switches::IsNewProfileManagement() || |
| + !entry->IsSigninRequired() || !profile)) { |
| + return profile; |
| + } |
| + |
| + // We want to show the user manager. To indicate this, return the guest |
| + // profile. However, we can only do this if the system profile (where the user |
| + // manager lives) also exists (or is creatable). |
| + return profile_manager->GetProfile(ProfileManager::GetSystemProfilePath()) ? |
| + profile_manager->GetProfile(ProfileManager::GetGuestProfilePath()) : |
| + nullptr; |
| +} |
| + |
| +Profile* GetFallbackStartupProfile() { |
| + ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| + // The only known reason for profiles to fail initialization is unable to |
|
Peter Kasting
2016/07/19 21:56:07
Nit: unable -> being unable
WC Leung
2016/07/27 18:00:06
Done.
|
| + // create the profile directory, and this has already happened in |
| + // GetStartupProfilePath() before calling this function. In this case, |
| + // creation of 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. |
|
Peter Kasting
2016/07/19 21:56:06
Nit: "The last used profile could not be initializ
WC Leung
2016/07/27 18:00:05
Done.
|
| + std::vector<Profile*> last_opened_profiles = |
| + ProfileManager::GetLastOpenedProfiles(); |
| + auto& storage = profile_manager->GetProfileAttributesStorage(); |
|
Peter Kasting
2016/07/19 21:56:07
Nit: Use auto* storage = &...
WC Leung
2016/07/27 18:00:05
Oh my bad... should have done this before. Why I d
|
| + for (Profile* last_opened_profile : last_opened_profiles) { |
|
Peter Kasting
2016/07/19 21:56:06
Nit: Avoids extra temp:
for (Profile* profile :
WC Leung
2016/07/27 18:00:05
Done.
|
| + // Return any profile that is not locked. |
| + 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. |
|
Peter Kasting
2016/07/19 21:56:07
Nit: "Couldn't initialize any last opened profiles
WC Leung
2016/07/27 18:00:06
Done.
|
| + 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 locked. |
|
Peter Kasting
2016/07/19 21:56:07
Nit: "Couldn't show the user manager either. Try
WC Leung
2016/07/27 18:00:05
Done.
|
| + std::vector<ProfileAttributesEntry*> entries = |
| + storage.GetAllProfilesAttributes(); |
| + for (ProfileAttributesEntry* entry : entries) { |
|
Peter Kasting
2016/07/19 21:56:07
Nit: Avoids extra temp:
for (ProfileAttributesE
WC Leung
2016/07/27 18:00:05
Done.
|
| + if (!entry->IsSigninRequired()) { |
| + Profile* profile = profile_manager->GetProfile(entry->GetPath()); |
| + if (profile) |
| + return profile; |
| + } |
| + } |
| + |
| + return nullptr; |
| +} |
| +#endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |