Index: chrome/browser/ui/startup/startup_browser_creator.cc |
diff --git a/chrome/browser/ui/startup/startup_browser_creator.cc b/chrome/browser/ui/startup/startup_browser_creator.cc |
index 8cb76a7171ef019ee311ff43e2587668cccb3051..046226aeccfaac23568209e25e96e6ef83430305 100644 |
--- a/chrome/browser/ui/startup/startup_browser_creator.cc |
+++ b/chrome/browser/ui/startup/startup_browser_creator.cc |
@@ -884,3 +884,85 @@ base::FilePath GetStartupProfilePath(const base::FilePath& user_data_dir, |
return g_browser_process->profile_manager()->GetLastUsedProfileDir( |
user_data_dir); |
} |
+ |
+#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
+Profile* GetStartupProfile(const base::FilePath& user_data_dir, |
+ const base::CommandLine& command_line) { |
+ ProfileManager* profile_manager = g_browser_process->profile_manager(); |
+ |
+ base::FilePath profile_path = |
+ GetStartupProfilePath(user_data_dir, command_line); |
+ Profile* profile = profile_manager->GetProfile(profile_path); |
+ |
+ // If we're using the --new-profile-management flag and this profile is |
+ // locked, then we should show the user manager instead. By switching the |
brettw
2016/07/01 23:13:22
The old comment had the wording "signed out". You
WC Leung
2016/07/07 17:01:54
Not sure you've read Mike's comment in https://cod
|
+ // active profile to the guest profile we ensure that no browser windows will |
+ // be opened for the guest profile. The initialization of guest profile is |
Peter Kasting
2016/07/01 00:53:23
Do you mean "for the active profile"? I'm not sur
WC Leung
2016/07/07 17:01:53
Oh... that sentence was not written by me. It was
|
+ // possible to fail. |
Peter Kasting
2016/07/01 00:53:23
Nit: is possible to -> may
But what is the import
WC Leung
2016/07/07 17:01:53
By design, I think it is not important at all. How
|
+ // If there is no entry in profile attributes storage, it means the profile is |
+ // deleted. In this case we should show the user manager. |
+ auto& storage = profile_manager->GetProfileAttributesStorage(); |
Peter Kasting
2016/07/01 00:53:23
Nit: Either use const auto& or auto* (2 places)
WC Leung
2016/07/07 17:01:53
Not sure here.
The declaration of GetProfileAttri
Peter Kasting
2016/07/11 02:58:58
This should be changed. If callers need a non-con
Mike Lerman
2016/07/11 10:01:08
Changing the return type of this function would be
WC Leung
2016/07/18 17:56:18
Done.
|
+ ProfileAttributesEntry* entry; |
+ bool has_entry = storage.GetProfileAttributesWithPath(profile_path, &entry); |
+ |
+ if (!has_entry || |
+ (switches::IsNewProfileManagement() && profile && |
+ entry->IsSigninRequired())) { |
Peter Kasting
2016/07/01 00:53:23
Nit: Reverse conditional and early-return |profile
WC Leung
2016/07/07 17:01:54
Done.
|
+ // To show the user manager, return the guest profile. However, we also |
+ // need to know that the system profile (where the user manager lives on) |
Peter Kasting
2016/07/01 00:53:23
Nit: where...on -> in which
WC Leung
2016/07/07 17:01:53
Done.
|
+ // exists or is creatable. If either profile is failing, return null to |
+ // denote failure. |
+ profile = |
+ profile_manager->GetProfile(ProfileManager::GetGuestProfilePath()); |
+ if (!profile_manager->GetProfile(ProfileManager::GetSystemProfilePath())) |
+ profile = nullptr; |
Peter Kasting
2016/07/01 00:53:23
Nit: Once early-return suggestion above is followe
WC Leung
2016/07/07 17:01:53
Done.
|
+ } |
+ |
+ return profile; |
+} |
+ |
+Profile* GetFallbackStartupProfile() { |
+ ProfileManager* profile_manager = g_browser_process->profile_manager(); |
+ // The only known reason for profiles to fail initialization is unable to |
+ // create the profile directory. This has already happened in the last used |
+ // profile before calling this function. Therefore, creation of all new |
+ // profiles is expected to fail. So only existing profiles are attempted for |
Peter Kasting
2016/07/01 00:53:23
If "directory creation" is the only reason for ini
WC Leung
2016/07/07 17:01:53
Appears that the only way is to have some users de
Peter Kasting
2016/07/11 02:58:59
I don't understand. Wouldn't these still be cases
WC Leung
2016/07/18 17:56:18
In this case we show the user manager. See https:/
|
+ // fallback. |
+ |
+ // If the last used profile is unable to initialize, see if any of other last |
+ // opened profiles can initialize successfully. |
+ std::vector<Profile*> last_opened_profiles = |
+ ProfileManager::GetLastOpenedProfiles(); |
+ auto& storage = profile_manager->GetProfileAttributesStorage(); |
+ for (Profile* last_opened_profile : last_opened_profiles) { |
+ // Return any profile that is not signed out. |
+ ProfileAttributesEntry* entry; |
+ bool has_entry = storage.GetProfileAttributesWithPath( |
+ last_opened_profile->GetPath(), &entry); |
+ if (!has_entry || !entry->IsSigninRequired()) |
+ return last_opened_profile; |
+ } |
+ |
+ // If it still fails, try to initialize a guest profile and a system profile. |
+ // Show the user manager if this is successful. |
+ Profile* guest_profile = |
+ profile_manager->GetProfile(ProfileManager::GetGuestProfilePath()); |
+ Profile* system_profile = |
Peter Kasting
2016/07/01 00:53:23
Nit: Can inline into next statement
WC Leung
2016/07/07 17:01:53
I'd rather not to change. With the extra braces in
Peter Kasting
2016/07/11 02:58:58
Really?:
if (guest_profile &&
profile_man
WC Leung
2016/07/18 17:56:18
I've been asked to add the braces when the conditi
Peter Kasting
2016/07/19 21:56:06
Both style guides are mute (the Chrome one intenti
WC Leung
2016/07/27 18:00:05
I see. Thanks!
|
+ profile_manager->GetProfile(ProfileManager::GetSystemProfilePath()); |
+ if (guest_profile && system_profile) |
+ return guest_profile; |
+ |
+ // If still fails, try to open any profile that is not signed out. |
+ std::vector<ProfileAttributesEntry*> entries = |
+ storage.GetAllProfilesAttributes(); |
+ for (ProfileAttributesEntry* entry : entries) { |
+ if (!entry->IsSigninRequired()) { |
+ Profile* profile = profile_manager->GetProfile(entry->GetPath()); |
+ if (profile) |
+ return profile; |
+ } |
+ } |
+ |
+ return nullptr; |
+} |
+#endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |