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

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: Refactored startup profile choosing code, reduced number of messages, bug fix (oops) Created 4 years, 6 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..8810de79969d9b8e562120863adb589f83b3355a 100644
--- a/chrome/browser/ui/startup/startup_browser_creator.cc
+++ b/chrome/browser/ui/startup/startup_browser_creator.cc
@@ -884,3 +884,75 @@ 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
+ // 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()) {
+ ProfileAttributesEntry* entry;
+ bool has_entry = profile_manager->GetProfileAttributesStorage()
+ .GetProfileAttributesWithPath(profile_path,
+ &entry);
Peter Kasting 2016/06/16 06:37:49 Nit: Shorter and IMO more readable: auto stor
WC Leung 2016/06/19 17:56:19 Done.
+ if (has_entry && entry->IsSigninRequired()) {
+ profile = profile_manager->GetProfile(
Peter Kasting 2016/06/16 06:37:49 Nit: Prefer to break after '=' instead
WC Leung 2016/06/19 17:56:19 Done.
+ ProfileManager::GetGuestProfilePath());
+ }
+ }
+
+ return profile;
+}
+
+Profile* GetFallbackStartupProfile() {
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ // If the last used profile is unable to initialize, see if any of other last
+ // opened profiles can initialize successfully (yes if the profile is found in
+ // |last_opened_profiles|). At this stage we assume creation of all new
Peter Kasting 2016/06/16 06:37:49 Nit: Remove parenthetical (comment should explain
WC Leung 2016/06/19 17:56:19 Done.
+ // profile (including guest profile) to fail.
Peter Kasting 2016/06/16 06:37:49 Nit: This sentence isn't grammatical, and doesn't
WC Leung 2016/06/19 17:56:19 Done.
+ std::vector<Profile*> last_opened_profiles =
+ ProfileManager::GetLastOpenedProfiles();
Peter Kasting 2016/06/16 06:37:49 Nit: I'd just inline this into the loop below.
WC Leung 2016/06/19 17:56:19 Done.
+ // Return the first profile that is not signed out.
+ for (Profile* last_opened_profile : last_opened_profiles) {
+ ProfileAttributesEntry* entry;
+ bool has_entry = profile_manager->GetProfileAttributesStorage()
+ .GetProfileAttributesWithPath(
+ last_opened_profile->GetPath(),
+ &entry);
Peter Kasting 2016/06/16 06:37:49 Nit: Shorter and IMO more readable: auto storag
WC Leung 2016/06/19 17:56:19 Done.
+ if (!has_entry || !entry->IsSigninRequired())
Peter Kasting 2016/06/16 06:37:49 I'm confused about why we return here if !has_entr
WC Leung 2016/06/19 17:56:19 AFAIK the only way for |has_entry| to be false is
WC Leung 2016/06/20 15:44:24 ping for this comment.
Mike Lerman 2016/06/20 15:50:31 In this case, couldn't the Guest Profile also be t
WC Leung 2016/06/23 15:40:33 Yes the guest profile can be a reason. BTW, I thin
+ return last_opened_profile;
+ }
+
+ // If it still fails, try to create a guest profile. Show the user manager
+ // if this is successful.
+ Profile* guest_profile =
+ profile_manager->GetProfile(ProfileManager::GetGuestProfilePath());
+
Peter Kasting 2016/06/16 06:37:49 Nit: Unnecessary blank line
WC Leung 2016/06/19 17:56:19 Done.
+ if (guest_profile)
+ return guest_profile;
WC Leung 2016/06/19 17:56:19 Anthony and Mike: do you know why we return the gu
+
+ // If still fails, try to open any non-signin profile.
Peter Kasting 2016/06/16 06:37:49 Nit: any profile not requiring authentication?
WC Leung 2016/06/19 17:56:19 Thanks for reminder. I changed to "any profile tha
WC Leung 2016/06/20 15:44:24 % mike's comment, I'll change all of these "signin
+ std::vector<ProfileAttributesEntry*> entries =
+ profile_manager->GetProfileAttributesStorage()
+ .GetAllProfilesAttributes();
Peter Kasting 2016/06/16 06:37:49 Nit: If you use |storage| here from my comment abo
WC Leung 2016/06/19 17:56:19 Done.
+ 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