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

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

Issue 2013883002: ✈ Remove unnecessary flag and DocumentModeManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 6 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
10 import org.chromium.base.ContextUtils;
11 import org.chromium.base.ThreadUtils;
12 import org.chromium.base.VisibleForTesting;
13
14 /**
15 * Tracks opt out status for document mode
16 */
17 public class DocumentModeManager {
18
19 public static final String OPT_OUT_STATE = "opt_out_state";
20 public static final int OPT_OUT_STATE_UNSET = -1;
21 public static final int OPT_IN_TO_DOCUMENT_MODE = 0;
22 public static final int OPT_OUT_PROMO_DISMISSED = 1;
23 public static final int OPTED_OUT_OF_DOCUMENT_MODE = 2;
24 public static final String OPT_OUT_SHOWN_COUNT = "opt_out_shown_count";
25 public static final String OPT_OUT_CLEAN_UP_PENDING = "opt_out_clean_up_pend ing";
26
27 private static DocumentModeManager sManager;
28
29 private final SharedPreferences mSharedPreferences;
30
31 private DocumentModeManager(Context context) {
32 mSharedPreferences = ContextUtils.getAppSharedPreferences();
33 }
34
35 /**
36 * Get the static instance of DocumentModeManager if it exists, else create it.
37 * @param context The current Android context
38 * @return the DocumentModeManager singleton
39 */
40 public static DocumentModeManager getInstance(Context context) {
41 ThreadUtils.assertOnUiThread();
42 if (sManager == null) {
43 sManager = new DocumentModeManager(context);
44 }
45 return sManager;
46 }
47
48 /**
49 * @return Whether the user set a preference to not use the document mode.
50 */
51 public boolean isOptedOutOfDocumentMode() {
52 return getOptOutState() == OPTED_OUT_OF_DOCUMENT_MODE;
53 }
54
55 /**
56 * Sets the opt out preference.
57 * @param state One of OPTED_OUT_OF_DOCUMENT_MODE or OPT_OUT_PROMO_DISMISSED .
58 */
59 public void setOptedOutState(int state) {
60 SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.ed it();
61 sharedPreferencesEditor.putInt(OPT_OUT_STATE, state);
62 sharedPreferencesEditor.apply();
63 }
64
65 /**
66 * @return Whether we need to clean up old document activity tasks from Rece nts.
67 */
68 public boolean isOptOutCleanUpPending() {
69 return mSharedPreferences.getBoolean(OPT_OUT_CLEAN_UP_PENDING, false);
70 }
71
72 /**
73 * Mark that we need to clean up old documents from Recents or reset it afte r the task
74 * is done.
75 * @param pending Whether we need to clean up.
76 */
77 public void setOptOutCleanUpPending(boolean pending) {
78 SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.ed it();
79 sharedPreferencesEditor.putBoolean(OPT_OUT_CLEAN_UP_PENDING, pending);
80 sharedPreferencesEditor.apply();
81 }
82
83 private int getOptOutState() {
84 int optOutState = mSharedPreferences.getInt(OPT_OUT_STATE, OPT_OUT_STATE _UNSET);
85 if (optOutState == OPT_OUT_STATE_UNSET) {
86 boolean hasMigrated = mSharedPreferences.getBoolean(
87 ChromePreferenceManager.MIGRATION_ON_UPGRADE_ATTEMPTED, fals e);
88 if (!hasMigrated) {
89 optOutState = OPTED_OUT_OF_DOCUMENT_MODE;
90 } else {
91 optOutState = OPT_IN_TO_DOCUMENT_MODE;
92 }
93 setOptedOutState(optOutState);
94 }
95 return optOutState;
96 }
97
98 @VisibleForTesting
99 public int getOptOutStateForTesting() {
100 return mSharedPreferences.getInt(OPT_OUT_STATE, OPT_OUT_STATE_UNSET);
101 }
102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698