OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.accounts.Account; | 7 import android.accounts.Account; |
8 import android.app.Activity; | 8 import android.app.Activity; |
9 import android.content.Context; | 9 import android.content.Context; |
10 import android.os.Handler; | 10 import android.os.Handler; |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 } | 192 } |
193 return sSigninManager; | 193 return sSigninManager; |
194 } | 194 } |
195 | 195 |
196 private SigninManager(Context context) { | 196 private SigninManager(Context context) { |
197 ThreadUtils.assertOnUiThread(); | 197 ThreadUtils.assertOnUiThread(); |
198 mContext = context.getApplicationContext(); | 198 mContext = context.getApplicationContext(); |
199 mNativeSigninManagerAndroid = nativeInit(); | 199 mNativeSigninManagerAndroid = nativeInit(); |
200 mSigninAllowedByPolicy = nativeIsSigninAllowedByPolicy(mNativeSigninMana
gerAndroid); | 200 mSigninAllowedByPolicy = nativeIsSigninAllowedByPolicy(mNativeSigninMana
gerAndroid); |
201 | 201 |
202 AccountTrackerService.get(mContext).addSystemAccountsSeededListener(this
); | 202 AccountTrackerService.get().addSystemAccountsSeededListener(this); |
203 } | 203 } |
204 | 204 |
205 /** | 205 /** |
206 * Log the access point when the user see the view of choosing account to sig
n in. | 206 * Log the access point when the user see the view of choosing account to sig
n in. |
207 * @param accessPoint the enum value of AccessPoint defined in signin_metrics
.h. | 207 * @param accessPoint the enum value of AccessPoint defined in signin_metrics
.h. |
208 */ | 208 */ |
209 public static void logSigninStartAccessPoint(int accessPoint) { | 209 public static void logSigninStartAccessPoint(int accessPoint) { |
210 RecordHistogram.recordEnumeratedHistogram( | 210 RecordHistogram.recordEnumeratedHistogram( |
211 "Signin.SigninStartedAccessPoint", accessPoint, SigninAccessPoin
t.MAX); | 211 "Signin.SigninStartedAccessPoint", accessPoint, SigninAccessPoin
t.MAX); |
212 sSignInAccessPoint = accessPoint; | 212 sSignInAccessPoint = accessPoint; |
(...skipping 16 matching lines...) Expand all Loading... |
229 if (isSignInAllowed()) { | 229 if (isSignInAllowed()) { |
230 notifySignInAllowedChanged(); | 230 notifySignInAllowedChanged(); |
231 } | 231 } |
232 } | 232 } |
233 | 233 |
234 /** | 234 /** |
235 * Returns true if signin can be started now. | 235 * Returns true if signin can be started now. |
236 */ | 236 */ |
237 public boolean isSignInAllowed() { | 237 public boolean isSignInAllowed() { |
238 return !mFirstRunCheckIsPending && mSignInState == null && mSigninAllowe
dByPolicy | 238 return !mFirstRunCheckIsPending && mSignInState == null && mSigninAllowe
dByPolicy |
239 && ChromeSigninController.get(mContext).getSignedInUser() == nul
l | 239 && ChromeSigninController.get().getSignedInUser() == null && isS
igninSupported(); |
240 && isSigninSupported(); | |
241 } | 240 } |
242 | 241 |
243 /** | 242 /** |
244 * Returns true if signin is disabled by policy. | 243 * Returns true if signin is disabled by policy. |
245 */ | 244 */ |
246 public boolean isSigninDisabledByPolicy() { | 245 public boolean isSigninDisabledByPolicy() { |
247 return !mSigninAllowedByPolicy; | 246 return !mSigninAllowedByPolicy; |
248 } | 247 } |
249 | 248 |
250 /** | 249 /** |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 notifySignInAllowedChanged(); | 359 notifySignInAllowedChanged(); |
361 | 360 |
362 progressSignInFlowSeedSystemAccounts(); | 361 progressSignInFlowSeedSystemAccounts(); |
363 } | 362 } |
364 | 363 |
365 /** | 364 /** |
366 * Same as above but retrieves the Account object for the given accountName. | 365 * Same as above but retrieves the Account object for the given accountName. |
367 */ | 366 */ |
368 public void signIn(String accountName, @Nullable final Activity activity, | 367 public void signIn(String accountName, @Nullable final Activity activity, |
369 @Nullable final SignInCallback callback) { | 368 @Nullable final SignInCallback callback) { |
370 AccountManagerHelper.get(mContext).getAccountFromName(accountName, new C
allback<Account>() { | 369 AccountManagerHelper.get().getAccountFromName(accountName, new Callback<
Account>() { |
371 @Override | 370 @Override |
372 public void onResult(Account account) { | 371 public void onResult(Account account) { |
373 signIn(account, activity, callback); | 372 signIn(account, activity, callback); |
374 } | 373 } |
375 }); | 374 }); |
376 } | 375 } |
377 | 376 |
378 private void progressSignInFlowSeedSystemAccounts() { | 377 private void progressSignInFlowSeedSystemAccounts() { |
379 if (AccountTrackerService.get(mContext).checkAndSeedSystemAccounts()) { | 378 if (AccountTrackerService.get().checkAndSeedSystemAccounts()) { |
380 progressSignInFlowCheckPolicy(); | 379 progressSignInFlowCheckPolicy(); |
381 } else if (AccountIdProvider.getInstance().canBeUsed(mContext)) { | 380 } else if (AccountIdProvider.getInstance().canBeUsed()) { |
382 mSignInState.blockedOnAccountSeeding = true; | 381 mSignInState.blockedOnAccountSeeding = true; |
383 } else { | 382 } else { |
384 Activity activity = mSignInState.activity; | 383 Activity activity = mSignInState.activity; |
385 UserRecoverableErrorHandler errorHandler = activity != null | 384 UserRecoverableErrorHandler errorHandler = activity != null |
386 ? new UserRecoverableErrorHandler.ModalDialog(activity, !isF
orceSigninEnabled()) | 385 ? new UserRecoverableErrorHandler.ModalDialog(activity, !isF
orceSigninEnabled()) |
387 : new UserRecoverableErrorHandler.SystemNotification(); | 386 : new UserRecoverableErrorHandler.SystemNotification(); |
388 ExternalAuthUtils.getInstance().canUseGooglePlayServices(mContext, e
rrorHandler); | 387 ExternalAuthUtils.getInstance().canUseGooglePlayServices(mContext, e
rrorHandler); |
389 Log.w(TAG, "Cancelling the sign-in process as Google Play services i
s unavailable"); | 388 Log.w(TAG, "Cancelling the sign-in process as Google Play services i
s unavailable"); |
390 abortSignIn(); | 389 abortSignIn(); |
391 } | 390 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 | 445 |
447 private void finishSignIn() { | 446 private void finishSignIn() { |
448 // This method should be called at most once per sign-in flow. | 447 // This method should be called at most once per sign-in flow. |
449 assert mSignInState != null; | 448 assert mSignInState != null; |
450 | 449 |
451 // Tell the native side that sign-in has completed. | 450 // Tell the native side that sign-in has completed. |
452 nativeOnSignInCompleted(mNativeSigninManagerAndroid, mSignInState.accoun
t.name); | 451 nativeOnSignInCompleted(mNativeSigninManagerAndroid, mSignInState.accoun
t.name); |
453 | 452 |
454 // Cache the signed-in account name. This must be done after the native
call, otherwise | 453 // Cache the signed-in account name. This must be done after the native
call, otherwise |
455 // sync tries to start without being signed in natively and crashes. | 454 // sync tries to start without being signed in natively and crashes. |
456 ChromeSigninController.get(mContext).setSignedInAccountName(mSignInState
.account.name); | 455 ChromeSigninController.get().setSignedInAccountName(mSignInState.account
.name); |
457 AndroidSyncSettings.updateAccount(mContext, mSignInState.account); | 456 AndroidSyncSettings.updateAccount(mContext, mSignInState.account); |
458 | 457 |
459 if (mSignInState.callback != null) { | 458 if (mSignInState.callback != null) { |
460 mSignInState.callback.onSignInComplete(); | 459 mSignInState.callback.onSignInComplete(); |
461 } | 460 } |
462 | 461 |
463 // Trigger token requests via native. | 462 // Trigger token requests via native. |
464 logInSignedInUser(); | 463 logInSignedInUser(); |
465 | 464 |
466 if (mSignInState.isInteractive()) { | 465 if (mSignInState.isInteractive()) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 public void signOut(Runnable callback, WipeDataHooks wipeDataHooks) { | 525 public void signOut(Runnable callback, WipeDataHooks wipeDataHooks) { |
527 mSignOutInProgress = true; | 526 mSignOutInProgress = true; |
528 mSignOutCallback = callback; | 527 mSignOutCallback = callback; |
529 | 528 |
530 boolean wipeData = getManagementDomain() != null; | 529 boolean wipeData = getManagementDomain() != null; |
531 Log.d(TAG, "Signing out, wipe data? " + wipeData); | 530 Log.d(TAG, "Signing out, wipe data? " + wipeData); |
532 | 531 |
533 // Native signout must happen before resetting the account so data is de
leted correctly. | 532 // Native signout must happen before resetting the account so data is de
leted correctly. |
534 // http://crbug.com/589028 | 533 // http://crbug.com/589028 |
535 nativeSignOut(mNativeSigninManagerAndroid); | 534 nativeSignOut(mNativeSigninManagerAndroid); |
536 ChromeSigninController.get(mContext).setSignedInAccountName(null); | 535 ChromeSigninController.get().setSignedInAccountName(null); |
537 AndroidSyncSettings.updateAccount(mContext, null); | 536 AndroidSyncSettings.updateAccount(mContext, null); |
538 | 537 |
539 if (wipeData) { | 538 if (wipeData) { |
540 wipeProfileData(wipeDataHooks); | 539 wipeProfileData(wipeDataHooks); |
541 } else { | 540 } else { |
542 onSignOutDone(); | 541 onSignOutDone(); |
543 } | 542 } |
544 | 543 |
545 AccountTrackerService.get(mContext).invalidateAccountSeedStatus(true); | 544 AccountTrackerService.get().invalidateAccountSeedStatus(true); |
546 } | 545 } |
547 | 546 |
548 /** | 547 /** |
549 * Returns the management domain if the signed in account is managed, otherw
ise returns null. | 548 * Returns the management domain if the signed in account is managed, otherw
ise returns null. |
550 */ | 549 */ |
551 public String getManagementDomain() { | 550 public String getManagementDomain() { |
552 return nativeGetManagementDomain(mNativeSigninManagerAndroid); | 551 return nativeGetManagementDomain(mNativeSigninManagerAndroid); |
553 } | 552 } |
554 | 553 |
555 public void logInSignedInUser() { | 554 public void logInSignedInUser() { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 private native void nativeOnSignInCompleted(long nativeSigninManagerAndroid,
String username); | 676 private native void nativeOnSignInCompleted(long nativeSigninManagerAndroid,
String username); |
678 private native void nativeSignOut(long nativeSigninManagerAndroid); | 677 private native void nativeSignOut(long nativeSigninManagerAndroid); |
679 private native String nativeGetManagementDomain(long nativeSigninManagerAndr
oid); | 678 private native String nativeGetManagementDomain(long nativeSigninManagerAndr
oid); |
680 private native void nativeWipeProfileData(long nativeSigninManagerAndroid, W
ipeDataHooks hooks); | 679 private native void nativeWipeProfileData(long nativeSigninManagerAndroid, W
ipeDataHooks hooks); |
681 private native void nativeClearLastSignedInUser(long nativeSigninManagerAndr
oid); | 680 private native void nativeClearLastSignedInUser(long nativeSigninManagerAndr
oid); |
682 private native void nativeLogInSignedInUser(long nativeSigninManagerAndroid)
; | 681 private native void nativeLogInSignedInUser(long nativeSigninManagerAndroid)
; |
683 private native boolean nativeIsSignedInOnNative(long nativeSigninManagerAndr
oid); | 682 private native boolean nativeIsSignedInOnNative(long nativeSigninManagerAndr
oid); |
684 private native void nativeProhibitSignout( | 683 private native void nativeProhibitSignout( |
685 long nativeSigninManagerAndroid, boolean prohibitSignout); | 684 long nativeSigninManagerAndroid, boolean prohibitSignout); |
686 } | 685 } |
OLD | NEW |