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

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: Fix clang compile error 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..9f18c26ae1516d86e9da6e63204627077aca86bd 100644
--- a/chrome/browser/ui/startup/startup_browser_creator.cc
+++ b/chrome/browser/ui/startup/startup_browser_creator.cc
@@ -884,3 +884,78 @@ 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 being unable
+ // to 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 could not be initialized, see if any of other last
+ // opened profiles can be initialized successfully.
+ std::vector<Profile*> last_opened_profiles =
+ ProfileManager::GetLastOpenedProfiles();
+ auto* storage = &profile_manager->GetProfileAttributesStorage();
+ for (Profile* profile : last_opened_profiles) {
Peter Kasting 2016/07/28 20:09:49 Nit: You didn't actually inline |last_opened_profi
WC Leung 2016/08/01 18:03:06 Oops. Looks like I misunderstood your last comment
+ // Return any profile that is not locked.
+ ProfileAttributesEntry* entry;
+ bool has_entry = storage->GetProfileAttributesWithPath(profile->GetPath(),
+ &entry);
+ if (!has_entry || !entry->IsSigninRequired())
+ return profile;
+ }
+
+ // Couldn't initialize any last opened profiles. Try to show the user manager,
+ // which requires successful initialization of the guest and system profiles.
+ Profile* guest_profile =
+ profile_manager->GetProfile(ProfileManager::GetGuestProfilePath());
+ Profile* system_profile =
+ profile_manager->GetProfile(ProfileManager::GetSystemProfilePath());
+ if (guest_profile && system_profile)
+ return guest_profile;
+
+ // Couldn't show the user manager either. Try to open any profile that is not
+ // locked.
+ for (ProfileAttributesEntry* entry : storage->GetAllProfilesAttributes()) {
+ 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