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

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: 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 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 signed
898 // out, then we should show the user manager instead. By switching the active
899 // profile to the guest profile we ensure that no browser windows will be
900 // opened for the guest profile. The initialization of guest profile is
901 // possible to fail.
902 if (switches::IsNewProfileManagement() &&
903 profile && !profile->IsGuestSession()) {
904 ProfileAttributesEntry* entry;
905 bool has_entry = profile_manager->GetProfileAttributesStorage()
906 .GetProfileAttributesWithPath(profile_path,
907 &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.
908 if (has_entry && entry->IsSigninRequired()) {
909 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.
910 ProfileManager::GetGuestProfilePath());
911 }
912 }
913
914 return profile;
915 }
916
917 Profile* GetFallbackStartupProfile() {
918 ProfileManager* profile_manager = g_browser_process->profile_manager();
919 // If the last used profile is unable to initialize, see if any of other last
920 // opened profiles can initialize successfully (yes if the profile is found in
921 // |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.
922 // 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.
923 std::vector<Profile*> last_opened_profiles =
924 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.
925 // Return the first profile that is not signed out.
926 for (Profile* last_opened_profile : last_opened_profiles) {
927 ProfileAttributesEntry* entry;
928 bool has_entry = profile_manager->GetProfileAttributesStorage()
929 .GetProfileAttributesWithPath(
930 last_opened_profile->GetPath(),
931 &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.
932 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
933 return last_opened_profile;
934 }
935
936 // If it still fails, try to create a guest profile. Show the user manager
937 // if this is successful.
938 Profile* guest_profile =
939 profile_manager->GetProfile(ProfileManager::GetGuestProfilePath());
940
Peter Kasting 2016/06/16 06:37:49 Nit: Unnecessary blank line
WC Leung 2016/06/19 17:56:19 Done.
941 if (guest_profile)
942 return guest_profile;
WC Leung 2016/06/19 17:56:19 Anthony and Mike: do you know why we return the gu
943
944 // 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
945 std::vector<ProfileAttributesEntry*> entries =
946 profile_manager->GetProfileAttributesStorage()
947 .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.
948 for (ProfileAttributesEntry* entry : entries) {
949 if (!entry->IsSigninRequired()) {
950 Profile* profile = profile_manager->GetProfile(entry->GetPath());
951 if (profile)
952 return profile;
953 }
954 }
955
956 return nullptr;
957 }
958 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698