Chromium Code Reviews| 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..9a534d717a7a8a5b88272906c472331f714c3ca1 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,36 @@ |
| package org.chromium.chrome.browser.locale; |
| +import android.content.Context; |
| +import android.content.SharedPreferences; |
| + |
| +import org.chromium.base.ContextUtils; |
| +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}. |
| + */ |
| + public static LocaleManager getInstance() { |
| + if (sInstance == null) { |
|
Maria
2016/10/04 03:42:22
this should either be synchronized or assert that
Ian Wen
2016/10/04 18:28:45
Done.
|
| + sInstance = ((ChromeApplication) ContextUtils.getApplicationContext()) |
| + .createLocaleManager(); |
| + } |
| + return sInstance; |
| + } |
| + |
| + /** |
| * Starts recording metrics in deferred startup. |
| */ |
| public void recordStartupMetrics() {} |
| @@ -52,7 +71,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 +86,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. |