[ios] Add flag for long message duration and set feature parameters

- Add feature flag for long message duration.
- Add two feature parameters for default message and long presentation
message, so we can change the duration second in finch config.

Bug: 1252923
Change-Id: If8a4ebd21343753fbd3639948b327b0f6a657d27
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3183382
Commit-Queue: Tina Wang <[email protected]>
Reviewed-by: Chris Lu <[email protected]>
Cr-Commit-Position: refs/heads/main@{#924979}
diff --git a/chrome/browser/flag-metadata.json b/chrome/browser/flag-metadata.json
index ea5d212..5ec28d1 100644
--- a/chrome/browser/flag-metadata.json
+++ b/chrome/browser/flag-metadata.json
@@ -2146,6 +2146,11 @@
     "expiry_milestone": 92
   },
   {
+    "name": "enable-long-message-duration",
+    "owners": [ "tinazwang", "[email protected]" ],
+    "expiry_milestone": 110
+  },
+  {
     "name": "enable-magnifier-continuous-mouse-following-mode-setting",
     "owners": [ "josiahk", "//ui/accessibility/OWNERS" ],
     "expiry_milestone": 92
diff --git a/ios/chrome/browser/flags/BUILD.gn b/ios/chrome/browser/flags/BUILD.gn
index a155def0..8730e92 100644
--- a/ios/chrome/browser/flags/BUILD.gn
+++ b/ios/chrome/browser/flags/BUILD.gn
@@ -59,6 +59,7 @@
     "//ios/chrome/browser/ui/download:features",
     "//ios/chrome/browser/ui/fullscreen:feature_flags",
     "//ios/chrome/browser/ui/ntp:feature_flags",
+    "//ios/chrome/browser/ui/overlays/infobar_banner:feature_flags",
     "//ios/chrome/browser/ui/popup_menu/public:feature_flags",
     "//ios/chrome/browser/ui/reading_list:features",
     "//ios/chrome/browser/ui/start_surface:feature_flags",
diff --git a/ios/chrome/browser/flags/about_flags.mm b/ios/chrome/browser/flags/about_flags.mm
index 0ef5b97..f32aff6 100644
--- a/ios/chrome/browser/flags/about_flags.mm
+++ b/ios/chrome/browser/flags/about_flags.mm
@@ -71,6 +71,7 @@
 #import "ios/chrome/browser/ui/download/features.h"
 #import "ios/chrome/browser/ui/fullscreen/fullscreen_features.h"
 #import "ios/chrome/browser/ui/ntp/new_tab_page_feature.h"
+#import "ios/chrome/browser/ui/overlays/infobar_banner/infobar_banner_features.h"
 #import "ios/chrome/browser/ui/popup_menu/public/feature_flags.h"
 #import "ios/chrome/browser/ui/reading_list/reading_list_features.h"
 #import "ios/chrome/browser/ui/start_surface/start_surface_features.h"
@@ -471,6 +472,10 @@
      flag_descriptions::kEnableFullPageScreenshotName,
      flag_descriptions::kEnableFullPageScreenshotDescription, flags_ui::kOsIos,
      FEATURE_VALUE_TYPE(kEnableFullPageScreenshot)},
