Add flag to refactor ToolbarUI from Broadcasting to Observer Pattern

Feature flag to refactor ToolbarUI from broadcasting to observer
based architecture.

Change-Id: I4964bdd351e9c0a27b9c63a78983b79c430287e0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6218387
Reviewed-by: Ewann Pellé <ewannpv@chromium.org>
Reviewed-by: Asami Doi <asamidoi@chromium.org>
Commit-Queue: Prasanaa Vingadassamy <prasanaa@google.com>
Cr-Commit-Position: refs/heads/main@{#1415506}
diff --git a/chrome/browser/flag-metadata.json b/chrome/browser/flag-metadata.json
index af3d84a..a60b53e2 100644
--- a/chrome/browser/flag-metadata.json
+++ b/chrome/browser/flag-metadata.json
@@ -7541,6 +7541,11 @@
     "expiry_milestone": 90
   },
   {
+    "name": "refactor-toolbar-ui",
+    "owners": [ "prasanaa@google.com", "alionadangla@chromium.org" ],
+    "expiry_milestone": 150
+  },
+  {
     "name": "refresh-feed-on-start",
     "owners": ["//chrome/android/feed/OWNERS", "jianli@chromium.org"],
     "expiry_milestone": 140
diff --git a/ios/chrome/browser/flags/about_flags.mm b/ios/chrome/browser/flags/about_flags.mm
index e4cf057c..81d5718 100644
--- a/ios/chrome/browser/flags/about_flags.mm
+++ b/ios/chrome/browser/flags/about_flags.mm
@@ -2370,6 +2370,9 @@
      FEATURE_WITH_PARAMS_VALUE_TYPE(kDeprecateFeedHeader,
                                     kDeprecateFeedHeaderVariations,
                                     "IOSDeprecateFeedHeader")},
+    {"refactor-toolbar-ui", flag_descriptions::kRefactorToolbarUIName,
+     flag_descriptions::kRefactorToolbarUIDescription, flags_ui::kOsIos,
+     FEATURE_VALUE_TYPE(kRefactorToolbarUI)},
 };
 
 bool SkipConditionalFeatureEntry(const flags_ui::FeatureEntry& entry) {
diff --git a/ios/chrome/browser/flags/ios_chrome_flag_descriptions.cc b/ios/chrome/browser/flags/ios_chrome_flag_descriptions.cc
index 583bf40..3056959fb 100644
--- a/ios/chrome/browser/flags/ios_chrome_flag_descriptions.cc
+++ b/ios/chrome/browser/flags/ios_chrome_flag_descriptions.cc
@@ -1041,6 +1041,10 @@
     "Displays the menu item for the notification controls inside the chrome "
     "settings UI.";
 
+const char kRefactorToolbarUIName[] = "Refactor toolbar UI";
+const char kRefactorToolbarUIDescription[] =
+    "When enabled, the toolbar ui does not use broadcaster but observers.";
+
 const char kRemoveExcessNTPsExperimentName[] = "Remove extra New Tab Pages";
 const char kRemoveExcessNTPsExperimentDescription[] =
     "When enabled, extra tabs with the New Tab Page open and no navigation "
diff --git a/ios/chrome/browser/flags/ios_chrome_flag_descriptions.h b/ios/chrome/browser/flags/ios_chrome_flag_descriptions.h
index e72571c..fdf8f2d 100644
--- a/ios/chrome/browser/flags/ios_chrome_flag_descriptions.h
+++ b/ios/chrome/browser/flags/ios_chrome_flag_descriptions.h
@@ -925,6 +925,10 @@
 extern const char kNotificationSettingsMenuItemName[];
 extern const char kNotificationSettingsMenuItemDescription[];
 
+// Title and description for the flag to refactor the toolbarUI.
+extern const char kRefactorToolbarUIName[];
+extern const char kRefactorToolbarUIDescription[];
+
 // Title and description for the flag to remove excess NTP tabs that don't have
 // navigation history.
 extern const char kRemoveExcessNTPsExperimentName[];
diff --git a/ios/chrome/browser/shared/public/features/features.h b/ios/chrome/browser/shared/public/features/features.h
index dc71df3..0e24e78 100644
--- a/ios/chrome/browser/shared/public/features/features.h
+++ b/ios/chrome/browser/shared/public/features/features.h
@@ -1053,4 +1053,9 @@
 // the fullscreen transition or the speed of the transition.
 BASE_DECLARE_FEATURE(kFullscreenTransition);
 
+// Feature flag for switching the toolbar UI to an observer-based architecture.
+BASE_DECLARE_FEATURE(kRefactorToolbarUI);
+
+bool IsRefactorToolbarUI();
+
 #endif  // IOS_CHROME_BROWSER_SHARED_PUBLIC_FEATURES_FEATURES_H_
diff --git a/ios/chrome/browser/shared/public/features/features.mm b/ios/chrome/browser/shared/public/features/features.mm
index c52743e..339d9e2e 100644
--- a/ios/chrome/browser/shared/public/features/features.mm
+++ b/ios/chrome/browser/shared/public/features/features.mm
@@ -1280,3 +1280,11 @@
 BASE_FEATURE(kFullscreenTransition,
              "FullscreenTransition",
              base::FEATURE_DISABLED_BY_DEFAULT);
+
+BASE_FEATURE(kRefactorToolbarUI,
+             "RefactorToolbarUI",
+             base::FEATURE_DISABLED_BY_DEFAULT);
+
+bool IsRefactorToolbarUI() {
+  return base::FeatureList::IsEnabled(kRefactorToolbarUI);
+}