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 #include "components/signin/ios/browser/profile_oauth2_token_service_ios.h" | 5 #include "components/signin/ios/browser/profile_oauth2_token_service_ios.h" |
6 | 6 |
7 #include <Foundation/Foundation.h> | 7 #include <Foundation/Foundation.h> |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 DCHECK(!primary_account_id.empty()); | 205 DCHECK(!primary_account_id.empty()); |
206 | 206 |
207 GetProvider()->InitializeSharedAuthentication(); | 207 GetProvider()->InitializeSharedAuthentication(); |
208 ReloadCredentials(); | 208 ReloadCredentials(); |
209 FireRefreshTokensLoaded(); | 209 FireRefreshTokensLoaded(); |
210 } | 210 } |
211 | 211 |
212 void ProfileOAuth2TokenServiceIOS::ReloadCredentials() { | 212 void ProfileOAuth2TokenServiceIOS::ReloadCredentials() { |
213 DCHECK(thread_checker_.CalledOnValidThread()); | 213 DCHECK(thread_checker_.CalledOnValidThread()); |
214 | 214 |
215 ScopedBacthChange batch(this); | 215 ScopedBatchChange batch(this); |
216 | 216 |
217 // Remove all old accounts that do not appear in |new_accounts| and then | 217 // Remove all old accounts that do not appear in |new_accounts| and then |
218 // load |new_accounts|. | 218 // load |new_accounts|. |
219 std::vector<std::string> new_accounts(GetProvider()->GetAllAccountIds()); | 219 std::vector<std::string> new_accounts(GetProvider()->GetAllAccountIds()); |
220 std::vector<std::string> old_accounts(GetAccounts()); | 220 std::vector<std::string> old_accounts(GetAccounts()); |
221 for (auto i = old_accounts.begin(); i != old_accounts.end(); ++i) { | 221 for (auto i = old_accounts.begin(); i != old_accounts.end(); ++i) { |
222 if (std::find(new_accounts.begin(), new_accounts.end(), *i) == | 222 if (std::find(new_accounts.begin(), new_accounts.end(), *i) == |
223 new_accounts.end()) { | 223 new_accounts.end()) { |
224 RemoveAccount(*i); | 224 RemoveAccount(*i); |
225 } | 225 } |
226 } | 226 } |
227 | 227 |
228 // Load all new_accounts. | 228 // Load all new_accounts. |
229 for (auto i = new_accounts.begin(); i != new_accounts.end(); ++i) { | 229 for (auto i = new_accounts.begin(); i != new_accounts.end(); ++i) { |
230 AddOrUpdateAccount(*i); | 230 AddOrUpdateAccount(*i); |
231 } | 231 } |
232 } | 232 } |
233 | 233 |
234 void ProfileOAuth2TokenServiceIOS::UpdateCredentials( | 234 void ProfileOAuth2TokenServiceIOS::UpdateCredentials( |
235 const std::string& account_id, | 235 const std::string& account_id, |
236 const std::string& refresh_token) { | 236 const std::string& refresh_token) { |
237 DCHECK(thread_checker_.CalledOnValidThread()); | 237 DCHECK(thread_checker_.CalledOnValidThread()); |
238 NOTREACHED() << "Unexpected call to UpdateCredentials when using shared " | 238 NOTREACHED() << "Unexpected call to UpdateCredentials when using shared " |
239 "authentication."; | 239 "authentication."; |
240 } | 240 } |
241 | 241 |
242 void ProfileOAuth2TokenServiceIOS::RevokeAllCredentials() { | 242 void ProfileOAuth2TokenServiceIOS::RevokeAllCredentials() { |
243 DCHECK(thread_checker_.CalledOnValidThread()); | 243 DCHECK(thread_checker_.CalledOnValidThread()); |
244 | 244 |
245 ScopedBacthChange batch(this); | 245 ScopedBatchChange batch(this); |
246 CancelAllRequests(); | 246 CancelAllRequests(); |
247 ClearCache(); | 247 ClearCache(); |
248 AccountInfoMap toRemove = accounts_; | 248 AccountInfoMap toRemove = accounts_; |
249 for (AccountInfoMap::iterator i = toRemove.begin(); i != toRemove.end(); ++i) | 249 for (AccountInfoMap::iterator i = toRemove.begin(); i != toRemove.end(); ++i) |
250 RemoveAccount(i->first); | 250 RemoveAccount(i->first); |
251 | 251 |
252 DCHECK_EQ(0u, accounts_.size()); | 252 DCHECK_EQ(0u, accounts_.size()); |
253 } | 253 } |
254 | 254 |
255 OAuth2AccessTokenFetcher* | 255 OAuth2AccessTokenFetcher* |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 DCHECK(thread_checker_.CalledOnValidThread()); | 343 DCHECK(thread_checker_.CalledOnValidThread()); |
344 DCHECK(!account_id.empty()); | 344 DCHECK(!account_id.empty()); |
345 | 345 |
346 if (accounts_.count(account_id) > 0) { | 346 if (accounts_.count(account_id) > 0) { |
347 CancelRequestsForAccount(account_id); | 347 CancelRequestsForAccount(account_id); |
348 ClearCacheForAccount(account_id); | 348 ClearCacheForAccount(account_id); |
349 accounts_.erase(account_id); | 349 accounts_.erase(account_id); |
350 FireRefreshTokenRevoked(account_id); | 350 FireRefreshTokenRevoked(account_id); |
351 } | 351 } |
352 } | 352 } |
OLD | NEW |