Commit 11d39517 authored by Ramin Halavati's avatar Ramin Halavati Committed by Commit Bot

Update profile support of ephemeral Guest mode.

Support of ephemeral Guest profiles in several classes of
chrome/browser/profile folder is updated.

Bug: 1125474
Change-Id: I829bbc3f812f51466b90b6c2286c724fce85f767
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2461011Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Commit-Queue: Ramin Halavati <rhalavati@chromium.org>
Cr-Commit-Position: refs/heads/master@{#817467}
parent 4c191011
......@@ -148,11 +148,11 @@ void OffTheRecordProfileImpl::Init() {
BrowserContextDependencyManager::GetInstance()->CreateBrowserContextServices(
this);
// Incognito is not available for ephemeral Guest profiles.
CHECK(!profile_->IsEphemeralGuestProfile());
// Always crash when incognito is not available.
// Guest profiles may always be OTR, and non primary OTRs are always allowed.
// Check IncognitoModePrefs otherwise.
CHECK(profile_->IsGuestSession() || profile_->IsSystemProfile() ||
!IsPrimaryOTRProfile() ||
CHECK(!profile_->IsIncognitoProfile() ||
IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) !=
IncognitoModePrefs::DISABLED);
......
......@@ -31,7 +31,7 @@ constexpr base::TimeDelta kLongTimeOfInactivity =
base::TimeDelta::FromMinutes(30);
int GetMetricsBucketIndex(const Profile* profile) {
if (profile->IsGuestSession())
if (profile->IsGuestSession() || profile->IsEphemeralGuestProfile())
return 0;
ProfileAttributesEntry* entry;
......
......@@ -600,13 +600,17 @@ void ProfileManager::CreateProfileAsync(const base::FilePath& profile_path,
if (!callback.is_null()) {
if (iter != profiles_info_.end() && info->created) {
Profile* profile = info->profile.get();
// If this was the guest profile, apply settings and go OffTheRecord.
// If this was the non-ephemeral Guest profile, apply settings and go
// OffTheRecord.
// The system profile also needs characteristics of being off the record,
// such as having no extensions, not writing to disk, etc.
if (profile->IsGuestSession() || profile->IsSystemProfile()) {
if (profile->IsGuestSession() || profile->IsEphemeralGuestProfile() ||
profile->IsSystemProfile()) {
SetNonPersonalProfilePrefs(profile);
profile = profile->GetPrimaryOTRProfile();
}
if (profile->IsGuestSession() || profile->IsSystemProfile())
profile = profile->GetPrimaryOTRProfile();
// Profile has already been created. Run callback immediately.
callback.Run(profile, Profile::CREATE_STATUS_INITIALIZED);
} else {
......@@ -718,7 +722,7 @@ std::vector<Profile*> ProfileManager::GetLastOpenedProfiles(
if (profile) {
// crbug.com/823338 -> CHECK that the profiles aren't guest or
// incognito, causing a crash during session restore.
CHECK(!profile->IsGuestSession())
CHECK(!profile->IsGuestSession() && !profile->IsEphemeralGuestProfile())
<< "Guest profiles shouldn't have been saved as active profiles";
CHECK(!profile->IsOffTheRecord())
<< "OTR profiles shouldn't have been saved as active profiles";
......@@ -1060,7 +1064,7 @@ void ProfileManager::InitProfileUserPrefs(Profile* profile) {
size_t avatar_index;
std::string profile_name;
std::string supervised_user_id;
if (profile->IsGuestSession()) {
if (profile->IsGuestSession() || profile->IsEphemeralGuestProfile()) {
profile_name = l10n_util::GetStringUTF8(IDS_PROFILES_GUEST_PROFILE_NAME);
avatar_index = 0;
} else {
......@@ -1198,8 +1202,10 @@ void ProfileManager::OnProfileCreated(Profile* profile,
if (profile) {
// If this was the guest or system profile, finish setting its special
// status.
if (profile->IsGuestSession() || profile->IsSystemProfile())
if (profile->IsGuestSession() || profile->IsSystemProfile() ||
profile->IsEphemeralGuestProfile()) {
SetNonPersonalProfilePrefs(profile);
}
// Invoke CREATED callback for incognito profiles.
if (go_off_the_record)
......
......@@ -178,7 +178,7 @@ profile_metrics::BrowserProfileType ProfileMetrics::GetBrowserProfileType(
Profile* profile) {
if (profile->IsSystemProfile())
return profile_metrics::BrowserProfileType::kSystem;
if (profile->IsGuestSession())
if (profile->IsGuestSession() || profile->IsEphemeralGuestProfile())
return profile_metrics::BrowserProfileType::kGuest;
// A regular profile can be in a guest session or a system profile. Hence it
// should be checked after them.
......
......@@ -205,7 +205,7 @@ void OpenBrowserWindowForProfile(ProfileManager::CreateCallback callback,
}
#if !defined(OS_CHROMEOS)
if (!profile->IsGuestSession()) {
if (!profile->IsGuestSession() && !profile->IsEphemeralGuestProfile()) {
ProfileAttributesEntry* entry;
if (g_browser_process->profile_manager()->GetProfileAttributesStorage().
GetProfileAttributesWithPath(profile->GetPath(), &entry) &&
......@@ -284,7 +284,8 @@ void SwitchToGuestProfile(ProfileManager::CreateCallback callback) {
#endif
bool HasProfileSwitchTargets(Profile* profile) {
size_t min_profiles = profile->IsGuestSession() ? 1 : 2;
size_t min_profiles =
(profile->IsGuestSession() || profile->IsEphemeralGuestProfile()) ? 1 : 2;
size_t number_of_profiles =
g_browser_process->profile_manager()->GetNumberOfProfiles();
return number_of_profiles >= min_profiles;
......@@ -354,8 +355,10 @@ void LockProfile(Profile* profile) {
bool IsLockAvailable(Profile* profile) {
DCHECK(profile);
if (profile->IsGuestSession() || profile->IsSystemProfile())
if (profile->IsGuestSession() || profile->IsSystemProfile() ||
profile->IsEphemeralGuestProfile()) {
return false;
}
std::string hosted_domain = profile->GetPrefs()->
GetString(prefs::kGoogleServicesHostedDomain);
......
......@@ -230,8 +230,11 @@ IN_PROC_BROWSER_TEST_F(ProfileWindowBrowserTest, OpenGuestBrowser) {
}
IN_PROC_BROWSER_TEST_F(ProfileWindowBrowserTest, GuestIsIncognito) {
Browser* guest_browser = OpenGuestBrowser();
EXPECT_TRUE(guest_browser->profile()->IsOffTheRecord());
Profile* guest_profile = OpenGuestBrowser()->profile();
if (guest_profile->IsEphemeralGuestProfile())
EXPECT_FALSE(guest_profile->IsOffTheRecord());
else
EXPECT_TRUE(guest_profile->IsOffTheRecord());
}
IN_PROC_BROWSER_TEST_F(ProfileWindowBrowserTest, GuestIgnoresHistory) {
......@@ -249,7 +252,10 @@ IN_PROC_BROWSER_TEST_F(ProfileWindowBrowserTest, GuestIgnoresHistory) {
std::vector<GURL> urls =
ui_test_utils::HistoryEnumerator(guest_browser->profile()).urls();
ASSERT_EQ(0U, urls.size());
unsigned int expect_history =
guest_browser->profile()->IsEphemeralGuestProfile() ? 1 : 0;
ASSERT_EQ(expect_history, urls.size());
}
IN_PROC_BROWSER_TEST_F(ProfileWindowBrowserTest, GuestClearsCookies) {
......
......@@ -164,7 +164,8 @@ void UpdateProfileName(Profile* profile,
bool IsRegularOrGuestSession(Browser* browser) {
Profile* profile = browser->profile();
return profile->IsRegularProfile() || profile->IsGuestSession();
return profile->IsRegularProfile() || profile->IsGuestSession() ||
profile->IsEphemeralGuestProfile();
}
bool IsProfileLocked(const base::FilePath& profile_path) {
......
......@@ -163,11 +163,11 @@ void AccountConsistencyModeManager::SetIgnoreMissingOAuthClientForTesting() {
bool AccountConsistencyModeManager::ShouldBuildServiceForProfile(
Profile* profile) {
// IsGuestSession() returns true for the ProfileImpl associated with Guest
// profiles. This profile manually sets the kSigninAllowed prference, which
// profiles. This profile manually sets the kSigninAllowed preference, which
// causes crashes if the AccountConsistencyModeManager is instantiated. See
// https://crbug.com/940026
return profile->IsRegularProfile() && !profile->IsGuestSession() &&
!profile->IsSystemProfile();
!profile->IsEphemeralGuestProfile() && !profile->IsSystemProfile();
}
AccountConsistencyMethod
......
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