Chromium Code Reviews| 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 | |
| 898 // 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
| |
| 899 // active profile to the guest profile we ensure that no browser windows will | |
| 900 // 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
| |
| 901 // 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
| |
| 902 // If there is no entry in profile attributes storage, it means the profile is | |
| 903 // deleted. In this case we should show the user manager. | |
| 904 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.
| |
| 905 ProfileAttributesEntry* entry; | |
| 906 bool has_entry = storage.GetProfileAttributesWithPath(profile_path, &entry); | |
| 907 | |
| 908 if (!has_entry || | |
| 909 (switches::IsNewProfileManagement() && profile && | |
| 910 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.
| |
| 911 // To show the user manager, return the guest profile. However, we also | |
| 912 // 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.
| |
| 913 // exists or is creatable. If either profile is failing, return null to | |
| 914 // denote failure. | |
| 915 profile = | |
| 916 profile_manager->GetProfile(ProfileManager::GetGuestProfilePath()); | |
| 917 if (!profile_manager->GetProfile(ProfileManager::GetSystemProfilePath())) | |
| 918 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.
| |
| 919 } | |
| 920 | |
| 921 return profile; | |
| 922 } | |
| 923 | |
| 924 Profile* GetFallbackStartupProfile() { | |
| 925 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
| 926 // The only known reason for profiles to fail initialization is unable to | |
| 927 // create the profile directory. This has already happened in the last used | |
| 928 // profile before calling this function. Therefore, creation of all new | |
| 929 // 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:/
| |
| 930 // fallback. | |
| 931 | |
| 932 // If the last used profile is unable to initialize, see if any of other last | |
| 933 // opened profiles can initialize successfully. | |
| 934 std::vector<Profile*> last_opened_profiles = | |
| 935 ProfileManager::GetLastOpenedProfiles(); | |
| 936 auto& storage = profile_manager->GetProfileAttributesStorage(); | |
| 937 for (Profile* last_opened_profile : last_opened_profiles) { | |
| 938 // Return any profile that is not signed out. | |
| 939 ProfileAttributesEntry* entry; | |
| 940 bool has_entry = storage.GetProfileAttributesWithPath( | |
| 941 last_opened_profile->GetPath(), &entry); | |
| 942 if (!has_entry || !entry->IsSigninRequired()) | |
| 943 return last_opened_profile; | |
| 944 } | |
| 945 | |
| 946 // If it still fails, try to initialize a guest profile and a system profile. | |
| 947 // Show the user manager if this is successful. | |
| 948 Profile* guest_profile = | |
| 949 profile_manager->GetProfile(ProfileManager::GetGuestProfilePath()); | |
| 950 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!
| |
| 951 profile_manager->GetProfile(ProfileManager::GetSystemProfilePath()); | |
| 952 if (guest_profile && system_profile) | |
| 953 return guest_profile; | |
| 954 | |
| 955 // If still fails, try to open any profile that is not signed out. | |
| 956 std::vector<ProfileAttributesEntry*> entries = | |
| 957 storage.GetAllProfilesAttributes(); | |
| 958 for (ProfileAttributesEntry* entry : entries) { | |
| 959 if (!entry->IsSigninRequired()) { | |
| 960 Profile* profile = profile_manager->GetProfile(entry->GetPath()); | |
| 961 if (profile) | |
| 962 return profile; | |
| 963 } | |
| 964 } | |
| 965 | |
| 966 return nullptr; | |
| 967 } | |
| 968 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | |
| OLD | NEW |