[iOS] Add a pref to check if the YT Incognito UI has been shown

This CL adds a pref variable to check whether the Youtube Incognito UI
has already been shown, in addition it adds a new exp setting variable to allow the tester to have the UI displayed upon each incognito link
opening.

Bug: 381236406, 374935531
Change-Id: Ic16d5c64f2fb84dd5693157b48259dc93dc696d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6158326
Reviewed-by: Sylvain Defresne <sdefresne@chromium.org>
Commit-Queue: Elmehdi Rahmaoui <erahmaoui@google.com>
Cr-Commit-Position: refs/heads/main@{#1405980}
NOKEYCHECK=True
GitOrigin-RevId: 733b3c58d3e463f38c85c661111cc3242c376526
diff --git a/chrome/app/resources/Settings.bundle/Experimental.plist b/chrome/app/resources/Settings.bundle/Experimental.plist
index c9c48a2..92f4086 100644
--- a/chrome/app/resources/Settings.bundle/Experimental.plist
+++ b/chrome/app/resources/Settings.bundle/Experimental.plist
@@ -501,6 +501,7 @@
 				<string>500ms</string>
 				<string>FirstPartyIncognitoNoDelay</string>
 				<string>FirstPartyIncognito500Delay</string>
+                                <string>AlwaysShowTheUI</string>
 			</array>
 			<key>Titles</key>
 			<array>
@@ -508,6 +509,7 @@
 				<string>500ms delay</string>
 				<string>With first party incognito</string>
 				<string>With 500ms delayed first party incognito</string>
+                                <string>Always show the UI</string>
 			</array>
 		</dict>
 		<dict>
diff --git a/chrome/browser/shared/model/prefs/browser_prefs.mm b/chrome/browser/shared/model/prefs/browser_prefs.mm
index 5b32168..b012e47 100644
--- a/chrome/browser/shared/model/prefs/browser_prefs.mm
+++ b/chrome/browser/shared/model/prefs/browser_prefs.mm
@@ -705,6 +705,8 @@
       prefs::kProminenceNotificationAlertImpressionCount, 0);
 
   registry->RegisterIntegerPref(prefs::kChromeDataRegionSetting, 0);
+
+  registry->RegisterBooleanPref(prefs::kYoutubeIncognitoHasBeenShown, false);
 }
 
 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
diff --git a/chrome/browser/shared/model/prefs/pref_names.h b/chrome/browser/shared/model/prefs/pref_names.h
index e870908..b48c952 100644
--- a/chrome/browser/shared/model/prefs/pref_names.h
+++ b/chrome/browser/shared/model/prefs/pref_names.h
@@ -730,6 +730,11 @@
 // - 2: Europe
 inline constexpr char kChromeDataRegionSetting[] = "chrome_data_region_setting";
 
+// A boolean used to determine if the Youtube Incognito Interstitial sheet has
+// been shown.
+inline constexpr char kYoutubeIncognitoHasBeenShown[] =
+    "ios.youtube_incognito.has_been_shown";
+
 }  // namespace prefs
 
 #endif  // IOS_CHROME_BROWSER_SHARED_MODEL_PREFS_PREF_NAMES_H_
diff --git a/chrome/browser/shared/public/features/system_flags.h b/chrome/browser/shared/public/features/system_flags.h
index ff1032f..b73ec05 100644
--- a/chrome/browser/shared/public/features/system_flags.h
+++ b/chrome/browser/shared/public/features/system_flags.h
@@ -176,6 +176,9 @@
 // Whether the a delay should be added to the asynchronous startup.
 bool ShouldDelayAsyncStartup();
 
+// Whether to always show the first party incognito experience UI.
+bool AlwaysShowTheFirstPartyIncognitoUI();
+
 }  // namespace experimental_flags
 
 #endif  // IOS_CHROME_BROWSER_SHARED_PUBLIC_FEATURES_SYSTEM_FLAGS_H_
