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

Side by Side Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/preferences/ChromePreferenceManager.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 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
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.preferences;
6
7 import android.content.Context;
8 import android.content.SharedPreferences;
9 import android.preference.PreferenceManager;
10
11 import org.chromium.base.annotations.SuppressFBWarnings;
12 import org.chromium.chrome.browser.signin.SigninPromoUma;
13
14 /**
15 * ChromePreferenceManager stores and retrieves various values in Android shared preferences.
16 */
17 public class ChromePreferenceManager {
18
19 private static final String BREAKPAD_UPLOAD_SUCCESS = "breakpad_upload_succe ss";
20 private static final String BREAKPAD_UPLOAD_FAIL = "breakpad_upload_fail";
21 private static final String PROMOS_SKIPPED_ON_FIRST_START = "promos_skipped_ on_first_start";
22 private static final String SIGNIN_PROMO_LAST_SHOWN = "signin_promo_last_tim estamp_key";
23 private static final String SHOW_SIGNIN_PROMO = "show_signin_promo";
24 private static final String MIGRATION_ON_UPGRADE_ATTEMPTED = "migration_on_u pgrade_attempted";
25 private static final String ALLOW_LOW_END_DEVICE_UI = "allow_low_end_device_ ui";
26 private static final String PREF_WEBSITE_SETTINGS_FILTER = "website_settings _filter";
27 private static final String CONTEXTUAL_SEARCH_TAP_TRIGGERED_PROMO_COUNT =
28 "contextual_search_tap_triggered_promo_count";
29 private static final String CONTEXTUAL_SEARCH_TAP_COUNT = "contextual_search _tap_count";
30
31 private static final int SIGNIN_PROMO_CYCLE_IN_DAYS = 120;
32 private static final long MILLISECONDS_IN_DAY = 1000 * 60 * 60 * 24;
33
34 private static ChromePreferenceManager sPrefs;
35
36 private final SharedPreferences mSharedPreferences;
37 private final Context mContext;
38
39 private ChromePreferenceManager(Context context) {
40 mContext = context.getApplicationContext();
41 mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(mCont ext);
42 }
43
44 /**
45 * Get the static instance of ChromePreferenceManager if exists else create it.
46 * @param context
47 * @return the ChromePreferenceManager singleton
48 */
49 @SuppressFBWarnings("CHROMIUM_SYNCHRONIZED_METHOD")
50 public static synchronized ChromePreferenceManager getInstance(Context conte xt) {
51 if (sPrefs == null) {
52 sPrefs = new ChromePreferenceManager(context);
53 }
54 return sPrefs;
55 }
56
57 /**
58 * @return Number of times the upload intent service successfully uploaded
59 * a minidump.
60 */
61 public int getBreakpadUploadSuccessCount() {
62 return mSharedPreferences.getInt(BREAKPAD_UPLOAD_SUCCESS, 0);
63 }
64
65 public void setBreakpadUploadSuccessCount(int count) {
66 SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.ed it();
67 sharedPreferencesEditor.putInt(BREAKPAD_UPLOAD_SUCCESS, count);
68 sharedPreferencesEditor.apply();
69 }
70
71 public void incrementBreakpadUploadSuccessCount() {
72 setBreakpadUploadSuccessCount(getBreakpadUploadSuccessCount() + 1);
73 }
74
75 /**
76 * @return Number of times the upload intent service gave up on uploading
77 * minidump after a few tries.
78 */
79 public int getBreakpadUploadFailCount() {
80 return mSharedPreferences.getInt(BREAKPAD_UPLOAD_FAIL, 0);
81 }
82
83 public void setBreakpadUploadFailCount(int count) {
84 SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.ed it();
85 sharedPreferencesEditor.putInt(BREAKPAD_UPLOAD_FAIL, count);
86 sharedPreferencesEditor.apply();
87 }
88
89 public void incrementBreakpadUploadFailCount() {
90 setBreakpadUploadFailCount(getBreakpadUploadFailCount() + 1);
91 }
92
93 /**
94 * @return Whether we have attempted to migrate tabbed state to document mod e after OS upgrade.
95 */
96 public boolean hasAttemptedMigrationOnUpgrade() {
97 return mSharedPreferences.getBoolean(MIGRATION_ON_UPGRADE_ATTEMPTED, fal se);
98 }
99
100 /**
101 * Mark that we have made an attempt to migrate tabbed state to document mod e after OS upgrade.
102 */
103 public void setAttemptedMigrationOnUpgrade() {
104 SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.ed it();
105 sharedPreferencesEditor.putBoolean(MIGRATION_ON_UPGRADE_ATTEMPTED, true) ;
106 sharedPreferencesEditor.apply();
107 }
108
109 /**
110 * @return Whether the promotion for data reduction has been skipped on firs t invocation.
111 */
112 public boolean getPromosSkippedOnFirstStart() {
113 return mSharedPreferences.getBoolean(PROMOS_SKIPPED_ON_FIRST_START, fals e);
114 }
115
116 /**
117 * Marks whether the data reduction promotion was skipped on first
118 * invocation.
119 * @param displayed Whether the promotion was shown.
120 */
121 public void setPromosSkippedOnFirstStart(boolean displayed) {
122 SharedPreferences.Editor ed = mSharedPreferences.edit();
123 ed.putBoolean(PROMOS_SKIPPED_ON_FIRST_START, displayed);
124 ed.apply();
125 }
126
127 /**
128 * @return The value for the website settings filter (the one that specifies
129 * which sites to show in the list).
130 */
131 public String getWebsiteSettingsFilterPreference() {
132 return mSharedPreferences.getString(
133 ChromePreferenceManager.PREF_WEBSITE_SETTINGS_FILTER, "");
134 }
135
136 /**
137 * Sets the filter value for website settings (which websites to show in the list).
138 * @param prefValue The type to restrict the filter to.
139 */
140 public void setWebsiteSettingsFilterPreference(String prefValue) {
141 SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.ed it();
142 sharedPreferencesEditor.putString(
143 ChromePreferenceManager.PREF_WEBSITE_SETTINGS_FILTER, prefValue) ;
144 sharedPreferencesEditor.apply();
145 }
146
147 /**
148 * Set shared preference to allow low end device ui.
149 */
150 public void setAllowLowEndDeviceUi() {
151 SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.ed it();
152 sharedPreferencesEditor.putBoolean(ALLOW_LOW_END_DEVICE_UI, true);
153 sharedPreferencesEditor.apply();
154 }
155
156 /**
157 * @return Whether low end device ui is allowed.
158 */
159 public boolean getAllowLowEndDeviceUi() {
160 return mSharedPreferences.getBoolean(ALLOW_LOW_END_DEVICE_UI, false);
161 }
162
163 /**
164 * Signin promo could be shown at most once every 12 weeks. This method chec ks
165 * wheter the signin promo has already been shown in the current cycle.
166 * @return Whether the signin promo has been shown in the current cycle.
167 */
168 public boolean getSigninPromoShown() {
169 long signinPromoLastShown = mSharedPreferences.getLong(SIGNIN_PROMO_LAST _SHOWN, 0);
170 long numDaysElapsed =
171 (System.currentTimeMillis() - signinPromoLastShown) / MILLISECON DS_IN_DAY;
172 return numDaysElapsed < SIGNIN_PROMO_CYCLE_IN_DAYS;
173 }
174
175 /**
176 * Sets the preference for tracking when the signin promo was last shown.
177 */
178 public void setSigninPromoShown() {
179 SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.ed it();
180 sharedPreferencesEditor.putLong(SIGNIN_PROMO_LAST_SHOWN, System.currentT imeMillis());
181 sharedPreferencesEditor.apply();
182 }
183
184 /**
185 * @return Whether the signin promo has been marked to be shown on next star tup.
186 */
187 public boolean getShowSigninPromo() {
188 return mSharedPreferences.getBoolean(SHOW_SIGNIN_PROMO, false);
189 }
190
191 /**
192 * Sets the preference to indicate that the signin promo should be shown on next startup.
193 * @param shouldShow Whether the signin promo should be shown.
194 */
195 public void setShowSigninPromo(boolean shouldShow) {
196 SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.ed it();
197 sharedPreferencesEditor.putBoolean(SHOW_SIGNIN_PROMO, shouldShow).apply( );
198
199 if (shouldShow) SigninPromoUma.recordAction(SigninPromoUma.SIGNIN_PROMO_ ENABLED);
200 }
201
202 /**
203 * @return Number of times the promo was triggered by a tap gesture, or a ne gative value
204 * if in the disabled state.
205 */
206 public int getContextualSearchTapTriggeredPromoCount() {
207 return mSharedPreferences.getInt(CONTEXTUAL_SEARCH_TAP_TRIGGERED_PROMO_C OUNT, 0);
208 }
209
210 /**
211 * Sets the number of times the promo was triggered by a tap gesture. Use a negative value
212 * to record that the counter has been disabled.
213 * @param count Number of times the promo was triggered by a tap gesture, or a negative value
214 * to record that the counter has been disabled.
215 */
216 public void setContextualSearchTapTriggeredPromoCount(int count) {
217 SharedPreferences.Editor ed = mSharedPreferences.edit();
218 ed.putInt(CONTEXTUAL_SEARCH_TAP_TRIGGERED_PROMO_COUNT, count);
219 ed.apply();
220 }
221
222 /**
223 * @return Number of tap gestures that have been received when not waiting f or the promo.
224 */
225 public int getContextualSearchTapCount() {
226 return mSharedPreferences.getInt(CONTEXTUAL_SEARCH_TAP_COUNT, 0);
227 }
228
229 /**
230 * Sets the number of tap gestures that have been received when not waiting for the promo.
231 * @param count Number of taps that have been received when not waiting for the promo.
232 */
233 public void setContextualSearchTapCount(int count) {
234 SharedPreferences.Editor ed = mSharedPreferences.edit();
235 ed.putInt(CONTEXTUAL_SEARCH_TAP_COUNT, count);
236 ed.apply();
237 }
238 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698