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 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 unable to | |
Peter Kasting
2016/07/19 21:56:07
Nit: unable -> being unable
WC Leung
2016/07/27 18:00:06
Done.
| |
921 // 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 is unable to initialize, see if any of other last | |
927 // opened profiles can initialize successfully. | |
Peter Kasting
2016/07/19 21:56:06
Nit: "The last used profile could not be initializ
WC Leung
2016/07/27 18:00:05
Done.
| |
928 std::vector<Profile*> last_opened_profiles = | |
929 ProfileManager::GetLastOpenedProfiles(); | |
930 auto& storage = profile_manager->GetProfileAttributesStorage(); | |
Peter Kasting
2016/07/19 21:56:07
Nit: Use auto* storage = &...
WC Leung
2016/07/27 18:00:05
Oh my bad... should have done this before. Why I d
| |
931 for (Profile* last_opened_profile : last_opened_profiles) { | |
Peter Kasting
2016/07/19 21:56:06
Nit: Avoids extra temp:
for (Profile* profile :
WC Leung
2016/07/27 18:00:05
Done.
| |
932 // Return any profile that is not locked. | |
933 ProfileAttributesEntry* entry; | |
934 bool has_entry = storage.GetProfileAttributesWithPath( | |
935 last_opened_profile->GetPath(), &entry); | |
936 if (!has_entry || !entry->IsSigninRequired()) | |
937 return last_opened_profile; | |
938 } | |
939 | |
940 // If it still fails, try to initialize a guest profile and a system profile. | |
941 // Show the user manager if this is successful. | |
Peter Kasting
2016/07/19 21:56:07
Nit: "Couldn't initialize any last opened profiles
WC Leung
2016/07/27 18:00:06
Done.
| |
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 // If still fails, try to open any profile that is not locked. | |
Peter Kasting
2016/07/19 21:56:07
Nit: "Couldn't show the user manager either. Try
WC Leung
2016/07/27 18:00:05
Done.
| |
950 std::vector<ProfileAttributesEntry*> entries = | |
951 storage.GetAllProfilesAttributes(); | |
952 for (ProfileAttributesEntry* entry : entries) { | |
Peter Kasting
2016/07/19 21:56:07
Nit: Avoids extra temp:
for (ProfileAttributesE
WC Leung
2016/07/27 18:00:05
Done.
| |
953 if (!entry->IsSigninRequired()) { | |
954 Profile* profile = profile_manager->GetProfile(entry->GetPath()); | |
955 if (profile) | |
956 return profile; | |
957 } | |
958 } | |
959 | |
960 return nullptr; | |
961 } | |
962 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | |
OLD | NEW |