diff --git a/chrome/browser/shared/public/features/system_flags.mm b/chrome/browser/shared/public/features/system_flags.mm
index a33f874..9c1d913 100644
--- a/chrome/browser/shared/public/features/system_flags.mm
+++ b/chrome/browser/shared/public/features/system_flags.mm
@@ -338,7 +338,8 @@
   NSString* value = [[NSUserDefaults standardUserDefaults]
       stringForKey:kAsyncStartupOverrideResponse];
   return ([value isEqualToString:@"FirstPartyIncognitoNoDelay"] ||
-          [value isEqualToString:@"FirstPartyIncognito500Delay"]);
+          [value isEqualToString:@"FirstPartyIncognito500Delay"] ||
+          [value isEqualToString:@"AlwaysShowTheUI"]);
 }
 
 bool ShouldDelayAsyncStartup() {
@@ -348,4 +349,10 @@
           [value isEqualToString:@"500ms"]);
 }
 
+bool AlwaysShowTheFirstPartyIncognitoUI() {
+  NSString* value = [[NSUserDefaults standardUserDefaults]
+      stringForKey:kAsyncStartupOverrideResponse];
+  return [value isEqualToString:@"AlwaysShowTheUI"];
+}
+
 }  // namespace experimental_flags
diff --git a/chrome/browser/youtube_incognito/coordinator/BUILD.gn b/chrome/browser/youtube_incognito/coordinator/BUILD.gn
index 1efc36e..520a3e9 100644
--- a/chrome/browser/youtube_incognito/coordinator/BUILD.gn
+++ b/chrome/browser/youtube_incognito/coordinator/BUILD.gn
@@ -9,10 +9,14 @@
     "youtube_incognito_coordinator_delegate.h",
   ]
   deps = [
+    "//components/prefs",
     "//ios/chrome/app/application_delegate:tab_opening",
     "//ios/chrome/browser/ntp/ui_bundled",
     "//ios/chrome/browser/ntp/ui_bundled/incognito:util",
     "//ios/chrome/browser/shared/coordinator/chrome_coordinator",
+    "//ios/chrome/browser/shared/model/application_context",
+    "//ios/chrome/browser/shared/model/prefs:pref_names",
+    "//ios/chrome/browser/shared/public/features:system_flags",
     "//ios/chrome/browser/url_loading/model",
     "//ios/chrome/browser/url_loading/model:url_loading_params_header",
     "//ios/chrome/browser/youtube_incognito/ui:ui",
diff --git a/chrome/browser/youtube_incognito/coordinator/youtube_incognito_coordinator.mm b/chrome/browser/youtube_incognito/coordinator/youtube_incognito_coordinator.mm
index ef8b205..9601e8e 100644
--- a/chrome/browser/youtube_incognito/coordinator/youtube_incognito_coordinator.mm
+++ b/chrome/browser/youtube_incognito/coordinator/youtube_incognito_coordinator.mm
@@ -5,9 +5,13 @@
 #import "ios/chrome/browser/youtube_incognito/coordinator/youtube_incognito_coordinator.h"
 
 #import "base/strings/sys_string_conversions.h"
+#import "components/prefs/pref_service.h"
 #import "ios/chrome/app/application_delegate/tab_opening.h"
 #import "ios/chrome/browser/ntp/ui_bundled/incognito/incognito_view_util.h"
 #import "ios/chrome/browser/ntp/ui_bundled/new_tab_page_url_loader_delegate.h"
+#import "ios/chrome/browser/shared/model/application_context/application_context.h"
+#import "ios/chrome/browser/shared/model/prefs/pref_names.h"
+#import "ios/chrome/browser/shared/public/features/system_flags.h"
 #import "ios/chrome/browser/url_loading/model/url_loading_browser_agent.h"
 #import "ios/chrome/browser/url_loading/model/url_loading_params.h"
 #import "ios/chrome/browser/youtube_incognito/coordinator/youtube_incognito_coordinator_delegate.h"
@@ -34,11 +38,18 @@
 - (void)start {
   if (self.incognitoDisabled) {
     [self presentEnterpriseViewController];
-  } else {
-    // TODO(crbug.com/374935670): Show toast when the view was presented
-    // already.
-    [self presentViewController];
+    return;
   }
+
+  PrefService* localState = GetApplicationContext()->GetLocalState();
+  if (!localState->GetBoolean(prefs::kYoutubeIncognitoHasBeenShown) ||
+      experimental_flags::AlwaysShowTheFirstPartyIncognitoUI()) {
+    localState->SetBoolean(prefs::kYoutubeIncognitoHasBeenShown, true);
+    [self presentViewController];
+    return;
+  }
+  // TODO(crbug.com/374935670): Show toast when the view was presented
+  // already.
 }
 
 - (void)stop {