Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1104)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/locale/LocaleManager.java

Issue 2380133002: Show search engine promo dialog for special locale (Closed)
Patch Set: maria's comment Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/locale/LocaleManager.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/locale/LocaleManager.java b/chrome/android/java/src/org/chromium/chrome/browser/locale/LocaleManager.java
index 6e9f71699fb8e7076b43a9bb45db6df6d7513b31..39c012ac79ee1c9b8c1e832890493d98343e64d9 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/locale/LocaleManager.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/locale/LocaleManager.java
@@ -4,17 +4,38 @@
package org.chromium.chrome.browser.locale;
+import android.content.Context;
+import android.content.SharedPreferences;
+
+import org.chromium.base.ContextUtils;
+import org.chromium.base.ThreadUtils;
+import org.chromium.chrome.browser.ChromeApplication;
import org.chromium.chrome.browser.ChromeFeatureList;
/**
* Manager for some locale specific logics.
*/
public class LocaleManager {
+ public static final String PREF_PROMO_SHOWN = "LocaleManager_PREF_PROMO_SHOWN";
public static final String SPECIAL_LOCALE_ID = "US";
+ private static LocaleManager sInstance;
+
private SpecialLocaleHandler mLocaleHandler;
/**
+ * @return An instance of the {@link LocaleManager}. This should only be called on UI thread.
+ */
+ public static LocaleManager getInstance() {
+ assert ThreadUtils.runningOnUiThread();
+ if (sInstance == null) {
+ sInstance = ((ChromeApplication) ContextUtils.getApplicationContext())
+ .createLocaleManager();
+ }
+ return sInstance;
+ }
+
+ /**
* Starts recording metrics in deferred startup.
*/
public void recordStartupMetrics() {}
@@ -52,7 +73,6 @@ public class LocaleManager {
* no-op if the user has changed DSP settings before.
*/
public void overrideDefaultSearchEngine() {
- // TODO(ianwen): Let this method be called in promotion.
// TODO(ianwen): Implement search engine auto switching.
if (!isSpecialLocaleEnabled()) return;
getSpecialLocaleHandler().overrideDefaultSearchProvider();
@@ -68,6 +88,25 @@ public class LocaleManager {
}
/**
+ * Shows a promotion dialog saying the default search engine will be set to Sogou. No-op if
+ * device is not in special locale.
+ *
+ * @return Whether such dialog is needed.
+ */
+ public boolean showSearchEnginePromoIfNeeded(Context context) {
+ if (!isSpecialLocaleEnabled()) return false;
+ SharedPreferences preferences = ContextUtils.getAppSharedPreferences();
+ if (preferences.getBoolean(PREF_PROMO_SHOWN, false)) {
+ return false;
+ }
+
+ new SearchEnginePromoDialog(context, this).show();
+
+ preferences.edit().putBoolean(PREF_PROMO_SHOWN, true).apply();
+ return true;
+ }
+
+ /**
* Does some extra checking about whether the user is in special locale.
* @param inSpecialLocale Whether the variation service thinks the client is in special locale.
* @return The result after extra confirmation.

Powered by Google App Engine
This is Rietveld 408576698