OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.locale; | 5 package org.chromium.chrome.browser.locale; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.content.SharedPreferences; | 8 import android.content.SharedPreferences; |
9 | 9 |
10 import org.chromium.base.ContextUtils; | 10 import org.chromium.base.ContextUtils; |
11 import org.chromium.chrome.browser.ChromeApplication; | 11 import org.chromium.chrome.browser.ChromeApplication; |
12 import org.chromium.chrome.browser.ChromeFeatureList; | 12 import org.chromium.chrome.browser.ChromeFeatureList; |
13 | 13 |
14 /** | 14 /** |
15 * Manager for some locale specific logics. | 15 * Manager for some locale specific logics. |
16 */ | 16 */ |
17 public class LocaleManager { | 17 public class LocaleManager { |
18 public static final String PREF_PROMO_SHOWN = "LocaleManager_PREF_PROMO_SHOW
N"; | 18 public static final String PREF_PROMO_SHOWN = "LocaleManager_PREF_PROMO_SHOW
N"; |
| 19 public static final String PREF_WAS_IN_SPECIAL_LOCALE = "LocaleManager_WAS_I
N_SPECIAL_LOCALE"; |
19 public static final String SPECIAL_LOCALE_ID = "US"; | 20 public static final String SPECIAL_LOCALE_ID = "US"; |
20 | 21 |
21 private static LocaleManager sInstance; | 22 private static LocaleManager sInstance; |
22 | 23 |
23 private SpecialLocaleHandler mLocaleHandler; | 24 private SpecialLocaleHandler mLocaleHandler; |
24 | 25 |
25 /** | 26 /** |
| 27 * Starts listening to state changes of the phone. |
| 28 */ |
| 29 public void observePhoneStateChanges() {} |
| 30 |
| 31 /** |
| 32 * Stops listening to state changes of the phone. |
| 33 */ |
| 34 public void stopObservePhoneStateChanges() {} |
| 35 |
| 36 /** |
26 * @return An instance of the {@link LocaleManager}. | 37 * @return An instance of the {@link LocaleManager}. |
27 */ | 38 */ |
28 public static LocaleManager getInstance() { | 39 public static LocaleManager getInstance() { |
29 if (sInstance == null) { | 40 if (sInstance == null) { |
30 sInstance = ((ChromeApplication) ContextUtils.getApplicationContext(
)) | 41 sInstance = ((ChromeApplication) ContextUtils.getApplicationContext(
)) |
31 .createLocaleManager(); | 42 .createLocaleManager(); |
32 } | 43 } |
33 return sInstance; | 44 return sInstance; |
34 } | 45 } |
35 | 46 |
36 /** | 47 /** |
37 * Starts recording metrics in deferred startup. | 48 * Starts recording metrics in deferred startup. |
38 */ | 49 */ |
39 public void recordStartupMetrics() {} | 50 public void recordStartupMetrics() {} |
40 | 51 |
41 /** | 52 /** |
42 * @return Whether the Chrome instance is running in a special locale. | 53 * @return Whether the Chrome instance is running in a special locale. |
43 */ | 54 */ |
44 public boolean isSpecialLocaleEnabled() { | 55 public boolean isSpecialLocaleEnabled() { |
45 // If there is a kill switch sent from the server, disable the feature. | 56 // If there is a kill switch sent from the server, disable the feature. |
46 if (!ChromeFeatureList.isEnabled("SpecialLocaleWrapper")) { | 57 if (!ChromeFeatureList.isEnabled("SpecialLocaleWrapper")) { |
47 return false; | 58 return false; |
48 } | 59 } |
49 boolean inSpecialLocale = ChromeFeatureList.isEnabled("SpecialLocale"); | 60 boolean inSpecialLocale = ChromeFeatureList.isEnabled("SpecialLocale"); |
50 return isReallyInSpecialLocale(inSpecialLocale); | 61 inSpecialLocale = isReallyInSpecialLocale(inSpecialLocale); |
| 62 ContextUtils.getAppSharedPreferences().edit() |
| 63 .putBoolean(PREF_WAS_IN_SPECIAL_LOCALE, inSpecialLocale).apply()
; |
| 64 return inSpecialLocale; |
51 } | 65 } |
52 | 66 |
53 /** | 67 /** |
54 * @return The country id of the special locale. | 68 * @return The country id of the special locale. |
55 */ | 69 */ |
56 public String getSpecialLocaleId() { | 70 public String getSpecialLocaleId() { |
57 return SPECIAL_LOCALE_ID; | 71 return SPECIAL_LOCALE_ID; |
58 } | 72 } |
59 | 73 |
60 /** | 74 /** |
61 * Adds local search engines for special locale. | 75 * Adds local search engines for special locale. |
62 */ | 76 */ |
63 public void addSpecialSearchEngines() { | 77 public void addSpecialSearchEngines() { |
64 // TODO(ianwen): Let this method be called in ChromeActivity#finishNativ
eInitialization(). | |
65 if (!isSpecialLocaleEnabled()) return; | 78 if (!isSpecialLocaleEnabled()) return; |
66 getSpecialLocaleHandler().loadTemplateUrls(); | 79 getSpecialLocaleHandler().loadTemplateUrls(); |
67 } | 80 } |
68 | 81 |
69 /** | 82 /** |
70 * Overrides the default search engine to a different search engine we desig
nate. This is a | 83 * Overrides the default search engine to a different search engine we desig
nate. This is a |
71 * no-op if the user has changed DSP settings before. | 84 * no-op if the user has changed DSP settings before. |
72 */ | 85 */ |
73 public void overrideDefaultSearchEngine() { | 86 public void overrideDefaultSearchEngine() { |
74 // TODO(ianwen): Implement search engine auto switching. | 87 // TODO(ianwen): Implement search engine auto switching. |
75 if (!isSpecialLocaleEnabled()) return; | 88 if (!isSpecialLocaleEnabled()) return; |
76 getSpecialLocaleHandler().overrideDefaultSearchProvider(); | 89 getSpecialLocaleHandler().overrideDefaultSearchProvider(); |
77 } | 90 } |
78 | 91 |
79 /** | 92 /** |
80 * Removes local search engines for special locale. | 93 * Removes local search engines for special locale. |
81 */ | 94 */ |
82 public void removeSpecialSearchEngines() { | 95 public void removeSpecialSearchEngines() { |
83 // TODO(ianwen): Let this method be called when device configuration cha
nges. | |
84 if (isSpecialLocaleEnabled()) return; | 96 if (isSpecialLocaleEnabled()) return; |
85 getSpecialLocaleHandler().removeTemplateUrls(); | 97 getSpecialLocaleHandler().removeTemplateUrls(); |
86 } | 98 } |
87 | 99 |
88 /** | 100 /** |
89 * Shows a promotion dialog saying the default search engine will be set to
Sogou. No-op if | 101 * Shows a promotion dialog saying the default search engine will be set to
Sogou. No-op if |
90 * device is not in special locale. | 102 * device is not in special locale. |
91 * | 103 * |
92 * @return Whether such dialog is needed. | 104 * @return Whether such dialog is needed. |
93 */ | 105 */ |
(...skipping 17 matching lines...) Expand all Loading... |
111 */ | 123 */ |
112 protected boolean isReallyInSpecialLocale(boolean inSpecialLocale) { | 124 protected boolean isReallyInSpecialLocale(boolean inSpecialLocale) { |
113 return inSpecialLocale; | 125 return inSpecialLocale; |
114 } | 126 } |
115 | 127 |
116 private SpecialLocaleHandler getSpecialLocaleHandler() { | 128 private SpecialLocaleHandler getSpecialLocaleHandler() { |
117 if (mLocaleHandler == null) mLocaleHandler = new SpecialLocaleHandler(ge
tSpecialLocaleId()); | 129 if (mLocaleHandler == null) mLocaleHandler = new SpecialLocaleHandler(ge
tSpecialLocaleId()); |
118 return mLocaleHandler; | 130 return mLocaleHandler; |
119 } | 131 } |
120 } | 132 } |
OLD | NEW |