Chromium Code Reviews| 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..560aaccf9c8889f4753cc0440ed7fb40783cd5b8 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/TabbedModeOptInInfoBarDelegate.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.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 |
|
gone
2015/11/17 23:18:16
nit: opt-in
Kibeom Kim (inactive)
2015/11/20 11:44:14
Done.
|
| + * to use. |
| + */ |
| +public class TabbedModeOptInInfoBarDelegate { |
| + |
| + private static final String PREF_USER_INTERACTED_TABBED_MODE_OPT_IN_INFOBAR = |
|
gone
2015/11/17 23:18:16
user_interacted or user_denied? the string is inc
Kibeom Kim (inactive)
2015/11/20 11:44:14
Done.
|
| + "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 Activity mActivity; |
|
gone
2015/11/17 23:18:16
Newt says to use the themedApplicationContext inst
Kibeom Kim (inactive)
2015/11/20 11:44:14
I needed Activity for "DocumentMigrationHelper.mig
gone
2015/11/20 19:26:14
Can you use the most recent foreground ChromeActiv
|
| + |
| + 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) { |
|
gone
2015/11/17 23:18:16
Why do you pass in a second Activity here? Why do
Kibeom Kim (inactive)
2015/11/20 11:44:15
commented above.
|
| + 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.nativeLaunchTabbedModeOptInInfoBar(activity.getActivityTab()); |
|
gone
2015/11/17 23:18:16
I don't think I've ever heard of using "Launching"
Kibeom Kim (inactive)
2015/11/20 11:44:14
Done. (initially I stole the name from FullscreenI
|
| + } |
| + } |
| + |
| + private void recordUserInteraction() { |
| + PreferenceManager.getDefaultSharedPreferences(mActivity).edit() |
| + .putBoolean(PREF_USER_INTERACTED_TABBED_MODE_OPT_IN_INFOBAR, true).commit(); |
| + } |
| + |
| + @CalledByNative |
| + private void accept() { |
| + recordUserInteraction(); |
| + DocumentModeManager mDocumentModeManager = DocumentModeManager.getInstance(mActivity); |
|
gone
2015/11/17 23:18:16
Can you refactor out the logic in DocumentModePref
Kibeom Kim (inactive)
2015/11/20 11:44:15
Done.
|
| + mDocumentModeManager.setOptedOutState(DocumentModeManager.OPTED_OUT_OF_DOCUMENT_MODE); |
| + mDocumentModeManager.setOptOutCleanUpPending(true); |
| + DocumentMigrationHelper.migrateTabs(false, mActivity, true); |
| + } |
| + |
| + @CalledByNative |
| + private void cancel() { |
| + recordUserInteraction(); |
| + } |
| + |
| + private native long nativeLaunchTabbedModeOptInInfoBar(Tab tab); |
| +} |