Index: chrome/android/java/src/org/chromium/chrome/browser/infobar/TabbedModeOptInInfoBar.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/infobar/TabbedModeOptInInfoBar.java b/chrome/android/java/src/org/chromium/chrome/browser/infobar/TabbedModeOptInInfoBar.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d7bc4d4d309454c1e1a6275f6ddeb1735ec5579c |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/TabbedModeOptInInfoBar.java |
@@ -0,0 +1,94 @@ |
+// 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.metrics.RecordUserAction; |
+import org.chromium.chrome.R; |
+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.util.FeatureUtilities; |
+import org.chromium.components.variations.VariationsAssociatedData; |
+ |
+/** |
+ * Infobar for tabbed mode opt-in promotion. This is for the existing users on the devices that does |
+ * not have a convenient system tab switcher button. |
+ */ |
+public class TabbedModeOptInInfoBar extends ConfirmInfoBar { |
+ |
+ private static final String PREF_USER_INTERACTED_TABBED_MODE_OPT_IN_INFOBAR = |
+ "user_denied_tabbed_mode_opt_in_infobar"; |
+ private static final String FIELD_TRIAL_NAME = "TabbedModeOptInInfoBar"; |
+ private static final String FIELD_TRIAL_PARAM_ENABLED = "enabled"; |
+ private final Activity mActivity; |
+ |
+ /** |
+ * Show this infobar if needed. It checks |
+ * 1. Whether this is an eligible device for this infobar. |
+ * 2. Whether it's running document mode currently. |
+ * 3. Whether user already interacted with this infobar before. |
+ * 4. Whether user explicitly opted into document mode from the settings. |
+ * 5. Whether this should be shown according to field trial config. |
+ * |
+ * @param activity Activity instance that should be associated with this infobar. |
+ */ |
+ public static void showIfNecessary(ChromeActivity activity) { |
+ if (DocumentModeManager.isDeviceTabbedModeByDefault() |
+ && FeatureUtilities.isDocumentMode(activity) |
+ && !PreferenceManager.getDefaultSharedPreferences(activity) |
+ .getBoolean(PREF_USER_INTERACTED_TABBED_MODE_OPT_IN_INFOBAR, false) |
+ && !DocumentModeManager.getInstance(activity).isOptedInToDocumentMode() |
+ && VariationsAssociatedData |
+ .getVariationParamValue(FIELD_TRIAL_NAME, FIELD_TRIAL_PARAM_ENABLED) |
+ .equals("enabled")) { |
+ RecordUserAction.record("TabbdedModeOptInInfoBar_Shown"); |
+ activity.getActivityTab().getInfoBarContainer().addInfoBar( |
+ new TabbedModeOptInInfoBar(activity)); |
+ } |
+ } |
+ |
+ private TabbedModeOptInInfoBar(Activity activity) { |
+ super(null, R.drawable.tabbed_mode_opt_in_infobar_icon, null, |
+ activity.getString(R.string.tabbed_mode_opt_in_infobar), null, |
+ activity.getString(R.string.show), |
+ activity.getString(R.string.no_thanks)); |
+ mActivity = activity; |
+ } |
+ |
+ private void userDenied() { |
+ RecordUserAction.record("TabbdedModeOptInInfoBar_UserDismissed"); |
+ recordUserInteraction(); |
+ } |
+ |
+ private void recordUserInteraction() { |
+ PreferenceManager.getDefaultSharedPreferences(mActivity).edit() |
+ .putBoolean(PREF_USER_INTERACTED_TABBED_MODE_OPT_IN_INFOBAR, true); |
+ } |
+ |
+ @Override |
+ public void onCloseButtonClicked() { |
+ super.onCloseButtonClicked(); |
+ userDenied(); |
+ } |
+ |
+ @Override |
+ public void onButtonClicked(boolean isPrimaryButton) { |
+ super.onButtonClicked(isPrimaryButton); |
+ if (isPrimaryButton) { |
+ RecordUserAction.record("TabbdedModeOptInInfoBar_UserOptIn"); |
+ recordUserInteraction(); |
+ DocumentModeManager mDocumentModeManager = DocumentModeManager.getInstance(mActivity); |
+ mDocumentModeManager.setOptedOutState(DocumentModeManager.OPTED_OUT_OF_DOCUMENT_MODE); |
+ mDocumentModeManager.setOptOutCleanUpPending(true); |
+ DocumentMigrationHelper.migrateTabs(false, mActivity, true); |
+ } else { |
+ userDenied(); |
+ } |
+ dismissJavaOnlyInfoBar(); |
+ } |
+} |