Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.signin; | 5 package org.chromium.chrome.browser.signin; |
| 6 | 6 |
| 7 import android.content.Context; | |
| 7 import android.content.Intent; | 8 import android.content.Intent; |
| 8 import android.os.Bundle; | 9 import android.os.Bundle; |
| 10 import android.support.annotation.IntDef; | |
| 9 import android.support.v7.app.AppCompatActivity; | 11 import android.support.v7.app.AppCompatActivity; |
| 10 import android.view.LayoutInflater; | 12 import android.view.LayoutInflater; |
| 11 | 13 |
| 12 import org.chromium.base.Log; | 14 import org.chromium.base.Log; |
| 13 import org.chromium.base.annotations.SuppressFBWarnings; | 15 import org.chromium.base.annotations.SuppressFBWarnings; |
| 14 import org.chromium.base.library_loader.ProcessInitException; | 16 import org.chromium.base.library_loader.ProcessInitException; |
| 15 import org.chromium.base.metrics.RecordUserAction; | 17 import org.chromium.base.metrics.RecordUserAction; |
| 16 import org.chromium.chrome.R; | 18 import org.chromium.chrome.R; |
| 17 import org.chromium.chrome.browser.firstrun.ProfileDataCache; | 19 import org.chromium.chrome.browser.firstrun.ProfileDataCache; |
| 18 import org.chromium.chrome.browser.init.ChromeBrowserInitializer; | 20 import org.chromium.chrome.browser.init.ChromeBrowserInitializer; |
| 19 import org.chromium.chrome.browser.preferences.PreferencesLauncher; | 21 import org.chromium.chrome.browser.preferences.PreferencesLauncher; |
| 20 import org.chromium.chrome.browser.profiles.Profile; | 22 import org.chromium.chrome.browser.profiles.Profile; |
| 23 import org.chromium.chrome.browser.signin.SigninManager.SignInCallback; | |
| 24 | |
| 25 import java.lang.annotation.Retention; | |
| 26 import java.lang.annotation.RetentionPolicy; | |
| 21 | 27 |
| 22 /** | 28 /** |
| 23 * An Activity displayed from the MainPreferences to allow the user to pick an a ccount to | 29 * An Activity displayed from the MainPreferences to allow the user to pick an a ccount to |
| 24 * sign in to. The AccountSigninView.Delegate interface is fulfilled by the AppC ompatActivity. | 30 * sign in to. The AccountSigninView.Delegate interface is fulfilled by the AppC ompatActivity. |
| 25 */ | 31 */ |
| 26 public class AccountSigninActivity extends AppCompatActivity | 32 public class AccountSigninActivity extends AppCompatActivity |
| 27 implements AccountSigninView.Listener, AccountSigninView.Delegate, | 33 implements AccountSigninView.Listener, AccountSigninView.Delegate { |
| 28 SigninManager.SignInCallback{ | 34 private static final String TAG = "AccountSigninActivity"; |
| 29 private static final String TAG = "SigninActivity"; | 35 private static final String INTENT_SIGNIN_ACCESS_POINT = |
| 30 | 36 "AccountSigninActivity.SigninAccessPoint"; |
| 31 private static final String CONFIRM_IMPORT_SYNC_DATA_DIALOG_TAG = | |
| 32 "signin_import_data_tag"; | |
| 33 | 37 |
| 34 private AccountSigninView mView; | 38 private AccountSigninView mView; |
| 35 private String mAccountName; | 39 private ProfileDataCache mProfileDataCache; |
| 36 private boolean mShowSigninSettings = false; | 40 |
| 41 @IntDef({SigninAccessPoint.SETTINGS, SigninAccessPoint.BOOKMARK_MANAGER, | |
| 42 SigninAccessPoint.RECENT_TABS}) | |
| 43 @Retention(RetentionPolicy.SOURCE) | |
| 44 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.
| |
| 45 @AccessPoint private int mAccessPoint; | |
| 46 | |
| 47 /** | |
| 48 * A convenience method to create a AccountSigninActivity passing the access point as an | |
| 49 * intent. | |
| 50 * @param accessPoint - A SigninAccessPoint designating where the activity i s created from. | |
| 51 */ | |
| 52 public static void startAccountSigninActivity(Context context, @AccessPoint int accessPoint) { | |
| 53 Intent intent = new Intent(context, AccountSigninActivity.class); | |
| 54 intent.putExtra(INTENT_SIGNIN_ACCESS_POINT, accessPoint); | |
| 55 context.startActivity(intent); | |
| 56 } | |
| 37 | 57 |
| 38 @Override | 58 @Override |
| 39 @SuppressFBWarnings("DM_EXIT") | 59 @SuppressFBWarnings("DM_EXIT") |
| 40 protected void onCreate(Bundle savedInstanceState) { | 60 protected void onCreate(Bundle savedInstanceState) { |
| 41 // The browser process must be started here because this activity may be started from the | 61 // The browser process must be started here because this activity may be started from the |
| 42 // recent apps list and it relies on other activities and the native lib rary to be loaded. | 62 // recent apps list and it relies on other activities and the native lib rary to be loaded. |
| 43 try { | 63 try { |
| 44 ChromeBrowserInitializer.getInstance(this).handleSynchronousStartup( ); | 64 ChromeBrowserInitializer.getInstance(this).handleSynchronousStartup( ); |
| 45 } catch (ProcessInitException e) { | 65 } catch (ProcessInitException e) { |
| 46 Log.e(TAG, "Failed to start browser process.", e); | 66 Log.e(TAG, "Failed to start browser process.", e); |
| 47 // Since the library failed to initialize nothing in the application | 67 // Since the library failed to initialize nothing in the application |
| 48 // can work, so kill the whole application not just the activity | 68 // can work, so kill the whole application not just the activity |
| 49 System.exit(-1); | 69 System.exit(-1); |
| 50 } | 70 } |
| 51 | 71 |
| 52 // We don't trust android to restore the saved state correctly, so pass null. | 72 // We don't trust android to restore the saved state correctly, so pass null. |
| 53 super.onCreate(null); | 73 super.onCreate(null); |
| 54 | 74 |
| 75 mAccessPoint = getIntent().getIntExtra(INTENT_SIGNIN_ACCESS_POINT, -1); | |
| 76 assert mAccessPoint == SigninAccessPoint.BOOKMARK_MANAGER | |
| 77 || mAccessPoint == SigninAccessPoint.RECENT_TABS | |
| 78 || mAccessPoint == SigninAccessPoint.SETTINGS : "invalid access point"; | |
| 79 | |
| 80 if (savedInstanceState == null && getAccessPoint() == SigninAccessPoint. BOOKMARK_MANAGER) { | |
| 81 RecordUserAction.record("Stars_SignInPromoActivity_Launched"); | |
| 82 } | |
| 83 | |
| 55 mView = (AccountSigninView) LayoutInflater.from(this).inflate( | 84 mView = (AccountSigninView) LayoutInflater.from(this).inflate( |
| 56 R.layout.account_signin_view, null); | 85 R.layout.account_signin_view, null); |
| 57 mView.init(new ProfileDataCache(this, Profile.getLastUsedProfile())); | 86 mView.init(getProfileDataCache()); |
| 58 mView.setListener(this); | 87 mView.setListener(this); |
| 59 mView.setDelegate(this); | 88 mView.setDelegate(this); |
| 60 | 89 |
| 90 if (getAccessPoint() == SigninAccessPoint.BOOKMARK_MANAGER | |
| 91 || getAccessPoint() == SigninAccessPoint.RECENT_TABS) { | |
| 92 mView.configureForRecentTabsOrBookmarksPage(); | |
| 93 } | |
| 94 | |
| 95 SigninManager.logSigninStartAccessPoint(getAccessPoint()); | |
| 96 | |
| 61 setContentView(mView); | 97 setContentView(mView); |
| 62 } | 98 } |
| 63 | 99 |
| 64 @Override | 100 @Override |
| 101 public void onDestroy() { | |
| 102 super.onDestroy(); | |
| 103 | |
| 104 if (mProfileDataCache != null) { | |
| 105 mProfileDataCache.destroy(); | |
| 106 mProfileDataCache = null; | |
| 107 } | |
| 108 } | |
| 109 | |
| 110 private ProfileDataCache getProfileDataCache() { | |
| 111 if (mProfileDataCache == null) { | |
| 112 mProfileDataCache = new ProfileDataCache(this, Profile.getLastUsedPr ofile()); | |
| 113 } | |
| 114 return mProfileDataCache; | |
| 115 } | |
| 116 | |
| 117 @AccessPoint private int getAccessPoint() { | |
| 118 return mAccessPoint; | |
| 119 } | |
| 120 | |
| 121 @Override | |
| 65 public void onAccountSelectionCanceled() { | 122 public void onAccountSelectionCanceled() { |
| 66 finish(); | 123 finish(); |
| 67 } | 124 } |
| 68 | 125 |
| 69 @Override | 126 @Override |
| 70 public void onNewAccount() { | 127 public void onNewAccount() { |
| 128 if (getAccessPoint() == SigninAccessPoint.BOOKMARK_MANAGER) { | |
| 129 RecordUserAction.record("Stars_SignInPromoActivity_NewAccount"); | |
| 130 } | |
| 131 | |
| 71 AccountAdder.getInstance().addAccount(this, AccountAdder.ADD_ACCOUNT_RES ULT); | 132 AccountAdder.getInstance().addAccount(this, AccountAdder.ADD_ACCOUNT_RES ULT); |
| 72 } | 133 } |
| 73 | 134 |
| 74 @Override | 135 @Override |
| 75 public void onAccountSelected(String accountName, boolean settingsClicked) { | 136 public void onAccountSelected(final String accountName, final boolean settin gsClicked) { |
| 76 mShowSigninSettings = settingsClicked; | 137 switch (getAccessPoint()) { |
| 77 mAccountName = accountName; | 138 case SigninAccessPoint.BOOKMARK_MANAGER: |
| 78 RecordUserAction.record("Signin_Signin_FromSettings"); | 139 RecordUserAction.record("Stars_SignInPromoActivity_SignedIn"); |
| 79 SigninManager.get(this).signIn(accountName, this, this); | 140 RecordUserAction.record("Signin_Signin_FromBookmarkManager"); |
| 141 break; | |
| 142 case SigninAccessPoint.RECENT_TABS: | |
| 143 RecordUserAction.record("Signin_Signin_FromRecentTabs"); | |
| 144 break; | |
| 145 case SigninAccessPoint.SETTINGS: | |
| 146 RecordUserAction.record("Signin_Signin_FromSettings"); | |
| 147 break; | |
| 148 default: | |
| 149 } | |
| 150 | |
| 151 final Context context = this; | |
| 152 SigninManager.get(this).signIn(accountName, this, new SignInCallback(){ | |
| 153 | |
| 154 @Override | |
| 155 public void onSignInComplete() { | |
| 156 if (settingsClicked) { | |
| 157 Intent intent = PreferencesLauncher.createIntentForSettingsP age( | |
| 158 context, AccountManagementFragment.class.getName()); | |
| 159 startActivity(intent); | |
| 160 } | |
| 161 | |
| 162 finish(); | |
| 163 } | |
| 164 | |
| 165 @Override | |
| 166 public void onSignInAborted() {} | |
| 167 }); | |
| 80 } | 168 } |
| 81 | 169 |
| 82 @Override | 170 @Override |
| 83 public void onFailedToSetForcedAccount(String forcedAccountName) { | 171 public void onFailedToSetForcedAccount(String forcedAccountName) {} |
| 84 assert false : "No forced accounts in account switching preferences."; | |
| 85 | |
| 86 } | |
| 87 | |
| 88 @Override | |
| 89 public void onSignInComplete() { | |
| 90 if (mShowSigninSettings) { | |
| 91 Intent intent = PreferencesLauncher.createIntentForSettingsPage( | |
| 92 this, AccountManagementFragment.class.getName()); | |
| 93 startActivity(intent); | |
| 94 } | |
| 95 | |
| 96 finish(); | |
| 97 } | |
| 98 | |
| 99 @Override | |
| 100 public void onSignInAborted() { | |
| 101 assert false : "Signin cannot be aborted when forced."; | |
| 102 } | |
| 103 } | 172 } |
| OLD | NEW |