OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.childaccounts; | 5 package org.chromium.chrome.browser.childaccounts; |
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 | 10 |
11 import org.chromium.base.Callback; | 11 import org.chromium.base.Callback; |
| 12 import org.chromium.base.ContextUtils; |
12 import org.chromium.base.ThreadUtils; | 13 import org.chromium.base.ThreadUtils; |
13 import org.chromium.base.annotations.CalledByNative; | 14 import org.chromium.base.annotations.CalledByNative; |
14 import org.chromium.components.signin.AccountManagerHelper; | 15 import org.chromium.components.signin.AccountManagerHelper; |
15 import org.chromium.ui.base.WindowAndroid; | 16 import org.chromium.ui.base.WindowAndroid; |
16 | 17 |
17 /** | 18 /** |
18 * This class serves as a simple interface for querying the child account inform
ation. It has two | 19 * This class serves as a simple interface for querying the child account inform
ation. It has two |
19 * methods for querying the child account information; checkHasChildAccount(...)
which is | 20 * methods for querying the child account information; checkHasChildAccount(...)
which is |
20 * asynchronous and queries the system directly for the information and the sync
hronous | 21 * asynchronous and queries the system directly for the information and the sync
hronous |
21 * isChildAccount() which asks the native side assuming it has been set correctl
y already. | 22 * isChildAccount() which asks the native side assuming it has been set correctl
y already. |
(...skipping 12 matching lines...) Expand all Loading... |
34 // Only for static usage. | 35 // Only for static usage. |
35 } | 36 } |
36 | 37 |
37 /** | 38 /** |
38 * Checks for the presence of child accounts on the device. | 39 * Checks for the presence of child accounts on the device. |
39 * | 40 * |
40 * @param callback A callback which will be called with the result. | 41 * @param callback A callback which will be called with the result. |
41 */ | 42 */ |
42 public static void checkHasChildAccount(Context context, final Callback<Bool
ean> callback) { | 43 public static void checkHasChildAccount(Context context, final Callback<Bool
ean> callback) { |
43 ThreadUtils.assertOnUiThread(); | 44 ThreadUtils.assertOnUiThread(); |
44 final AccountManagerHelper helper = AccountManagerHelper.get(); | 45 final AccountManagerHelper helper = AccountManagerHelper.get(context); |
45 helper.getGoogleAccounts(new Callback<Account[]>() { | 46 helper.getGoogleAccounts(new Callback<Account[]>() { |
46 @Override | 47 @Override |
47 public void onResult(Account[] accounts) { | 48 public void onResult(Account[] accounts) { |
48 if (accounts.length != 1) { | 49 if (accounts.length != 1) { |
49 callback.onResult(false); | 50 callback.onResult(false); |
50 } else { | 51 } else { |
51 helper.checkChildAccount(accounts[0], callback); | 52 helper.checkChildAccount(accounts[0], callback); |
52 } | 53 } |
53 } | 54 } |
54 }); | 55 }); |
(...skipping 27 matching lines...) Expand all Loading... |
82 ThreadUtils.postOnUiThread(new Runnable() { | 83 ThreadUtils.postOnUiThread(new Runnable() { |
83 @Override | 84 @Override |
84 public void run() { | 85 public void run() { |
85 nativeOnReauthenticationResult(nativeCallback, false); | 86 nativeOnReauthenticationResult(nativeCallback, false); |
86 } | 87 } |
87 }); | 88 }); |
88 return; | 89 return; |
89 } | 90 } |
90 | 91 |
91 Account account = AccountManagerHelper.createAccountFromName(accountName
); | 92 Account account = AccountManagerHelper.createAccountFromName(accountName
); |
92 AccountManagerHelper.get().updateCredentials(account, activity, new Call
back<Boolean>() { | 93 AccountManagerHelper.get(ContextUtils.getApplicationContext()) |
93 @Override | 94 .updateCredentials(account, activity, new Callback<Boolean>() { |
94 public void onResult(Boolean result) { | 95 @Override |
95 nativeOnReauthenticationResult(nativeCallback, result); | 96 public void onResult(Boolean result) { |
96 } | 97 nativeOnReauthenticationResult(nativeCallback, result); |
97 }); | 98 } |
| 99 }); |
98 } | 100 } |
99 | 101 |
100 private static native boolean nativeIsChildAccount(); | 102 private static native boolean nativeIsChildAccount(); |
101 | 103 |
102 private static native void nativeListenForChildStatusReceived(Callback<Boole
an> callback); | 104 private static native void nativeListenForChildStatusReceived(Callback<Boole
an> callback); |
103 | 105 |
104 private static native void nativeOnReauthenticationResult( | 106 private static native void nativeOnReauthenticationResult( |
105 long callbackPtr, boolean reauthSuccessful); | 107 long callbackPtr, boolean reauthSuccessful); |
106 } | 108 } |
OLD | NEW |