Index: chrome/browser/profiles/profile_manager.cc |
diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc |
index b4d70c8f3507240907543281fd8da21556c319bd..01bb1f71e116ff7697df7365ac27b69a4f8428df 100644 |
--- a/chrome/browser/profiles/profile_manager.cc |
+++ b/chrome/browser/profiles/profile_manager.cc |
@@ -111,12 +111,6 @@ using content::BrowserThread; |
namespace { |
-// Profiles that should be deleted on shutdown. |
-std::vector<base::FilePath>& ProfilesToDelete() { |
- CR_DEFINE_STATIC_LOCAL(std::vector<base::FilePath>, profiles_to_delete, ()); |
- return profiles_to_delete; |
-} |
- |
int64 ComputeFilesSize(const base::FilePath& directory, |
const base::FilePath::StringType& pattern) { |
int64 running_size = 0; |
@@ -181,6 +175,12 @@ void ProfileSizeTask(const base::FilePath& path, int enabled_app_count) { |
UMA_HISTOGRAM_COUNTS_10000("Profile.AppCount", enabled_app_count); |
} |
+// Profiles that should be deleted on shutdown. |
+std::vector<base::FilePath>& ProfilesToDelete() { |
+ CR_DEFINE_STATIC_LOCAL(std::vector<base::FilePath>, profiles_to_delete, ()); |
+ return profiles_to_delete; |
+} |
+ |
void QueueProfileDirectoryForDeletion(const base::FilePath& path) { |
ProfilesToDelete().push_back(path); |
} |
@@ -297,45 +297,18 @@ void ProfileManager::NukeDeletedProfilesFromDisk() { |
} |
// static |
-Profile* ProfileManager::GetLastUsedProfile() { |
- ProfileManager* profile_manager = g_browser_process->profile_manager(); |
- return profile_manager->GetLastUsedProfile(profile_manager->user_data_dir_); |
-} |
- |
-// static |
-Profile* ProfileManager::GetLastUsedProfileAllowedByPolicy() { |
- Profile* profile = GetLastUsedProfile(); |
- if (profile->IsGuestSession() || |
- profile->IsSystemProfile() || |
- IncognitoModePrefs::GetAvailability(profile->GetPrefs()) == |
- IncognitoModePrefs::FORCED) { |
- return profile->GetOffTheRecordProfile(); |
- } |
- return profile; |
-} |
- |
-// static |
-std::vector<Profile*> ProfileManager::GetLastOpenedProfiles() { |
- ProfileManager* profile_manager = g_browser_process->profile_manager(); |
- return profile_manager->GetLastOpenedProfiles( |
- profile_manager->user_data_dir_); |
-} |
- |
-// static |
Profile* ProfileManager::GetPrimaryUserProfile() { |
ProfileManager* profile_manager = g_browser_process->profile_manager(); |
#if defined(OS_CHROMEOS) |
if (!profile_manager->IsLoggedIn() || |
!user_manager::UserManager::IsInitialized()) |
- return profile_manager->GetActiveUserOrOffTheRecordProfileFromPath( |
- profile_manager->user_data_dir()); |
+ return profile_manager->GetActiveUserOrOffTheRecordProfileFromPath(); |
user_manager::UserManager* manager = user_manager::UserManager::Get(); |
// Note: The ProfileHelper will take care of guest profiles. |
return chromeos::ProfileHelper::Get()->GetProfileByUserUnsafe( |
manager->GetPrimaryUser()); |
#else |
- return profile_manager->GetActiveUserOrOffTheRecordProfileFromPath( |
- profile_manager->user_data_dir()); |
+ return profile_manager->GetActiveUserOrOffTheRecordProfileFromPath(); |
#endif |
} |
@@ -348,8 +321,7 @@ Profile* ProfileManager::GetActiveUserProfile() { |
if (!profile_manager->IsLoggedIn() || |
!user_manager::UserManager::IsInitialized()) { |
- return profile_manager->GetActiveUserOrOffTheRecordProfileFromPath( |
- profile_manager->user_data_dir()); |
+ return profile_manager->GetActiveUserOrOffTheRecordProfileFromPath(); |
} |
user_manager::UserManager* manager = user_manager::UserManager::Get(); |
@@ -363,8 +335,7 @@ Profile* ProfileManager::GetActiveUserProfile() { |
#endif |
Profile* profile = |
- profile_manager->GetActiveUserOrOffTheRecordProfileFromPath( |
- profile_manager->user_data_dir()); |
+ profile_manager->GetActiveUserOrOffTheRecordProfileFromPath(); |
// |profile| could be null if the user doesn't have a profile yet and the path |
// is on a read-only volume (preventing Chrome from making a new one). |
// However, most callers of this function immediately dereference the result |
@@ -482,35 +453,42 @@ base::FilePath ProfileManager::GetInitialProfileDir() { |
return relative_profile_dir.AppendASCII(chrome::kInitialProfile); |
} |
-Profile* ProfileManager::GetLastUsedProfile( |
- const base::FilePath& user_data_dir) { |
+Profile* ProfileManager::GetLastUsedProfile() { |
#if defined(OS_CHROMEOS) |
// Use default login profile if user has not logged in yet. |
- if (!logged_in_) { |
- return GetActiveUserOrOffTheRecordProfileFromPath(user_data_dir); |
- } else { |
- // CrOS multi-profiles implementation is different so GetLastUsedProfile |
- // has custom implementation too. |
- base::FilePath profile_dir; |
- // In case of multi-profiles we ignore "last used profile" preference |
- // since it may refer to profile that has been in use in previous session. |
- // That profile dir may not be mounted in this session so instead return |
- // active profile from current session. |
- profile_dir = chromeos::ProfileHelper::Get()->GetActiveUserProfileDir(); |
- |
- base::FilePath profile_path(user_data_dir); |
- Profile* profile = GetProfile(profile_path.Append(profile_dir)); |
- return profile->IsGuestSession() ? profile->GetOffTheRecordProfile() : |
- profile; |
- } |
+ if (!logged_in_) |
+ return GetActiveUserOrOffTheRecordProfileFromPath(); |
+ |
+ // CrOS multi-profiles implementation is different so GetLastUsedProfile |
+ // has custom implementation too. |
+ // In case of multi-profiles we ignore "last used profile" preference |
+ // since it may refer to profile that has been in use in previous session. |
+ // That profile dir may not be mounted in this session so instead return |
+ // active profile from current session. |
+ base::FilePath profile_dir = |
+ chromeos::ProfileHelper::Get()->GetActiveUserProfileDir(); |
+ |
+ Profile* profile = GetProfile(user_data_dir_.Append(profile_dir)); |
+ return profile->IsGuestSession() ? profile->GetOffTheRecordProfile() |
+ : profile; |
+#else |
+ return GetProfile(GetLastUsedProfileDir()); |
#endif |
+} |
- return GetProfile(GetLastUsedProfileDir(user_data_dir)); |
+Profile* ProfileManager::GetLastUsedProfileAllowedByPolicy() { |
+ Profile* profile = GetLastUsedProfile(); |
+ if (profile->IsGuestSession() || |
+ profile->IsSystemProfile() || |
+ IncognitoModePrefs::GetAvailability(profile->GetPrefs()) == |
+ IncognitoModePrefs::FORCED) { |
+ return profile->GetOffTheRecordProfile(); |
+ } |
+ return profile; |
} |
-base::FilePath ProfileManager::GetLastUsedProfileDir( |
- const base::FilePath& user_data_dir) { |
- return user_data_dir.AppendASCII(GetLastUsedProfileName()); |
+base::FilePath ProfileManager::GetLastUsedProfileDir() { |
+ return user_data_dir_.AppendASCII(GetLastUsedProfileName()); |
} |
std::string ProfileManager::GetLastUsedProfileName() { |
@@ -524,8 +502,7 @@ std::string ProfileManager::GetLastUsedProfileName() { |
return chrome::kInitialProfile; |
} |
-std::vector<Profile*> ProfileManager::GetLastOpenedProfiles( |
- const base::FilePath& user_data_dir) { |
+std::vector<Profile*> ProfileManager::GetLastOpenedProfiles() { |
PrefService* local_state = g_browser_process->local_state(); |
DCHECK(local_state); |
@@ -542,7 +519,7 @@ std::vector<Profile*> ProfileManager::GetLastOpenedProfiles( |
LOG(WARNING) << "Invalid entry in " << prefs::kProfilesLastActive; |
continue; |
} |
- to_return.push_back(GetProfile(user_data_dir.AppendASCII(profile))); |
+ to_return.push_back(GetProfile(user_data_dir_.AppendASCII(profile))); |
} |
} |
return to_return; |
@@ -622,12 +599,7 @@ base::FilePath ProfileManager::GenerateNextProfileDirectoryPath() { |
int next_directory = local_state->GetInteger(prefs::kProfilesNumCreated); |
std::string profile_name = chrome::kMultiProfileDirPrefix; |
profile_name.append(base::IntToString(next_directory)); |
- base::FilePath new_path = user_data_dir_; |
-#if defined(OS_WIN) |
- new_path = new_path.Append(base::ASCIIToUTF16(profile_name)); |
-#else |
- new_path = new_path.Append(profile_name); |
-#endif |
+ base::FilePath new_path = user_data_dir_.AppendASCII(profile_name); |
local_state->SetInteger(prefs::kProfilesNumCreated, ++next_directory); |
return new_path; |
} |
@@ -677,19 +649,19 @@ void ProfileManager::ScheduleProfileForDeletion( |
} |
} |
- base::FilePath new_path; |
if (last_non_supervised_profile_path.empty()) { |
// If we are using --new-avatar-menu, then assign the default |
// placeholder avatar and name. Otherwise, use random ones. |
- bool is_new_avatar_menu = switches::IsNewAvatarMenu(); |
- int avatar_index = profiles::GetPlaceholderAvatarIndex(); |
- base::string16 new_avatar_url = is_new_avatar_menu ? |
- base::UTF8ToUTF16(profiles::GetDefaultAvatarIconUrl(avatar_index)) : |
- base::string16(); |
- base::string16 new_profile_name = is_new_avatar_menu ? |
- cache.ChooseNameForNewProfile(avatar_index) : base::string16(); |
- |
- new_path = GenerateNextProfileDirectoryPath(); |
+ base::string16 new_profile_name; |
+ base::string16 new_avatar_url; |
+ if (switches::IsNewAvatarMenu()) { |
+ int avatar_index = profiles::GetPlaceholderAvatarIndex(); |
+ new_profile_name = cache.ChooseNameForNewProfile(avatar_index); |
+ new_avatar_url = |
+ base::UTF8ToUTF16(profiles::GetDefaultAvatarIconUrl(avatar_index)); |
+ } |
+ |
+ base::FilePath new_path = GenerateNextProfileDirectoryPath(); |
CreateProfileAsync(new_path, |
base::Bind(&ProfileManager::OnNewActiveProfileLoaded, |
base::Unretained(this), |
@@ -709,8 +681,7 @@ void ProfileManager::ScheduleProfileForDeletion( |
// On the Mac, the browser process is not killed when all browser windows are |
// closed, so just in case we are deleting the active profile, and no other |
// profile has been loaded, we must pre-load a next one. |
- const base::FilePath last_used_profile = |
- GetLastUsedProfileDir(user_data_dir_); |
+ const base::FilePath last_used_profile = GetLastUsedProfileDir(); |
if (last_used_profile == profile_dir || |
last_used_profile == GetGuestProfilePath()) { |
CreateProfileAsync(last_non_supervised_profile_path, |
@@ -1122,12 +1093,11 @@ Profile* ProfileManager::CreateProfileAsyncHelper(const base::FilePath& path, |
Profile::CREATE_MODE_ASYNCHRONOUS); |
} |
-Profile* ProfileManager::GetActiveUserOrOffTheRecordProfileFromPath( |
- const base::FilePath& user_data_dir) { |
+Profile* ProfileManager::GetActiveUserOrOffTheRecordProfileFromPath() { |
#if defined(OS_CHROMEOS) |
- base::FilePath default_profile_dir(user_data_dir); |
if (!logged_in_) { |
- default_profile_dir = profiles::GetDefaultProfileDir(user_data_dir); |
+ base::FilePath default_profile_dir = |
+ profiles::GetDefaultProfileDir(user_data_dir_); |
Profile* profile = GetProfile(default_profile_dir); |
// For cros, return the OTR profile so we never accidentally keep |
// user data in an unencrypted profile. But doing this makes |
@@ -1139,12 +1109,13 @@ Profile* ProfileManager::GetActiveUserOrOffTheRecordProfileFromPath( |
return profile; |
} |
- default_profile_dir = default_profile_dir.Append(GetInitialProfileDir()); |
+ base::FilePath default_profile_dir = |
+ user_data_dir_.Append(GetInitialProfileDir()); |
ProfileInfo* profile_info = GetProfileInfoByPath(default_profile_dir); |
// Fallback to default off-the-record profile, if user profile has not fully |
// loaded yet. |
if (profile_info && !profile_info->created) |
- default_profile_dir = profiles::GetDefaultProfileDir(user_data_dir); |
+ default_profile_dir = profiles::GetDefaultProfileDir(user_data_dir_); |
Profile* profile = GetProfile(default_profile_dir); |
// Some unit tests didn't initialize the UserManager. |
@@ -1153,8 +1124,8 @@ Profile* ProfileManager::GetActiveUserOrOffTheRecordProfileFromPath( |
return profile->GetOffTheRecordProfile(); |
return profile; |
#else |
- base::FilePath default_profile_dir(user_data_dir); |
- default_profile_dir = default_profile_dir.Append(GetInitialProfileDir()); |
+ base::FilePath default_profile_dir = |
+ user_data_dir_.Append(GetInitialProfileDir()); |
return GetProfile(default_profile_dir); |
#endif |
} |