OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.content.Context; | 8 import android.content.Context; |
9 import android.os.AsyncTask; | 9 import android.os.AsyncTask; |
10 | 10 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 sInstance = new SigninHelper(context.getApplicationContext()); | 114 sInstance = new SigninHelper(context.getApplicationContext()); |
115 } | 115 } |
116 } | 116 } |
117 return sInstance; | 117 return sInstance; |
118 } | 118 } |
119 | 119 |
120 private SigninHelper(Context context) { | 120 private SigninHelper(Context context) { |
121 mContext = context; | 121 mContext = context; |
122 mProfileSyncService = ProfileSyncService.get(); | 122 mProfileSyncService = ProfileSyncService.get(); |
123 mSigninManager = SigninManager.get(mContext); | 123 mSigninManager = SigninManager.get(mContext); |
124 mAccountTrackerService = AccountTrackerService.get(mContext); | 124 mAccountTrackerService = AccountTrackerService.get(); |
125 mOAuth2TokenService = OAuth2TokenService.getForProfile(Profile.getLastUs
edProfile()); | 125 mOAuth2TokenService = OAuth2TokenService.getForProfile(Profile.getLastUs
edProfile()); |
126 mChromeSigninController = ChromeSigninController.get(mContext); | 126 mChromeSigninController = ChromeSigninController.get(); |
127 } | 127 } |
128 | 128 |
129 public void validateAccountSettings(boolean accountsChanged) { | 129 public void validateAccountSettings(boolean accountsChanged) { |
130 // Ensure System accounts have been seeded. | 130 // Ensure System accounts have been seeded. |
131 mAccountTrackerService.checkAndSeedSystemAccounts(); | 131 mAccountTrackerService.checkAndSeedSystemAccounts(); |
132 if (!accountsChanged) { | 132 if (!accountsChanged) { |
133 mAccountTrackerService.validateSystemAccounts(); | 133 mAccountTrackerService.validateSystemAccounts(); |
134 } | 134 } |
135 | 135 |
136 Account syncAccount = mChromeSigninController.getSignedInUser(); | 136 Account syncAccount = mChromeSigninController.getSignedInUser(); |
137 if (syncAccount == null) { | 137 if (syncAccount == null) { |
138 ChromePreferenceManager chromePreferenceManager = ChromePreferenceMa
nager.getInstance(); | 138 ChromePreferenceManager chromePreferenceManager = ChromePreferenceMa
nager.getInstance(); |
139 if (chromePreferenceManager.getShowSigninPromo()) return; | 139 if (chromePreferenceManager.getShowSigninPromo()) return; |
140 | 140 |
141 // Never shows a signin promo if user has manually disconnected. | 141 // Never shows a signin promo if user has manually disconnected. |
142 String lastSyncAccountName = | 142 String lastSyncAccountName = |
143 PrefServiceBridge.getInstance().getSyncLastAccountName(); | 143 PrefServiceBridge.getInstance().getSyncLastAccountName(); |
144 if (lastSyncAccountName != null && !lastSyncAccountName.isEmpty()) r
eturn; | 144 if (lastSyncAccountName != null && !lastSyncAccountName.isEmpty()) r
eturn; |
145 | 145 |
146 if (!chromePreferenceManager.getSigninPromoShown() | 146 if (!chromePreferenceManager.getSigninPromoShown() |
147 && AccountManagerHelper.get(mContext).getGoogleAccountNames(
).size() > 0) { | 147 && AccountManagerHelper.get().getGoogleAccountNames().size()
> 0) { |
148 chromePreferenceManager.setShowSigninPromo(true); | 148 chromePreferenceManager.setShowSigninPromo(true); |
149 } | 149 } |
150 | 150 |
151 return; | 151 return; |
152 } | 152 } |
153 | 153 |
154 String renamedAccount = getNewSignedInAccountName(mContext); | 154 String renamedAccount = getNewSignedInAccountName(mContext); |
155 if (accountsChanged && renamedAccount != null) { | 155 if (accountsChanged && renamedAccount != null) { |
156 handleAccountRename(ChromeSigninController.get(mContext).getSignedIn
AccountName(), | 156 handleAccountRename( |
157 renamedAccount); | 157 ChromeSigninController.get().getSignedInAccountName(), renam
edAccount); |
158 return; | 158 return; |
159 } | 159 } |
160 | 160 |
161 // Always check for account deleted. | 161 // Always check for account deleted. |
162 if (!accountExists(mContext, syncAccount)) { | 162 if (!accountExists(mContext, syncAccount)) { |
163 // It is possible that Chrome got to this point without account | 163 // It is possible that Chrome got to this point without account |
164 // rename notification. Let us signout before doing a rename. | 164 // rename notification. Let us signout before doing a rename. |
165 // updateAccountRenameData(mContext, new SystemAccountChangeEventChe
cker()); | 165 // updateAccountRenameData(mContext, new SystemAccountChangeEventChe
cker()); |
166 AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>()
{ | 166 AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>()
{ |
167 @Override | 167 @Override |
(...skipping 17 matching lines...) Expand all Loading... |
185 } | 185 } |
186 } | 186 } |
187 }; | 187 }; |
188 task.execute(); | 188 task.execute(); |
189 return; | 189 return; |
190 } | 190 } |
191 | 191 |
192 if (accountsChanged) { | 192 if (accountsChanged) { |
193 // Account details have changed so inform the token service that cre
dentials | 193 // Account details have changed so inform the token service that cre
dentials |
194 // should now be available. | 194 // should now be available. |
195 mOAuth2TokenService.validateAccounts(mContext, false); | 195 mOAuth2TokenService.validateAccounts(false); |
196 } | 196 } |
197 | 197 |
198 if (mProfileSyncService != null && AndroidSyncSettings.isSyncEnabled(mCo
ntext)) { | 198 if (mProfileSyncService != null && AndroidSyncSettings.isSyncEnabled(mCo
ntext)) { |
199 if (mProfileSyncService.isFirstSetupComplete()) { | 199 if (mProfileSyncService.isFirstSetupComplete()) { |
200 if (accountsChanged) { | 200 if (accountsChanged) { |
201 // Nudge the syncer to ensure it does a full sync. | 201 // Nudge the syncer to ensure it does a full sync. |
202 InvalidationServiceFactory.getForProfile(Profile.getLastUsed
Profile()) | 202 InvalidationServiceFactory.getForProfile(Profile.getLastUsed
Profile()) |
203 .requestSyncFromNativeChromeForAllTypes(
); | 203 .requestSyncFromNativeChromeForAllTypes(
); |
204 } | 204 } |
205 } else { | 205 } else { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 } | 248 } |
249 validateAccountSettings(true); | 249 validateAccountSettings(true); |
250 } | 250 } |
251 | 251 |
252 @Override | 252 @Override |
253 public void onSignInAborted() {} | 253 public void onSignInAborted() {} |
254 }); | 254 }); |
255 } | 255 } |
256 | 256 |
257 private static boolean accountExists(Context context, Account account) { | 257 private static boolean accountExists(Context context, Account account) { |
258 Account[] accounts = AccountManagerHelper.get(context).getGoogleAccounts
(); | 258 Account[] accounts = AccountManagerHelper.get().getGoogleAccounts(); |
259 for (Account a : accounts) { | 259 for (Account a : accounts) { |
260 if (a.equals(account)) { | 260 if (a.equals(account)) { |
261 return true; | 261 return true; |
262 } | 262 } |
263 } | 263 } |
264 return false; | 264 return false; |
265 } | 265 } |
266 | 266 |
267 /** | 267 /** |
268 * Sets the ACCOUNTS_CHANGED_PREFS_KEY to true. | 268 * Sets the ACCOUNTS_CHANGED_PREFS_KEY to true. |
(...skipping 23 matching lines...) Expand all Loading... |
292 private static String getLastKnownAccountName(Context context) { | 292 private static String getLastKnownAccountName(Context context) { |
293 // This is the last known name of the currently signed in user. | 293 // This is the last known name of the currently signed in user. |
294 // It can be: | 294 // It can be: |
295 // 1. The signed in account name known to the ChromeSigninController. | 295 // 1. The signed in account name known to the ChromeSigninController. |
296 // 2. A pending newly choosen name that is differed from the one known
to | 296 // 2. A pending newly choosen name that is differed from the one known
to |
297 // ChromeSigninController but is stored in ACCOUNT_RENAMED_PREFS_KEY
. | 297 // ChromeSigninController but is stored in ACCOUNT_RENAMED_PREFS_KEY
. |
298 String name = ContextUtils.getAppSharedPreferences().getString( | 298 String name = ContextUtils.getAppSharedPreferences().getString( |
299 ACCOUNT_RENAMED_PREFS_KEY, null); | 299 ACCOUNT_RENAMED_PREFS_KEY, null); |
300 | 300 |
301 // If there is no pending rename, take the name known to ChromeSigninCon
troller. | 301 // If there is no pending rename, take the name known to ChromeSigninCon
troller. |
302 return name == null ? ChromeSigninController.get(context).getSignedInAcc
ountName() : name; | 302 return name == null ? ChromeSigninController.get().getSignedInAccountNam
e() : name; |
303 } | 303 } |
304 | 304 |
305 public static void updateAccountRenameData(Context context) { | 305 public static void updateAccountRenameData(Context context) { |
306 updateAccountRenameData(context, new SystemAccountChangeEventChecker()); | 306 updateAccountRenameData(context, new SystemAccountChangeEventChecker()); |
307 } | 307 } |
308 | 308 |
309 @VisibleForTesting | 309 @VisibleForTesting |
310 public static void updateAccountRenameData(Context context, AccountChangeEve
ntChecker checker) { | 310 public static void updateAccountRenameData(Context context, AccountChangeEve
ntChecker checker) { |
311 String curName = getLastKnownAccountName(context); | 311 String curName = getLastKnownAccountName(context); |
312 | 312 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 .getBoolean(ACCOUNTS_CHANGED_PREFS_KEY, false)) { | 372 .getBoolean(ACCOUNTS_CHANGED_PREFS_KEY, false)) { |
373 // Clear the value in prefs. | 373 // Clear the value in prefs. |
374 ContextUtils.getAppSharedPreferences() | 374 ContextUtils.getAppSharedPreferences() |
375 .edit().putBoolean(ACCOUNTS_CHANGED_PREFS_KEY, false).apply(
); | 375 .edit().putBoolean(ACCOUNTS_CHANGED_PREFS_KEY, false).apply(
); |
376 return true; | 376 return true; |
377 } else { | 377 } else { |
378 return false; | 378 return false; |
379 } | 379 } |
380 } | 380 } |
381 } | 381 } |
OLD | NEW |