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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/infobar/DocumentModeOptOutInfoBarDelegate.java

Issue 1435263003: [Android] Show document mode opt-out InfoBar on selected devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed comments, renaming Created 5 years, 1 month 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.infobar;
6
7 import android.content.Context;
8 import android.preference.PreferenceManager;
9
10 import org.chromium.base.ApplicationStatus;
11 import org.chromium.base.annotations.CalledByNative;
12 import org.chromium.chrome.browser.document.DocumentMigrationHelper;
13 import org.chromium.chrome.browser.preferences.DocumentModeManager;
14 import org.chromium.chrome.browser.tab.Tab;
15 import org.chromium.chrome.browser.util.FeatureUtilities;
16 import org.chromium.components.variations.VariationsAssociatedData;
17
18 /**
19 * Handles InfoBar requesting document mode opt-out for the devices that documen t mode is
20 * inconvenient to use.
21 */
22 public class DocumentModeOptOutInfoBarDelegate {
23
24 private static final String USER_INTERACTED_WITH_DOCUMENT_MODE_OPT_OUT_INFOB AR =
25 "user_interacted_document_mode_opt_out_infobar";
26 private static final String FIELD_TRIAL_NAME = "DocumentModeOptOutInfoBar";
27 private static final String FIELD_TRIAL_PARAM_ENABLED = "enabled";
28
29 private Context mContext;
30
31 private DocumentModeOptOutInfoBarDelegate(Context context) {
32 mContext = context;
33 }
34
35 /**
36 * Show document mode opt-out promotion InfoBar if all the required conditio ns are met.
37 * @param context Context for checking preconditions and showing InfoBar.
38 * @param tab Tab that InfoBar should be shown.
39 */
40 public static void showIfNecessary(Context context, Tab tab) {
41 if (FeatureUtilities.isDocumentMode(context)
42 && DocumentModeManager.isDeviceTabbedModeByDefault()
43 && !PreferenceManager.getDefaultSharedPreferences(context)
44 .getBoolean(USER_INTERACTED_WITH_DOCUMENT_MODE_OPT_OUT_I NFOBAR, false)
45 && VariationsAssociatedData
46 .getVariationParamValue(FIELD_TRIAL_NAME, FIELD_TRIAL_PA RAM_ENABLED)
47 .equals("enabled")) {
48 DocumentModeOptOutInfoBarDelegate delegate =
49 new DocumentModeOptOutInfoBarDelegate(context);
50 delegate.nativeShowDocumentModeOptOutInfoBar(tab);
51 }
52 }
53
54 private void recordUserInteraction() {
55 PreferenceManager.getDefaultSharedPreferences(mContext).edit()
56 .putBoolean(USER_INTERACTED_WITH_DOCUMENT_MODE_OPT_OUT_INFOBAR, true).commit();
57 }
58
59 @CalledByNative
60 private void accept() {
61 recordUserInteraction();
62 DocumentMigrationHelper.migrateTabs(false,
63 ApplicationStatus.getLastTrackedFocusedActivity(), true);
64 }
65
66 @CalledByNative
67 private void cancel() {
68 recordUserInteraction();
69 }
70
71 private native long nativeShowDocumentModeOptOutInfoBar(Tab tab);
72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698