Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5337)

Unified Diff: chrome/browser/ui/startup/startup_browser_creator.cc

Issue 2047483003: Add fallback behavior if the last used profile cannot initialize (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bug-614753-fix
Patch Set: Respond to pkasting@'s comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..f6ae6c3c8972345dfb4c8edbded6cabe45a39b80 100644
--- a/chrome/browser/ui/startup/startup_browser_creator.cc
+++ b/chrome/browser/ui/startup/startup_browser_creator.cc
@@ -884,3 +884,81 @@ 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
+ // locked, then we should show the user manager instead. This is done by
+ // returning the guest profile. The initialization of guest profile is
+ // possible to fail.
Peter Kasting 2016/07/11 02:58:59 Nit: Let's try to keep the bits about the guest pr
WC Leung 2016/07/18 17:56:18 Sounds good.
+ // If there is no entry in profile attributes storage, it means the profile is
+ // deleted. In this case we should show the user manager.
+ 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;
+ }
+
+ // To show the user manager, return the guest profile. However, we also
+ // need to know that the system profile (where the user manager lives in)
+ // exists or is creatable. If either profile is failing, return null to
+ // denote failure.
Peter Kasting 2016/07/11 02:58:59 Nit: How about: We want the caller to show the us
WC Leung 2016/07/18 17:56:18 Sounds good. Thanks.
+ 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
+ // 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)

Powered by Google App Engine
This is Rietveld 408576698