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 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 #if defined(ENABLE_APP_LIST) | 880 #if defined(ENABLE_APP_LIST) |
881 // If we are showing the app list then chrome isn't shown so load the app | 881 // If we are showing the app list then chrome isn't shown so load the app |
882 // list's profile rather than chrome's. | 882 // list's profile rather than chrome's. |
883 if (command_line.HasSwitch(switches::kShowAppList)) | 883 if (command_line.HasSwitch(switches::kShowAppList)) |
884 return AppListService::Get()->GetProfilePath(user_data_dir); | 884 return AppListService::Get()->GetProfilePath(user_data_dir); |
885 #endif | 885 #endif |
886 | 886 |
887 return g_browser_process->profile_manager()->GetLastUsedProfileDir( | 887 return g_browser_process->profile_manager()->GetLastUsedProfileDir( |
888 user_data_dir); | 888 user_data_dir); |
889 } | 889 } |
| 890 |
| 891 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 892 Profile* GetStartupProfile(const base::FilePath& user_data_dir, |
| 893 const base::CommandLine& command_line) { |
| 894 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 895 |
| 896 base::FilePath profile_path = |
| 897 GetStartupProfilePath(user_data_dir, command_line); |
| 898 Profile* profile = profile_manager->GetProfile(profile_path); |
| 899 |
| 900 // If there is no entry in profile attributes storage, the profile is deleted, |
| 901 // and we should show the user manager. Also, when using |
| 902 // --new-profile-management, if the profile is locked we should show the user |
| 903 // manager as well. When neither of these is true, we can safely start up with |
| 904 // |profile|. |
| 905 auto* storage = &profile_manager->GetProfileAttributesStorage(); |
| 906 ProfileAttributesEntry* entry; |
| 907 bool has_entry = storage->GetProfileAttributesWithPath(profile_path, &entry); |
| 908 if (has_entry && (!switches::IsNewProfileManagement() || |
| 909 !entry->IsSigninRequired() || !profile)) { |
| 910 return profile; |
| 911 } |
| 912 |
| 913 // We want to show the user manager. To indicate this, return the guest |
| 914 // profile. However, we can only do this if the system profile (where the user |
| 915 // manager lives) also exists (or is creatable). |
| 916 return profile_manager->GetProfile(ProfileManager::GetSystemProfilePath()) ? |
| 917 profile_manager->GetProfile(ProfileManager::GetGuestProfilePath()) : |
| 918 nullptr; |
| 919 } |
| 920 |
| 921 Profile* GetFallbackStartupProfile() { |
| 922 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 923 // The only known reason for profiles to fail initialization is being unable |
| 924 // to create the profile directory, and this has already happened in |
| 925 // GetStartupProfilePath() before calling this function. In this case, |
| 926 // creation of new profiles is expected to fail. So only existing profiles are |
| 927 // attempted for fallback. |
| 928 |
| 929 // If the last used profile could not be initialized, see if any of other last |
| 930 // opened profiles can be initialized successfully. |
| 931 auto* storage = &profile_manager->GetProfileAttributesStorage(); |
| 932 for (Profile* profile : ProfileManager::GetLastOpenedProfiles()) { |
| 933 // Return any profile that is not locked. |
| 934 ProfileAttributesEntry* entry; |
| 935 bool has_entry = storage->GetProfileAttributesWithPath(profile->GetPath(), |
| 936 &entry); |
| 937 if (!has_entry || !entry->IsSigninRequired()) |
| 938 return profile; |
| 939 } |
| 940 |
| 941 // Couldn't initialize any last opened profiles. Try to show the user manager, |
| 942 // which requires successful initialization of the guest and system profiles. |
| 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 // Couldn't show the user manager either. Try to open any profile that is not |
| 951 // locked. |
| 952 for (ProfileAttributesEntry* entry : storage->GetAllProfilesAttributes()) { |
| 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 |