diff options
author | Roger Tawa <rogerta@chromium.org> | 2015-06-09 14:34:36 -0400 |
---|---|---|
committer | Roger Tawa <rogerta@chromium.org> | 2015-06-09 18:36:33 +0000 |
commit | b6366498db192cec036a588a42db4cdc3c998fc0 (patch) | |
tree | 7117fe587ba7ad631017190a20fa83243a0dc557 | |
parent | 3824cef38fd50992da5f74ac5095ea691a5d3bb6 (diff) | |
download | chromium_src-b6366498db192cec036a588a42db4cdc3c998fc0.zip chromium_src-b6366498db192cec036a588a42db4cdc3c998fc0.tar.gz chromium_src-b6366498db192cec036a588a42db4cdc3c998fc0.tar.bz2 |
[Merge] Prevent the System Profile from being used as the last used profile.
BUG=486914
TBR=anthonyvd@chromium.org
Committed: https://crrev.com/b19ad03e72c644434181e279201a302839df08c2
Cr-Commit-Position: refs/heads/master@{#332648}
Review URL: https://codereview.chromium.org/1170253002
Cr-Commit-Position: refs/branch-heads/2403@{#258}
Cr-Branched-From: f54b8097a9c45ed4ad308133d49f05325d6c5070-refs/heads/master@{#330231}
-rw-r--r-- | chrome/browser/chrome_browser_main.cc | 2 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_manager.cc | 28 | ||||
-rw-r--r-- | chrome/browser/profiles/profiles_state.cc | 18 | ||||
-rw-r--r-- | chrome/browser/profiles/profiles_state.h | 4 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/profiles/user_manager_mac_unittest.mm | 3 |
5 files changed, 38 insertions, 17 deletions
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc index 58235fa..02226a5 100644 --- a/chrome/browser/chrome_browser_main.cc +++ b/chrome/browser/chrome_browser_main.cc @@ -345,7 +345,7 @@ Profile* CreatePrimaryProfile(const content::MainFunctionParams& parameters, base::Time start = base::Time::Now(); if (profiles::IsMultipleProfilesEnabled() && parsed_command_line.HasSwitch(switches::kProfileDirectory)) { - g_browser_process->local_state()->SetString(prefs::kProfileLastUsed, + profiles::SetLastUsedProfile( parsed_command_line.GetSwitchValueASCII(switches::kProfileDirectory)); // Clear kProfilesLastActive since the user only wants to launch a specific // profile. diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc index 67c0e4d..03852cb 100644 --- a/chrome/browser/profiles/profile_manager.cc +++ b/chrome/browser/profiles/profile_manager.cc @@ -516,8 +516,13 @@ std::string ProfileManager::GetLastUsedProfileName() { DCHECK(local_state); const std::string last_used_profile_name = local_state->GetString(prefs::kProfileLastUsed); - if (!last_used_profile_name.empty()) + // Make sure the system profile can't be the one marked as the last one used + // since it shouldn't get a browser. + if (!last_used_profile_name.empty() && + last_used_profile_name != + base::FilePath(chrome::kSystemProfileDir).AsUTF8Unsafe()) { return last_used_profile_name; + } return chrome::kInitialProfile; } @@ -536,7 +541,8 @@ std::vector<Profile*> ProfileManager::GetLastOpenedProfiles( base::ListValue::const_iterator it; std::string profile; for (it = profile_list->begin(); it != profile_list->end(); ++it) { - if (!(*it)->GetAsString(&profile) || profile.empty()) { + if (!(*it)->GetAsString(&profile) || profile.empty() || + profile == base::FilePath(chrome::kSystemProfileDir).AsUTF8Unsafe()) { LOG(WARNING) << "Invalid entry in " << prefs::kProfilesLastActive; continue; } @@ -773,9 +779,7 @@ void ProfileManager::CleanUpEphemeralProfiles() { if (new_profile_path.empty()) new_profile_path = GenerateNextProfileDirectoryPath(); - PrefService* local_state = g_browser_process->local_state(); - local_state->SetString(prefs::kProfileLastUsed, - new_profile_path.BaseName().MaybeAsASCII()); + profiles::SetLastUsedProfile(new_profile_path.BaseName().MaybeAsASCII()); } // This uses a separate loop, because deleting the profile from the @@ -964,8 +968,12 @@ void ProfileManager::Observe( for (it = active_profiles_.begin(); it != active_profiles_.end(); ++it) { std::string profile_path = (*it)->GetPath().BaseName().MaybeAsASCII(); // Some profiles might become ephemeral after they are created. + // Don't persist the System Profile as one of the last actives, it should + // never get a browser. if (!(*it)->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles) && - profile_paths.find(profile_path) == profile_paths.end()) { + profile_paths.find(profile_path) == profile_paths.end() && + profile_path != + base::FilePath(chrome::kSystemProfileDir).AsUTF8Unsafe()) { profile_paths.insert(profile_path); profile_list->Append(new base::StringValue(profile_path)); } @@ -1204,10 +1212,8 @@ void ProfileManager::FinishDeletingProfile( const base::FilePath& new_active_profile_dir) { // Update the last used profile pref before closing browser windows. This // way the correct last used profile is set for any notification observers. - PrefService* local_state = g_browser_process->local_state(); - DCHECK(local_state); - local_state->SetString(prefs::kProfileLastUsed, - new_active_profile_dir.BaseName().MaybeAsASCII()); + profiles::SetLastUsedProfile( + new_active_profile_dir.BaseName().MaybeAsASCII()); ProfileInfoCache& cache = GetProfileInfoCache(); // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we @@ -1373,7 +1379,7 @@ void ProfileManager::UpdateLastUser(Profile* last_active) { std::string profile_path_base = last_active->GetPath().BaseName().MaybeAsASCII(); if (profile_path_base != GetLastUsedProfileName()) - local_state->SetString(prefs::kProfileLastUsed, profile_path_base); + profiles::SetLastUsedProfile(profile_path_base); ProfileInfoCache& cache = GetProfileInfoCache(); size_t profile_index = diff --git a/chrome/browser/profiles/profiles_state.cc b/chrome/browser/profiles/profiles_state.cc index b819c3f..042b2c3 100644 --- a/chrome/browser/profiles/profiles_state.cc +++ b/chrome/browser/profiles/profiles_state.cc @@ -212,11 +212,8 @@ bool SetActiveProfileToGuestIfLocked() { if (!cache.ProfileIsSigninRequiredAtIndex(index)) return false; - PrefService* local_state = g_browser_process->local_state(); - DCHECK(local_state); - local_state->SetString( - prefs::kProfileLastUsed, - guest_path.BaseName().MaybeAsASCII()); + SetLastUsedProfile(guest_path.BaseName().MaybeAsASCII()); + return true; } @@ -240,4 +237,15 @@ void RemoveBrowsingDataForProfile(const base::FilePath& profile_path) { // BrowsingDataRemover deletes itself. } +void SetLastUsedProfile(const std::string& profile_dir) { + // We should never be saving the System Profile as the last one used since it + // shouldn't have a browser. + if (profile_dir == base::FilePath(chrome::kSystemProfileDir).AsUTF8Unsafe()) + return; + + PrefService* local_state = g_browser_process->local_state(); + DCHECK(local_state); + local_state->SetString(prefs::kProfileLastUsed, profile_dir); +} + } // namespace profiles diff --git a/chrome/browser/profiles/profiles_state.h b/chrome/browser/profiles/profiles_state.h index 3b25c2c..9e54a0a 100644 --- a/chrome/browser/profiles/profiles_state.h +++ b/chrome/browser/profiles/profiles_state.h @@ -99,6 +99,10 @@ void SetFastUserSwitchingTutorialDismissedState(bool dismissed); // dismissed by a user, false otherwise. bool GetFastUserSwitchingTutorialDismissedState(); +// Sets the last used profile pref to |profile_dir|, unless |profile_dir| is the +// System Profile directory, which is an invalid last used profile. +void SetLastUsedProfile(const std::string& profile_dir); + } // namespace profiles #endif // CHROME_BROWSER_PROFILES_PROFILES_STATE_H_ diff --git a/chrome/browser/ui/cocoa/profiles/user_manager_mac_unittest.mm b/chrome/browser/ui/cocoa/profiles/user_manager_mac_unittest.mm index 760adcb..e4769a1 100644 --- a/chrome/browser/ui/cocoa/profiles/user_manager_mac_unittest.mm +++ b/chrome/browser/ui/cocoa/profiles/user_manager_mac_unittest.mm @@ -22,6 +22,9 @@ class UserManagerMacTest : public BrowserWithTestWindowTest { void SetUp() override { BrowserWithTestWindowTest::SetUp(); ASSERT_TRUE(testing_profile_manager_.SetUp()); + // Create a user to make sure the System Profile isn't the only one since it + // shouldn't be added to the ProfileInfoCache. + testing_profile_manager_.CreateTestingProfile("Default"); // Pre-load the system profile so we don't have to wait for the User Manager // to asynchronously create it. testing_profile_manager_.CreateSystemProfile(); |