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

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

Issue 2385543002: Adjust Chrome to normal behavior once user leaves special locale (Closed)
Patch Set: compile 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 unified diff | Download patch
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ChromeTabbedActivity.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.base.ThreadUtils; 11 import org.chromium.base.ThreadUtils;
12 import org.chromium.chrome.browser.ChromeApplication; 12 import org.chromium.chrome.browser.ChromeApplication;
13 import org.chromium.chrome.browser.ChromeFeatureList; 13 import org.chromium.chrome.browser.ChromeFeatureList;
14 14
15 /** 15 /**
16 * Manager for some locale specific logics. 16 * Manager for some locale specific logics.
17 */ 17 */
18 public class LocaleManager { 18 public class LocaleManager {
19 public static final String PREF_PROMO_SHOWN = "LocaleManager_PREF_PROMO_SHOW N"; 19 public static final String PREF_PROMO_SHOWN = "LocaleManager_PREF_PROMO_SHOW N";
20 public static final String PREF_WAS_IN_SPECIAL_LOCALE = "LocaleManager_WAS_I N_SPECIAL_LOCALE";
20 public static final String SPECIAL_LOCALE_ID = "US"; 21 public static final String SPECIAL_LOCALE_ID = "US";
21 22
22 private static LocaleManager sInstance; 23 private static LocaleManager sInstance;
23 24
24 private SpecialLocaleHandler mLocaleHandler; 25 private SpecialLocaleHandler mLocaleHandler;
25 26
26 /** 27 /**
28 * Starts listening to state changes of the phone.
29 */
30 public void startObservingPhoneChanges() {}
31
32 /**
33 * Stops listening to state changes of the phone.
34 */
35 public void stopObservingPhoneChanges() {}
36
37 /**
27 * @return An instance of the {@link LocaleManager}. This should only be cal led on UI thread. 38 * @return An instance of the {@link LocaleManager}. This should only be cal led on UI thread.
28 */ 39 */
29 public static LocaleManager getInstance() { 40 public static LocaleManager getInstance() {
30 assert ThreadUtils.runningOnUiThread(); 41 assert ThreadUtils.runningOnUiThread();
31 if (sInstance == null) { 42 if (sInstance == null) {
32 sInstance = ((ChromeApplication) ContextUtils.getApplicationContext( )) 43 sInstance = ((ChromeApplication) ContextUtils.getApplicationContext( ))
33 .createLocaleManager(); 44 .createLocaleManager();
34 } 45 }
35 return sInstance; 46 return sInstance;
36 } 47 }
37 48
38 /** 49 /**
39 * Starts recording metrics in deferred startup. 50 * Starts recording metrics in deferred startup.
40 */ 51 */
41 public void recordStartupMetrics() {} 52 public void recordStartupMetrics() {}
42 53
43 /** 54 /**
44 * @return Whether the Chrome instance is running in a special locale. 55 * @return Whether the Chrome instance is running in a special locale.
45 */ 56 */
46 public boolean isSpecialLocaleEnabled() { 57 public boolean isSpecialLocaleEnabled() {
47 // If there is a kill switch sent from the server, disable the feature. 58 // If there is a kill switch sent from the server, disable the feature.
48 if (!ChromeFeatureList.isEnabled("SpecialLocaleWrapper")) { 59 if (!ChromeFeatureList.isEnabled("SpecialLocaleWrapper")) {
49 return false; 60 return false;
50 } 61 }
51 boolean inSpecialLocale = ChromeFeatureList.isEnabled("SpecialLocale"); 62 boolean inSpecialLocale = ChromeFeatureList.isEnabled("SpecialLocale");
52 return isReallyInSpecialLocale(inSpecialLocale); 63 inSpecialLocale = isReallyInSpecialLocale(inSpecialLocale);
64 ContextUtils.getAppSharedPreferences().edit()
65 .putBoolean(PREF_WAS_IN_SPECIAL_LOCALE, inSpecialLocale).apply() ;
66 return inSpecialLocale;
53 } 67 }
54 68
55 /** 69 /**
56 * @return The country id of the special locale. 70 * @return The country id of the special locale.
57 */ 71 */
58 public String getSpecialLocaleId() { 72 public String getSpecialLocaleId() {
59 return SPECIAL_LOCALE_ID; 73 return SPECIAL_LOCALE_ID;
60 } 74 }
61 75
62 /** 76 /**
63 * Adds local search engines for special locale. 77 * Adds local search engines for special locale.
64 */ 78 */
65 public void addSpecialSearchEngines() { 79 public void addSpecialSearchEngines() {
66 // TODO(ianwen): Let this method be called in ChromeActivity#finishNativ eInitialization().
67 if (!isSpecialLocaleEnabled()) return; 80 if (!isSpecialLocaleEnabled()) return;
68 getSpecialLocaleHandler().loadTemplateUrls(); 81 getSpecialLocaleHandler().loadTemplateUrls();
69 } 82 }
70 83
71 /** 84 /**
72 * Overrides the default search engine to a different search engine we desig nate. This is a 85 * Overrides the default search engine to a different search engine we desig nate. This is a
73 * no-op if the user has changed DSP settings before. 86 * no-op if the user has changed DSP settings before.
74 */ 87 */
75 public void overrideDefaultSearchEngine() { 88 public void overrideDefaultSearchEngine() {
76 // TODO(ianwen): Implement search engine auto switching. 89 // TODO(ianwen): Implement search engine auto switching.
77 if (!isSpecialLocaleEnabled()) return; 90 if (!isSpecialLocaleEnabled()) return;
78 getSpecialLocaleHandler().overrideDefaultSearchProvider(); 91 getSpecialLocaleHandler().overrideDefaultSearchProvider();
79 } 92 }
80 93
81 /** 94 /**
82 * Removes local search engines for special locale. 95 * Removes local search engines for special locale.
83 */ 96 */
84 public void removeSpecialSearchEngines() { 97 public void removeSpecialSearchEngines() {
85 // TODO(ianwen): Let this method be called when device configuration cha nges.
86 if (isSpecialLocaleEnabled()) return; 98 if (isSpecialLocaleEnabled()) return;
87 getSpecialLocaleHandler().removeTemplateUrls(); 99 getSpecialLocaleHandler().removeTemplateUrls();
88 } 100 }
89 101
90 /** 102 /**
91 * Shows a promotion dialog saying the default search engine will be set to Sogou. No-op if 103 * Shows a promotion dialog saying the default search engine will be set to Sogou. No-op if
92 * device is not in special locale. 104 * device is not in special locale.
93 * 105 *
94 * @return Whether such dialog is needed. 106 * @return Whether such dialog is needed.
95 */ 107 */
(...skipping 17 matching lines...) Expand all
113 */ 125 */
114 protected boolean isReallyInSpecialLocale(boolean inSpecialLocale) { 126 protected boolean isReallyInSpecialLocale(boolean inSpecialLocale) {
115 return inSpecialLocale; 127 return inSpecialLocale;
116 } 128 }
117 129
118 private SpecialLocaleHandler getSpecialLocaleHandler() { 130 private SpecialLocaleHandler getSpecialLocaleHandler() {
119 if (mLocaleHandler == null) mLocaleHandler = new SpecialLocaleHandler(ge tSpecialLocaleId()); 131 if (mLocaleHandler == null) mLocaleHandler = new SpecialLocaleHandler(ge tSpecialLocaleId());
120 return mLocaleHandler; 132 return mLocaleHandler;
121 } 133 }
122 } 134 }
OLDNEW
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ChromeTabbedActivity.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698