OLD | NEW |
---|---|
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 Loading... | |
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 | |
Mike Lerman
2016/06/20 01:09:36
it's not that the profile is signed out, it's that
WC Leung
2016/06/20 15:44:24
Acknowledged.
| |
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 auto& storage = profile_manager->GetProfileAttributesStorage(); | |
905 ProfileAttributesEntry* entry; | |
906 bool has_entry = storage.GetProfileAttributesWithPath(profile_path, &entry); | |
907 | |
908 if (has_entry && entry->IsSigninRequired()) { | |
909 profile = | |
910 profile_manager->GetProfile(ProfileManager::GetGuestProfilePath()); | |
911 if (!profile_manager->GetProfile(ProfileManager::GetSystemProfilePath())) | |
912 profile = nullptr; | |
913 } | |
914 } | |
915 | |
916 return profile; | |
917 } | |
918 | |
919 Profile* GetFallbackStartupProfile() { | |
920 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
921 // The only known reason for profiles to fail initialization is unable to | |
922 // create the profile directory. This has already happened in the last used | |
923 // profile before calling this function. Therefore, creation of all new | |
924 // profiles is expected to fail. So only existing profiles are attempted for | |
925 // fallback. | |
926 | |
927 // If the last used profile is unable to initialize, see if any of other last | |
928 // opened profiles can initialize successfully. | |
929 std::vector<Profile*> last_opened_profiles = | |
930 ProfileManager::GetLastOpenedProfiles(); | |
931 auto& storage = profile_manager->GetProfileAttributesStorage(); | |
932 for (Profile* last_opened_profile : last_opened_profiles) { | |
933 // Return any profile that is not signed out. | |
934 ProfileAttributesEntry* entry; | |
935 bool has_entry = storage.GetProfileAttributesWithPath( | |
936 last_opened_profile->GetPath(), &entry); | |
937 if (!has_entry || !entry->IsSigninRequired()) | |
938 return last_opened_profile; | |
939 } | |
940 | |
941 // If it still fails, try to initialize a guest profile and a system profile. | |
942 // Show the user manager if this is successful. | |
943 Profile* guest_profile = | |
944 profile_manager->GetProfile(ProfileManager::GetGuestProfilePath()); | |
945 Profile* system_profile = | |
946 profile_manager->GetProfile(ProfileManager::GetSystemProfilePath()); | |
947 if (guest_profile && system_profile) | |
948 return guest_profile; | |
949 | |
950 // If still fails, try to open any profile that is not signed out. | |
951 std::vector<ProfileAttributesEntry*> entries = | |
952 storage.GetAllProfilesAttributes(); | |
953 for (ProfileAttributesEntry* entry : entries) { | |
954 if (!entry->IsSigninRequired()) { | |
955 Profile* profile = profile_manager->GetProfile(entry->GetPath()); | |
956 if (profile) | |
957 return profile; | |
958 } | |
959 } | |
960 | |
961 return nullptr; | |
962 } | |
963 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | |
OLD | NEW |