Commit 9dd4a3d4 authored by Ramin Halavati's avatar Ramin Halavati Committed by Commit Bot

Update ProfileManager to use multiple OTR APIs.

Profile Manager and its tests are updated to match the new profile APIs
for multiple OTR profile support.

Bug: 1033903
Change-Id: I01c5c6389c75e9288deb1b03c5a18aa7307bf270
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2144131Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Commit-Queue: Ramin Halavati <rhalavati@chromium.org>
Cr-Commit-Position: refs/heads/master@{#762015}
parent 008a7737
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
...@@ -337,7 +338,7 @@ void OnProfileLoaded(ProfileManager::ProfileLoadedCallback client_callback, ...@@ -337,7 +338,7 @@ void OnProfileLoaded(ProfileManager::ProfileLoadedCallback client_callback,
} }
DCHECK(profile); DCHECK(profile);
std::move(client_callback) std::move(client_callback)
.Run(incognito ? profile->GetOffTheRecordProfile() : profile); .Run(incognito ? profile->GetPrimaryOTRProfile() : profile);
} }
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
...@@ -418,7 +419,7 @@ Profile* ProfileManager::GetLastUsedProfileAllowedByPolicy() { ...@@ -418,7 +419,7 @@ Profile* ProfileManager::GetLastUsedProfileAllowedByPolicy() {
if (!profile) if (!profile)
return nullptr; return nullptr;
if (IsOffTheRecordModeForced(profile)) if (IsOffTheRecordModeForced(profile))
return profile->GetOffTheRecordProfile(); return profile->GetPrimaryOTRProfile();
return profile; return profile;
} }
...@@ -499,7 +500,7 @@ Profile* ProfileManager::CreateInitialProfile() { ...@@ -499,7 +500,7 @@ Profile* ProfileManager::CreateInitialProfile() {
profile_manager->GetInitialProfileDir())); profile_manager->GetInitialProfileDir()));
if (profile_manager->ShouldGoOffTheRecord(profile)) if (profile_manager->ShouldGoOffTheRecord(profile))
return profile->GetOffTheRecordProfile(); return profile->GetPrimaryOTRProfile();
return profile; return profile;
} }
...@@ -608,7 +609,7 @@ void ProfileManager::CreateProfileAsync(const base::FilePath& profile_path, ...@@ -608,7 +609,7 @@ void ProfileManager::CreateProfileAsync(const base::FilePath& profile_path,
// such as having no extensions, not writing to disk, etc. // such as having no extensions, not writing to disk, etc.
if (profile->IsGuestSession() || profile->IsSystemProfile()) { if (profile->IsGuestSession() || profile->IsSystemProfile()) {
SetNonPersonalProfilePrefs(profile); SetNonPersonalProfilePrefs(profile);
profile = profile->GetOffTheRecordProfile(); profile = profile->GetPrimaryOTRProfile();
} }
// Profile has already been created. Run callback immediately. // Profile has already been created. Run callback immediately.
callback.Run(profile, Profile::CREATE_STATUS_INITIALIZED); callback.Run(profile, Profile::CREATE_STATUS_INITIALIZED);
...@@ -625,11 +626,12 @@ bool ProfileManager::IsValidProfile(const void* profile) { ...@@ -625,11 +626,12 @@ bool ProfileManager::IsValidProfile(const void* profile) {
++iter) { ++iter) {
if (iter->second->created) { if (iter->second->created) {
Profile* candidate = iter->second->profile.get(); Profile* candidate = iter->second->profile.get();
if (candidate == profile || if (candidate == profile)
(candidate->HasOffTheRecordProfile() && return true;
candidate->GetOffTheRecordProfile() == profile)) { std::vector<Profile*> otr_profiles =
candidate->GetAllOffTheRecordProfiles();
if (base::Contains(otr_profiles, profile))
return true; return true;
}
} }
} }
return false; return false;
...@@ -669,8 +671,7 @@ Profile* ProfileManager::GetLastUsedProfile( ...@@ -669,8 +671,7 @@ Profile* ProfileManager::GetLastUsedProfile(
LOG_IF(FATAL, !profile) << "Calling GetLastUsedProfile() before profile " LOG_IF(FATAL, !profile) << "Calling GetLastUsedProfile() before profile "
<< "initialization is completed."; << "initialization is completed.";
return profile->IsGuestSession() ? profile->GetOffTheRecordProfile() return profile->IsGuestSession() ? profile->GetPrimaryOTRProfile() : profile;
: profile;
#else #else
return GetProfile(GetLastUsedProfileDir(user_data_dir)); return GetProfile(GetLastUsedProfileDir(user_data_dir));
#endif #endif
...@@ -1168,7 +1169,7 @@ void ProfileManager::OnProfileCreated(Profile* profile, ...@@ -1168,7 +1169,7 @@ void ProfileManager::OnProfileCreated(Profile* profile,
if (success) { if (success) {
DoFinalInit(info, go_off_the_record); DoFinalInit(info, go_off_the_record);
if (go_off_the_record) if (go_off_the_record)
profile = profile->GetOffTheRecordProfile(); profile = profile->GetPrimaryOTRProfile();
} else { } else {
profile = nullptr; profile = nullptr;
profiles_info_.erase(iter); profiles_info_.erase(iter);
...@@ -1385,7 +1386,7 @@ Profile* ProfileManager::GetActiveUserOrOffTheRecordProfileFromPath( ...@@ -1385,7 +1386,7 @@ Profile* ProfileManager::GetActiveUserOrOffTheRecordProfileFromPath(
// many of the browser and ui tests fail. We do return the OTR profile // many of the browser and ui tests fail. We do return the OTR profile
// if the login-profile switch is passed so that we can test this. // if the login-profile switch is passed so that we can test this.
if (ShouldGoOffTheRecord(profile)) if (ShouldGoOffTheRecord(profile))
return profile->GetOffTheRecordProfile(); return profile->GetPrimaryOTRProfile();
DCHECK(!user_manager::UserManager::Get()->IsLoggedInAsGuest()); DCHECK(!user_manager::UserManager::Get()->IsLoggedInAsGuest());
return profile; return profile;
} }
...@@ -1401,7 +1402,7 @@ Profile* ProfileManager::GetActiveUserOrOffTheRecordProfileFromPath( ...@@ -1401,7 +1402,7 @@ Profile* ProfileManager::GetActiveUserOrOffTheRecordProfileFromPath(
// Some unit tests didn't initialize the UserManager. // Some unit tests didn't initialize the UserManager.
if (user_manager::UserManager::IsInitialized() && if (user_manager::UserManager::IsInitialized() &&
user_manager::UserManager::Get()->IsLoggedInAsGuest()) user_manager::UserManager::Get()->IsLoggedInAsGuest())
return profile->GetOffTheRecordProfile(); return profile->GetPrimaryOTRProfile();
return profile; return profile;
#else #else
base::FilePath default_profile_dir(user_data_dir); base::FilePath default_profile_dir(user_data_dir);
...@@ -1753,7 +1754,7 @@ void ProfileManager::SaveActiveProfiles() { ...@@ -1753,7 +1754,7 @@ void ProfileManager::SaveActiveProfiles() {
profile_list->Clear(); profile_list->Clear();
// crbug.com/120112 -> several non-incognito profiles might have the same // crbug.com/120112 -> several non-off-the-record profiles might have the same
// GetPath().BaseName(). In that case, we cannot restore both // GetPath().BaseName(). In that case, we cannot restore both
// profiles. Include each base name only once in the last active profile // profiles. Include each base name only once in the last active profile
// list. // list.
......
...@@ -615,14 +615,14 @@ IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, IncognitoProfile) { ...@@ -615,14 +615,14 @@ IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, IncognitoProfile) {
Profile* profile = ProfileManager::GetActiveUserProfile(); Profile* profile = ProfileManager::GetActiveUserProfile();
ASSERT_TRUE(profile); ASSERT_TRUE(profile);
EXPECT_FALSE(profile->HasOffTheRecordProfile()); EXPECT_FALSE(profile->HasPrimaryOTRProfile());
size_t initial_profile_count = profile_manager->GetNumberOfProfiles(); size_t initial_profile_count = profile_manager->GetNumberOfProfiles();
// Create an incognito profile. // Create an incognito profile.
Profile* incognito_profile = profile->GetOffTheRecordProfile(); Profile* incognito_profile = profile->GetPrimaryOTRProfile();
EXPECT_TRUE(profile->HasOffTheRecordProfile()); EXPECT_TRUE(profile->HasPrimaryOTRProfile());
ASSERT_TRUE(profile_manager->IsValidProfile(incognito_profile)); ASSERT_TRUE(profile_manager->IsValidProfile(incognito_profile));
EXPECT_EQ(initial_profile_count, profile_manager->GetNumberOfProfiles()); EXPECT_EQ(initial_profile_count, profile_manager->GetNumberOfProfiles());
...@@ -639,9 +639,10 @@ IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, IncognitoProfile) { ...@@ -639,9 +639,10 @@ IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, IncognitoProfile) {
.empty()); .empty());
// Delete the incognito profile. // Delete the incognito profile.
incognito_profile->GetOriginalProfile()->DestroyOffTheRecordProfile(); incognito_profile->GetOriginalProfile()->DestroyOffTheRecordProfile(
incognito_profile);
EXPECT_FALSE(profile->HasOffTheRecordProfile()); EXPECT_FALSE(profile->HasPrimaryOTRProfile());
EXPECT_FALSE(profile_manager->IsValidProfile(incognito_profile)); EXPECT_FALSE(profile_manager->IsValidProfile(incognito_profile));
EXPECT_EQ(initial_profile_count, profile_manager->GetNumberOfProfiles()); EXPECT_EQ(initial_profile_count, profile_manager->GetNumberOfProfiles());
// After destroying the incognito profile incognito preferences should be // After destroying the incognito profile incognito preferences should be
......
...@@ -885,8 +885,8 @@ TEST_F(ProfileManagerTest, GetLastUsedProfileAllowedByPolicy) { ...@@ -885,8 +885,8 @@ TEST_F(ProfileManagerTest, GetLastUsedProfileAllowedByPolicy) {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// On CrOS, profile returned by GetLastUsedProfile is a sign-in profile that // On CrOS, profile returned by GetLastUsedProfile is a sign-in profile that
// is forced to be incognito. That's why we need to create at least one user // is forced to be off-the-record. That's why we need to create at least one
// to get a regular profile. // user to get a regular profile.
RegisterUser( RegisterUser(
AccountId::FromUserEmailGaiaId("test-user@example.com", "1234567890")); AccountId::FromUserEmailGaiaId("test-user@example.com", "1234567890"));
#endif #endif
...@@ -898,13 +898,13 @@ TEST_F(ProfileManagerTest, GetLastUsedProfileAllowedByPolicy) { ...@@ -898,13 +898,13 @@ TEST_F(ProfileManagerTest, GetLastUsedProfileAllowedByPolicy) {
EXPECT_EQ(IncognitoModePrefs::kDefaultAvailability, EXPECT_EQ(IncognitoModePrefs::kDefaultAvailability,
IncognitoModePrefs::GetAvailability(prefs)); IncognitoModePrefs::GetAvailability(prefs));
ASSERT_TRUE(profile->GetOffTheRecordProfile()); ASSERT_TRUE(profile->GetPrimaryOTRProfile());
IncognitoModePrefs::SetAvailability(prefs, IncognitoModePrefs::DISABLED); IncognitoModePrefs::SetAvailability(prefs, IncognitoModePrefs::DISABLED);
EXPECT_FALSE( EXPECT_FALSE(
profile_manager->GetLastUsedProfileAllowedByPolicy()->IsOffTheRecord()); profile_manager->GetLastUsedProfileAllowedByPolicy()->IsOffTheRecord());
// GetLastUsedProfileAllowedByPolicy() returns the incognito Profile when // GetLastUsedProfileAllowedByPolicy() returns the off-the-record Profile when
// incognito mode is forced. // incognito mode is forced.
IncognitoModePrefs::SetAvailability(prefs, IncognitoModePrefs::FORCED); IncognitoModePrefs::SetAvailability(prefs, IncognitoModePrefs::FORCED);
EXPECT_TRUE( EXPECT_TRUE(
...@@ -1057,8 +1057,7 @@ TEST_F(ProfileManagerTest, LastOpenedProfilesDoesNotContainIncognito) { ...@@ -1057,8 +1057,7 @@ TEST_F(ProfileManagerTest, LastOpenedProfilesDoesNotContainIncognito) {
EXPECT_EQ(profile1, last_opened_profiles[0]); EXPECT_EQ(profile1, last_opened_profiles[0]);
// And for profile2. // And for profile2.
Browser::CreateParams profile2_params(profile1->GetOffTheRecordProfile(), Browser::CreateParams profile2_params(profile1->GetPrimaryOTRProfile(), true);
true);
std::unique_ptr<Browser> browser2a( std::unique_ptr<Browser> browser2a(
CreateBrowserWithTestWindowForParams(&profile2_params)); CreateBrowserWithTestWindowForParams(&profile2_params));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment