[iOS] Restore CPE's gaia fallback path
The gaia fallback path had been identified as a potential culprit
for an issue where there were many daily gaia related issue when
going through the onborading process. Despite an initial dip, the
number of errors bounced back to its original value, so the gaia
fallback path was a red herring. Also, the number of onboardings
itself has significantly decreased (about 10-15%), so this CL
put the fallback path back in the CPE, as removing it does not
appear to have solved anything and may even have hurt the chances
of a user successfully onboarding a device.
Bug: 380790152
Change-Id: Id61b90700d52d32095f19499e53a8fd7f1685c63
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6361800
Commit-Queue: Alexis Hétu <sugoi@chromium.org>
Reviewed-by: Tommy Martino <tmartino@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1433737}
diff --git a/ios/chrome/credential_provider_extension/credential_provider_view_controller.mm b/ios/chrome/credential_provider_extension/credential_provider_view_controller.mm
index a025edc..de6f550 100644
--- a/ios/chrome/credential_provider_extension/credential_provider_view_controller.mm
+++ b/ios/chrome/credential_provider_extension/credential_provider_view_controller.mm
@@ -542,8 +542,21 @@
// Returns the gaia ID associated with the current account.
- (NSString*)gaia {
- return UserDefaultsStringForKey(
+ NSString* gaia = UserDefaultsStringForKey(
AppGroupUserDefaultsCredentialProviderUserID(), /*default_value=*/@"");
+ if (gaia.length > 0) {
+ return gaia;
+ }
+
+ // As a fallback, attempt to get a valid gaia from existing credentials.
+ NSArray<id<Credential>>* credentials = self.credentialStore.credentials;
+ NSUInteger credentialIndex =
+ [credentials indexOfObjectPassingTest:^BOOL(id<Credential> credential,
+ NSUInteger idx, BOOL* stop) {
+ return credential.gaia.length > 0;
+ }];
+ return credentialIndex != NSNotFound ? credentials[credentialIndex].gaia
+ : nil;
}
// Returns the email address associated with the current account.