Commit c086a4b1 authored by David Black's avatar David Black Committed by Chromium LUCI CQ

Enable holding space for guest mode users.

This CL enables holding space for guest mode but redirects service
creation to be associated with the original (non-incognito) profile.

Bug: 1161717
Change-Id: I8328f861e13fbdf863ff27463a23929eeb88f31a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2606291
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#839832}
parent 922211c8
...@@ -191,11 +191,11 @@ const char* HoldingSpaceTray::GetClassName() const { ...@@ -191,11 +191,11 @@ const char* HoldingSpaceTray::GetClassName() const {
void HoldingSpaceTray::UpdateVisibility() { void HoldingSpaceTray::UpdateVisibility() {
HoldingSpaceModel* model = HoldingSpaceController::Get()->model(); HoldingSpaceModel* model = HoldingSpaceController::Get()->model();
LoginStatus login_status = shelf()->GetStatusAreaWidget()->login_status();
const bool in_active_session = login_status != LoginStatus::NOT_LOGGED_IN &&
login_status != LoginStatus::LOCKED;
const bool logged_in = if (!model || !in_active_session) {
shelf()->GetStatusAreaWidget()->login_status() == LoginStatus::USER;
if (!model || !logged_in) {
SetVisiblePreferred(false); SetVisiblePreferred(false);
return; return;
} }
......
...@@ -37,12 +37,33 @@ HoldingSpaceKeyedService* HoldingSpaceKeyedServiceFactory::GetService( ...@@ -37,12 +37,33 @@ HoldingSpaceKeyedService* HoldingSpaceKeyedServiceFactory::GetService(
GetInstance()->GetServiceForBrowserContext(context, /*create=*/true)); GetInstance()->GetServiceForBrowserContext(context, /*create=*/true));
} }
content::BrowserContext*
HoldingSpaceKeyedServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
Profile* profile = Profile::FromBrowserContext(context);
user_manager::User* user =
chromeos::ProfileHelper::Get()->GetUserByProfile(profile);
if (!user)
return nullptr;
// Guest users are supported but should redirect to create the holding space
// service for the original (e.g. non-incognito) profile.
if (user->GetType() == user_manager::USER_TYPE_GUEST)
return profile->GetOriginalProfile();
// Don't create the service for off the record profiles of other user types.
return profile->IsOffTheRecord() ? nullptr : context;
}
KeyedService* HoldingSpaceKeyedServiceFactory::BuildServiceInstanceFor( KeyedService* HoldingSpaceKeyedServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const { content::BrowserContext* context) const {
if (!features::IsTemporaryHoldingSpaceEnabled()) if (!features::IsTemporaryHoldingSpaceEnabled())
return nullptr; return nullptr;
Profile* profile = Profile::FromBrowserContext(context); Profile* profile = Profile::FromBrowserContext(context);
DCHECK(!profile->IsOffTheRecord());
user_manager::User* user = user_manager::User* user =
chromeos::ProfileHelper::Get()->GetUserByProfile(profile); chromeos::ProfileHelper::Get()->GetUserByProfile(profile);
if (!user) if (!user)
......
...@@ -26,6 +26,8 @@ class HoldingSpaceKeyedServiceFactory ...@@ -26,6 +26,8 @@ class HoldingSpaceKeyedServiceFactory
protected: protected:
// BrowserContextKeyedServiceFactory: // BrowserContextKeyedServiceFactory:
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
KeyedService* BuildServiceInstanceFor( KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override; content::BrowserContext* context) const override;
void RegisterProfilePrefs( void RegisterProfilePrefs(
......
...@@ -282,6 +282,20 @@ class HoldingSpaceKeyedServiceTest : public BrowserWithTestWindowTest { ...@@ -282,6 +282,20 @@ class HoldingSpaceKeyedServiceTest : public BrowserWithTestWindowTest {
base::BindRepeating(&BuildVolumeManager)}}); base::BindRepeating(&BuildVolumeManager)}});
} }
TestingProfile* CreateGuestProfile() {
user_manager::User* guest_user = fake_user_manager_->AddGuestUser();
fake_user_manager_->LoginUser(fake_user_manager_->GetGuestAccountId());
chromeos::ProfileHelper::Get()->SetProfileToUserMappingForTesting(
guest_user);
return profile_manager()->CreateTestingProfile(
guest_user->GetAccountId().GetUserEmail(),
/*testing_factories=*/{
{file_manager::VolumeManagerFactory::GetInstance(),
base::BindRepeating(&BuildVolumeManager)}});
}
TestingProfile* CreateSecondaryProfile( TestingProfile* CreateSecondaryProfile(
std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs = nullptr) { std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs = nullptr) {
const std::string kSecondaryProfileName = "secondary_profile"; const std::string kSecondaryProfileName = "secondary_profile";
...@@ -509,6 +523,56 @@ TEST_F(HoldingSpaceKeyedServiceTest, AddScreenshotItem) { ...@@ -509,6 +523,56 @@ TEST_F(HoldingSpaceKeyedServiceTest, AddScreenshotItem) {
EXPECT_EQ(base::ASCIIToUTF16("Screenshot 2.png"), item_2->text()); EXPECT_EQ(base::ASCIIToUTF16("Screenshot 2.png"), item_2->text());
} }
TEST_F(HoldingSpaceKeyedServiceTest, GuestUserProfile) {
// Service instances should be created for guest users.
TestingProfile* const guest_profile = CreateGuestProfile();
ASSERT_TRUE(guest_profile);
ASSERT_FALSE(guest_profile->IsOffTheRecord());
HoldingSpaceKeyedService* const guest_profile_service =
HoldingSpaceKeyedServiceFactory::GetInstance()->GetService(guest_profile);
ASSERT_TRUE(guest_profile_service);
// Construct an incognito profile from `guest_profile`.
TestingProfile::Builder incognito_guest_profile_builder;
incognito_guest_profile_builder.SetGuestSession();
incognito_guest_profile_builder.SetProfileName(
guest_profile->GetProfileUserName());
Profile* const incognito_guest_profile =
incognito_guest_profile_builder.BuildIncognito(guest_profile);
ASSERT_TRUE(incognito_guest_profile);
ASSERT_TRUE(incognito_guest_profile->IsOffTheRecord());
// Service instances should be created for guest users w/ OTR profiles but
// should redirect to use the original (e.g. non-incognito) profile.
HoldingSpaceKeyedService* const incognito_guest_profile_service =
HoldingSpaceKeyedServiceFactory::GetInstance()->GetService(
incognito_guest_profile);
ASSERT_EQ(incognito_guest_profile_service, guest_profile_service);
}
TEST_F(HoldingSpaceKeyedServiceTest, OffTheRecordProfile) {
// Service instances should be created for on the record profiles.
HoldingSpaceKeyedService* const primary_profile_service =
HoldingSpaceKeyedServiceFactory::GetInstance()->GetService(GetProfile());
ASSERT_TRUE(primary_profile_service);
// Construct an incognito profile from the primary profile.
TestingProfile::Builder incognito_primary_profile_builder;
incognito_primary_profile_builder.SetProfileName(
GetProfile()->GetProfileUserName());
Profile* const incognito_primary_profile =
incognito_primary_profile_builder.BuildIncognito(GetProfile());
ASSERT_TRUE(incognito_primary_profile);
ASSERT_TRUE(incognito_primary_profile->IsOffTheRecord());
// Service instances should *not* typically be created for OTR profiles. The
// once exception is for guest users who redirect to use original profile.
HoldingSpaceKeyedService* const incognito_primary_profile_service =
HoldingSpaceKeyedServiceFactory::GetInstance()->GetService(
incognito_primary_profile);
ASSERT_FALSE(incognito_primary_profile_service);
}
TEST_F(HoldingSpaceKeyedServiceTest, SecondaryUserProfile) { TEST_F(HoldingSpaceKeyedServiceTest, SecondaryUserProfile) {
HoldingSpaceKeyedService* const primary_holding_space_service = HoldingSpaceKeyedService* const primary_holding_space_service =
HoldingSpaceKeyedServiceFactory::GetInstance()->GetService(GetProfile()); HoldingSpaceKeyedServiceFactory::GetInstance()->GetService(GetProfile());
......
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