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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/startup/startup_browser_creator.h" 5 #include "chrome/browser/ui/startup/startup_browser_creator.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> // For max(). 9 #include <algorithm> // For max().
10 #include <memory> 10 #include <memory>
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 #if defined(ENABLE_APP_LIST) 877 #if defined(ENABLE_APP_LIST)
878 // If we are showing the app list then chrome isn't shown so load the app 878 // If we are showing the app list then chrome isn't shown so load the app
879 // list's profile rather than chrome's. 879 // list's profile rather than chrome's.
880 if (command_line.HasSwitch(switches::kShowAppList)) 880 if (command_line.HasSwitch(switches::kShowAppList))
881 return AppListService::Get()->GetProfilePath(user_data_dir); 881 return AppListService::Get()->GetProfilePath(user_data_dir);
882 #endif 882 #endif
883 883
884 return g_browser_process->profile_manager()->GetLastUsedProfileDir( 884 return g_browser_process->profile_manager()->GetLastUsedProfileDir(
885 user_data_dir); 885 user_data_dir);
886 } 886 }
887
888 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
889 Profile* GetStartupProfile(const base::FilePath& user_data_dir,
890 const base::CommandLine& command_line) {
891 ProfileManager* profile_manager = g_browser_process->profile_manager();
892
893 base::FilePath profile_path =
894 GetStartupProfilePath(user_data_dir, command_line);
895 Profile* profile = profile_manager->GetProfile(profile_path);
896
897 // If we're using the --new-profile-management flag and this profile is
898 // locked, then we should show the user manager instead. This is done by
899 // returning the guest profile. The initialization of guest profile is
900 // 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.
901 // If there is no entry in profile attributes storage, it means the profile is
902 // deleted. In this case we should show the user manager.
903 auto& storage = profile_manager->GetProfileAttributesStorage();
904 ProfileAttributesEntry* entry;
905 bool has_entry = storage.GetProfileAttributesWithPath(profile_path, &entry);
906 if (has_entry && (!switches::IsNewProfileManagement() ||
907 !entry->IsSigninRequired() || !profile)) {
908 return profile;
909 }
910
911 // To show the user manager, return the guest profile. However, we also
912 // need to know that the system profile (where the user manager lives in)
913 // exists or is creatable. If either profile is failing, return null to
914 // 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.
915 return profile_manager->GetProfile(ProfileManager::GetSystemProfilePath()) ?
916 profile_manager->GetProfile(ProfileManager::GetGuestProfilePath()) :
917 nullptr;
918 }
919
920 Profile* GetFallbackStartupProfile() {
921 ProfileManager* profile_manager = g_browser_process->profile_manager();
922 // The only known reason for profiles to fail initialization is unable to
923 // create the profile directory. This has already happened in the last used
924 // profile before calling this function. Therefore, creation of all new
925 // profiles is expected to fail. So only existing profiles are attempted for
926 // fallback.
927
928 // If the last used profile is unable to initialize, see if any of other last
929 // opened profiles can initialize successfully.
930 std::vector<Profile*> last_opened_profiles =
931 ProfileManager::GetLastOpenedProfiles();
932 auto& storage = profile_manager->GetProfileAttributesStorage();
933 for (Profile* last_opened_profile : last_opened_profiles) {
934 // Return any profile that is not signed out.
935 ProfileAttributesEntry* entry;
936 bool has_entry = storage.GetProfileAttributesWithPath(
937 last_opened_profile->GetPath(), &entry);
938 if (!has_entry || !entry->IsSigninRequired())
939 return last_opened_profile;
940 }
941
942 // If it still fails, try to initialize a guest profile and a system profile.
943 // Show the user manager if this is successful.
944 Profile* guest_profile =
945 profile_manager->GetProfile(ProfileManager::GetGuestProfilePath());
946 Profile* system_profile =
947 profile_manager->GetProfile(ProfileManager::GetSystemProfilePath());
948 if (guest_profile && system_profile)
949 return guest_profile;
950
951 // If still fails, try to open any profile that is not signed out.
952 std::vector<ProfileAttributesEntry*> entries =
953 storage.GetAllProfilesAttributes();
954 for (ProfileAttributesEntry* entry : entries) {
955 if (!entry->IsSigninRequired()) {
956 Profile* profile = profile_manager->GetProfile(entry->GetPath());
957 if (profile)
958 return profile;
959 }
960 }
961
962 return nullptr;
963 }
964 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698