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/core/browser/account_tracker_service.h" | 5 #include "components/signin/core/browser/account_tracker_service.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 } | 178 } |
179 | 179 |
180 void AccountTrackerService::NotifyAccountRemoved(const AccountState& state) { | 180 void AccountTrackerService::NotifyAccountRemoved(const AccountState& state) { |
181 DCHECK(!state.info.gaia.empty()); | 181 DCHECK(!state.info.gaia.empty()); |
182 FOR_EACH_OBSERVER( | 182 FOR_EACH_OBSERVER( |
183 Observer, observer_list_, OnAccountRemoved(state.info)); | 183 Observer, observer_list_, OnAccountRemoved(state.info)); |
184 } | 184 } |
185 | 185 |
186 void AccountTrackerService::StartTrackingAccount( | 186 void AccountTrackerService::StartTrackingAccount( |
187 const std::string& account_id) { | 187 const std::string& account_id) { |
188 if (!ContainsKey(accounts_, account_id)) { | 188 if (!base::ContainsKey(accounts_, account_id)) { |
189 DVLOG(1) << "StartTracking " << account_id; | 189 DVLOG(1) << "StartTracking " << account_id; |
190 AccountState state; | 190 AccountState state; |
191 state.info.account_id = account_id; | 191 state.info.account_id = account_id; |
192 state.info.is_child_account = false; | 192 state.info.is_child_account = false; |
193 accounts_.insert(make_pair(account_id, state)); | 193 accounts_.insert(make_pair(account_id, state)); |
194 } | 194 } |
195 } | 195 } |
196 | 196 |
197 void AccountTrackerService::StopTrackingAccount(const std::string& account_id) { | 197 void AccountTrackerService::StopTrackingAccount(const std::string& account_id) { |
198 DVLOG(1) << "StopTracking " << account_id; | 198 DVLOG(1) << "StopTracking " << account_id; |
199 if (ContainsKey(accounts_, account_id)) { | 199 if (base::ContainsKey(accounts_, account_id)) { |
200 AccountState& state = accounts_[account_id]; | 200 AccountState& state = accounts_[account_id]; |
201 RemoveFromPrefs(state); | 201 RemoveFromPrefs(state); |
202 if (!state.info.gaia.empty()) | 202 if (!state.info.gaia.empty()) |
203 NotifyAccountRemoved(state); | 203 NotifyAccountRemoved(state); |
204 | 204 |
205 accounts_.erase(account_id); | 205 accounts_.erase(account_id); |
206 } | 206 } |
207 } | 207 } |
208 | 208 |
209 void AccountTrackerService::SetAccountStateFromUserInfo( | 209 void AccountTrackerService::SetAccountStateFromUserInfo( |
210 const std::string& account_id, | 210 const std::string& account_id, |
211 const base::DictionaryValue* user_info) { | 211 const base::DictionaryValue* user_info) { |
212 DCHECK(ContainsKey(accounts_, account_id)); | 212 DCHECK(base::ContainsKey(accounts_, account_id)); |
213 AccountState& state = accounts_[account_id]; | 213 AccountState& state = accounts_[account_id]; |
214 | 214 |
215 std::string gaia_id; | 215 std::string gaia_id; |
216 std::string email; | 216 std::string email; |
217 if (user_info->GetString("id", &gaia_id) && | 217 if (user_info->GetString("id", &gaia_id) && |
218 user_info->GetString("email", &email)) { | 218 user_info->GetString("email", &email)) { |
219 state.info.gaia = gaia_id; | 219 state.info.gaia = gaia_id; |
220 state.info.email = email; | 220 state.info.email = email; |
221 | 221 |
222 std::string hosted_domain; | 222 std::string hosted_domain; |
(...skipping 14 matching lines...) Expand all Loading... |
237 state.info.picture_url = kNoPictureURLFound; | 237 state.info.picture_url = kNoPictureURLFound; |
238 } | 238 } |
239 } | 239 } |
240 if (state.info.IsValid()) | 240 if (state.info.IsValid()) |
241 NotifyAccountUpdated(state); | 241 NotifyAccountUpdated(state); |
242 SaveToPrefs(state); | 242 SaveToPrefs(state); |
243 } | 243 } |
244 | 244 |
245 void AccountTrackerService::SetIsChildAccount(const std::string& account_id, | 245 void AccountTrackerService::SetIsChildAccount(const std::string& account_id, |
246 const bool& is_child_account) { | 246 const bool& is_child_account) { |
247 DCHECK(ContainsKey(accounts_, account_id)); | 247 DCHECK(base::ContainsKey(accounts_, account_id)); |
248 AccountState& state = accounts_[account_id]; | 248 AccountState& state = accounts_[account_id]; |
249 if (state.info.is_child_account == is_child_account) | 249 if (state.info.is_child_account == is_child_account) |
250 return; | 250 return; |
251 state.info.is_child_account = is_child_account; | 251 state.info.is_child_account = is_child_account; |
252 if (state.info.IsValid()) | 252 if (state.info.IsValid()) |
253 NotifyAccountUpdated(state); | 253 NotifyAccountUpdated(state); |
254 SaveToPrefs(state); | 254 SaveToPrefs(state); |
255 } | 255 } |
256 | 256 |
257 bool AccountTrackerService::IsMigratable() const { | 257 bool AccountTrackerService::IsMigratable() const { |
(...skipping 14 matching lines...) Expand all Loading... |
272 void AccountTrackerService::MigrateToGaiaId() { | 272 void AccountTrackerService::MigrateToGaiaId() { |
273 std::set<std::string> to_remove; | 273 std::set<std::string> to_remove; |
274 std::map<std::string, AccountState> migrated_accounts; | 274 std::map<std::string, AccountState> migrated_accounts; |
275 for (std::map<std::string, AccountState>::const_iterator it = | 275 for (std::map<std::string, AccountState>::const_iterator it = |
276 accounts_.begin(); | 276 accounts_.begin(); |
277 it != accounts_.end(); ++it) { | 277 it != accounts_.end(); ++it) { |
278 const AccountState& state = it->second; | 278 const AccountState& state = it->second; |
279 std::string account_id = it->first; | 279 std::string account_id = it->first; |
280 if (account_id != state.info.gaia) { | 280 if (account_id != state.info.gaia) { |
281 std::string new_account_id = state.info.gaia; | 281 std::string new_account_id = state.info.gaia; |
282 if (!ContainsKey(accounts_, new_account_id)) { | 282 if (!base::ContainsKey(accounts_, new_account_id)) { |
283 AccountState new_state = state; | 283 AccountState new_state = state; |
284 new_state.info.account_id = new_account_id; | 284 new_state.info.account_id = new_account_id; |
285 migrated_accounts.insert(make_pair(new_account_id, new_state)); | 285 migrated_accounts.insert(make_pair(new_account_id, new_state)); |
286 SaveToPrefs(new_state); | 286 SaveToPrefs(new_state); |
287 } | 287 } |
288 to_remove.insert(account_id); | 288 to_remove.insert(account_id); |
289 } | 289 } |
290 } | 290 } |
291 | 291 |
292 // Remove any obsolete account. | 292 // Remove any obsolete account. |
293 for (auto account_id : to_remove) { | 293 for (auto account_id : to_remove) { |
294 if (ContainsKey(accounts_, account_id)) { | 294 if (base::ContainsKey(accounts_, account_id)) { |
295 AccountState& state = accounts_[account_id]; | 295 AccountState& state = accounts_[account_id]; |
296 RemoveFromPrefs(state); | 296 RemoveFromPrefs(state); |
297 accounts_.erase(account_id); | 297 accounts_.erase(account_id); |
298 } | 298 } |
299 } | 299 } |
300 | 300 |
301 for (std::map<std::string, AccountState>::const_iterator it = | 301 for (std::map<std::string, AccountState>::const_iterator it = |
302 migrated_accounts.begin(); | 302 migrated_accounts.begin(); |
303 it != migrated_accounts.end(); ++it) { | 303 it != migrated_accounts.end(); ++it) { |
304 accounts_.insert(*it); | 304 accounts_.insert(*it); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 return gaia; | 462 return gaia; |
463 default: | 463 default: |
464 NOTREACHED(); | 464 NOTREACHED(); |
465 return email; | 465 return email; |
466 } | 466 } |
467 } | 467 } |
468 | 468 |
469 std::string AccountTrackerService::SeedAccountInfo(const std::string& gaia, | 469 std::string AccountTrackerService::SeedAccountInfo(const std::string& gaia, |
470 const std::string& email) { | 470 const std::string& email) { |
471 const std::string account_id = PickAccountIdForAccount(gaia, email); | 471 const std::string account_id = PickAccountIdForAccount(gaia, email); |
472 const bool already_exists = ContainsKey(accounts_, account_id); | 472 const bool already_exists = base::ContainsKey(accounts_, account_id); |
473 StartTrackingAccount(account_id); | 473 StartTrackingAccount(account_id); |
474 AccountState& state = accounts_[account_id]; | 474 AccountState& state = accounts_[account_id]; |
475 DCHECK(!already_exists || state.info.gaia.empty() || state.info.gaia == gaia); | 475 DCHECK(!already_exists || state.info.gaia.empty() || state.info.gaia == gaia); |
476 state.info.gaia = gaia; | 476 state.info.gaia = gaia; |
477 state.info.email = email; | 477 state.info.email = email; |
478 SaveToPrefs(state); | 478 SaveToPrefs(state); |
479 | 479 |
480 DVLOG(1) << "AccountTrackerService::SeedAccountInfo" | 480 DVLOG(1) << "AccountTrackerService::SeedAccountInfo" |
481 << " account_id=" << account_id | 481 << " account_id=" << account_id |
482 << " gaia_id=" << gaia | 482 << " gaia_id=" << gaia |
483 << " email=" << email; | 483 << " email=" << email; |
484 | 484 |
485 return account_id; | 485 return account_id; |
486 } | 486 } |
487 | 487 |
488 std::string AccountTrackerService::SeedAccountInfo(AccountInfo info) { | 488 std::string AccountTrackerService::SeedAccountInfo(AccountInfo info) { |
489 info.account_id = PickAccountIdForAccount(info.gaia, info.email); | 489 info.account_id = PickAccountIdForAccount(info.gaia, info.email); |
490 | 490 |
491 if (!ContainsKey(accounts_, info.account_id)) { | 491 if (!base::ContainsKey(accounts_, info.account_id)) { |
492 StartTrackingAccount(info.account_id); | 492 StartTrackingAccount(info.account_id); |
493 } | 493 } |
494 | 494 |
495 AccountState& state = accounts_[info.account_id]; | 495 AccountState& state = accounts_[info.account_id]; |
496 // Update the missing fields in |state.info| with |info|. | 496 // Update the missing fields in |state.info| with |info|. |
497 if (state.info.UpdateWith(info)) { | 497 if (state.info.UpdateWith(info)) { |
498 if (state.info.IsValid()) { | 498 if (state.info.IsValid()) { |
499 // Notify only if the account info is fully updated, as it is equivalent | 499 // Notify only if the account info is fully updated, as it is equivalent |
500 // to having the account fully fetched. | 500 // to having the account fully fetched. |
501 NotifyAccountUpdated(state); | 501 NotifyAccountUpdated(state); |
502 } | 502 } |
503 SaveToPrefs(state); | 503 SaveToPrefs(state); |
504 } | 504 } |
505 return info.account_id; | 505 return info.account_id; |
506 } | 506 } |
507 | 507 |
508 void AccountTrackerService::RemoveAccount(const std::string& account_id) { | 508 void AccountTrackerService::RemoveAccount(const std::string& account_id) { |
509 StopTrackingAccount(account_id); | 509 StopTrackingAccount(account_id); |
510 } | 510 } |
OLD | NEW |