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

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: Fix clang compile error Created 4 years, 4 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 there is no entry in profile attributes storage, the profile is deleted,
898 // and we should show the user manager. Also, when using
899 // --new-profile-management, if the profile is locked we should show the user
900 // manager as well. When neither of these is true, we can safely start up with
901 // |profile|.
902 auto* storage = &profile_manager->GetProfileAttributesStorage();
903 ProfileAttributesEntry* entry;
904 bool has_entry = storage->GetProfileAttributesWithPath(profile_path, &entry);
905 if (has_entry && (!switches::IsNewProfileManagement() ||
906 !entry->IsSigninRequired() || !profile)) {
907 return profile;
908 }
909
910 // We want to show the user manager. To indicate this, return the guest
911 // profile. However, we can only do this if the system profile (where the user
912 // manager lives) also exists (or is creatable).
913 return profile_manager->GetProfile(ProfileManager::GetSystemProfilePath()) ?
914 profile_manager->GetProfile(ProfileManager::GetGuestProfilePath()) :
915 nullptr;
916 }
917
918 Profile* GetFallbackStartupProfile() {
919 ProfileManager* profile_manager = g_browser_process->profile_manager();
920 // The only known reason for profiles to fail initialization is being unable
921 // to create the profile directory, and this has already happened in
922 // GetStartupProfilePath() before calling this function. In this case,
923 // creation of new profiles is expected to fail. So only existing profiles are
924 // attempted for fallback.
925
926 // If the last used profile could not be initialized, see if any of other last
927 // opened profiles can be initialized successfully.
928 std::vector<Profile*> last_opened_profiles =
929 ProfileManager::GetLastOpenedProfiles();
930 auto* storage = &profile_manager->GetProfileAttributesStorage();
931 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
932 // Return any profile that is not locked.
933 ProfileAttributesEntry* entry;
934 bool has_entry = storage->GetProfileAttributesWithPath(profile->GetPath(),
935 &entry);
936 if (!has_entry || !entry->IsSigninRequired())
937 return profile;
938 }
939
940 // Couldn't initialize any last opened profiles. Try to show the user manager,
941 // which requires successful initialization of the guest and system profiles.
942 Profile* guest_profile =
943 profile_manager->GetProfile(ProfileManager::GetGuestProfilePath());
944 Profile* system_profile =
945 profile_manager->GetProfile(ProfileManager::GetSystemProfilePath());
946 if (guest_profile && system_profile)
947 return guest_profile;
948
949 // Couldn't show the user manager either. Try to open any profile that is not
950 // locked.
951 for (ProfileAttributesEntry* entry : storage->GetAllProfilesAttributes()) {
952 if (!entry->IsSigninRequired()) {
953 Profile* profile = profile_manager->GetProfile(entry->GetPath());
954 if (profile)
955 return profile;
956 }
957 }
958
959 return nullptr;
960 }
961 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698