Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/signin/AccountSigninActivity.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/signin/AccountSigninActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/signin/AccountSigninActivity.java |
| index 7d44cb1f0c7dfeee1bc5b49beb054b3e25e4a0df..21acd8cfe4e55ffab864fd84f9d9d9602c6f717e 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/signin/AccountSigninActivity.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/signin/AccountSigninActivity.java |
| @@ -4,8 +4,10 @@ |
| package org.chromium.chrome.browser.signin; |
| +import android.content.Context; |
| import android.content.Intent; |
| import android.os.Bundle; |
| +import android.support.annotation.IntDef; |
| import android.support.v7.app.AppCompatActivity; |
| import android.view.LayoutInflater; |
| @@ -18,22 +20,40 @@ import org.chromium.chrome.browser.firstrun.ProfileDataCache; |
| import org.chromium.chrome.browser.init.ChromeBrowserInitializer; |
| import org.chromium.chrome.browser.preferences.PreferencesLauncher; |
| import org.chromium.chrome.browser.profiles.Profile; |
| +import org.chromium.chrome.browser.signin.SigninManager.SignInCallback; |
| + |
| +import java.lang.annotation.Retention; |
| +import java.lang.annotation.RetentionPolicy; |
| /** |
| * An Activity displayed from the MainPreferences to allow the user to pick an account to |
| * sign in to. The AccountSigninView.Delegate interface is fulfilled by the AppCompatActivity. |
| */ |
| public class AccountSigninActivity extends AppCompatActivity |
| - implements AccountSigninView.Listener, AccountSigninView.Delegate, |
| - SigninManager.SignInCallback{ |
| - private static final String TAG = "SigninActivity"; |
| - |
| - private static final String CONFIRM_IMPORT_SYNC_DATA_DIALOG_TAG = |
| - "signin_import_data_tag"; |
| + implements AccountSigninView.Listener, AccountSigninView.Delegate { |
| + private static final String TAG = "AccountSigninActivity"; |
| + private static final String INTENT_SIGNIN_ACCESS_POINT = |
| + "AccountSigninActivity.SigninAccessPoint"; |
| private AccountSigninView mView; |
| - private String mAccountName; |
| - private boolean mShowSigninSettings = false; |
| + private ProfileDataCache mProfileDataCache; |
| + |
| + @IntDef({SigninAccessPoint.SETTINGS, SigninAccessPoint.BOOKMARK_MANAGER, |
| + SigninAccessPoint.RECENT_TABS}) |
| + @Retention(RetentionPolicy.SOURCE) |
| + public @interface AccessPoint {} |
|
Bernhard Bauer
2016/04/28 12:24:03
It would be awesome to change java_cpp_enum (the s
PEConn
2016/04/28 12:33:52
Acknowledged.
|
| + @AccessPoint private int mAccessPoint; |
| + |
| + /** |
| + * A convenience method to create a AccountSigninActivity passing the access point as an |
| + * intent. |
| + * @param accessPoint - A SigninAccessPoint designating where the activity is created from. |
| + */ |
| + public static void startAccountSigninActivity(Context context, @AccessPoint int accessPoint) { |
| + Intent intent = new Intent(context, AccountSigninActivity.class); |
| + intent.putExtra(INTENT_SIGNIN_ACCESS_POINT, accessPoint); |
| + context.startActivity(intent); |
| + } |
| @Override |
| @SuppressFBWarnings("DM_EXIT") |
| @@ -52,52 +72,101 @@ public class AccountSigninActivity extends AppCompatActivity |
| // We don't trust android to restore the saved state correctly, so pass null. |
| super.onCreate(null); |
| + mAccessPoint = getIntent().getIntExtra(INTENT_SIGNIN_ACCESS_POINT, -1); |
| + assert mAccessPoint == SigninAccessPoint.BOOKMARK_MANAGER |
| + || mAccessPoint == SigninAccessPoint.RECENT_TABS |
| + || mAccessPoint == SigninAccessPoint.SETTINGS : "invalid access point"; |
| + |
| + if (savedInstanceState == null && getAccessPoint() == SigninAccessPoint.BOOKMARK_MANAGER) { |
| + RecordUserAction.record("Stars_SignInPromoActivity_Launched"); |
| + } |
| + |
| mView = (AccountSigninView) LayoutInflater.from(this).inflate( |
| R.layout.account_signin_view, null); |
| - mView.init(new ProfileDataCache(this, Profile.getLastUsedProfile())); |
| + mView.init(getProfileDataCache()); |
| mView.setListener(this); |
| mView.setDelegate(this); |
| + if (getAccessPoint() == SigninAccessPoint.BOOKMARK_MANAGER |
| + || getAccessPoint() == SigninAccessPoint.RECENT_TABS) { |
| + mView.configureForRecentTabsOrBookmarksPage(); |
| + } |
| + |
| + SigninManager.logSigninStartAccessPoint(getAccessPoint()); |
| + |
| setContentView(mView); |
| } |
| @Override |
| - public void onAccountSelectionCanceled() { |
| - finish(); |
| + public void onDestroy() { |
| + super.onDestroy(); |
| + |
| + if (mProfileDataCache != null) { |
| + mProfileDataCache.destroy(); |
| + mProfileDataCache = null; |
| + } |
| } |
| - @Override |
| - public void onNewAccount() { |
| - AccountAdder.getInstance().addAccount(this, AccountAdder.ADD_ACCOUNT_RESULT); |
| + private ProfileDataCache getProfileDataCache() { |
| + if (mProfileDataCache == null) { |
| + mProfileDataCache = new ProfileDataCache(this, Profile.getLastUsedProfile()); |
| + } |
| + return mProfileDataCache; |
| + } |
| + |
| + @AccessPoint private int getAccessPoint() { |
| + return mAccessPoint; |
| } |
| @Override |
| - public void onAccountSelected(String accountName, boolean settingsClicked) { |
| - mShowSigninSettings = settingsClicked; |
| - mAccountName = accountName; |
| - RecordUserAction.record("Signin_Signin_FromSettings"); |
| - SigninManager.get(this).signIn(accountName, this, this); |
| + public void onAccountSelectionCanceled() { |
| + finish(); |
| } |
| @Override |
| - public void onFailedToSetForcedAccount(String forcedAccountName) { |
| - assert false : "No forced accounts in account switching preferences."; |
| + public void onNewAccount() { |
| + if (getAccessPoint() == SigninAccessPoint.BOOKMARK_MANAGER) { |
| + RecordUserAction.record("Stars_SignInPromoActivity_NewAccount"); |
| + } |
| + AccountAdder.getInstance().addAccount(this, AccountAdder.ADD_ACCOUNT_RESULT); |
| } |
| @Override |
| - public void onSignInComplete() { |
| - if (mShowSigninSettings) { |
| - Intent intent = PreferencesLauncher.createIntentForSettingsPage( |
| - this, AccountManagementFragment.class.getName()); |
| - startActivity(intent); |
| + public void onAccountSelected(final String accountName, final boolean settingsClicked) { |
| + switch (getAccessPoint()) { |
| + case SigninAccessPoint.BOOKMARK_MANAGER: |
| + RecordUserAction.record("Stars_SignInPromoActivity_SignedIn"); |
| + RecordUserAction.record("Signin_Signin_FromBookmarkManager"); |
| + break; |
| + case SigninAccessPoint.RECENT_TABS: |
| + RecordUserAction.record("Signin_Signin_FromRecentTabs"); |
| + break; |
| + case SigninAccessPoint.SETTINGS: |
| + RecordUserAction.record("Signin_Signin_FromSettings"); |
| + break; |
| + default: |
| } |
| - finish(); |
| + final Context context = this; |
| + SigninManager.get(this).signIn(accountName, this, new SignInCallback(){ |
| + |
| + @Override |
| + public void onSignInComplete() { |
| + if (settingsClicked) { |
| + Intent intent = PreferencesLauncher.createIntentForSettingsPage( |
| + context, AccountManagementFragment.class.getName()); |
| + startActivity(intent); |
| + } |
| + |
| + finish(); |
| + } |
| + |
| + @Override |
| + public void onSignInAborted() {} |
| + }); |
| } |
| @Override |
| - public void onSignInAborted() { |
| - assert false : "Signin cannot be aborted when forced."; |
| - } |
| + public void onFailedToSetForcedAccount(String forcedAccountName) {} |
| } |