Commit b37cd180 authored by gogerald's avatar gogerald Committed by Commit bot

[Signin] Update sign in promo triggering logic

BUG=626425

Review-Url: https://codereview.chromium.org/2400793003
Cr-Commit-Position: refs/heads/master@{#424087}
parent 1a039dd6
...@@ -9,6 +9,8 @@ class ChromeVersionConstants { ...@@ -9,6 +9,8 @@ class ChromeVersionConstants {
static final String PRODUCT_VERSION = "@MAJOR@.@MINOR@.@BUILD@.@PATCH@"; static final String PRODUCT_VERSION = "@MAJOR@.@MINOR@.@BUILD@.@PATCH@";
static final boolean IS_OFFICIAL_BUILD = @OFFICIAL_BUILD@ == 1; static final boolean IS_OFFICIAL_BUILD = @OFFICIAL_BUILD@ == 1;
static final int PRODUCT_MAJOR_VERSION = @MAJOR@;
static final int CHANNEL_DEFAULT = 0; static final int CHANNEL_DEFAULT = 0;
static final int CHANNEL_CANARY = 1; static final int CHANNEL_CANARY = 1;
static final int CHANNEL_DEV = 2; static final int CHANNEL_DEV = 2;
......
...@@ -358,6 +358,8 @@ public class ChromeTabbedActivity extends ChromeActivity implements OverviewMode ...@@ -358,6 +358,8 @@ public class ChromeTabbedActivity extends ChromeActivity implements OverviewMode
launchFirstRunExperience(); launchFirstRunExperience();
refreshSignIn();
ChromePreferenceManager preferenceManager = ChromePreferenceManager.getInstance(this); ChromePreferenceManager preferenceManager = ChromePreferenceManager.getInstance(this);
// Promos can only be shown when we start with ACTION_MAIN intent and // Promos can only be shown when we start with ACTION_MAIN intent and
// after FRE is complete. // after FRE is complete.
...@@ -375,8 +377,6 @@ public class ChromeTabbedActivity extends ChromeActivity implements OverviewMode ...@@ -375,8 +377,6 @@ public class ChromeTabbedActivity extends ChromeActivity implements OverviewMode
} }
} }
refreshSignIn();
initializeUI(); initializeUI();
// The dataset has already been created, we need to initialize our state. // The dataset has already been created, we need to initialize our state.
......
...@@ -59,4 +59,11 @@ public class ChromeVersionInfo { ...@@ -59,4 +59,11 @@ public class ChromeVersionInfo {
public static String getProductVersion() { public static String getProductVersion() {
return ChromeVersionConstants.PRODUCT_VERSION; return ChromeVersionConstants.PRODUCT_VERSION;
} }
/**
* @return The major version number.
*/
public static int getProductMajorVersion() {
return ChromeVersionConstants.PRODUCT_MAJOR_VERSION;
}
} }
...@@ -10,6 +10,7 @@ import android.content.SharedPreferences; ...@@ -10,6 +10,7 @@ import android.content.SharedPreferences;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.SuppressFBWarnings; import org.chromium.base.annotations.SuppressFBWarnings;
import org.chromium.chrome.browser.ChromeSwitches; import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.ChromeVersionInfo;
import org.chromium.chrome.browser.crash.MinidumpUploadService.ProcessType; import org.chromium.chrome.browser.crash.MinidumpUploadService.ProcessType;
import org.chromium.chrome.browser.util.FeatureUtilities; import org.chromium.chrome.browser.util.FeatureUtilities;
...@@ -23,7 +24,7 @@ public class ChromePreferenceManager { ...@@ -23,7 +24,7 @@ public class ChromePreferenceManager {
private static final String TAG = "preferences"; private static final String TAG = "preferences";
private static final String PROMOS_SKIPPED_ON_FIRST_START = "promos_skipped_on_first_start"; private static final String PROMOS_SKIPPED_ON_FIRST_START = "promos_skipped_on_first_start";
private static final String SIGNIN_PROMO_LAST_SHOWN = "signin_promo_last_timestamp_key"; private static final String SIGNIN_PROMO_LAST_SHOWN = "signin_promo_last_shown_chrome_version";
private static final String SHOW_SIGNIN_PROMO = "show_signin_promo"; private static final String SHOW_SIGNIN_PROMO = "show_signin_promo";
private static final String ALLOW_LOW_END_DEVICE_UI = "allow_low_end_device_ui"; private static final String ALLOW_LOW_END_DEVICE_UI = "allow_low_end_device_ui";
private static final String PREF_WEBSITE_SETTINGS_FILTER = "website_settings_filter"; private static final String PREF_WEBSITE_SETTINGS_FILTER = "website_settings_filter";
...@@ -51,9 +52,6 @@ public class ChromePreferenceManager { ...@@ -51,9 +52,6 @@ public class ChromePreferenceManager {
private static final String SUCCESS_UPLOAD_SUFFIX = "_crash_success_upload"; private static final String SUCCESS_UPLOAD_SUFFIX = "_crash_success_upload";
private static final String FAILURE_UPLOAD_SUFFIX = "_crash_failure_upload"; private static final String FAILURE_UPLOAD_SUFFIX = "_crash_failure_upload";
private static final int SIGNIN_PROMO_CYCLE_IN_DAYS = 120;
private static final long MILLISECONDS_IN_DAY = 1000 * 60 * 60 * 24;
private static ChromePreferenceManager sPrefs; private static ChromePreferenceManager sPrefs;
private final SharedPreferences mSharedPreferences; private final SharedPreferences mSharedPreferences;
...@@ -174,23 +172,28 @@ public class ChromePreferenceManager { ...@@ -174,23 +172,28 @@ public class ChromePreferenceManager {
} }
/** /**
* Signin promo could be shown at most once every 12 weeks. This method checks * Signin promo could be shown at most once every at least 2 Chrome major versions. This method
* wheter the signin promo has already been shown in the current cycle. * checks wheter the signin promo has already been shown in the current range.
* @return Whether the signin promo has been shown in the current cycle. * @return Whether the signin promo has been shown in the current range.
*/ */
public boolean getSigninPromoShown() { public boolean getSigninPromoShown() {
long signinPromoLastShown = mSharedPreferences.getLong(SIGNIN_PROMO_LAST_SHOWN, 0); int lastMajorVersion = mSharedPreferences.getInt(SIGNIN_PROMO_LAST_SHOWN, 0);
long numDaysElapsed = if (lastMajorVersion == 0) {
(System.currentTimeMillis() - signinPromoLastShown) / MILLISECONDS_IN_DAY; setSigninPromoShown();
return numDaysElapsed < SIGNIN_PROMO_CYCLE_IN_DAYS; return true;
}
return ChromeVersionInfo.getProductMajorVersion() < lastMajorVersion + 2;
} }
/** /**
* Sets the preference for tracking when the signin promo was last shown. * Sets the preference for tracking Chrome major version number when the signin promo was last
* shown.
*/ */
public void setSigninPromoShown() { public void setSigninPromoShown() {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit(); SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
sharedPreferencesEditor.putLong(SIGNIN_PROMO_LAST_SHOWN, System.currentTimeMillis()); sharedPreferencesEditor.putInt(
SIGNIN_PROMO_LAST_SHOWN, ChromeVersionInfo.getProductMajorVersion());
sharedPreferencesEditor.apply(); sharedPreferencesEditor.apply();
} }
......
...@@ -6,7 +6,6 @@ package org.chromium.chrome.browser.signin; ...@@ -6,7 +6,6 @@ package org.chromium.chrome.browser.signin;
import android.accounts.Account; import android.accounts.Account;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask; import android.os.AsyncTask;
import com.google.android.gms.auth.AccountChangeEvent; import com.google.android.gms.auth.AccountChangeEvent;
...@@ -28,9 +27,7 @@ import org.chromium.components.sync.AndroidSyncSettings; ...@@ -28,9 +27,7 @@ import org.chromium.components.sync.AndroidSyncSettings;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import javax.annotation.Nullable; import javax.annotation.Nullable;
...@@ -56,8 +53,6 @@ public class SigninHelper { ...@@ -56,8 +53,6 @@ public class SigninHelper {
private static final String ACCOUNT_RENAME_EVENT_INDEX_PREFS_KEY = private static final String ACCOUNT_RENAME_EVENT_INDEX_PREFS_KEY =
"prefs_sync_account_rename_event_index"; "prefs_sync_account_rename_event_index";
private static final String ANDROID_ACCOUNTS_PREFS_KEY = "prefs_sync_android_accounts";
private static SigninHelper sInstance; private static SigninHelper sInstance;
/** /**
...@@ -140,34 +135,20 @@ public class SigninHelper { ...@@ -140,34 +135,20 @@ public class SigninHelper {
Account syncAccount = mChromeSigninController.getSignedInUser(); Account syncAccount = mChromeSigninController.getSignedInUser();
if (syncAccount == null) { if (syncAccount == null) {
ChromePreferenceManager chromePreferenceManager =
ChromePreferenceManager.getInstance(mContext);
if (chromePreferenceManager.getShowSigninPromo()) return;
// Never shows a signin promo if user has manually disconnected. // Never shows a signin promo if user has manually disconnected.
String lastSyncAccountName = String lastSyncAccountName =
PrefServiceBridge.getInstance().getSyncLastAccountName(); PrefServiceBridge.getInstance().getSyncLastAccountName();
if (lastSyncAccountName != null && !lastSyncAccountName.isEmpty()) return; if (lastSyncAccountName != null && !lastSyncAccountName.isEmpty()) return;
SharedPreferences sharedPrefs = ContextUtils.getAppSharedPreferences(); if (!chromePreferenceManager.getSigninPromoShown()
boolean hasKnownAccountKeys = sharedPrefs.contains(ANDROID_ACCOUNTS_PREFS_KEY); && AccountManagerHelper.get(mContext).getGoogleAccountNames().size() > 0) {
// Nothing to do if Android accounts are not changed and already known to Chrome. chromePreferenceManager.setShowSigninPromo(true);
if (hasKnownAccountKeys && !accountsChanged) return;
List<String> currentAccountNames =
AccountManagerHelper.get(mContext).getGoogleAccountNames();
if (hasKnownAccountKeys) {
ChromePreferenceManager chromePreferenceManager =
ChromePreferenceManager.getInstance(mContext);
if (!chromePreferenceManager.getSigninPromoShown()) {
Set<String> lastKnownAccountNames = sharedPrefs.getStringSet(
ANDROID_ACCOUNTS_PREFS_KEY, new HashSet<String>());
Set<String> newAccountNames = new HashSet<String>(currentAccountNames);
newAccountNames.removeAll(lastKnownAccountNames);
if (!newAccountNames.isEmpty()) {
chromePreferenceManager.setShowSigninPromo(true);
}
}
} }
sharedPrefs.edit().putStringSet(
ANDROID_ACCOUNTS_PREFS_KEY, new HashSet<String>(currentAccountNames)).apply();
return; return;
} }
......
...@@ -39,7 +39,7 @@ public class SigninPromoUtil { ...@@ -39,7 +39,7 @@ public class SigninPromoUtil {
return false; return false;
} }
AccountSigninActivity.startAccountSigninActivity(activity, SigninAccessPoint.SIGNIN_PROMO); AccountSigninActivity.startIfAllowed(activity, SigninAccessPoint.SIGNIN_PROMO);
preferenceManager.setSigninPromoShown(); preferenceManager.setSigninPromoShown();
return true; return true;
} }
......
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