| 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.Context; |
| 8 import android.content.Intent; | 8 import android.content.Intent; |
| 9 import android.os.Bundle; | 9 import android.os.Bundle; |
| 10 import android.support.annotation.IntDef; | 10 import android.support.annotation.IntDef; |
| 11 import android.support.v7.app.AppCompatActivity; | 11 import android.support.v7.app.AppCompatActivity; |
| 12 import android.view.LayoutInflater; | 12 import android.view.LayoutInflater; |
| 13 | 13 |
| 14 import org.chromium.base.Log; | 14 import org.chromium.base.Log; |
| 15 import org.chromium.base.annotations.SuppressFBWarnings; | 15 import org.chromium.base.annotations.SuppressFBWarnings; |
| 16 import org.chromium.base.library_loader.ProcessInitException; | 16 import org.chromium.base.library_loader.ProcessInitException; |
| 17 import org.chromium.base.metrics.RecordUserAction; | 17 import org.chromium.base.metrics.RecordUserAction; |
| 18 import org.chromium.chrome.R; | 18 import org.chromium.chrome.R; |
| 19 import org.chromium.chrome.browser.firstrun.ProfileDataCache; | 19 import org.chromium.chrome.browser.firstrun.ProfileDataCache; |
| 20 import org.chromium.chrome.browser.init.ChromeBrowserInitializer; | 20 import org.chromium.chrome.browser.init.ChromeBrowserInitializer; |
| 21 import org.chromium.chrome.browser.preferences.ManagedPreferencesUtils; |
| 21 import org.chromium.chrome.browser.preferences.PreferencesLauncher; | 22 import org.chromium.chrome.browser.preferences.PreferencesLauncher; |
| 22 import org.chromium.chrome.browser.profiles.Profile; | 23 import org.chromium.chrome.browser.profiles.Profile; |
| 23 import org.chromium.chrome.browser.signin.SigninManager.SignInCallback; | 24 import org.chromium.chrome.browser.signin.SigninManager.SignInCallback; |
| 24 | 25 |
| 25 import java.lang.annotation.Retention; | 26 import java.lang.annotation.Retention; |
| 26 import java.lang.annotation.RetentionPolicy; | 27 import java.lang.annotation.RetentionPolicy; |
| 27 | 28 |
| 28 /** | 29 /** |
| 29 * An Activity displayed from the MainPreferences to allow the user to pick an a
ccount to | 30 * An Activity displayed from the MainPreferences to allow the user to pick an a
ccount to |
| 30 * sign in to. The AccountSigninView.Delegate interface is fulfilled by the AppC
ompatActivity. | 31 * sign in to. The AccountSigninView.Delegate interface is fulfilled by the AppC
ompatActivity. |
| 31 */ | 32 */ |
| 32 public class AccountSigninActivity extends AppCompatActivity | 33 public class AccountSigninActivity extends AppCompatActivity |
| 33 implements AccountSigninView.Listener, AccountSigninView.Delegate { | 34 implements AccountSigninView.Listener, AccountSigninView.Delegate { |
| 34 private static final String TAG = "AccountSigninActivity"; | 35 private static final String TAG = "AccountSigninActivity"; |
| 35 private static final String INTENT_SIGNIN_ACCESS_POINT = | 36 private static final String INTENT_SIGNIN_ACCESS_POINT = |
| 36 "AccountSigninActivity.SigninAccessPoint"; | 37 "AccountSigninActivity.SigninAccessPoint"; |
| 37 | 38 |
| 38 private AccountSigninView mView; | 39 private AccountSigninView mView; |
| 39 private ProfileDataCache mProfileDataCache; | 40 private ProfileDataCache mProfileDataCache; |
| 40 | 41 |
| 41 @IntDef({SigninAccessPoint.SETTINGS, SigninAccessPoint.BOOKMARK_MANAGER, | 42 @IntDef({SigninAccessPoint.SETTINGS, SigninAccessPoint.BOOKMARK_MANAGER, |
| 42 SigninAccessPoint.RECENT_TABS, SigninAccessPoint.SIGNIN_PROMO}) | 43 SigninAccessPoint.RECENT_TABS, SigninAccessPoint.SIGNIN_PROMO, |
| 44 SigninAccessPoint.NTP_LINK}) |
| 43 @Retention(RetentionPolicy.SOURCE) | 45 @Retention(RetentionPolicy.SOURCE) |
| 44 public @interface AccessPoint {} | 46 public @interface AccessPoint {} |
| 45 @AccessPoint private int mAccessPoint; | 47 @AccessPoint private int mAccessPoint; |
| 46 | 48 |
| 47 /** | 49 /** |
| 48 * A convenience method to create a AccountSigninActivity passing the access
point as an | 50 * A convenience method to create a AccountSigninActivity passing the access
point as an |
| 49 * intent. | 51 * intent. |
| 50 * @param accessPoint - A SigninAccessPoint designating where the activity i
s created from. | 52 * @param accessPoint - A SigninAccessPoint designating where the activity i
s created from. |
| 51 */ | 53 */ |
| 52 public static void startAccountSigninActivity(Context context, @AccessPoint
int accessPoint) { | 54 public static void startAccountSigninActivity(Context context, @AccessPoint
int accessPoint) { |
| 53 Intent intent = new Intent(context, AccountSigninActivity.class); | 55 Intent intent = new Intent(context, AccountSigninActivity.class); |
| 54 intent.putExtra(INTENT_SIGNIN_ACCESS_POINT, accessPoint); | 56 intent.putExtra(INTENT_SIGNIN_ACCESS_POINT, accessPoint); |
| 55 context.startActivity(intent); | 57 context.startActivity(intent); |
| 56 } | 58 } |
| 57 | 59 |
| 60 /** |
| 61 * A convenience method to create a AccountSigninActivity passing the access
point as an |
| 62 * intent. Checks if the sign in flow can be started before showing the acti
vity. |
| 63 * @param accessPoint - A SigninAccessPoint designating where the activity i
s created from. |
| 64 * @return {@code true} if sign in has been allowed. |
| 65 */ |
| 66 public static boolean startIfAllowed(Context context, @AccessPoint int acces
sPoint) { |
| 67 if (!SigninManager.get(context).isSignInAllowed()) { |
| 68 if (SigninManager.get(context).isSigninDisabledByPolicy()) { |
| 69 ManagedPreferencesUtils.showManagedByAdministratorToast(context)
; |
| 70 } |
| 71 return false; |
| 72 } |
| 73 |
| 74 startAccountSigninActivity(context, accessPoint); |
| 75 return true; |
| 76 } |
| 77 |
| 58 @Override | 78 @Override |
| 59 @SuppressFBWarnings("DM_EXIT") | 79 @SuppressFBWarnings("DM_EXIT") |
| 60 protected void onCreate(Bundle savedInstanceState) { | 80 protected void onCreate(Bundle savedInstanceState) { |
| 61 // The browser process must be started here because this activity may be
started from the | 81 // The browser process must be started here because this activity may be
started from the |
| 62 // recent apps list and it relies on other activities and the native lib
rary to be loaded. | 82 // recent apps list and it relies on other activities and the native lib
rary to be loaded. |
| 63 try { | 83 try { |
| 64 ChromeBrowserInitializer.getInstance(this).handleSynchronousStartup(
); | 84 ChromeBrowserInitializer.getInstance(this).handleSynchronousStartup(
); |
| 65 } catch (ProcessInitException e) { | 85 } catch (ProcessInitException e) { |
| 66 Log.e(TAG, "Failed to start browser process.", e); | 86 Log.e(TAG, "Failed to start browser process.", e); |
| 67 // Since the library failed to initialize nothing in the application | 87 // Since the library failed to initialize nothing in the application |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 RecordUserAction.record("Signin_Signin_FromSettings"); | 183 RecordUserAction.record("Signin_Signin_FromSettings"); |
| 164 break; | 184 break; |
| 165 case SigninAccessPoint.SIGNIN_PROMO: | 185 case SigninAccessPoint.SIGNIN_PROMO: |
| 166 RecordUserAction.record("Signin_Signin_FromSigninPromo"); | 186 RecordUserAction.record("Signin_Signin_FromSigninPromo"); |
| 167 break; | 187 break; |
| 168 default: | 188 default: |
| 169 assert false : "Invalid access point."; | 189 assert false : "Invalid access point."; |
| 170 } | 190 } |
| 171 } | 191 } |
| 172 } | 192 } |
| OLD | NEW |