Commit 9de59f58 authored by Rohit Rao's avatar Rohit Rao Committed by Commit Bot

[ios] Moves the GAIA refresh logic behind a feature flag.

Disables the feature by default.

BUG=1102794

Change-Id: Ia8132e8d959cc5017f18b5fd31618ae996de8b2e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2417654Reviewed-by: default avatarNohemi Fernandez <fernandex@chromium.org>
Commit-Queue: Rohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808869}
parent f37082fb
......@@ -10,6 +10,7 @@
#include <string>
#include "base/callback.h"
#include "base/feature_list.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/time/time.h"
......@@ -32,6 +33,9 @@ class WebStatePolicyDecider;
class AccountReconcilor;
class PrefService;
// Feature flag controlling whether to restore GAIA cookies if they are deleted.
extern const base::Feature kRestoreGAIACookiesIfDeleted;
// Handles actions necessary for keeping the list of Google accounts available
// on the web and those available on the iOS device from first-party Google apps
// consistent. This includes setting the Account Consistency cookie,
......
......@@ -78,6 +78,9 @@ class AccountConsistencyHandler : public web::WebStatePolicyDecider {
};
} // namespace
const base::Feature kRestoreGAIACookiesIfDeleted{
"RestoreGAIACookiesIfDeleted", base::FEATURE_DISABLED_BY_DEFAULT};
AccountConsistencyHandler::AccountConsistencyHandler(
web::WebState* web_state,
AccountConsistencyService* service,
......@@ -245,10 +248,15 @@ void AccountConsistencyService::TriggerGaiaCookieChangeIfDeleted(
return;
}
}
// The SAPISID cookie may have been deleted previous to this update due to
// ITP restrictions marking Google domains as potential trackers.
// Re-generate cookie to ensure that the user is properly signed in.
LogIOSGaiaCookiesPresentOnNavigation(false);
if (!base::FeatureList::IsEnabled(kRestoreGAIACookiesIfDeleted)) {
return;
}
// Re-generate cookie to ensure that the user is properly signed in.
identity_manager_->GetAccountsCookieMutator()->ForceTriggerOnCookieChange();
}
......
......@@ -13,6 +13,8 @@
#include "base/ios/ios_util.h"
#include "base/test/bind_test_util.h"
#import "base/test/ios/wait_util.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/values.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
......@@ -56,6 +58,10 @@ const char* kYoutubeDomain = "youtube.com";
// Google domain where the CHROME_CONNECTED cookie is set/removed.
const char* kCountryGoogleDomain = "google.de";
// Name of the histogram to record whether the GAIA cookie is present.
const char* kGAIACookiePresentHistogram =
"Signin.IOSGaiaCookiePresentOnNavigation";
// Returns a cookie domain that applies for all origins on |host_domain|.
std::string GetCookieDomain(const std::string& host_domain) {
DCHECK(net::cookie_util::DomainIsHostOnly(host_domain));
......@@ -573,7 +579,7 @@ TEST_F(AccountConsistencyServiceTest, SetChromeConnectedCookieAtUpdateTime) {
TEST_F(AccountConsistencyServiceTest, SetGaiaCookieUpdateNotUpdateTime) {
SimulateUpdateGaiaCookie();
// Advance clock past one-hour Gaia update time.
// Advance clock, but stay within the one-hour Gaia update time.
const base::Time first_update_time = base::Time::Now();
task_environment_.FastForwardBy(base::TimeDelta::FromMinutes(1));
SimulateUpdateGaiaCookie();
......@@ -592,6 +598,19 @@ TEST_F(AccountConsistencyServiceTest, SetGaiaCookieUpdateAtUpdateTime) {
EXPECT_EQ(second_update_time, GetGaiaLastUpdateTime());
}
// Ensures that the presence or absence of GAIA cookies is logged even if the
// |kRestoreGAIACookiesIfDeleted| experiment is disabled.
TEST_F(AccountConsistencyServiceTest, GAIACookieStatusLoggedProperly) {
base::HistogramTester histogram_tester;
base::test::ScopedFeatureList feature_list;
feature_list.InitAndDisableFeature(kRestoreGAIACookiesIfDeleted);
histogram_tester.ExpectTotalCount(kGAIACookiePresentHistogram, 0);
SimulateUpdateGaiaCookie();
base::RunLoop().RunUntilIdle();
histogram_tester.ExpectTotalCount(kGAIACookiePresentHistogram, 1);
}
// Ensures that set and remove cookie operations are handled in the order
// they are called resulting in no cookies.
TEST_F(AccountConsistencyServiceTest, DeleteChromeConnectedCookiesAfterSet) {
......
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