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 @@
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "base/no_destructor.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
......@@ -337,7 +338,7 @@ void OnProfileLoaded(ProfileManager::ProfileLoadedCallback client_callback,
}
DCHECK(profile);
std::move(client_callback)
.Run(incognito ? profile->GetOffTheRecordProfile() : profile);
.Run(incognito ? profile->GetPrimaryOTRProfile() : profile);
}
#if !defined(OS_ANDROID)
......@@ -418,7 +419,7 @@ Profile* ProfileManager::GetLastUsedProfileAllowedByPolicy() {
if (!profile)
return nullptr;
if (IsOffTheRecordModeForced(profile))
return profile->GetOffTheRecordProfile();
return profile->GetPrimaryOTRProfile();
return profile;
}
......@@ -499,7 +500,7 @@ Profile* ProfileManager::CreateInitialProfile() {
profile_manager->GetInitialProfileDir()));
if (profile_manager->ShouldGoOffTheRecord(profile))
return profile->GetOffTheRecordProfile();
return profile->GetPrimaryOTRProfile();
return profile;
}
......@@ -608,7 +609,7 @@ void ProfileManager::CreateProfileAsync(const base::FilePath& profile_path,
// such as having no extensions, not writing to disk, etc.
if (profile->IsGuestSession() || profile->IsSystemProfile()) {
SetNonPersonalProfilePrefs(profile);
profile = profile->GetOffTheRecordProfile();
profile = profile->GetPrimaryOTRProfile();
}
// Profile has already been created. Run callback immediately.
callback.Run(profile, Profile::CREATE_STATUS_INITIALIZED);
......@@ -625,11 +626,12 @@ bool ProfileManager::IsValidProfile(const void* profile) {
++iter) {
if (iter->second->created) {
Profile* candidate = iter->second->profile.get();
if (candidate == profile ||
(candidate->HasOffTheRecordProfile() &&
candidate->GetOffTheRecordProfile() == profile)) {
if (candidate == profile)
return true;
std::vector<Profile*> otr_profiles =
candidate->GetAllOffTheRecordProfiles();
if (base::Contains(otr_profiles, profile))
return true;
}
}
}
return false;
......@@ -669,8 +671,7 @@ Profile* ProfileManager::GetLastUsedProfile(
LOG_IF(FATAL, !profile) << "Calling GetLastUsedProfile() before profile "
<< "initialization is completed.";
return profile->IsGuestSession() ? profile->GetOffTheRecordProfile()
: profile;
return profile->IsGuestSession() ? profile->GetPrimaryOTRProfile() : profile;
#else
return GetProfile(GetLastUsedProfileDir(user_data_dir));
#endif
......@@ -1168,7 +1169,7 @@ void ProfileManager::OnProfileCreated(Profile* profile,
if (success) {
DoFinalInit(info, go_off_the_record);
if (go_off_the_record)
profile = profile->GetOffTheRecordProfile();
profile = profile->GetPrimaryOTRProfile();
} else {
profile = nullptr;
profiles_info_.erase(iter);
......@@ -1385,7 +1386,7 @@ Profile* ProfileManager::GetActiveUserOrOffTheRecordProfileFromPath(
// 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 (ShouldGoOffTheRecord(profile))
return profile->GetOffTheRecordProfile();
return profile->GetPrimaryOTRProfile();
DCHECK(!user_manager::UserManager::Get()->IsLoggedInAsGuest());
return profile;
}
......@@ -1401,7 +1402,7 @@ Profile* ProfileManager::GetActiveUserOrOffTheRecordProfileFromPath(
// Some unit tests didn't initialize the UserManager.
if (user_manager::UserManager::IsInitialized() &&
user_manager::UserManager::Get()->IsLoggedInAsGuest())
return profile->GetOffTheRecordProfile();
return profile->GetPrimaryOTRProfile();
return profile;
#else
base::FilePath default_profile_dir(user_data_dir);
......@@ -1753,7 +1754,7 @@ void ProfileManager::SaveActiveProfiles() {
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
// profiles. Include each base name only once in the last active profile
// list.
......
......@@ -615,14 +615,14 @@ IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, IncognitoProfile) {
Profile* profile = ProfileManager::GetActiveUserProfile();
ASSERT_TRUE(profile);
EXPECT_FALSE(profile->HasOffTheRecordProfile());
EXPECT_FALSE(profile->HasPrimaryOTRProfile());
size_t initial_profile_count = profile_manager->GetNumberOfProfiles();
// 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));
EXPECT_EQ(initial_profile_count, profile_manager->GetNumberOfProfiles());
......@@ -639,9 +639,10 @@ IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, IncognitoProfile) {
.empty());
// 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_EQ(initial_profile_count, profile_manager->GetNumberOfProfiles());
// After destroying the incognito profile incognito preferences should be
......
......@@ -885,8 +885,8 @@ TEST_F(ProfileManagerTest, GetLastUsedProfileAllowedByPolicy) {
#if defined(OS_CHROMEOS)
// 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
// to get a regular profile.
// is forced to be off-the-record. That's why we need to create at least one
// user to get a regular profile.
RegisterUser(
AccountId::FromUserEmailGaiaId("test-user@example.com", "1234567890"));
#endif
......@@ -898,13 +898,13 @@ TEST_F(ProfileManagerTest, GetLastUsedProfileAllowedByPolicy) {
EXPECT_EQ(IncognitoModePrefs::kDefaultAvailability,
IncognitoModePrefs::GetAvailability(prefs));
ASSERT_TRUE(profile->GetOffTheRecordProfile());
ASSERT_TRUE(profile->GetPrimaryOTRProfile());
IncognitoModePrefs::SetAvailability(prefs, IncognitoModePrefs::DISABLED);
EXPECT_FALSE(
profile_manager->GetLastUsedProfileAllowedByPolicy()->IsOffTheRecord());
// GetLastUsedProfileAllowedByPolicy() returns the incognito Profile when
// GetLastUsedProfileAllowedByPolicy() returns the off-the-record Profile when
// incognito mode is forced.
IncognitoModePrefs::SetAvailability(prefs, IncognitoModePrefs::FORCED);
EXPECT_TRUE(
......@@ -1057,8 +1057,7 @@ TEST_F(ProfileManagerTest, LastOpenedProfilesDoesNotContainIncognito) {
EXPECT_EQ(profile1, last_opened_profiles[0]);
// And for profile2.
Browser::CreateParams profile2_params(profile1->GetOffTheRecordProfile(),
true);
Browser::CreateParams profile2_params(profile1->GetPrimaryOTRProfile(), true);
std::unique_ptr<Browser> browser2a(
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