Commit e6b3d48c authored by Jialiu Lin's avatar Jialiu Lin Committed by Commit Bot

Return original profile's advanced protection status for incognito

The incognito mode profile should be aware of the user's advanced
protection status (from original profile) if the user signs into
Chrome.

Bug: 887754
Change-Id: Ic4dec677f9adf1464b8c7398934f2d10cb62323b
Reviewed-on: https://chromium-review.googlesource.com/1247001Reviewed-by: default avatarDaniel Rubery <drubery@chromium.org>
Commit-Queue: Jialiu Lin <jialiul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595177}
parent ab1855ae
...@@ -239,13 +239,14 @@ void AdvancedProtectionStatusManager::UpdateLastRefreshTime() { ...@@ -239,13 +239,14 @@ void AdvancedProtectionStatusManager::UpdateLastRefreshTime() {
// static // static
bool AdvancedProtectionStatusManager::IsUnderAdvancedProtection( bool AdvancedProtectionStatusManager::IsUnderAdvancedProtection(
Profile* profile) { Profile* profile) {
// Advanced protection is off for incognito mode. Profile* original_profile =
if (profile->IsOffTheRecord()) profile->IsOffTheRecord() ? profile->GetOriginalProfile() : profile;
return false;
return original_profile &&
return AdvancedProtectionStatusManagerFactory::GetInstance() AdvancedProtectionStatusManagerFactory::GetInstance()
->GetForBrowserContext(static_cast<content::BrowserContext*>(profile)) ->GetForBrowserContext(
->is_under_advanced_protection(); static_cast<content::BrowserContext*>(original_profile))
->is_under_advanced_protection();
} }
bool AdvancedProtectionStatusManager::IsPrimaryAccount( bool AdvancedProtectionStatusManager::IsPrimaryAccount(
......
...@@ -17,8 +17,10 @@ namespace safe_browsing { ...@@ -17,8 +17,10 @@ namespace safe_browsing {
// Responsible for keeping track of advanced protection status of the sign-in // Responsible for keeping track of advanced protection status of the sign-in
// profile. // profile.
// Note that for profile that is not signed-in or is in incognito mode, we // Note that for profile that is not signed-in, we consider it NOT under
// consider it NOT under advanced protection. // advanced protection.
// For incognito profile Chrome returns users' advanced protection status
// of its original profile.
class AdvancedProtectionStatusManager : public KeyedService, class AdvancedProtectionStatusManager : public KeyedService,
public AccountTrackerService::Observer, public AccountTrackerService::Observer,
public SigninManagerBase::Observer { public SigninManagerBase::Observer {
......
...@@ -51,9 +51,4 @@ bool AdvancedProtectionStatusManagerFactory:: ...@@ -51,9 +51,4 @@ bool AdvancedProtectionStatusManagerFactory::
return true; return true;
} }
bool AdvancedProtectionStatusManagerFactory::ServiceIsNULLWhileTesting() const {
// TODO(jialiul): Change this to 'false' when this class is wired into Chrome.
return true;
}
} // namespace safe_browsing } // namespace safe_browsing
...@@ -36,7 +36,6 @@ class AdvancedProtectionStatusManagerFactory ...@@ -36,7 +36,6 @@ class AdvancedProtectionStatusManagerFactory
KeyedService* BuildServiceInstanceFor( KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override; content::BrowserContext* context) const override;
bool ServiceIsCreatedWithBrowserContext() const override; bool ServiceIsCreatedWithBrowserContext() const override;
bool ServiceIsNULLWhileTesting() const override;
DISALLOW_COPY_AND_ASSIGN(AdvancedProtectionStatusManagerFactory); DISALLOW_COPY_AND_ASSIGN(AdvancedProtectionStatusManagerFactory);
}; };
......
...@@ -225,8 +225,8 @@ TEST_F(AdvancedProtectionStatusManagerTest, AlreadySignedInAndUnderAP) { ...@@ -225,8 +225,8 @@ TEST_F(AdvancedProtectionStatusManagerTest, AlreadySignedInAndUnderAP) {
prefs::kAdvancedProtectionLastRefreshInUs, prefs::kAdvancedProtectionLastRefreshInUs,
base::Time::Now().ToDeltaSinceWindowsEpoch().InMicroseconds()); base::Time::Now().ToDeltaSinceWindowsEpoch().InMicroseconds());
// Simulates the situation where user signed in long time ago, thus // Simulates the situation where the user has already signed in and is
// has no advanced protection status. // under advanced protection.
std::string account_id = std::string account_id =
SignIn("gaia_id", "email", /* is_under_advanced_protection = */ true); SignIn("gaia_id", "email", /* is_under_advanced_protection = */ true);
AdvancedProtectionStatusManager aps_manager( AdvancedProtectionStatusManager aps_manager(
...@@ -241,6 +241,44 @@ TEST_F(AdvancedProtectionStatusManagerTest, AlreadySignedInAndUnderAP) { ...@@ -241,6 +241,44 @@ TEST_F(AdvancedProtectionStatusManagerTest, AlreadySignedInAndUnderAP) {
aps_manager.UnsubscribeFromSigninEvents(); aps_manager.UnsubscribeFromSigninEvents();
} }
TEST_F(AdvancedProtectionStatusManagerTest,
AlreadySignedInAndUnderAPIncognito) {
testing_profile_->GetPrefs()->SetInt64(
prefs::kAdvancedProtectionLastRefreshInUs,
base::Time::Now().ToDeltaSinceWindowsEpoch().InMicroseconds());
// Simulates the situation where the user has already signed in and is
// under advanced protection.
std::string account_id =
SignIn("gaia_id", "email", /* is_under_advanced_protection = */ true);
// Incognito profile should share the advanced protection status with the
// original profile.
EXPECT_TRUE(AdvancedProtectionStatusManager::IsUnderAdvancedProtection(
testing_profile_->GetOffTheRecordProfile()));
EXPECT_TRUE(AdvancedProtectionStatusManager::IsUnderAdvancedProtection(
testing_profile_.get()));
}
TEST_F(AdvancedProtectionStatusManagerTest,
AlreadySignedInAndNotUnderAPIncognito) {
testing_profile_->GetPrefs()->SetInt64(
prefs::kAdvancedProtectionLastRefreshInUs,
base::Time::Now().ToDeltaSinceWindowsEpoch().InMicroseconds());
// Simulates the situation where the user has already signed in and is
// NOT under advanced protection.
std::string account_id =
SignIn("gaia_id", "email", /* is_under_advanced_protection = */ false);
// Incognito profile should share the advanced protection status with the
// original profile.
EXPECT_FALSE(AdvancedProtectionStatusManager::IsUnderAdvancedProtection(
testing_profile_->GetOffTheRecordProfile()));
EXPECT_FALSE(AdvancedProtectionStatusManager::IsUnderAdvancedProtection(
testing_profile_.get()));
}
TEST_F(AdvancedProtectionStatusManagerTest, StayInAdvancedProtection) { TEST_F(AdvancedProtectionStatusManagerTest, StayInAdvancedProtection) {
base::Time last_update = base::Time::Now(); base::Time last_update = base::Time::Now();
testing_profile_->GetPrefs()->SetInt64( testing_profile_->GetPrefs()->SetInt64(
......
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