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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/infobar/DocumentModeOptOutInfoBarDelegate.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/infobar/DocumentModeOptOutInfoBarDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/infobar/DocumentModeOptOutInfoBarDelegate.java
new file mode 100644
index 0000000000000000000000000000000000000000..be6f9c1972d06acf2d62101e600c87e637fb657f
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/DocumentModeOptOutInfoBarDelegate.java
@@ -0,0 +1,72 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.infobar;
+
+import android.content.Context;
+import android.preference.PreferenceManager;
+
+import org.chromium.base.ApplicationStatus;
+import org.chromium.base.annotations.CalledByNative;
+import org.chromium.chrome.browser.document.DocumentMigrationHelper;
+import org.chromium.chrome.browser.preferences.DocumentModeManager;
+import org.chromium.chrome.browser.tab.Tab;
+import org.chromium.chrome.browser.util.FeatureUtilities;
+import org.chromium.components.variations.VariationsAssociatedData;
+
+/**
+ * Handles InfoBar requesting document mode opt-out for the devices that document mode is
+ * inconvenient to use.
+ */
+public class DocumentModeOptOutInfoBarDelegate {
+
+ private static final String USER_INTERACTED_WITH_DOCUMENT_MODE_OPT_OUT_INFOBAR =
+ "user_interacted_document_mode_opt_out_infobar";
+ private static final String FIELD_TRIAL_NAME = "DocumentModeOptOutInfoBar";
+ private static final String FIELD_TRIAL_PARAM_ENABLED = "enabled";
+
+ private Context mContext;
+
+ private DocumentModeOptOutInfoBarDelegate(Context context) {
+ mContext = context;
+ }
+
+ /**
+ * Show document mode opt-out promotion InfoBar if all the required conditions are met.
+ * @param context Context for checking preconditions and showing InfoBar.
+ * @param tab Tab that InfoBar should be shown.
+ */
+ public static void showIfNecessary(Context context, Tab tab) {
+ if (FeatureUtilities.isDocumentMode(context)
+ && DocumentModeManager.isDeviceTabbedModeByDefault()
+ && !PreferenceManager.getDefaultSharedPreferences(context)
+ .getBoolean(USER_INTERACTED_WITH_DOCUMENT_MODE_OPT_OUT_INFOBAR, false)
+ && VariationsAssociatedData
+ .getVariationParamValue(FIELD_TRIAL_NAME, FIELD_TRIAL_PARAM_ENABLED)
+ .equals("enabled")) {
+ DocumentModeOptOutInfoBarDelegate delegate =
+ new DocumentModeOptOutInfoBarDelegate(context);
+ delegate.nativeShowDocumentModeOptOutInfoBar(tab);
+ }
+ }
+
+ private void recordUserInteraction() {
+ PreferenceManager.getDefaultSharedPreferences(mContext).edit()
+ .putBoolean(USER_INTERACTED_WITH_DOCUMENT_MODE_OPT_OUT_INFOBAR, true).commit();
+ }
+
+ @CalledByNative
+ private void accept() {
+ recordUserInteraction();
+ DocumentMigrationHelper.migrateTabs(false,
+ ApplicationStatus.getLastTrackedFocusedActivity(), true);
+ }
+
+ @CalledByNative
+ private void cancel() {
+ recordUserInteraction();
+ }
+
+ private native long nativeShowDocumentModeOptOutInfoBar(Tab tab);
+}

Powered by Google App Engine
This is Rietveld 408576698