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().addSystemAccountsSeededListener(this); | 202 AccountTrackerService.get(mContext).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().getSignedInUser() == null && isS
igninSupported(); | 239 && ChromeSigninController.get(mContext).getSignedInUser() == nul
l |
| 240 && isSigninSupported(); |
240 } | 241 } |
241 | 242 |
242 /** | 243 /** |
243 * Returns true if signin is disabled by policy. | 244 * Returns true if signin is disabled by policy. |
244 */ | 245 */ |
245 public boolean isSigninDisabledByPolicy() { | 246 public boolean isSigninDisabledByPolicy() { |
246 return !mSigninAllowedByPolicy; | 247 return !mSigninAllowedByPolicy; |
247 } | 248 } |
248 | 249 |
249 /** | 250 /** |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 notifySignInAllowedChanged(); | 360 notifySignInAllowedChanged(); |
360 | 361 |
361 progressSignInFlowSeedSystemAccounts(); | 362 progressSignInFlowSeedSystemAccounts(); |
362 } | 363 } |
363 | 364 |
364 /** | 365 /** |
365 * Same as above but retrieves the Account object for the given accountName. | 366 * Same as above but retrieves the Account object for the given accountName. |
366 */ | 367 */ |
367 public void signIn(String accountName, @Nullable final Activity activity, | 368 public void signIn(String accountName, @Nullable final Activity activity, |
368 @Nullable final SignInCallback callback) { | 369 @Nullable final SignInCallback callback) { |
369 AccountManagerHelper.get().getAccountFromName(accountName, new Callback<
Account>() { | 370 AccountManagerHelper.get(mContext).getAccountFromName(accountName, new C
allback<Account>() { |
370 @Override | 371 @Override |
371 public void onResult(Account account) { | 372 public void onResult(Account account) { |
372 signIn(account, activity, callback); | 373 signIn(account, activity, callback); |
373 } | 374 } |
374 }); | 375 }); |
375 } | 376 } |
376 | 377 |
377 private void progressSignInFlowSeedSystemAccounts() { | 378 private void progressSignInFlowSeedSystemAccounts() { |
378 if (AccountTrackerService.get().checkAndSeedSystemAccounts()) { | 379 if (AccountTrackerService.get(mContext).checkAndSeedSystemAccounts()) { |
379 progressSignInFlowCheckPolicy(); | 380 progressSignInFlowCheckPolicy(); |
380 } else if (AccountIdProvider.getInstance().canBeUsed()) { | 381 } else if (AccountIdProvider.getInstance().canBeUsed(mContext)) { |
381 mSignInState.blockedOnAccountSeeding = true; | 382 mSignInState.blockedOnAccountSeeding = true; |
382 } else { | 383 } else { |
383 Activity activity = mSignInState.activity; | 384 Activity activity = mSignInState.activity; |
384 UserRecoverableErrorHandler errorHandler = activity != null | 385 UserRecoverableErrorHandler errorHandler = activity != null |
385 ? new UserRecoverableErrorHandler.ModalDialog(activity, !isF
orceSigninEnabled()) | 386 ? new UserRecoverableErrorHandler.ModalDialog(activity, !isF
orceSigninEnabled()) |
386 : new UserRecoverableErrorHandler.SystemNotification(); | 387 : new UserRecoverableErrorHandler.SystemNotification(); |
387 ExternalAuthUtils.getInstance().canUseGooglePlayServices(mContext, e
rrorHandler); | 388 ExternalAuthUtils.getInstance().canUseGooglePlayServices(mContext, e
rrorHandler); |
388 Log.w(TAG, "Cancelling the sign-in process as Google Play services i
s unavailable"); | 389 Log.w(TAG, "Cancelling the sign-in process as Google Play services i
s unavailable"); |
389 abortSignIn(); | 390 abortSignIn(); |
390 } | 391 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 | 446 |
446 private void finishSignIn() { | 447 private void finishSignIn() { |
447 // This method should be called at most once per sign-in flow. | 448 // This method should be called at most once per sign-in flow. |
448 assert mSignInState != null; | 449 assert mSignInState != null; |
449 | 450 |
450 // Tell the native side that sign-in has completed. | 451 // Tell the native side that sign-in has completed. |
451 nativeOnSignInCompleted(mNativeSigninManagerAndroid, mSignInState.accoun
t.name); | 452 nativeOnSignInCompleted(mNativeSigninManagerAndroid, mSignInState.accoun
t.name); |
452 | 453 |
453 // Cache the signed-in account name. This must be done after the native
call, otherwise | 454 // Cache the signed-in account name. This must be done after the native
call, otherwise |
454 // sync tries to start without being signed in natively and crashes. | 455 // sync tries to start without being signed in natively and crashes. |
455 ChromeSigninController.get().setSignedInAccountName(mSignInState.account
.name); | 456 ChromeSigninController.get(mContext).setSignedInAccountName(mSignInState
.account.name); |
456 AndroidSyncSettings.updateAccount(mContext, mSignInState.account); | 457 AndroidSyncSettings.updateAccount(mContext, mSignInState.account); |
457 | 458 |
458 if (mSignInState.callback != null) { | 459 if (mSignInState.callback != null) { |
459 mSignInState.callback.onSignInComplete(); | 460 mSignInState.callback.onSignInComplete(); |
460 } | 461 } |
461 | 462 |
462 // Trigger token requests via native. | 463 // Trigger token requests via native. |
463 logInSignedInUser(); | 464 logInSignedInUser(); |
464 | 465 |
465 if (mSignInState.isInteractive()) { | 466 if (mSignInState.isInteractive()) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 public void signOut(Runnable callback, WipeDataHooks wipeDataHooks) { | 526 public void signOut(Runnable callback, WipeDataHooks wipeDataHooks) { |
526 mSignOutInProgress = true; | 527 mSignOutInProgress = true; |
527 mSignOutCallback = callback; | 528 mSignOutCallback = callback; |
528 | 529 |
529 boolean wipeData = getManagementDomain() != null; | 530 boolean wipeData = getManagementDomain() != null; |
530 Log.d(TAG, "Signing out, wipe data? " + wipeData); | 531 Log.d(TAG, "Signing out, wipe data? " + wipeData); |
531 | 532 |
532 // Native signout must happen before resetting the account so data is de
leted correctly. | 533 // Native signout must happen before resetting the account so data is de
leted correctly. |
533 // http://crbug.com/589028 | 534 // http://crbug.com/589028 |
534 nativeSignOut(mNativeSigninManagerAndroid); | 535 nativeSignOut(mNativeSigninManagerAndroid); |
535 ChromeSigninController.get().setSignedInAccountName(null); | 536 ChromeSigninController.get(mContext).setSignedInAccountName(null); |
536 AndroidSyncSettings.updateAccount(mContext, null); | 537 AndroidSyncSettings.updateAccount(mContext, null); |
537 | 538 |
538 if (wipeData) { | 539 if (wipeData) { |
539 wipeProfileData(wipeDataHooks); | 540 wipeProfileData(wipeDataHooks); |
540 } else { | 541 } else { |
541 onSignOutDone(); | 542 onSignOutDone(); |
542 } | 543 } |
543 | 544 |
544 AccountTrackerService.get().invalidateAccountSeedStatus(true); | 545 AccountTrackerService.get(mContext).invalidateAccountSeedStatus(true); |
545 } | 546 } |
546 | 547 |
547 /** | 548 /** |
548 * Returns the management domain if the signed in account is managed, otherw
ise returns null. | 549 * Returns the management domain if the signed in account is managed, otherw
ise returns null. |
549 */ | 550 */ |
550 public String getManagementDomain() { | 551 public String getManagementDomain() { |
551 return nativeGetManagementDomain(mNativeSigninManagerAndroid); | 552 return nativeGetManagementDomain(mNativeSigninManagerAndroid); |
552 } | 553 } |
553 | 554 |
554 public void logInSignedInUser() { | 555 public void logInSignedInUser() { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 private native void nativeOnSignInCompleted(long nativeSigninManagerAndroid,
String username); | 677 private native void nativeOnSignInCompleted(long nativeSigninManagerAndroid,
String username); |
677 private native void nativeSignOut(long nativeSigninManagerAndroid); | 678 private native void nativeSignOut(long nativeSigninManagerAndroid); |
678 private native String nativeGetManagementDomain(long nativeSigninManagerAndr
oid); | 679 private native String nativeGetManagementDomain(long nativeSigninManagerAndr
oid); |
679 private native void nativeWipeProfileData(long nativeSigninManagerAndroid, W
ipeDataHooks hooks); | 680 private native void nativeWipeProfileData(long nativeSigninManagerAndroid, W
ipeDataHooks hooks); |
680 private native void nativeClearLastSignedInUser(long nativeSigninManagerAndr
oid); | 681 private native void nativeClearLastSignedInUser(long nativeSigninManagerAndr
oid); |
681 private native void nativeLogInSignedInUser(long nativeSigninManagerAndroid)
; | 682 private native void nativeLogInSignedInUser(long nativeSigninManagerAndroid)
; |
682 private native boolean nativeIsSignedInOnNative(long nativeSigninManagerAndr
oid); | 683 private native boolean nativeIsSignedInOnNative(long nativeSigninManagerAndr
oid); |
683 private native void nativeProhibitSignout( | 684 private native void nativeProhibitSignout( |
684 long nativeSigninManagerAndroid, boolean prohibitSignout); | 685 long nativeSigninManagerAndroid, boolean prohibitSignout); |
685 } | 686 } |
OLD | NEW |