+    {"enable-long-message-duration",
+     flag_descriptions::kEnableLongMessageDurationName,
+     flag_descriptions::kEnableLongMessageDurationDescription, flags_ui::kOsIos,
+     FEATURE_VALUE_TYPE(kEnableLongMessageDuration)},
     {"enable-optimization-guide",
      flag_descriptions::kEnableOptimizationGuideName,
      flag_descriptions::kEnableOptimizationGuideDescription, flags_ui::kOsIos,
diff --git a/ios/chrome/browser/flags/ios_chrome_flag_descriptions.cc b/ios/chrome/browser/flags/ios_chrome_flag_descriptions.cc
index 7f2a9a1..79e468dd7 100644
--- a/ios/chrome/browser/flags/ios_chrome_flag_descriptions.cc
+++ b/ios/chrome/browser/flags/ios_chrome_flag_descriptions.cc
@@ -194,6 +194,10 @@
     "Enables the option of capturing an entire webpage as a PDF when a "
     "screenshot is taken.";
 
+const char kEnableLongMessageDurationName[] = "Enable long message duration";
+const char kEnableLongMessageDurationDescription[] =
+    "Enables a long duration when an overlay message is shown.";
+
 const char kEnableManualPasswordGenerationName[] =
     "Enable manual password generation.";
 const char kEnableManualPasswordGenerationDescription[] =
diff --git a/ios/chrome/browser/flags/ios_chrome_flag_descriptions.h b/ios/chrome/browser/flags/ios_chrome_flag_descriptions.h
index 3277d328..ef139bd 100644
--- a/ios/chrome/browser/flags/ios_chrome_flag_descriptions.h
+++ b/ios/chrome/browser/flags/ios_chrome_flag_descriptions.h
@@ -171,6 +171,10 @@
 extern const char kEnableFullPageScreenshotName[];
 extern const char kEnableFullPageScreenshotDescription[];
 
+// Title and description for the flag to enable long message duration.
+extern const char kEnableLongMessageDurationName[];
+extern const char kEnableLongMessageDurationDescription[];
+
 // Title and description for the flag to enable UI that allows the user to
 // create a strong password even if the field wasn't parsed as a new password
 // field.
diff --git a/ios/chrome/browser/ui/overlays/infobar_banner/BUILD.gn b/ios/chrome/browser/ui/overlays/infobar_banner/BUILD.gn
index 12bba23..9904074 100644
--- a/ios/chrome/browser/ui/overlays/infobar_banner/BUILD.gn
+++ b/ios/chrome/browser/ui/overlays/infobar_banner/BUILD.gn
@@ -14,6 +14,17 @@
   ]
 }
 
