OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/profiles/profile_info_cache.h" | 5 #include "chrome/browser/profiles/profile_info_cache.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/i18n/case_conversion.h" | 10 #include "base/i18n/case_conversion.h" |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 } | 229 } |
230 | 230 |
231 void ProfileInfoCache::DeleteProfileFromCache(const FilePath& profile_path) { | 231 void ProfileInfoCache::DeleteProfileFromCache(const FilePath& profile_path) { |
232 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); | 232 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); |
233 DictionaryValue* cache = update.Get(); | 233 DictionaryValue* cache = update.Get(); |
234 | 234 |
235 std::string key = CacheKeyFromProfilePath(profile_path); | 235 std::string key = CacheKeyFromProfilePath(profile_path); |
236 DictionaryValue* info = NULL; | 236 DictionaryValue* info = NULL; |
237 cache->GetDictionary(key, &info); | 237 cache->GetDictionary(key, &info); |
238 string16 name; | 238 string16 name; |
239 info->GetString(kNameKey, &name); | 239 size_t index = GetIndexOfProfileWithPath(profile_path); |
240 if (IsUsingGAIANameOfProfileAtIndex(index)) | |
sail
2011/12/09 17:48:00
In all these places you should be able to just cal
SteveT
2011/12/09 18:20:21
Just what I wanted. Done here and below where appr
| |
241 name = GetGAIANameOfProfileAtIndex(index); | |
242 else | |
243 info->GetString(kNameKey, &name); | |
240 | 244 |
241 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 245 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, |
242 observer_list_, | 246 observer_list_, |
243 OnProfileRemoved(name)); | 247 OnProfileRemoved(name)); |
244 | 248 |
245 cache->Remove(key, NULL); | 249 cache->Remove(key, NULL); |
246 sorted_keys_.erase(std::find(sorted_keys_.begin(), sorted_keys_.end(), key)); | 250 sorted_keys_.erase(std::find(sorted_keys_.begin(), sorted_keys_.end(), key)); |
247 | 251 |
248 content::NotificationService::current()->Notify( | 252 content::NotificationService::current()->Notify( |
249 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | 253 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
398 return GetDefaultAvatarIconResourceIDAtIndex(0); | 402 return GetDefaultAvatarIconResourceIDAtIndex(0); |
399 } | 403 } |
400 | 404 |
401 void ProfileInfoCache::SetNameOfProfileAtIndex(size_t index, | 405 void ProfileInfoCache::SetNameOfProfileAtIndex(size_t index, |
402 const string16& name) { | 406 const string16& name) { |
403 if (name == GetNameOfProfileAtIndex(index)) | 407 if (name == GetNameOfProfileAtIndex(index)) |
404 return; | 408 return; |
405 | 409 |
406 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 410 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); |
407 string16 old_name; | 411 string16 old_name; |
408 info->GetString(kNameKey, &old_name); | 412 if (IsUsingGAIANameOfProfileAtIndex(index)) |
413 old_name = GetGAIANameOfProfileAtIndex(index); | |
414 else | |
415 info->GetString(kNameKey, &old_name); | |
409 info->SetString(kNameKey, name); | 416 info->SetString(kNameKey, name); |
410 // This takes ownership of |info|. | 417 // This takes ownership of |info|. |
411 SetInfoForProfileAtIndex(index, info.release()); | 418 SetInfoForProfileAtIndex(index, info.release()); |
412 UpdateSortForProfileIndex(index); | 419 UpdateSortForProfileIndex(index); |
413 | 420 |
414 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 421 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, |
415 observer_list_, | 422 observer_list_, |
416 OnProfileNameChanged(old_name, name)); | 423 OnProfileNameChanged(old_name, name)); |
417 } | 424 } |
418 | 425 |
419 void ProfileInfoCache::SetUserNameOfProfileAtIndex(size_t index, | 426 void ProfileInfoCache::SetUserNameOfProfileAtIndex(size_t index, |
420 const string16& user_name) { | 427 const string16& user_name) { |
421 if (user_name == GetUserNameOfProfileAtIndex(index)) | 428 if (user_name == GetUserNameOfProfileAtIndex(index)) |
422 return; | 429 return; |
423 | 430 |
424 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 431 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); |
425 info->SetString(kUserNameKey, user_name); | 432 info->SetString(kUserNameKey, user_name); |
426 // This takes ownership of |info|. | 433 // This takes ownership of |info|. |
427 SetInfoForProfileAtIndex(index, info.release()); | 434 SetInfoForProfileAtIndex(index, info.release()); |
428 } | 435 } |
429 | 436 |
430 void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index, | 437 void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index, |
431 size_t icon_index) { | 438 size_t icon_index) { |
432 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 439 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); |
433 string16 name; | 440 string16 name; |
434 info->GetString(kNameKey, &name); | 441 if (IsUsingGAIANameOfProfileAtIndex(index)) |
442 name = GetGAIANameOfProfileAtIndex(index); | |
443 else | |
444 info->GetString(kNameKey, &name); | |
435 info->SetString(kAvatarIconKey, GetDefaultAvatarIconUrl(icon_index)); | 445 info->SetString(kAvatarIconKey, GetDefaultAvatarIconUrl(icon_index)); |
436 // This takes ownership of |info|. | 446 // This takes ownership of |info|. |
437 SetInfoForProfileAtIndex(index, info.release()); | 447 SetInfoForProfileAtIndex(index, info.release()); |
438 | 448 |
439 FilePath profile_path = GetPathOfProfileAtIndex(index); | 449 FilePath profile_path = GetPathOfProfileAtIndex(index); |
440 std::string key = CacheKeyFromProfilePath(profile_path); | 450 std::string key = CacheKeyFromProfilePath(profile_path); |
441 gfx::Image& avatar_img = | 451 gfx::Image& avatar_img = |
442 ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 452 ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
443 GetDefaultAvatarIconResourceIDAtIndex(icon_index)); | 453 GetDefaultAvatarIconResourceIDAtIndex(icon_index)); |
444 | 454 |
(...skipping 25 matching lines...) Expand all Loading... | |
470 SetInfoForProfileAtIndex(index, info.release()); | 480 SetInfoForProfileAtIndex(index, info.release()); |
471 UpdateSortForProfileIndex(index); | 481 UpdateSortForProfileIndex(index); |
472 } | 482 } |
473 | 483 |
474 void ProfileInfoCache::SetIsUsingGAIANameOfProfileAtIndex(size_t index, | 484 void ProfileInfoCache::SetIsUsingGAIANameOfProfileAtIndex(size_t index, |
475 bool value) { | 485 bool value) { |
476 if (value == IsUsingGAIANameOfProfileAtIndex(index)) | 486 if (value == IsUsingGAIANameOfProfileAtIndex(index)) |
477 return; | 487 return; |
478 | 488 |
479 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 489 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); |
490 string16 old_name; | |
491 info->GetString(kNameKey, &old_name); | |
480 info->SetBoolean(kUseGAIANameKey, value); | 492 info->SetBoolean(kUseGAIANameKey, value); |
481 // This takes ownership of |info|. | 493 // This takes ownership of |info|. |
482 SetInfoForProfileAtIndex(index, info.release()); | 494 SetInfoForProfileAtIndex(index, info.release()); |
495 string16 new_name = GetGAIANameOfProfileAtIndex(index); | |
483 UpdateSortForProfileIndex(index); | 496 UpdateSortForProfileIndex(index); |
497 | |
498 if (value) { | |
499 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | |
500 observer_list_, | |
501 OnProfileNameChanged(old_name, new_name)); | |
502 } | |
484 } | 503 } |
485 | 504 |
486 void ProfileInfoCache::SetGAIAPictureOfProfileAtIndex(size_t index, | 505 void ProfileInfoCache::SetGAIAPictureOfProfileAtIndex(size_t index, |
487 const gfx::Image* image) { | 506 const gfx::Image* image) { |
488 FilePath path = GetPathOfProfileAtIndex(index); | 507 FilePath path = GetPathOfProfileAtIndex(index); |
489 std::string key = CacheKeyFromProfilePath(path); | 508 std::string key = CacheKeyFromProfilePath(path); |
490 | 509 |
491 // Delete the old bitmap from cache. | 510 // Delete the old bitmap from cache. |
492 std::map<std::string, gfx::Image*>::iterator it = gaia_pictures_.find(key); | 511 std::map<std::string, gfx::Image*>::iterator it = gaia_pictures_.find(key); |
493 if (it != gaia_pictures_.end()) { | 512 if (it != gaia_pictures_.end()) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
528 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 547 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); |
529 info->SetString(kGAIAPictureFileNameKey, new_file_name); | 548 info->SetString(kGAIAPictureFileNameKey, new_file_name); |
530 // This takes ownership of |info|. | 549 // This takes ownership of |info|. |
531 SetInfoForProfileAtIndex(index, info.release()); | 550 SetInfoForProfileAtIndex(index, info.release()); |
532 } | 551 } |
533 | 552 |
534 void ProfileInfoCache::SetIsUsingGAIAPictureOfProfileAtIndex(size_t index, | 553 void ProfileInfoCache::SetIsUsingGAIAPictureOfProfileAtIndex(size_t index, |
535 bool value) { | 554 bool value) { |
536 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 555 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); |
537 string16 name; | 556 string16 name; |
538 info->GetString(kNameKey, &name); | 557 if (IsUsingGAIANameOfProfileAtIndex(index)) |
558 name = GetGAIANameOfProfileAtIndex(index); | |
559 else | |
560 info->GetString(kNameKey, &name); | |
539 info->SetBoolean(kUseGAIAPictureKey, value); | 561 info->SetBoolean(kUseGAIAPictureKey, value); |
540 // This takes ownership of |info|. | 562 // This takes ownership of |info|. |
541 SetInfoForProfileAtIndex(index, info.release()); | 563 SetInfoForProfileAtIndex(index, info.release()); |
542 | 564 |
543 // Retrieve some info to update observers who care about avatar changes. | 565 // Retrieve some info to update observers who care about avatar changes. |
544 if (value) { | 566 if (value) { |
545 FilePath profile_path = GetPathOfProfileAtIndex(index); | 567 FilePath profile_path = GetPathOfProfileAtIndex(index); |
546 std::string key = CacheKeyFromProfilePath(profile_path); | 568 std::string key = CacheKeyFromProfilePath(profile_path); |
547 if (gaia_pictures_.find(key) != gaia_pictures_.end()) { | 569 if (gaia_pictures_.find(key) != gaia_pictures_.end()) { |
548 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 570 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
761 info->GetString(kNameKey, &name); | 783 info->GetString(kNameKey, &name); |
762 names.push_back(name); | 784 names.push_back(name); |
763 } | 785 } |
764 return names; | 786 return names; |
765 } | 787 } |
766 | 788 |
767 // static | 789 // static |
768 void ProfileInfoCache::RegisterPrefs(PrefService* prefs) { | 790 void ProfileInfoCache::RegisterPrefs(PrefService* prefs) { |
769 prefs->RegisterDictionaryPref(prefs::kProfileInfoCache); | 791 prefs->RegisterDictionaryPref(prefs::kProfileInfoCache); |
770 } | 792 } |
OLD | NEW |