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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/infobar/TabbedModeOptInInfoBarDelegate.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 Dan's comments 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/TabbedModeOptInInfoBarDelegate.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/infobar/TabbedModeOptInInfoBarDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/infobar/TabbedModeOptInInfoBarDelegate.java
new file mode 100644
index 0000000000000000000000000000000000000000..713ce7763a9a2b28d32ecb52cba68c189480c40d
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/TabbedModeOptInInfoBarDelegate.java
@@ -0,0 +1,69 @@
+// 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.app.Activity;
+import android.preference.PreferenceManager;
+
+import org.chromium.base.annotations.CalledByNative;
+import org.chromium.chrome.browser.ChromeActivity;
+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 tabbed mode opt-in for the devices that document mode is inconvenient
+ * to use.
+ */
+public class TabbedModeOptInInfoBarDelegate {
+
+ private static final String PREF_USER_INTERACTED_TABBED_MODE_OPT_IN_INFOBAR =
gone 2015/11/20 19:26:14 nit: USER_INTERACTED_WITH
Kibeom Kim (inactive) 2015/11/20 23:13:14 Done.
+ "user_interacted_tabbed_mode_opt_in_infobar";
+ private static final String FIELD_TRIAL_NAME = "TabbedModeOptInInfoBar";
+ private static final String FIELD_TRIAL_PARAM_ENABLED = "enabled";
+
+ private Activity mActivity;
+
+ private TabbedModeOptInInfoBarDelegate(ChromeActivity activity) {
+ mActivity = activity;
+ }
+
+ /**
+ * Show tabbed mode opt-in promotion InfoBar if all the required conditions are met.
+ * @param activity Chrome activity that will be associated with this InfoBar.
+ */
+ public static void showIfNecessary(ChromeActivity activity) {
+ if (FeatureUtilities.isDocumentMode(activity)
+ && DocumentModeManager.isDeviceTabbedModeByDefault()
+ && !PreferenceManager.getDefaultSharedPreferences(activity)
+ .getBoolean(PREF_USER_INTERACTED_TABBED_MODE_OPT_IN_INFOBAR, false)
+ && VariationsAssociatedData
+ .getVariationParamValue(FIELD_TRIAL_NAME, FIELD_TRIAL_PARAM_ENABLED)
+ .equals("enabled")) {
+ TabbedModeOptInInfoBarDelegate delegate = new TabbedModeOptInInfoBarDelegate(activity);
+ delegate.nativeShowTabbedModeOptInInfoBar(activity.getActivityTab());
+ }
+ }
+
+ private void recordUserInteraction() {
+ PreferenceManager.getDefaultSharedPreferences(mActivity).edit()
+ .putBoolean(PREF_USER_INTERACTED_TABBED_MODE_OPT_IN_INFOBAR, true).commit();
+ }
+
+ @CalledByNative
+ private void accept() {
+ recordUserInteraction();
+ DocumentMigrationHelper.migrateTabs(false, mActivity, true);
+ }
+
+ @CalledByNative
+ private void cancel() {
+ recordUserInteraction();
+ }
+
+ private native long nativeShowTabbedModeOptInInfoBar(Tab tab);
+}

Powered by Google App Engine
This is Rietveld 408576698