Commit 319d1d3a authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Signin][Android] Remove old signin promos from Bookmarks and RecentTabs

This CL removes support for old generic signin promos from Bookmarks and
RecentTabs. These promos were superseded by personalized signin promos.
Old promos were implemented in SigninAndSyncView, so this CL also
removes support for signin promos from this class. SigninAndSyncView
will be renamed in follow-up CLs.

Bug: 792430
Change-Id: I752f90339377e34c70766109a13f5e92e5ef1ea7
Reviewed-on: https://chromium-review.googlesource.com/836867Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#525336}
parent 8810b5f2
...@@ -35,16 +35,6 @@ ...@@ -35,16 +35,6 @@
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="horizontal" > android:orientation="horizontal" >
<Button
android:id="@+id/no_thanks"
style="@style/ButtonCompatBorderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no_thanks"
android:textAllCaps="true"
android:textColor="@color/light_active_color"
android:textSize="15sp" />
<org.chromium.ui.widget.ButtonCompat <org.chromium.ui.widget.ButtonCompat
android:id="@+id/sign_in" android:id="@+id/sign_in"
android:layout_width="wrap_content" android:layout_width="wrap_content"
......
...@@ -34,14 +34,13 @@ class BookmarkItemsAdapter ...@@ -34,14 +34,13 @@ class BookmarkItemsAdapter
* Specifies the view types that the bookmark manager screen can contain. * Specifies the view types that the bookmark manager screen can contain.
*/ */
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
@IntDef({ViewType.PERSONALIZED_SIGNIN_PROMO, ViewType.GENERIC_SIGNIN_PROMO, ViewType.SYNC_PROMO, @IntDef({ViewType.PERSONALIZED_SIGNIN_PROMO, ViewType.SYNC_PROMO, ViewType.FOLDER,
ViewType.FOLDER, ViewType.BOOKMARK}) ViewType.BOOKMARK})
private @interface ViewType { private @interface ViewType {
int PERSONALIZED_SIGNIN_PROMO = 0; int PERSONALIZED_SIGNIN_PROMO = 0;
int GENERIC_SIGNIN_PROMO = 1; int SYNC_PROMO = 1;
int SYNC_PROMO = 2; int FOLDER = 2;
int FOLDER = 3; int BOOKMARK = 3;
int BOOKMARK = 4;
} }
private static final int MAXIMUM_NUMBER_OF_SEARCH_RESULTS = 500; private static final int MAXIMUM_NUMBER_OF_SEARCH_RESULTS = 500;
...@@ -213,8 +212,6 @@ class BookmarkItemsAdapter ...@@ -213,8 +212,6 @@ class BookmarkItemsAdapter
switch (viewType) { switch (viewType) {
case ViewType.PERSONALIZED_SIGNIN_PROMO: case ViewType.PERSONALIZED_SIGNIN_PROMO:
return mPromoHeaderManager.createPersonalizedSigninPromoHolder(parent); return mPromoHeaderManager.createPersonalizedSigninPromoHolder(parent);
case ViewType.GENERIC_SIGNIN_PROMO:
return mPromoHeaderManager.createGenericSigninPromoHolder(parent);
case ViewType.SYNC_PROMO: case ViewType.SYNC_PROMO:
return mPromoHeaderManager.createSyncPromoHolder(parent); return mPromoHeaderManager.createSyncPromoHolder(parent);
case ViewType.FOLDER: case ViewType.FOLDER:
...@@ -240,7 +237,6 @@ class BookmarkItemsAdapter ...@@ -240,7 +237,6 @@ class BookmarkItemsAdapter
PersonalizedSigninPromoView view = (PersonalizedSigninPromoView) holder.itemView; PersonalizedSigninPromoView view = (PersonalizedSigninPromoView) holder.itemView;
mPromoHeaderManager.setupPersonalizedSigninPromo(view); mPromoHeaderManager.setupPersonalizedSigninPromo(view);
break; break;
case ViewType.GENERIC_SIGNIN_PROMO:
case ViewType.SYNC_PROMO: case ViewType.SYNC_PROMO:
break; break;
case ViewType.FOLDER: case ViewType.FOLDER:
...@@ -377,9 +373,6 @@ class BookmarkItemsAdapter ...@@ -377,9 +373,6 @@ class BookmarkItemsAdapter
case BookmarkPromoHeader.PromoState.PROMO_SIGNIN_PERSONALIZED: case BookmarkPromoHeader.PromoState.PROMO_SIGNIN_PERSONALIZED:
mPromoHeaderSection.add(ViewType.PERSONALIZED_SIGNIN_PROMO); mPromoHeaderSection.add(ViewType.PERSONALIZED_SIGNIN_PROMO);
return; return;
case BookmarkPromoHeader.PromoState.PROMO_SIGNIN_GENERIC:
mPromoHeaderSection.add(ViewType.GENERIC_SIGNIN_PROMO);
return;
case BookmarkPromoHeader.PromoState.PROMO_SYNC: case BookmarkPromoHeader.PromoState.PROMO_SYNC:
mPromoHeaderSection.add(ViewType.SYNC_PROMO); mPromoHeaderSection.add(ViewType.SYNC_PROMO);
return; return;
......
...@@ -17,7 +17,6 @@ import android.view.ViewGroup; ...@@ -17,7 +17,6 @@ import android.view.ViewGroup;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.signin.DisplayableProfileData; import org.chromium.chrome.browser.signin.DisplayableProfileData;
import org.chromium.chrome.browser.signin.PersonalizedSigninPromoView; import org.chromium.chrome.browser.signin.PersonalizedSigninPromoView;
...@@ -47,21 +46,17 @@ class BookmarkPromoHeader implements AndroidSyncSettingsObserver, SignInStateObs ...@@ -47,21 +46,17 @@ class BookmarkPromoHeader implements AndroidSyncSettingsObserver, SignInStateObs
* Specifies the various states in which the Bookmarks promo can be. * Specifies the various states in which the Bookmarks promo can be.
*/ */
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
@IntDef({PromoState.PROMO_NONE, PromoState.PROMO_SIGNIN_PERSONALIZED, @IntDef({PromoState.PROMO_NONE, PromoState.PROMO_SIGNIN_PERSONALIZED, PromoState.PROMO_SYNC})
PromoState.PROMO_SIGNIN_GENERIC, PromoState.PROMO_SYNC})
@interface PromoState { @interface PromoState {
int PROMO_NONE = 0; int PROMO_NONE = 0;
int PROMO_SIGNIN_PERSONALIZED = 1; int PROMO_SIGNIN_PERSONALIZED = 1;
int PROMO_SIGNIN_GENERIC = 2; int PROMO_SYNC = 2;
int PROMO_SYNC = 3;
} }
// Personalized signin promo preference. // Personalized signin promo preference.
private static final String PREF_PERSONALIZED_SIGNIN_PROMO_DECLINED = private static final String PREF_PERSONALIZED_SIGNIN_PROMO_DECLINED =
"signin_promo_bookmarks_declined"; "signin_promo_bookmarks_declined";
// Generic signin and sync promo preferences. // Generic signin and sync promo preferences.
private static final String PREF_GENERIC_SIGNIN_PROMO_DECLINED =
"enhanced_bookmark_signin_promo_declined";
private static final String PREF_SIGNIN_AND_SYNC_PROMO_SHOW_COUNT = private static final String PREF_SIGNIN_AND_SYNC_PROMO_SHOW_COUNT =
"enhanced_bookmark_signin_promo_show_count"; "enhanced_bookmark_signin_promo_show_count";
// TODO(kkimlabs): Figure out the optimal number based on UMA data. // TODO(kkimlabs): Figure out the optimal number based on UMA data.
...@@ -87,8 +82,7 @@ class BookmarkPromoHeader implements AndroidSyncSettingsObserver, SignInStateObs ...@@ -87,8 +82,7 @@ class BookmarkPromoHeader implements AndroidSyncSettingsObserver, SignInStateObs
AndroidSyncSettings.registerObserver(mContext, this); AndroidSyncSettings.registerObserver(mContext, this);
if (SigninPromoController.arePersonalizedPromosEnabled() if (SigninPromoController.hasNotReachedImpressionLimit(
&& SigninPromoController.hasNotReachedImpressionLimit(
SigninAccessPoint.BOOKMARK_MANAGER)) { SigninAccessPoint.BOOKMARK_MANAGER)) {
int imageSize = int imageSize =
mContext.getResources().getDimensionPixelSize(R.dimen.user_picture_size); mContext.getResources().getDimensionPixelSize(R.dimen.user_picture_size);
...@@ -105,17 +99,13 @@ class BookmarkPromoHeader implements AndroidSyncSettingsObserver, SignInStateObs ...@@ -105,17 +99,13 @@ class BookmarkPromoHeader implements AndroidSyncSettingsObserver, SignInStateObs
mSignInManager.addSignInStateObserver(this); mSignInManager.addSignInStateObserver(this);
mPromoState = calculatePromoState(); mPromoState = calculatePromoState();
if (mPromoState == PromoState.PROMO_SIGNIN_GENERIC if (mPromoState == PromoState.PROMO_SYNC) {
|| mPromoState == PromoState.PROMO_SYNC) {
int promoShowCount = ContextUtils.getAppSharedPreferences().getInt( int promoShowCount = ContextUtils.getAppSharedPreferences().getInt(
PREF_SIGNIN_AND_SYNC_PROMO_SHOW_COUNT, 0); PREF_SIGNIN_AND_SYNC_PROMO_SHOW_COUNT, 0);
ContextUtils.getAppSharedPreferences() ContextUtils.getAppSharedPreferences()
.edit() .edit()
.putInt(PREF_SIGNIN_AND_SYNC_PROMO_SHOW_COUNT, promoShowCount + 1) .putInt(PREF_SIGNIN_AND_SYNC_PROMO_SHOW_COUNT, promoShowCount + 1)
.apply(); .apply();
if (mPromoState == PromoState.PROMO_SIGNIN_GENERIC) {
RecordUserAction.record("Signin_Impression_FromBookmarkManager");
}
} }
} }
...@@ -154,25 +144,13 @@ class BookmarkPromoHeader implements AndroidSyncSettingsObserver, SignInStateObs ...@@ -154,25 +144,13 @@ class BookmarkPromoHeader implements AndroidSyncSettingsObserver, SignInStateObs
return new ViewHolder(view) {}; return new ViewHolder(view) {};
} }
/**
* TODO(crbug.com/737743): Remove this after rolling out personalized promos.
* @return Generic signin promo header {@link ViewHolder} instance that can be used with
* {@link RecyclerView}.
*/
ViewHolder createGenericSigninPromoHolder(ViewGroup parent) {
// The generic signin promo and the sync promo use the same view.
return createSyncPromoHolder(parent);
}
/** /**
* @return Sync promo header {@link ViewHolder} instance that can be used with * @return Sync promo header {@link ViewHolder} instance that can be used with
* {@link RecyclerView}. * {@link RecyclerView}.
*/ */
ViewHolder createSyncPromoHolder(ViewGroup parent) { ViewHolder createSyncPromoHolder(ViewGroup parent) {
SigninAndSyncView.Listener listener = this::setGenericSigninPromoDeclined;
SigninAndSyncView view = SigninAndSyncView view =
SigninAndSyncView.create(parent, listener, SigninAccessPoint.BOOKMARK_MANAGER); SigninAndSyncView.create(parent, SigninAccessPoint.BOOKMARK_MANAGER);
// ViewHolder is abstract and it cannot be instantiated directly. // ViewHolder is abstract and it cannot be instantiated directly.
return new ViewHolder(view) {}; return new ViewHolder(view) {};
...@@ -213,19 +191,6 @@ class BookmarkPromoHeader implements AndroidSyncSettingsObserver, SignInStateObs ...@@ -213,19 +191,6 @@ class BookmarkPromoHeader implements AndroidSyncSettingsObserver, SignInStateObs
mPromoHeaderChangeAction.run(); mPromoHeaderChangeAction.run();
} }
/**
* Saves that the generic signin promo was declined and updates the UI.
* TODO(crbug.com/737743): Remove this after rolling out personalized promos.
*/
private void setGenericSigninPromoDeclined() {
SharedPreferences.Editor sharedPreferencesEditor =
ContextUtils.getAppSharedPreferences().edit();
sharedPreferencesEditor.putBoolean(PREF_GENERIC_SIGNIN_PROMO_DECLINED, true);
sharedPreferencesEditor.apply();
mPromoState = calculatePromoState();
mPromoHeaderChangeAction.run();
}
/** /**
* @return Whether the user declined the personalized signin promo. * @return Whether the user declined the personalized signin promo.
*/ */
...@@ -234,15 +199,6 @@ class BookmarkPromoHeader implements AndroidSyncSettingsObserver, SignInStateObs ...@@ -234,15 +199,6 @@ class BookmarkPromoHeader implements AndroidSyncSettingsObserver, SignInStateObs
PREF_PERSONALIZED_SIGNIN_PROMO_DECLINED, false); PREF_PERSONALIZED_SIGNIN_PROMO_DECLINED, false);
} }
/**
* TODO(crbug.com/737743): Remove this after rolling out personalized promos.
* @return Whether user tapped "No" button on the generic signin promo.
*/
private boolean wasGenericSigninPromoDeclined() {
return ContextUtils.getAppSharedPreferences().getBoolean(
PREF_GENERIC_SIGNIN_PROMO_DECLINED, false);
}
private @PromoState int calculatePromoState() { private @PromoState int calculatePromoState() {
if (sPromoStateForTests != null) { if (sPromoStateForTests != null) {
return sPromoStateForTests; return sPromoStateForTests;
...@@ -252,36 +208,21 @@ class BookmarkPromoHeader implements AndroidSyncSettingsObserver, SignInStateObs ...@@ -252,36 +208,21 @@ class BookmarkPromoHeader implements AndroidSyncSettingsObserver, SignInStateObs
return PromoState.PROMO_NONE; return PromoState.PROMO_NONE;
} }
// If the user is signed in, then we should show the sync promo if Chrome sync is disabled if (!ChromeSigninController.get().isSignedIn()) {
// and the impression limit has not been reached yet. boolean impressionLimitReached = !SigninPromoController.hasNotReachedImpressionLimit(
if (ChromeSigninController.get().isSignedIn()) { SigninAccessPoint.BOOKMARK_MANAGER);
boolean impressionLimitNotReached = ContextUtils.getAppSharedPreferences().getInt( if (!mSignInManager.isSignInAllowed() || impressionLimitReached
PREF_SIGNIN_AND_SYNC_PROMO_SHOW_COUNT, 0) || wasPersonalizedSigninPromoDeclined()) {
< MAX_SIGNIN_AND_SYNC_PROMO_SHOW_COUNT;
if (!AndroidSyncSettings.isChromeSyncEnabled(mContext) && impressionLimitNotReached) {
return PromoState.PROMO_SYNC;
}
return PromoState.PROMO_NONE;
}
if (!mSignInManager.isSignInAllowed()) {
return PromoState.PROMO_NONE; return PromoState.PROMO_NONE;
} }
if (SigninPromoController.arePersonalizedPromosEnabled()) {
if (SigninPromoController.hasNotReachedImpressionLimit(
SigninAccessPoint.BOOKMARK_MANAGER)
&& !wasPersonalizedSigninPromoDeclined()) {
return PromoState.PROMO_SIGNIN_PERSONALIZED; return PromoState.PROMO_SIGNIN_PERSONALIZED;
} }
return PromoState.PROMO_NONE;
}
int numImpressions = ContextUtils.getAppSharedPreferences().getInt( boolean impressionLimitNotReached = ContextUtils.getAppSharedPreferences().getInt(
PREF_SIGNIN_AND_SYNC_PROMO_SHOW_COUNT, 0); PREF_SIGNIN_AND_SYNC_PROMO_SHOW_COUNT, 0)
boolean impressionLimitNotReached = numImpressions < MAX_SIGNIN_AND_SYNC_PROMO_SHOW_COUNT; < MAX_SIGNIN_AND_SYNC_PROMO_SHOW_COUNT;
if (impressionLimitNotReached && !wasGenericSigninPromoDeclined()) { if (!AndroidSyncSettings.isChromeSyncEnabled(mContext) && impressionLimitNotReached) {
return PromoState.PROMO_SIGNIN_GENERIC; return PromoState.PROMO_SYNC;
} }
return PromoState.PROMO_NONE; return PromoState.PROMO_NONE;
} }
......
...@@ -57,13 +57,11 @@ public class RecentTabsManager implements AndroidSyncSettingsObserver, SignInSta ...@@ -57,13 +57,11 @@ public class RecentTabsManager implements AndroidSyncSettingsObserver, SignInSta
void onUpdated(); void onUpdated();
} }
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
@IntDef({PromoState.PROMO_NONE, PromoState.PROMO_SIGNIN_PERSONALIZED, @IntDef({PromoState.PROMO_NONE, PromoState.PROMO_SIGNIN_PERSONALIZED, PromoState.PROMO_SYNC})
PromoState.PROMO_SIGNIN_GENERIC, PromoState.PROMO_SYNC})
@interface PromoState { @interface PromoState {
int PROMO_NONE = 0; int PROMO_NONE = 0;
int PROMO_SIGNIN_PERSONALIZED = 1; int PROMO_SIGNIN_PERSONALIZED = 1;
int PROMO_SIGNIN_GENERIC = 2; int PROMO_SYNC = 2;
int PROMO_SYNC = 3;
} }
private static final int RECENTLY_CLOSED_MAX_TAB_COUNT = 5; private static final int RECENTLY_CLOSED_MAX_TAB_COUNT = 5;
...@@ -359,23 +357,19 @@ public class RecentTabsManager implements AndroidSyncSettingsObserver, SignInSta ...@@ -359,23 +357,19 @@ public class RecentTabsManager implements AndroidSyncSettingsObserver, SignInSta
*/ */
@PromoState @PromoState
int getPromoType() { int getPromoType() {
if (ChromeSigninController.get().isSignedIn()) { if (!ChromeSigninController.get().isSignedIn()) {
if (AndroidSyncSettings.isSyncEnabled(mContext) if (!SigninManager.get(mContext).isSignInAllowed()) {
&& AndroidSyncSettings.isChromeSyncEnabled(mContext)
&& !mForeignSessions.isEmpty()) {
return PromoState.PROMO_NONE; return PromoState.PROMO_NONE;
} }
return PromoState.PROMO_SYNC; return PromoState.PROMO_SIGNIN_PERSONALIZED;
} }
if (!SigninManager.get(mContext).isSignInAllowed()) { if (AndroidSyncSettings.isSyncEnabled(mContext)
&& AndroidSyncSettings.isChromeSyncEnabled(mContext)
&& !mForeignSessions.isEmpty()) {
return PromoState.PROMO_NONE; return PromoState.PROMO_NONE;
} }
return PromoState.PROMO_SYNC;
if (SigninPromoController.arePersonalizedPromosEnabled()) {
return PromoState.PROMO_SIGNIN_PERSONALIZED;
}
return PromoState.PROMO_SIGNIN_GENERIC;
} }
void recordRecentTabMetrics() { void recordRecentTabMetrics() {
......
...@@ -21,7 +21,6 @@ import android.widget.TextView; ...@@ -21,7 +21,6 @@ import android.widget.TextView;
import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconImageCallback; import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconImageCallback;
import org.chromium.chrome.browser.ntp.ForeignSessionHelper.ForeignSession; import org.chromium.chrome.browser.ntp.ForeignSessionHelper.ForeignSession;
...@@ -30,7 +29,6 @@ import org.chromium.chrome.browser.ntp.ForeignSessionHelper.ForeignSessionWindow ...@@ -30,7 +29,6 @@ import org.chromium.chrome.browser.ntp.ForeignSessionHelper.ForeignSessionWindow
import org.chromium.chrome.browser.signin.PersonalizedSigninPromoView; import org.chromium.chrome.browser.signin.PersonalizedSigninPromoView;
import org.chromium.chrome.browser.signin.SigninAccessPoint; import org.chromium.chrome.browser.signin.SigninAccessPoint;
import org.chromium.chrome.browser.signin.SigninAndSyncView; import org.chromium.chrome.browser.signin.SigninAndSyncView;
import org.chromium.components.signin.ChromeSigninController;
import org.chromium.ui.base.DeviceFormFactor; import org.chromium.ui.base.DeviceFormFactor;
import org.chromium.ui.mojom.WindowOpenDisposition; import org.chromium.ui.mojom.WindowOpenDisposition;
...@@ -48,7 +46,6 @@ public class RecentTabsRowAdapter extends BaseExpandableListAdapter { ...@@ -48,7 +46,6 @@ public class RecentTabsRowAdapter extends BaseExpandableListAdapter {
NONE, NONE,
DEFAULT_CONTENT, DEFAULT_CONTENT,
PERSONALIZED_SIGNIN_PROMO, PERSONALIZED_SIGNIN_PROMO,
GENERIC_SIGNIN_PROMO,
SYNC_PROMO SYNC_PROMO
} }
...@@ -392,29 +389,6 @@ public class RecentTabsRowAdapter extends BaseExpandableListAdapter { ...@@ -392,29 +389,6 @@ public class RecentTabsRowAdapter extends BaseExpandableListAdapter {
} }
} }
/**
* A group containing the generic signin promo.
* TODO(crbug.com/737743): Remove this after rolling out personalized promos.
*/
class GenericSigninPromoGroup extends PromoGroup {
@Override
public ChildType getChildType() {
return ChildType.GENERIC_SIGNIN_PROMO;
}
@Override
View getChildView(
int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = SigninAndSyncView.create(parent, null, SigninAccessPoint.RECENT_TABS);
}
if (!ChromeSigninController.get().isSignedIn()) {
RecordUserAction.record("Signin_Impression_FromRecentTabs");
}
return convertView;
}
}
/** /**
* A group containing the sync promo. * A group containing the sync promo.
*/ */
...@@ -428,7 +402,7 @@ public class RecentTabsRowAdapter extends BaseExpandableListAdapter { ...@@ -428,7 +402,7 @@ public class RecentTabsRowAdapter extends BaseExpandableListAdapter {
View getChildView( View getChildView(
int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
if (convertView == null) { if (convertView == null) {
convertView = SigninAndSyncView.create(parent, null, SigninAccessPoint.RECENT_TABS); convertView = SigninAndSyncView.create(parent, SigninAccessPoint.RECENT_TABS);
} }
return convertView; return convertView;
} }
...@@ -795,9 +769,6 @@ public class RecentTabsRowAdapter extends BaseExpandableListAdapter { ...@@ -795,9 +769,6 @@ public class RecentTabsRowAdapter extends BaseExpandableListAdapter {
case RecentTabsManager.PromoState.PROMO_SIGNIN_PERSONALIZED: case RecentTabsManager.PromoState.PROMO_SIGNIN_PERSONALIZED:
addGroup(new PersonalizedSigninPromoGroup()); addGroup(new PersonalizedSigninPromoGroup());
break; break;
case RecentTabsManager.PromoState.PROMO_SIGNIN_GENERIC:
addGroup(new GenericSigninPromoGroup());
break;
case RecentTabsManager.PromoState.PROMO_SYNC: case RecentTabsManager.PromoState.PROMO_SYNC:
addGroup(new SyncPromoGroup()); addGroup(new SyncPromoGroup());
break; break;
......
...@@ -131,8 +131,7 @@ public class SignInPreference ...@@ -131,8 +131,7 @@ public class SignInPreference
return; return;
} }
if (SigninPromoController.hasNotReachedImpressionLimit(SigninAccessPoint.SETTINGS) if (SigninPromoController.hasNotReachedImpressionLimit(SigninAccessPoint.SETTINGS)) {
&& SigninPromoController.arePersonalizedPromosEnabled()) {
setupPersonalizedPromo(); setupPersonalizedPromo();
return; return;
} }
......
...@@ -19,62 +19,35 @@ import org.chromium.base.ThreadUtils; ...@@ -19,62 +19,35 @@ import org.chromium.base.ThreadUtils;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.preferences.PreferencesLauncher; import org.chromium.chrome.browser.preferences.PreferencesLauncher;
import org.chromium.chrome.browser.signin.AccountSigninActivity.AccessPoint; import org.chromium.chrome.browser.signin.AccountSigninActivity.AccessPoint;
import org.chromium.chrome.browser.signin.SigninManager.SignInStateObserver;
import org.chromium.chrome.browser.sync.ui.SyncCustomizationFragment; import org.chromium.chrome.browser.sync.ui.SyncCustomizationFragment;
import org.chromium.components.signin.ChromeSigninController;
import org.chromium.components.sync.AndroidSyncSettings; import org.chromium.components.sync.AndroidSyncSettings;
import org.chromium.components.sync.AndroidSyncSettings.AndroidSyncSettingsObserver; import org.chromium.components.sync.AndroidSyncSettings.AndroidSyncSettingsObserver;
import javax.annotation.Nullable;
/** /**
* A View that shows the user the next step they must complete to start syncing their data (eg. * A View that shows the user the next step they must complete to start syncing their data (eg.
* Recent Tabs or Bookmarks). For example, if the user is not signed in, the View will prompt them * Recent Tabs or Bookmarks). For example, if the user is not signed in, the View will prompt them
* to do so and link to the AccountSigninActivity. * to do so and link to the AccountSigninActivity.
* If inflated manually, {@link SigninAndSyncView#init(Listener, int)} must be called before * If inflated manually, {@link SigninAndSyncView#init(int)} must be called before
* attaching this View to a ViewGroup. * attaching this View to a ViewGroup.
*/ */
public class SigninAndSyncView extends LinearLayout public class SigninAndSyncView extends LinearLayout implements AndroidSyncSettingsObserver {
implements AndroidSyncSettingsObserver, SignInStateObserver {
private @Nullable Listener mListener;
private @AccessPoint int mAccessPoint; private @AccessPoint int mAccessPoint;
private boolean mInitialized; private boolean mInitialized;
private final SigninManager mSigninManager;
private TextView mTitle; private TextView mTitle;
private TextView mDescription; private TextView mDescription;
private Button mNegativeButton;
private Button mPositiveButton; private Button mPositiveButton;
/**
* A listener for the container of the SigninAndSyncView to be informed of certain user
* interactions.
*/
public interface Listener {
/**
* The user has pressed 'no thanks' and expects the view to be removed from its parent.
*/
void onViewDismissed();
}
/** /**
* A convenience method to inflate and initialize a SigninAndSyncView. * A convenience method to inflate and initialize a SigninAndSyncView.
* @param parent A parent used to provide LayoutParams (the SigninAndSyncView will not be * @param parent A parent used to provide LayoutParams (the SigninAndSyncView will not be
* attached). * attached).
* @param listener Listener for user interactions. A null listener marks that the promo is not
* dismissible.
* @param accessPoint Where the SigninAndSyncView is used. * @param accessPoint Where the SigninAndSyncView is used.
*/ */
public static SigninAndSyncView create( public static SigninAndSyncView create(ViewGroup parent, @AccessPoint int accessPoint) {
ViewGroup parent, @Nullable Listener listener, @AccessPoint int accessPoint) {
if (listener == null) {
assert accessPoint
== SigninAccessPoint.RECENT_TABS
: "The promo should not be dismissible in Recent Tabs!";
}
SigninAndSyncView signinView = (SigninAndSyncView) LayoutInflater.from(parent.getContext()) SigninAndSyncView signinView = (SigninAndSyncView) LayoutInflater.from(parent.getContext())
.inflate(R.layout.signin_and_sync_view, parent, false); .inflate(R.layout.signin_and_sync_view, parent, false);
signinView.init(listener, accessPoint); signinView.init(accessPoint);
return signinView; return signinView;
} }
...@@ -83,7 +56,6 @@ public class SigninAndSyncView extends LinearLayout ...@@ -83,7 +56,6 @@ public class SigninAndSyncView extends LinearLayout
*/ */
public SigninAndSyncView(Context context, AttributeSet attrs) { public SigninAndSyncView(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
mSigninManager = SigninManager.get(getContext());
} }
@Override @Override
...@@ -92,17 +64,14 @@ public class SigninAndSyncView extends LinearLayout ...@@ -92,17 +64,14 @@ public class SigninAndSyncView extends LinearLayout
mTitle = (TextView) findViewById(R.id.title); mTitle = (TextView) findViewById(R.id.title);
mDescription = (TextView) findViewById(R.id.description); mDescription = (TextView) findViewById(R.id.description);
mNegativeButton = (Button) findViewById(R.id.no_thanks);
mPositiveButton = (Button) findViewById(R.id.sign_in); mPositiveButton = (Button) findViewById(R.id.sign_in);
} }
/** /**
* Provide the information necessary for this class to function. * Provide the information necessary for this class to function.
* @param listener Listener for user interactions.
* @param accessPoint Where this UI component is used. * @param accessPoint Where this UI component is used.
*/ */
public void init(Listener listener, @AccessPoint int accessPoint) { public void init(@AccessPoint int accessPoint) {
mListener = listener;
mAccessPoint = accessPoint; mAccessPoint = accessPoint;
mInitialized = true; mInitialized = true;
...@@ -122,16 +91,14 @@ public class SigninAndSyncView extends LinearLayout ...@@ -122,16 +91,14 @@ public class SigninAndSyncView extends LinearLayout
private void update() { private void update() {
ViewState viewState; ViewState viewState;
if (!ChromeSigninController.get().isSignedIn()) { if (!AndroidSyncSettings.isMasterSyncEnabled(getContext())) {
viewState = getStateForSignin();
} else if (!AndroidSyncSettings.isMasterSyncEnabled(getContext())) {
viewState = getStateForEnableAndroidSync(); viewState = getStateForEnableAndroidSync();
} else if (!AndroidSyncSettings.isChromeSyncEnabled(getContext())) { } else if (!AndroidSyncSettings.isChromeSyncEnabled(getContext())) {
viewState = getStateForEnableChromeSync(); viewState = getStateForEnableChromeSync();
} else { } else {
viewState = getStateForStartUsing(); viewState = getStateForStartUsing();
} }
viewState.apply(mDescription, mPositiveButton, mNegativeButton); viewState.apply(mDescription, mPositiveButton);
} }
/** /**
...@@ -142,18 +109,14 @@ public class SigninAndSyncView extends LinearLayout ...@@ -142,18 +109,14 @@ public class SigninAndSyncView extends LinearLayout
private static class ViewState { private static class ViewState {
private final int mDescriptionText; private final int mDescriptionText;
private final ButtonState mPositiveButtonState; private final ButtonState mPositiveButtonState;
private final ButtonState mNegativeButtonState;
public ViewState(int mDescriptionText, public ViewState(int mDescriptionText, ButtonState mPositiveButtonState) {
ButtonState mPositiveButtonState, ButtonState mNegativeButtonState) {
this.mDescriptionText = mDescriptionText; this.mDescriptionText = mDescriptionText;
this.mPositiveButtonState = mPositiveButtonState; this.mPositiveButtonState = mPositiveButtonState;
this.mNegativeButtonState = mNegativeButtonState;
} }
public void apply(TextView description, Button positiveButton, Button negativeButton) { public void apply(TextView description, Button positiveButton) {
description.setText(mDescriptionText); description.setText(mDescriptionText);
mNegativeButtonState.apply(negativeButton);
mPositiveButtonState.apply(positiveButton); mPositiveButtonState.apply(positiveButton);
} }
} }
...@@ -190,28 +153,6 @@ public class SigninAndSyncView extends LinearLayout ...@@ -190,28 +153,6 @@ public class SigninAndSyncView extends LinearLayout
} }
} }
private ViewState getStateForSignin() {
int descId = mAccessPoint == SigninAccessPoint.BOOKMARK_MANAGER
? R.string.bookmark_sign_in_promo_description
: R.string.recent_tabs_sign_in_promo_description;
ButtonState positiveButton = new ButtonPresent(R.string.sign_in_button, view -> {
Context context = getContext();
context.startActivity(AccountSigninActivity.createIntentForDefaultSigninFlow(
context, mAccessPoint, false));
});
ButtonState negativeButton;
if (mAccessPoint == SigninAccessPoint.RECENT_TABS) {
negativeButton = new ButtonAbsent();
} else {
negativeButton =
new ButtonPresent(R.string.no_thanks, view -> mListener.onViewDismissed());
}
return new ViewState(descId, positiveButton, negativeButton);
}
private ViewState getStateForEnableAndroidSync() { private ViewState getStateForEnableAndroidSync() {
assert mAccessPoint == SigninAccessPoint.RECENT_TABS assert mAccessPoint == SigninAccessPoint.RECENT_TABS
: "Enable Android Sync should not be showing from bookmarks"; : "Enable Android Sync should not be showing from bookmarks";
...@@ -226,7 +167,7 @@ public class SigninAndSyncView extends LinearLayout ...@@ -226,7 +167,7 @@ public class SigninAndSyncView extends LinearLayout
getContext().startActivity(intent); getContext().startActivity(intent);
}); });
return new ViewState(descId, positiveButton, new ButtonAbsent()); return new ViewState(descId, positiveButton);
} }
private ViewState getStateForEnableChromeSync() { private ViewState getStateForEnableChromeSync() {
...@@ -238,7 +179,7 @@ public class SigninAndSyncView extends LinearLayout ...@@ -238,7 +179,7 @@ public class SigninAndSyncView extends LinearLayout
view -> PreferencesLauncher.launchSettingsPage( view -> PreferencesLauncher.launchSettingsPage(
getContext(), SyncCustomizationFragment.class.getName())); getContext(), SyncCustomizationFragment.class.getName()));
return new ViewState(descId, positiveButton, new ButtonAbsent()); return new ViewState(descId, positiveButton);
} }
private ViewState getStateForStartUsing() { private ViewState getStateForStartUsing() {
...@@ -247,8 +188,7 @@ public class SigninAndSyncView extends LinearLayout ...@@ -247,8 +188,7 @@ public class SigninAndSyncView extends LinearLayout
// visible. I want there to be a guarantee that this state is never seen, but to do so would // visible. I want there to be a guarantee that this state is never seen, but to do so would
// require some code restructuring. // require some code restructuring.
return new ViewState(R.string.ntp_recent_tabs_sync_promo_instructions, return new ViewState(R.string.ntp_recent_tabs_sync_promo_instructions, new ButtonAbsent());
new ButtonAbsent(), new ButtonAbsent());
} }
@Override @Override
...@@ -256,7 +196,6 @@ public class SigninAndSyncView extends LinearLayout ...@@ -256,7 +196,6 @@ public class SigninAndSyncView extends LinearLayout
assert mInitialized : "init(...) must be called on SigninAndSyncView before use."; assert mInitialized : "init(...) must be called on SigninAndSyncView before use.";
super.onAttachedToWindow(); super.onAttachedToWindow();
mSigninManager.addSignInStateObserver(this);
AndroidSyncSettings.registerObserver(getContext(), this); AndroidSyncSettings.registerObserver(getContext(), this);
update(); update();
} }
...@@ -264,21 +203,9 @@ public class SigninAndSyncView extends LinearLayout ...@@ -264,21 +203,9 @@ public class SigninAndSyncView extends LinearLayout
@Override @Override
protected void onDetachedFromWindow() { protected void onDetachedFromWindow() {
super.onDetachedFromWindow(); super.onDetachedFromWindow();
mSigninManager.removeSignInStateObserver(this);
AndroidSyncSettings.unregisterObserver(getContext(), this); AndroidSyncSettings.unregisterObserver(getContext(), this);
} }
// SigninStateObserver
@Override
public void onSignedIn() {
update();
}
@Override
public void onSignedOut() {
update();
}
// AndroidSyncStateObserver // AndroidSyncStateObserver
@Override @Override
public void androidSyncSettingsChanged() { public void androidSyncSettingsChanged() {
......
...@@ -275,8 +275,7 @@ public class BookmarkTest { ...@@ -275,8 +275,7 @@ public class BookmarkTest {
@Test @Test
@MediumTest @MediumTest
public void testSearchBookmarks() throws Exception { public void testSearchBookmarks() throws Exception {
BookmarkPromoHeader.forcePromoStateForTests( BookmarkPromoHeader.forcePromoStateForTests(BookmarkPromoHeader.PromoState.PROMO_SYNC);
BookmarkPromoHeader.PromoState.PROMO_SIGNIN_GENERIC);
addBookmark(TEST_PAGE_TITLE_GOOGLE, mTestPage); addBookmark(TEST_PAGE_TITLE_GOOGLE, mTestPage);
addBookmark(TEST_PAGE_TITLE_FOO, mTestPageFoo); addBookmark(TEST_PAGE_TITLE_FOO, mTestPageFoo);
openBookmarkManager(); openBookmarkManager();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment