Commit 100983af authored by Ramin Halavati's avatar Ramin Halavati Committed by Commit Bot

Add Ephemeral Guest profiles.

This CL adds a new Guest profile type without the enforced OTR layer
over it. In subsequent CLs, all calls to |IsGuestSession| function
should be audited and based on whether they are needed for new profiles
or not, would be covered by |IsEphemeralGuestProfile| as well.

Please refer to go/guest-on-disk for more context.

Bug: 1125474
Change-Id: I2516e3d0822c6753ddb2421e2756ac51c38e49df
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2434925Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Commit-Queue: Ramin Halavati <rhalavati@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813627}
parent 30263318
...@@ -144,7 +144,10 @@ void OffTheRecordProfileImpl::Init() { ...@@ -144,7 +144,10 @@ void OffTheRecordProfileImpl::Init() {
// Must be done before CreateBrowserContextServices(), since some of them // Must be done before CreateBrowserContextServices(), since some of them
// change behavior based on whether the provided context is a guest session. // change behavior based on whether the provided context is a guest session.
set_is_guest_profile(profile_->IsGuestSession()); // TODO(https://crbug.com/1125474): Remove |IsEphemeralGuestProfile| when
// Incognito is disabled for ephemeral Guest profiles.
set_is_guest_profile(profile_->IsGuestSession() ||
profile_->IsEphemeralGuestProfile());
BrowserContextDependencyManager::GetInstance()->CreateBrowserContextServices( BrowserContextDependencyManager::GetInstance()->CreateBrowserContextServices(
this); this);
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "chrome/browser/signin/identity_manager_factory.h" #include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/common/buildflags.h" #include "chrome/common/buildflags.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
...@@ -371,7 +372,20 @@ bool Profile::IsRegularProfile() const { ...@@ -371,7 +372,20 @@ bool Profile::IsRegularProfile() const {
} }
bool Profile::IsIncognitoProfile() const { bool Profile::IsIncognitoProfile() const {
return IsPrimaryOTRProfile() && !IsGuestSession(); // TODO(https://crbug.com/1125474): Remove |IsEphemeralGuestProfile| when
// Incognito is disabled for ephemeral Guest profiles.
return IsPrimaryOTRProfile() && !IsGuestSession() &&
!IsEphemeralGuestProfile();
}
// static
bool Profile::IsEphemeralGuestProfileEnabled() {
#if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MAC)
return base::FeatureList::IsEnabled(
features::kEnableEphemeralGuestProfilesOnDesktop);
#else
return false;
#endif
} }
bool Profile::IsGuestSession() const { bool Profile::IsGuestSession() const {
...@@ -390,10 +404,14 @@ bool Profile::IsGuestSession() const { ...@@ -390,10 +404,14 @@ bool Profile::IsGuestSession() const {
->session_type == crosapi::mojom::SessionType::kGuestSession; ->session_type == crosapi::mojom::SessionType::kGuestSession;
} }
#endif // BUILDFLAG(IS_LACROS) #endif // BUILDFLAG(IS_LACROS)
return is_guest_profile_; return is_guest_profile_ && !IsEphemeralGuestProfileEnabled();
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
} }
bool Profile::IsEphemeralGuestProfile() const {
return is_guest_profile_ && IsEphemeralGuestProfileEnabled();
}
bool Profile::IsSystemProfile() const { bool Profile::IsSystemProfile() const {
return is_system_profile_; return is_system_profile_;
} }
......
...@@ -411,10 +411,24 @@ class Profile : public content::BrowserContext { ...@@ -411,10 +411,24 @@ class Profile : public content::BrowserContext {
// OffTheRecord profile used for incognito mode and guest sessions. // OffTheRecord profile used for incognito mode and guest sessions.
bool IsPrimaryOTRProfile() const; bool IsPrimaryOTRProfile() const;
// Returns whether it is a guest session. This covers both the guest profile // Returns whether ephemeral Guest profiles are enabled.
// and its parent. static bool IsEphemeralGuestProfileEnabled();
// Returns whether it is a Guest session. This covers both regular and
// off-the-record profiles of a Guest session.
// This function only returns true for non-ephemeral Guest sessions.
// TODO(https://crbug.com/1125474): Audit all use cases and consider adding
// |IsEphemeralGuestProfile|. Remove after audit is done on all relevant
// platforms and non-ephemeral Guest profiles are deprecated.
virtual bool IsGuestSession() const; virtual bool IsGuestSession() const;
// Returns whether it is an ephemeral Guest profile. This covers both regular
// and off-the-record profiles of a Guest session.
// TODO(https://crbug.com/1125474): After auditing all use cases of
// |IsGuestSession| on all platforms and removal of all calls to
// |IsGuestSession|, rename to |IsGuestProfile|.
virtual bool IsEphemeralGuestProfile() const;
// Returns whether it is a system profile. // Returns whether it is a system profile.
virtual bool IsSystemProfile() const; virtual bool IsSystemProfile() const;
......
...@@ -793,8 +793,16 @@ base::FilePath ProfileManager::GetGuestProfilePath() { ...@@ -793,8 +793,16 @@ base::FilePath ProfileManager::GetGuestProfilePath() {
ProfileManager* profile_manager = g_browser_process->profile_manager(); ProfileManager* profile_manager = g_browser_process->profile_manager();
base::FilePath guest_path = profile_manager->user_data_dir(); // TODO(https://crbug.com/1125474): Consider adding a different naming system
return guest_path.Append(chrome::kGuestProfileDir); // for Guest profiles.
if (profile_manager->guest_profile_path_.empty()) {
profile_manager->guest_profile_path_ =
Profile::IsEphemeralGuestProfileEnabled()
? profile_manager->GenerateNextProfileDirectoryPath()
: profile_manager->user_data_dir().Append(chrome::kGuestProfileDir);
}
return profile_manager->guest_profile_path_;
} }
// static // static
...@@ -1616,6 +1624,27 @@ void ProfileManager::FinishDeletingProfile( ...@@ -1616,6 +1624,27 @@ void ProfileManager::FinishDeletingProfile(
// Prevents CreateProfileAsync from re-creating the profile. // Prevents CreateProfileAsync from re-creating the profile.
MarkProfileDirectoryForDeletion(profile_dir); MarkProfileDirectoryForDeletion(profile_dir);
} }
// static
void ProfileManager::CleanUpGuestProfile() {
// ChromeOS handles guest data independently.
#if !defined(OS_CHROMEOS)
ProfileManager* profile_manager = g_browser_process->profile_manager();
Profile* profile =
profile_manager->GetProfileByPath(profile_manager->GetGuestProfilePath());
if (profile) {
// Clear all browsing data once a Guest Session completes. The Guest
// profile has BrowserContextKeyedServices that the ProfileDestroyer
// can't delete it properly.
// TODO(https://crbug.com/88586): Delete the guest when regular profiles
// become deletable when not needed.
profiles::RemoveBrowsingDataForProfile(GetGuestProfilePath());
}
profile_manager->guest_profile_path_.clear();
#endif //! defined(OS_CHROMEOS)
}
#endif // !defined(OS_ANDROID) #endif // !defined(OS_ANDROID)
ProfileManager::ProfileInfo* ProfileManager::RegisterProfile( ProfileManager::ProfileInfo* ProfileManager::RegisterProfile(
...@@ -1726,6 +1755,9 @@ void ProfileManager::AddProfileToStorage(Profile* profile) { ...@@ -1726,6 +1755,9 @@ void ProfileManager::AddProfileToStorage(Profile* profile) {
storage.GetProfileAttributesWithPath(profile->GetPath(), &entry); storage.GetProfileAttributesWithPath(profile->GetPath(), &entry);
DCHECK(has_entry); DCHECK(has_entry);
if (profile->IsEphemeralGuestProfile())
profile->GetPrefs()->SetBoolean(prefs::kForceEphemeralProfiles, true);
if (profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) if (profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles))
entry->SetIsEphemeral(true); entry->SetIsEphemeral(true);
...@@ -1775,7 +1807,7 @@ void ProfileManager::SaveActiveProfiles() { ...@@ -1775,7 +1807,7 @@ void ProfileManager::SaveActiveProfiles() {
for (it = active_profiles_.begin(); it != active_profiles_.end(); ++it) { for (it = active_profiles_.begin(); it != active_profiles_.end(); ++it) {
// crbug.com/823338 -> CHECK that the profiles aren't guest or incognito, // crbug.com/823338 -> CHECK that the profiles aren't guest or incognito,
// causing a crash during session restore. // causing a crash during session restore.
CHECK(!(*it)->IsGuestSession()) CHECK((!(*it)->IsGuestSession()) && (!(*it)->IsEphemeralGuestProfile()))
<< "Guest profiles shouldn't be saved as active profiles"; << "Guest profiles shouldn't be saved as active profiles";
CHECK(!(*it)->IsOffTheRecord()) CHECK(!(*it)->IsOffTheRecord())
<< "OTR profiles shouldn't be saved as active profiles"; << "OTR profiles shouldn't be saved as active profiles";
...@@ -1829,6 +1861,9 @@ void ProfileManager::OnBrowserClosed(Browser* browser) { ...@@ -1829,6 +1861,9 @@ void ProfileManager::OnBrowserClosed(Browser* browser) {
return; return;
} }
if (profile->IsGuestSession() || profile->IsEphemeralGuestProfile())
CleanUpGuestProfile();
base::FilePath path = profile->GetPath(); base::FilePath path = profile->GetPath();
if (IsProfileDirectoryMarkedForDeletion(path)) { if (IsProfileDirectoryMarkedForDeletion(path)) {
// Do nothing if the profile is already being deleted. // Do nothing if the profile is already being deleted.
......
...@@ -215,6 +215,9 @@ class ProfileManager : public content::NotificationObserver, ...@@ -215,6 +215,9 @@ class ProfileManager : public content::NotificationObserver,
// that case the callback will be called when profile creation is complete. // that case the callback will be called when profile creation is complete.
void ScheduleProfileForDeletion(const base::FilePath& profile_dir, void ScheduleProfileForDeletion(const base::FilePath& profile_dir,
ProfileLoadedCallback callback); ProfileLoadedCallback callback);
// Deletes Guest profile's browsing data.
static void CleanUpGuestProfile();
#endif #endif
// Autoloads profiles if they are running background apps. // Autoloads profiles if they are running background apps.
...@@ -458,6 +461,9 @@ class ProfileManager : public content::NotificationObserver, ...@@ -458,6 +461,9 @@ class ProfileManager : public content::NotificationObserver,
// Controls whether to initialize some services. Only disabled for testing. // Controls whether to initialize some services. Only disabled for testing.
bool do_final_services_init_ = true; bool do_final_services_init_ = true;
// Path to Guest profile. Can be empty when the profile does not exist.
base::FilePath guest_profile_path_;
// TODO(chrome/browser/profiles/OWNERS): Usage of this in profile_manager.cc // TODO(chrome/browser/profiles/OWNERS): Usage of this in profile_manager.cc
// should likely be turned into DCHECK_CURRENTLY_ON(BrowserThread::UI) for // should likely be turned into DCHECK_CURRENTLY_ON(BrowserThread::UI) for
// consistency with surrounding code in the same file but that wasn't trivial // consistency with surrounding code in the same file but that wasn't trivial
......
...@@ -602,19 +602,9 @@ Browser::~Browser() { ...@@ -602,19 +602,9 @@ Browser::~Browser() {
// //
// Non-primary OffTheRecord profiles should not be destroyed directly by // Non-primary OffTheRecord profiles should not be destroyed directly by
// Browser (e.g. for offscreen tabs, https://crbug.com/664351). // Browser (e.g. for offscreen tabs, https://crbug.com/664351).
if (profile_->IsPrimaryOTRProfile() && if (profile_->IsIncognitoProfile() &&
!BrowserList::IsOffTheRecordBrowserInUse(profile_) && !BrowserList::IsOffTheRecordBrowserInUse(profile_) &&
!profile_->GetOriginalProfile()->IsSystemProfile()) { !profile_->GetOriginalProfile()->IsSystemProfile()) {
if (profile_->IsGuestSession()) {
// ChromeOS handles guest data independently.
#if !defined(OS_CHROMEOS)
// Clear all browsing data once a Guest Session completes. The Guest
// profile has BrowserContextKeyedServices that the Incognito profile
// doesn't, so the ProfileDestroyer can't delete it properly.
// TODO(mlerman): Delete the guest using an improved ProfileDestroyer.
profiles::RemoveBrowsingDataForProfile(profile_->GetPath());
#endif
} else {
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
// The Printing Background Manager holds onto preview dialog WebContents // The Printing Background Manager holds onto preview dialog WebContents
// whose corresponding print jobs have not yet fully spooled. Make sure // whose corresponding print jobs have not yet fully spooled. Make sure
...@@ -626,7 +616,6 @@ Browser::~Browser() { ...@@ -626,7 +616,6 @@ Browser::~Browser() {
// An incognito profile is no longer needed, this indirectly frees // An incognito profile is no longer needed, this indirectly frees
// its cache and cookies once it gets destroyed at the appropriate time. // its cache and cookies once it gets destroyed at the appropriate time.
ProfileDestroyer::DestroyProfileWhenAppropriate(profile_); ProfileDestroyer::DestroyProfileWhenAppropriate(profile_);
}
} }
// There may be pending file dialogs, we need to tell them that we've gone // There may be pending file dialogs, we need to tell them that we've gone
......
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