+source_set("feature_flags") {
+  sources = [
+    "infobar_banner_features.h",
+    "infobar_banner_features.mm",
+  ]
+
+  configs += [ "//build/config/compiler:enable_arc" ]
+
+  deps = [ "//base" ]
+}
+
 source_set("coordinators") {
   sources = [
     "infobar_banner_overlay_coordinator.h",
@@ -23,6 +34,7 @@
   configs += [ "//build/config/compiler:enable_arc" ]
 
   deps = [
+    ":feature_flags",
     ":mediators",
     "//base",
     "//ios/chrome/browser/overlays",
diff --git a/ios/chrome/browser/ui/overlays/infobar_banner/infobar_banner_features.h b/ios/chrome/browser/ui/overlays/infobar_banner/infobar_banner_features.h
new file mode 100644
index 0000000..7c35b44f
--- /dev/null
+++ b/ios/chrome/browser/ui/overlays/infobar_banner/infobar_banner_features.h
@@ -0,0 +1,30 @@
+// Copyright 2021 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef IOS_CHROME_BROWSER_UI_OVERLAYS_INFOBAR_BANNER_INFOBAR_BANNER_FEATURES_H_
+#define IOS_CHROME_BROWSER_UI_OVERLAYS_INFOBAR_BANNER_INFOBAR_BANNER_FEATURES_H_
+
+#include "base/feature_list.h"
+
+// The feature parameter that indicates the duration of a long presentation
+// message.
+extern const char kLongPresentationMessagesDurationFeatureParam[];
+
+// The feature parameter that indicates the duration of a default
+// presentation message.
+extern const char kDefaultPresentationMessagesDurationFeatureParam[];
+
+// The feature to enable long message duration
+extern const base::Feature kEnableLongMessageDuration;
+
+// Checks whether the long message duration feature is enabled.
+bool IsLongMessageDurationEnabled();
+
+// Returns the duration of the default presentation messages.
+double GetDefaultPresentationMessageDuration();
+
+// Returns the duration of the long presentation messages.
+double GetLongPresentationMessageDuration();
+
+#endif  // IOS_CHROME_BROWSER_UI_OVERLAYS_INFOBAR_BANNER_INFOBAR_BANNER_FEATURES_H_
diff --git a/ios/chrome/browser/ui/overlays/infobar_banner/infobar_banner_features.mm b/ios/chrome/browser/ui/overlays/infobar_banner/infobar_banner_features.mm
new file mode 100644
index 0000000..eb167d96
--- /dev/null
+++ b/ios/chrome/browser/ui/overlays/infobar_banner/infobar_banner_features.mm
@@ -0,0 +1,35 @@
+// Copyright 2021 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/chrome/browser/ui/overlays/infobar_banner/infobar_banner_features.h"
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+const base::Feature kEnableLongMessageDuration{
+    "EnableLongMessageDuration", base::FEATURE_DISABLED_BY_DEFAULT};
+
+const char kLongPresentationMessagesDurationFeatureParam[] =
+    "LongPresentationMessagesDurationFeatureParam";
+
+const char kDefaultPresentationMessagesDurationFeatureParam[] =
+    "DefaultPresentationMessagesDurationFeatureParam";
+
+bool IsLongMessageDurationEnabled() {
+  return base::FeatureList::IsEnabled(kEnableLongMessageDuration);
+}
+
+double GetDefaultPresentationMessageDuration() {
+  return base::GetFieldTrialParamByFeatureAsDouble(
+      kEnableLongMessageDuration,
+      kDefaultPresentationMessagesDurationFeatureParam,
+      15 /*default to 15 second*/);
+}
+
+double GetLongPresentationMessageDuration() {
+  return base::GetFieldTrialParamByFeatureAsDouble(
+      kEnableLongMessageDuration, kLongPresentationMessagesDurationFeatureParam,
+      20 /*default to 20 second*/);
+}
diff --git a/ios/chrome/browser/ui/overlays/infobar_banner/infobar_banner_overlay_coordinator.mm b/ios/chrome/browser/ui/overlays/infobar_banner/infobar_banner_overlay_coordinator.mm
index ae964bd8..4d2714b 100644
--- a/ios/chrome/browser/ui/overlays/infobar_banner/infobar_banner_overlay_coordinator.mm
+++ b/ios/chrome/browser/ui/overlays/infobar_banner/infobar_banner_overlay_coordinator.mm
@@ -18,6 +18,7 @@
 #import "ios/chrome/browser/ui/infobars/presentation/infobar_banner_transition_driver.h"
 #import "ios/chrome/browser/ui/overlays/infobar_banner/autofill_address_profile/save_address_profile_infobar_banner_overlay_mediator.h"
 #import "ios/chrome/browser/ui/overlays/infobar_banner/confirm/confirm_infobar_banner_overlay_mediator.h"
+#import "ios/chrome/browser/ui/overlays/infobar_banner/infobar_banner_features.h"
 #import "ios/chrome/browser/ui/overlays/infobar_banner/infobar_banner_overlay_mediator.h"
 #import "ios/chrome/browser/ui/overlays/infobar_banner/passwords/save_password_infobar_banner_overlay_mediator.h"
 #import "ios/chrome/browser/ui/overlays/infobar_banner/passwords/update_password_infobar_banner_overlay_mediator.h"
@@ -119,12 +120,19 @@
   self.started = YES;
 
   if (!UIAccessibilityIsVoiceOverRunning()) {
-    // Auto-dismiss the banner after timeout if VoiceOver is off (banner should
-    // persist until user explicitly swipes it away).
-    NSTimeInterval timeout =
-        config->is_high_priority()
-            ? kInfobarBannerLongPresentationDurationInSeconds
-            : kInfobarBannerDefaultPresentationDurationInSeconds;
+    NSTimeInterval timeout;
+    if (IsLongMessageDurationEnabled()) {
+      // If long message duration is enabled, set a longer timeout.
+      timeout = config->is_high_priority()
+                    ? GetLongPresentationMessageDuration()
+                    : GetDefaultPresentationMessageDuration();
+    } else {
+      // Auto-dismiss the banner after timeout if VoiceOver is off (banner
+      // should persist until user explicitly swipes it away).
+      timeout = config->is_high_priority()
+                    ? kInfobarBannerLongPresentationDurationInSeconds
+                    : kInfobarBannerDefaultPresentationDurationInSeconds;
+    }
     [self performSelector:@selector(dismissBannerIfReady)
                withObject:nil
                afterDelay:timeout];