Revert "Remove SoleIntegration flag"

This reverts commit bfd17e5e46cad8a9aa563a627e3d492ef78aa836.

Reason for revert: broke Clank downstream

Original change's description:
> Remove SoleIntegration flag
> 
> Sole integration was launched in M65, and we no longer need this flag.
> 
> Bug: 778805
> Change-Id: I6669a87dcb7a6ff4705a30aaa2cf71d6670a822a
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1578101
> Commit-Queue: Wei-Yin Chen (陳威尹) <[email protected]>
> Reviewed-by: Theresa <[email protected]>
> Cr-Commit-Position: refs/heads/master@{#653718}

[email protected],[email protected]

Change-Id: I9cd3a7f54acb633c6390d4ca0c9d47efa5e8e066
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 778805
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1583064
Reviewed-by: Wei-Yin Chen (陳威尹) <[email protected]>
Commit-Queue: Wei-Yin Chen (陳威尹) <[email protected]>
Cr-Commit-Position: refs/heads/master@{#653741}
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ChromeFeatureList.java b/chrome/android/java/src/org/chromium/chrome/browser/ChromeFeatureList.java
index 2d0a1e43..05643ef 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ChromeFeatureList.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ChromeFeatureList.java
@@ -306,6 +306,7 @@
     public static final String SERVICE_MANAGER_FOR_DOWNLOAD = "ServiceManagerForDownload";
     public static final String SERVICE_WORKER_PAYMENT_APPS = "ServiceWorkerPaymentApps";
     public static final String SHOW_TRUSTED_PUBLISHER_URL = "ShowTrustedPublisherURL";
+    public static final String SOLE_INTEGRATION = "SoleIntegration";
     public static final String SSL_COMMITTED_INTERSTITIALS = "SSLCommittedInterstitials";
     public static final String SPANNABLE_INLINE_AUTOCOMPLETE = "SpannableInlineAutocomplete";
     public static final String SUBRESOURCE_FILTER = "SubresourceFilter";
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/ChromePreferenceManager.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/ChromePreferenceManager.java
index e0023f4..d0f8604 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/ChromePreferenceManager.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/ChromePreferenceManager.java
@@ -242,9 +242,9 @@
     private static final String FAILURE_UPLOAD_SUFFIX = "_crash_failure_upload";
 
     /**
-     * Deprecated in M76. This value may still exist in the shared preferences file. Do not reuse.
+     * Whether or not Sole integration is enabled.
+     * Default value is true.
      */
-    @Deprecated
     public static final String SOLE_INTEGRATION_ENABLED_KEY = "sole_integration_enabled";
 
     /**
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/util/FeatureUtilities.java b/chrome/android/java/src/org/chromium/chrome/browser/util/FeatureUtilities.java
index f787e60..55647033 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/util/FeatureUtilities.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/util/FeatureUtilities.java
@@ -72,6 +72,7 @@
     private static Boolean sHasGoogleAccountAuthenticator;
     private static Boolean sHasRecognitionIntentHandler;
 
+    private static Boolean sIsSoleEnabled;
     private static Boolean sIsHomePageButtonForceEnabled;
     private static Boolean sIsHomepageTileEnabled;
     private static Boolean sIsNewTabPageButtonEnabled;
@@ -191,6 +192,7 @@
      * Caches flags that must take effect on startup but are set via native code.
      */
     public static void cacheNativeFlags() {
+        cacheSoleEnabled();
         cacheCommandLineOnNonRootedEnabled();
         FirstRunUtils.cacheFirstRunPrefs();
         cacheHomePageButtonForceEnabled();
@@ -511,6 +513,33 @@
     }
 
     /**
+     * Cache whether or not Sole integration is enabled.
+     */
+    public static void cacheSoleEnabled() {
+        boolean featureEnabled = ChromeFeatureList.isEnabled(ChromeFeatureList.SOLE_INTEGRATION);
+        ChromePreferenceManager prefManager = ChromePreferenceManager.getInstance();
+        boolean prefEnabled =
+                prefManager.readBoolean(ChromePreferenceManager.SOLE_INTEGRATION_ENABLED_KEY, true);
+        if (featureEnabled == prefEnabled) return;
+
+        prefManager.writeBoolean(
+                ChromePreferenceManager.SOLE_INTEGRATION_ENABLED_KEY, featureEnabled);
+    }
+
+    /**
+     * @return Whether or not Sole integration is enabled.
+     */
+    public static boolean isSoleEnabled() {
+        if (sIsSoleEnabled == null) {
+            ChromePreferenceManager prefManager = ChromePreferenceManager.getInstance();
+
+            sIsSoleEnabled = prefManager.readBoolean(
+                    ChromePreferenceManager.SOLE_INTEGRATION_ENABLED_KEY, true);
+        }
+        return sIsSoleEnabled;
+    }
+
+    /**
      * @param activityContext The context for the containing activity.
      * @return Whether contextual suggestions are enabled.
      */
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
index dd7a82c..334f2ce 100644
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -2965,6 +2965,12 @@
      kOsDesktop, FEATURE_VALUE_TYPE(device::kWebAuthPINSupport)},
 #endif  // !defined(OS_ANDROID)
 
+#if defined(OS_ANDROID)
+    {"enable-sole-integration", flag_descriptions::kSoleIntegrationName,
+     flag_descriptions::kSoleIntegrationDescription, kOsAndroid,
+     FEATURE_VALUE_TYPE(chrome::android::kSoleIntegration)},
+#endif  // defined(OS_ANDROID)
+
     {"enable-viz-display-compositor",
      flag_descriptions::kVizDisplayCompositorName,
      flag_descriptions::kVizDisplayCompositorDescription, kOsAndroid | kOsCrOS,
diff --git a/chrome/browser/android/chrome_feature_list.cc b/chrome/browser/android/chrome_feature_list.cc
index 8628deb..431ee687 100644
--- a/chrome/browser/android/chrome_feature_list.cc
+++ b/chrome/browser/android/chrome_feature_list.cc
@@ -163,6 +163,7 @@
     &kSearchEnginePromoNewDevice,
     &kServiceManagerForBackgroundPrefetch,
     &kServiceManagerForDownload,
+    &kSoleIntegration,
     &kSpannableInlineAutocomplete,
     &kSpecialLocaleWrapper,
     &kSpecialUserDecision,
@@ -478,6 +479,9 @@
 const base::Feature kServiceManagerForDownload{
     "ServiceManagerForDownload", base::FEATURE_DISABLED_BY_DEFAULT};
 
+const base::Feature kSoleIntegration{"SoleIntegration",
+                                     base::FEATURE_ENABLED_BY_DEFAULT};
+
 const base::Feature kSpannableInlineAutocomplete{
     "SpannableInlineAutocomplete", base::FEATURE_ENABLED_BY_DEFAULT};
 
diff --git a/chrome/browser/android/chrome_feature_list.h b/chrome/browser/android/chrome_feature_list.h
index fc159dc..df76e52 100644
--- a/chrome/browser/android/chrome_feature_list.h
+++ b/chrome/browser/android/chrome_feature_list.h
@@ -95,6 +95,7 @@
 extern const base::Feature kSearchReadyOmniboxFeature;
 extern const base::Feature kServiceManagerForBackgroundPrefetch;
 extern const base::Feature kServiceManagerForDownload;
+extern const base::Feature kSoleIntegration;
 extern const base::Feature kSpannableInlineAutocomplete;
 extern const base::Feature kSpecialLocaleWrapper;
 extern const base::Feature kSpecialUserDecision;
diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descriptions.cc
index a582f50d..fbd61e6 100644
--- a/chrome/browser/flag_descriptions.cc
+++ b/chrome/browser/flag_descriptions.cc
@@ -1815,6 +1815,11 @@
 const char kSmoothScrollingDescription[] =
     "Animate smoothly when scrolling page content.";
 
+const char kSoleIntegrationName[] = "Sole integration";
+const char kSoleIntegrationDescription[] =
+    "Enable Sole integration for browser customization. You must restart "
+    "the browser twice for changes to take effect.";
+
 const char kSpeculativeServiceWorkerStartOnQueryInputName[] =
     "Enable speculative start of a service worker when a search is predicted.";
 const char kSpeculativeServiceWorkerStartOnQueryInputDescription[] =
diff --git a/chrome/browser/flag_descriptions.h b/chrome/browser/flag_descriptions.h
index dcb78282..4c8bddaa 100644
--- a/chrome/browser/flag_descriptions.h
+++ b/chrome/browser/flag_descriptions.h
@@ -1084,6 +1084,9 @@
 extern const char kSmoothScrollingName[];
 extern const char kSmoothScrollingDescription[];
 
+extern const char kSoleIntegrationName[];
+extern const char kSoleIntegrationDescription[];
+
 extern const char kSpeculativeServiceWorkerStartOnQueryInputName[];
 extern const char kSpeculativeServiceWorkerStartOnQueryInputDescription[];