| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 info->SetBoolean(kIsUsingDefaultAvatarKey, true); | 202 info->SetBoolean(kIsUsingDefaultAvatarKey, true); |
| 203 cache->SetWithoutPathExpansion(key, info.release()); | 203 cache->SetWithoutPathExpansion(key, info.release()); |
| 204 | 204 |
| 205 sorted_keys_.insert(FindPositionForProfile(key, name), key); | 205 sorted_keys_.insert(FindPositionForProfile(key, name), key); |
| 206 profile_attributes_entries_[user_data_dir_.AppendASCII(key).value()] = | 206 profile_attributes_entries_[user_data_dir_.AppendASCII(key).value()] = |
| 207 std::unique_ptr<ProfileAttributesEntry>(); | 207 std::unique_ptr<ProfileAttributesEntry>(); |
| 208 | 208 |
| 209 if (!disable_avatar_download_for_testing_) | 209 if (!disable_avatar_download_for_testing_) |
| 210 DownloadHighResAvatarIfNeeded(icon_index, profile_path); | 210 DownloadHighResAvatarIfNeeded(icon_index, profile_path); |
| 211 | 211 |
| 212 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 212 for (auto& observer : observer_list_) |
| 213 observer_list_, | 213 observer.OnProfileAdded(profile_path); |
| 214 OnProfileAdded(profile_path)); | |
| 215 } | 214 } |
| 216 | 215 |
| 217 void ProfileInfoCache::AddObserver(ProfileInfoCacheObserver* obs) { | 216 void ProfileInfoCache::AddObserver(ProfileInfoCacheObserver* obs) { |
| 218 observer_list_.AddObserver(obs); | 217 observer_list_.AddObserver(obs); |
| 219 } | 218 } |
| 220 | 219 |
| 221 void ProfileInfoCache::RemoveObserver(ProfileInfoCacheObserver* obs) { | 220 void ProfileInfoCache::RemoveObserver(ProfileInfoCacheObserver* obs) { |
| 222 observer_list_.RemoveObserver(obs); | 221 observer_list_.RemoveObserver(obs); |
| 223 } | 222 } |
| 224 | 223 |
| 225 void ProfileInfoCache::DeleteProfileFromCache( | 224 void ProfileInfoCache::DeleteProfileFromCache( |
| 226 const base::FilePath& profile_path) { | 225 const base::FilePath& profile_path) { |
| 227 size_t profile_index = GetIndexOfProfileWithPath(profile_path); | 226 size_t profile_index = GetIndexOfProfileWithPath(profile_path); |
| 228 if (profile_index == std::string::npos) { | 227 if (profile_index == std::string::npos) { |
| 229 NOTREACHED(); | 228 NOTREACHED(); |
| 230 return; | 229 return; |
| 231 } | 230 } |
| 232 base::string16 name = GetNameOfProfileAtIndex(profile_index); | 231 base::string16 name = GetNameOfProfileAtIndex(profile_index); |
| 233 | 232 |
| 234 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 233 for (auto& observer : observer_list_) |
| 235 observer_list_, | 234 observer.OnProfileWillBeRemoved(profile_path); |
| 236 OnProfileWillBeRemoved(profile_path)); | |
| 237 | 235 |
| 238 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); | 236 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); |
| 239 base::DictionaryValue* cache = update.Get(); | 237 base::DictionaryValue* cache = update.Get(); |
| 240 std::string key = CacheKeyFromProfilePath(profile_path); | 238 std::string key = CacheKeyFromProfilePath(profile_path); |
| 241 cache->Remove(key, NULL); | 239 cache->Remove(key, NULL); |
| 242 sorted_keys_.erase(std::find(sorted_keys_.begin(), sorted_keys_.end(), key)); | 240 sorted_keys_.erase(std::find(sorted_keys_.begin(), sorted_keys_.end(), key)); |
| 243 profile_attributes_entries_.erase(profile_path.value()); | 241 profile_attributes_entries_.erase(profile_path.value()); |
| 244 | 242 |
| 245 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 243 for (auto& observer : observer_list_) |
| 246 observer_list_, | 244 observer.OnProfileWasRemoved(profile_path, name); |
| 247 OnProfileWasRemoved(profile_path, name)); | |
| 248 } | 245 } |
| 249 | 246 |
| 250 size_t ProfileInfoCache::GetNumberOfProfiles() const { | 247 size_t ProfileInfoCache::GetNumberOfProfiles() const { |
| 251 return sorted_keys_.size(); | 248 return sorted_keys_.size(); |
| 252 } | 249 } |
| 253 | 250 |
| 254 size_t ProfileInfoCache::GetIndexOfProfileWithPath( | 251 size_t ProfileInfoCache::GetIndexOfProfileWithPath( |
| 255 const base::FilePath& profile_path) const { | 252 const base::FilePath& profile_path) const { |
| 256 if (profile_path.DirName() != user_data_dir_) | 253 if (profile_path.DirName() != user_data_dir_) |
| 257 return std::string::npos; | 254 return std::string::npos; |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 info->SetString(kNameKey, name); | 552 info->SetString(kNameKey, name); |
| 556 | 553 |
| 557 // This takes ownership of |info|. | 554 // This takes ownership of |info|. |
| 558 SetInfoForProfileAtIndex(index, info.release()); | 555 SetInfoForProfileAtIndex(index, info.release()); |
| 559 | 556 |
| 560 base::string16 new_display_name = GetNameOfProfileAtIndex(index); | 557 base::string16 new_display_name = GetNameOfProfileAtIndex(index); |
| 561 base::FilePath profile_path = GetPathOfProfileAtIndex(index); | 558 base::FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 562 UpdateSortForProfileIndex(index); | 559 UpdateSortForProfileIndex(index); |
| 563 | 560 |
| 564 if (old_display_name != new_display_name) { | 561 if (old_display_name != new_display_name) { |
| 565 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 562 for (auto& observer : observer_list_) |
| 566 observer_list_, | 563 observer.OnProfileNameChanged(profile_path, old_display_name); |
| 567 OnProfileNameChanged(profile_path, old_display_name)); | |
| 568 } | 564 } |
| 569 } | 565 } |
| 570 | 566 |
| 571 void ProfileInfoCache::SetShortcutNameOfProfileAtIndex( | 567 void ProfileInfoCache::SetShortcutNameOfProfileAtIndex( |
| 572 size_t index, | 568 size_t index, |
| 573 const base::string16& shortcut_name) { | 569 const base::string16& shortcut_name) { |
| 574 if (shortcut_name == GetShortcutNameOfProfileAtIndex(index)) | 570 if (shortcut_name == GetShortcutNameOfProfileAtIndex(index)) |
| 575 return; | 571 return; |
| 576 std::unique_ptr<base::DictionaryValue> info( | 572 std::unique_ptr<base::DictionaryValue> info( |
| 577 GetInfoForProfileAtIndex(index)->DeepCopy()); | 573 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 593 std::unique_ptr<base::DictionaryValue> info( | 589 std::unique_ptr<base::DictionaryValue> info( |
| 594 GetInfoForProfileAtIndex(index)->DeepCopy()); | 590 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 595 | 591 |
| 596 info->SetString(kGAIAIdKey, gaia_id); | 592 info->SetString(kGAIAIdKey, gaia_id); |
| 597 info->SetString(kUserNameKey, user_name); | 593 info->SetString(kUserNameKey, user_name); |
| 598 | 594 |
| 599 // This takes ownership of |info|. | 595 // This takes ownership of |info|. |
| 600 SetInfoForProfileAtIndex(index, info.release()); | 596 SetInfoForProfileAtIndex(index, info.release()); |
| 601 | 597 |
| 602 base::FilePath profile_path = GetPathOfProfileAtIndex(index); | 598 base::FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 603 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 599 for (auto& observer : observer_list_) |
| 604 observer_list_, | 600 observer.OnProfileAuthInfoChanged(profile_path); |
| 605 OnProfileAuthInfoChanged(profile_path)); | |
| 606 } | 601 } |
| 607 | 602 |
| 608 void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index, | 603 void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index, |
| 609 size_t icon_index) { | 604 size_t icon_index) { |
| 610 std::unique_ptr<base::DictionaryValue> info( | 605 std::unique_ptr<base::DictionaryValue> info( |
| 611 GetInfoForProfileAtIndex(index)->DeepCopy()); | 606 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 612 info->SetString(kAvatarIconKey, | 607 info->SetString(kAvatarIconKey, |
| 613 profiles::GetDefaultAvatarIconUrl(icon_index)); | 608 profiles::GetDefaultAvatarIconUrl(icon_index)); |
| 614 // This takes ownership of |info|. | 609 // This takes ownership of |info|. |
| 615 SetInfoForProfileAtIndex(index, info.release()); | 610 SetInfoForProfileAtIndex(index, info.release()); |
| 616 | 611 |
| 617 base::FilePath profile_path = GetPathOfProfileAtIndex(index); | 612 base::FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 618 | 613 |
| 619 if (!disable_avatar_download_for_testing_) | 614 if (!disable_avatar_download_for_testing_) |
| 620 DownloadHighResAvatarIfNeeded(icon_index, profile_path); | 615 DownloadHighResAvatarIfNeeded(icon_index, profile_path); |
| 621 | 616 |
| 622 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 617 for (auto& observer : observer_list_) |
| 623 observer_list_, | 618 observer.OnProfileAvatarChanged(profile_path); |
| 624 OnProfileAvatarChanged(profile_path)); | |
| 625 } | 619 } |
| 626 | 620 |
| 627 void ProfileInfoCache::SetIsOmittedProfileAtIndex(size_t index, | 621 void ProfileInfoCache::SetIsOmittedProfileAtIndex(size_t index, |
| 628 bool is_omitted) { | 622 bool is_omitted) { |
| 629 if (IsOmittedProfileAtIndex(index) == is_omitted) | 623 if (IsOmittedProfileAtIndex(index) == is_omitted) |
| 630 return; | 624 return; |
| 631 std::unique_ptr<base::DictionaryValue> info( | 625 std::unique_ptr<base::DictionaryValue> info( |
| 632 GetInfoForProfileAtIndex(index)->DeepCopy()); | 626 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 633 info->SetBoolean(kIsOmittedFromProfileListKey, is_omitted); | 627 info->SetBoolean(kIsOmittedFromProfileListKey, is_omitted); |
| 634 // This takes ownership of |info|. | 628 // This takes ownership of |info|. |
| 635 SetInfoForProfileAtIndex(index, info.release()); | 629 SetInfoForProfileAtIndex(index, info.release()); |
| 636 | 630 |
| 637 base::FilePath profile_path = GetPathOfProfileAtIndex(index); | 631 base::FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 638 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 632 for (auto& observer : observer_list_) |
| 639 observer_list_, | 633 observer.OnProfileIsOmittedChanged(profile_path); |
| 640 OnProfileIsOmittedChanged(profile_path)); | |
| 641 } | 634 } |
| 642 | 635 |
| 643 void ProfileInfoCache::SetSupervisedUserIdOfProfileAtIndex( | 636 void ProfileInfoCache::SetSupervisedUserIdOfProfileAtIndex( |
| 644 size_t index, | 637 size_t index, |
| 645 const std::string& id) { | 638 const std::string& id) { |
| 646 if (GetSupervisedUserIdOfProfileAtIndex(index) == id) | 639 if (GetSupervisedUserIdOfProfileAtIndex(index) == id) |
| 647 return; | 640 return; |
| 648 std::unique_ptr<base::DictionaryValue> info( | 641 std::unique_ptr<base::DictionaryValue> info( |
| 649 GetInfoForProfileAtIndex(index)->DeepCopy()); | 642 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 650 info->SetString(kSupervisedUserId, id); | 643 info->SetString(kSupervisedUserId, id); |
| 651 // This takes ownership of |info|. | 644 // This takes ownership of |info|. |
| 652 SetInfoForProfileAtIndex(index, info.release()); | 645 SetInfoForProfileAtIndex(index, info.release()); |
| 653 | 646 |
| 654 base::FilePath profile_path = GetPathOfProfileAtIndex(index); | 647 base::FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 655 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 648 for (auto& observer : observer_list_) |
| 656 observer_list_, | 649 observer.OnProfileSupervisedUserIdChanged(profile_path); |
| 657 OnProfileSupervisedUserIdChanged(profile_path)); | |
| 658 } | 650 } |
| 659 | 651 |
| 660 void ProfileInfoCache::SetLocalAuthCredentialsOfProfileAtIndex( | 652 void ProfileInfoCache::SetLocalAuthCredentialsOfProfileAtIndex( |
| 661 size_t index, | 653 size_t index, |
| 662 const std::string& credentials) { | 654 const std::string& credentials) { |
| 663 std::unique_ptr<base::DictionaryValue> info( | 655 std::unique_ptr<base::DictionaryValue> info( |
| 664 GetInfoForProfileAtIndex(index)->DeepCopy()); | 656 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 665 info->SetString(kAuthCredentialsKey, credentials); | 657 info->SetString(kAuthCredentialsKey, credentials); |
| 666 // This takes ownership of |info|. | 658 // This takes ownership of |info|. |
| 667 SetInfoForProfileAtIndex(index, info.release()); | 659 SetInfoForProfileAtIndex(index, info.release()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 698 std::unique_ptr<base::DictionaryValue> info( | 690 std::unique_ptr<base::DictionaryValue> info( |
| 699 GetInfoForProfileAtIndex(index)->DeepCopy()); | 691 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 700 info->SetString(kGAIANameKey, name); | 692 info->SetString(kGAIANameKey, name); |
| 701 // This takes ownership of |info|. | 693 // This takes ownership of |info|. |
| 702 SetInfoForProfileAtIndex(index, info.release()); | 694 SetInfoForProfileAtIndex(index, info.release()); |
| 703 base::string16 new_display_name = GetNameOfProfileAtIndex(index); | 695 base::string16 new_display_name = GetNameOfProfileAtIndex(index); |
| 704 base::FilePath profile_path = GetPathOfProfileAtIndex(index); | 696 base::FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 705 UpdateSortForProfileIndex(index); | 697 UpdateSortForProfileIndex(index); |
| 706 | 698 |
| 707 if (old_display_name != new_display_name) { | 699 if (old_display_name != new_display_name) { |
| 708 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 700 for (auto& observer : observer_list_) |
| 709 observer_list_, | 701 observer.OnProfileNameChanged(profile_path, old_display_name); |
| 710 OnProfileNameChanged(profile_path, old_display_name)); | |
| 711 } | 702 } |
| 712 } | 703 } |
| 713 | 704 |
| 714 void ProfileInfoCache::SetGAIAGivenNameOfProfileAtIndex( | 705 void ProfileInfoCache::SetGAIAGivenNameOfProfileAtIndex( |
| 715 size_t index, | 706 size_t index, |
| 716 const base::string16& name) { | 707 const base::string16& name) { |
| 717 if (name == GetGAIAGivenNameOfProfileAtIndex(index)) | 708 if (name == GetGAIAGivenNameOfProfileAtIndex(index)) |
| 718 return; | 709 return; |
| 719 | 710 |
| 720 base::string16 old_display_name = GetNameOfProfileAtIndex(index); | 711 base::string16 old_display_name = GetNameOfProfileAtIndex(index); |
| 721 std::unique_ptr<base::DictionaryValue> info( | 712 std::unique_ptr<base::DictionaryValue> info( |
| 722 GetInfoForProfileAtIndex(index)->DeepCopy()); | 713 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 723 info->SetString(kGAIAGivenNameKey, name); | 714 info->SetString(kGAIAGivenNameKey, name); |
| 724 // This takes ownership of |info|. | 715 // This takes ownership of |info|. |
| 725 SetInfoForProfileAtIndex(index, info.release()); | 716 SetInfoForProfileAtIndex(index, info.release()); |
| 726 base::string16 new_display_name = GetNameOfProfileAtIndex(index); | 717 base::string16 new_display_name = GetNameOfProfileAtIndex(index); |
| 727 base::FilePath profile_path = GetPathOfProfileAtIndex(index); | 718 base::FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 728 UpdateSortForProfileIndex(index); | 719 UpdateSortForProfileIndex(index); |
| 729 | 720 |
| 730 if (old_display_name != new_display_name) { | 721 if (old_display_name != new_display_name) { |
| 731 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 722 for (auto& observer : observer_list_) |
| 732 observer_list_, | 723 observer.OnProfileNameChanged(profile_path, old_display_name); |
| 733 OnProfileNameChanged(profile_path, old_display_name)); | |
| 734 } | 724 } |
| 735 } | 725 } |
| 736 | 726 |
| 737 void ProfileInfoCache::SetGAIAPictureOfProfileAtIndex(size_t index, | 727 void ProfileInfoCache::SetGAIAPictureOfProfileAtIndex(size_t index, |
| 738 const gfx::Image* image) { | 728 const gfx::Image* image) { |
| 739 base::FilePath path = GetPathOfProfileAtIndex(index); | 729 base::FilePath path = GetPathOfProfileAtIndex(index); |
| 740 std::string key = CacheKeyFromProfilePath(path); | 730 std::string key = CacheKeyFromProfilePath(path); |
| 741 | 731 |
| 742 // Delete the old bitmap from cache. | 732 // Delete the old bitmap from cache. |
| 743 cached_avatar_images_.erase(key); | 733 cached_avatar_images_.erase(key); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 762 SaveAvatarImageAtPath( | 752 SaveAvatarImageAtPath( |
| 763 GetPathOfProfileAtIndex(index), image, key, image_path); | 753 GetPathOfProfileAtIndex(index), image, key, image_path); |
| 764 } | 754 } |
| 765 | 755 |
| 766 std::unique_ptr<base::DictionaryValue> info( | 756 std::unique_ptr<base::DictionaryValue> info( |
| 767 GetInfoForProfileAtIndex(index)->DeepCopy()); | 757 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 768 info->SetString(kGAIAPictureFileNameKey, new_file_name); | 758 info->SetString(kGAIAPictureFileNameKey, new_file_name); |
| 769 // This takes ownership of |info|. | 759 // This takes ownership of |info|. |
| 770 SetInfoForProfileAtIndex(index, info.release()); | 760 SetInfoForProfileAtIndex(index, info.release()); |
| 771 | 761 |
| 772 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 762 for (auto& observer : observer_list_) |
| 773 observer_list_, | 763 observer.OnProfileAvatarChanged(path); |
| 774 OnProfileAvatarChanged(path)); | |
| 775 } | 764 } |
| 776 | 765 |
| 777 void ProfileInfoCache::SetIsUsingGAIAPictureOfProfileAtIndex(size_t index, | 766 void ProfileInfoCache::SetIsUsingGAIAPictureOfProfileAtIndex(size_t index, |
| 778 bool value) { | 767 bool value) { |
| 779 std::unique_ptr<base::DictionaryValue> info( | 768 std::unique_ptr<base::DictionaryValue> info( |
| 780 GetInfoForProfileAtIndex(index)->DeepCopy()); | 769 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 781 info->SetBoolean(kUseGAIAPictureKey, value); | 770 info->SetBoolean(kUseGAIAPictureKey, value); |
| 782 // This takes ownership of |info|. | 771 // This takes ownership of |info|. |
| 783 SetInfoForProfileAtIndex(index, info.release()); | 772 SetInfoForProfileAtIndex(index, info.release()); |
| 784 | 773 |
| 785 base::FilePath profile_path = GetPathOfProfileAtIndex(index); | 774 base::FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 786 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 775 for (auto& observer : observer_list_) |
| 787 observer_list_, | 776 observer.OnProfileAvatarChanged(profile_path); |
| 788 OnProfileAvatarChanged(profile_path)); | |
| 789 } | 777 } |
| 790 | 778 |
| 791 void ProfileInfoCache::SetProfileSigninRequiredAtIndex(size_t index, | 779 void ProfileInfoCache::SetProfileSigninRequiredAtIndex(size_t index, |
| 792 bool value) { | 780 bool value) { |
| 793 if (value == ProfileIsSigninRequiredAtIndex(index)) | 781 if (value == ProfileIsSigninRequiredAtIndex(index)) |
| 794 return; | 782 return; |
| 795 | 783 |
| 796 std::unique_ptr<base::DictionaryValue> info( | 784 std::unique_ptr<base::DictionaryValue> info( |
| 797 GetInfoForProfileAtIndex(index)->DeepCopy()); | 785 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 798 info->SetBoolean(kSigninRequiredKey, value); | 786 info->SetBoolean(kSigninRequiredKey, value); |
| 799 // This takes ownership of |info|. | 787 // This takes ownership of |info|. |
| 800 SetInfoForProfileAtIndex(index, info.release()); | 788 SetInfoForProfileAtIndex(index, info.release()); |
| 801 | 789 |
| 802 base::FilePath profile_path = GetPathOfProfileAtIndex(index); | 790 base::FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 803 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 791 for (auto& observer : observer_list_) |
| 804 observer_list_, | 792 observer.OnProfileSigninRequiredChanged(profile_path); |
| 805 OnProfileSigninRequiredChanged(profile_path)); | |
| 806 } | 793 } |
| 807 | 794 |
| 808 void ProfileInfoCache::SetProfileIsEphemeralAtIndex(size_t index, bool value) { | 795 void ProfileInfoCache::SetProfileIsEphemeralAtIndex(size_t index, bool value) { |
| 809 if (value == ProfileIsEphemeralAtIndex(index)) | 796 if (value == ProfileIsEphemeralAtIndex(index)) |
| 810 return; | 797 return; |
| 811 | 798 |
| 812 std::unique_ptr<base::DictionaryValue> info( | 799 std::unique_ptr<base::DictionaryValue> info( |
| 813 GetInfoForProfileAtIndex(index)->DeepCopy()); | 800 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 814 info->SetBoolean(kProfileIsEphemeral, value); | 801 info->SetBoolean(kProfileIsEphemeral, value); |
| 815 // This takes ownership of |info|. | 802 // This takes ownership of |info|. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 826 std::unique_ptr<base::DictionaryValue> info( | 813 std::unique_ptr<base::DictionaryValue> info( |
| 827 GetInfoForProfileAtIndex(index)->DeepCopy()); | 814 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 828 info->SetBoolean(kIsUsingDefaultNameKey, value); | 815 info->SetBoolean(kIsUsingDefaultNameKey, value); |
| 829 // This takes ownership of |info|. | 816 // This takes ownership of |info|. |
| 830 SetInfoForProfileAtIndex(index, info.release()); | 817 SetInfoForProfileAtIndex(index, info.release()); |
| 831 | 818 |
| 832 base::string16 new_display_name = GetNameOfProfileAtIndex(index); | 819 base::string16 new_display_name = GetNameOfProfileAtIndex(index); |
| 833 const base::FilePath profile_path = GetPathOfProfileAtIndex(index); | 820 const base::FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 834 | 821 |
| 835 if (old_display_name != new_display_name) { | 822 if (old_display_name != new_display_name) { |
| 836 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 823 for (auto& observer : observer_list_) |
| 837 observer_list_, | 824 observer.OnProfileNameChanged(profile_path, old_display_name); |
| 838 OnProfileNameChanged(profile_path, old_display_name)); | |
| 839 } | 825 } |
| 840 } | 826 } |
| 841 | 827 |
| 842 void ProfileInfoCache::SetProfileIsUsingDefaultAvatarAtIndex( | 828 void ProfileInfoCache::SetProfileIsUsingDefaultAvatarAtIndex( |
| 843 size_t index, bool value) { | 829 size_t index, bool value) { |
| 844 if (value == ProfileIsUsingDefaultAvatarAtIndex(index)) | 830 if (value == ProfileIsUsingDefaultAvatarAtIndex(index)) |
| 845 return; | 831 return; |
| 846 | 832 |
| 847 std::unique_ptr<base::DictionaryValue> info( | 833 std::unique_ptr<base::DictionaryValue> info( |
| 848 GetInfoForProfileAtIndex(index)->DeepCopy()); | 834 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1139 // Place an empty image in the cache to avoid reloading it again. | 1125 // Place an empty image in the cache to avoid reloading it again. |
| 1140 cached_avatar_images_[key].reset(new gfx::Image()); | 1126 cached_avatar_images_[key].reset(new gfx::Image()); |
| 1141 } | 1127 } |
| 1142 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461175 | 1128 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461175 |
| 1143 // is fixed. | 1129 // is fixed. |
| 1144 tracked_objects::ScopedTracker tracking_profile4( | 1130 tracked_objects::ScopedTracker tracking_profile4( |
| 1145 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1131 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1146 "461175 ProfileInfoCache::OnAvatarPictureLoaded::DeleteImage")); | 1132 "461175 ProfileInfoCache::OnAvatarPictureLoaded::DeleteImage")); |
| 1147 delete image; | 1133 delete image; |
| 1148 | 1134 |
| 1149 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 1135 for (auto& observer : observer_list_) |
| 1150 observer_list_, | 1136 observer.OnProfileHighResAvatarLoaded(profile_path); |
| 1151 OnProfileHighResAvatarLoaded(profile_path)); | |
| 1152 } | 1137 } |
| 1153 | 1138 |
| 1154 void ProfileInfoCache::OnAvatarPictureSaved( | 1139 void ProfileInfoCache::OnAvatarPictureSaved( |
| 1155 const std::string& file_name, | 1140 const std::string& file_name, |
| 1156 const base::FilePath& profile_path) { | 1141 const base::FilePath& profile_path) { |
| 1157 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1142 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1158 | 1143 |
| 1159 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 1144 for (auto& observer : observer_list_) |
| 1160 observer_list_, | 1145 observer.OnProfileHighResAvatarLoaded(profile_path); |
| 1161 OnProfileHighResAvatarLoaded(profile_path)); | |
| 1162 } | 1146 } |
| 1163 | 1147 |
| 1164 void ProfileInfoCache::MigrateLegacyProfileNamesAndDownloadAvatars() { | 1148 void ProfileInfoCache::MigrateLegacyProfileNamesAndDownloadAvatars() { |
| 1165 // Only do this on desktop platforms. | 1149 // Only do this on desktop platforms. |
| 1166 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | 1150 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
| 1167 // Migrate any legacy profile names ("First user", "Default Profile") to | 1151 // Migrate any legacy profile names ("First user", "Default Profile") to |
| 1168 // new style default names ("Person 1"). The problem here is that every | 1152 // new style default names ("Person 1"). The problem here is that every |
| 1169 // time you rename a profile, the ProfileInfoCache sorts itself, so | 1153 // time you rename a profile, the ProfileInfoCache sorts itself, so |
| 1170 // whatever you were iterating through is no longer valid. We need to | 1154 // whatever you were iterating through is no longer valid. We need to |
| 1171 // save a list of the profile paths (which thankfully do not change) that | 1155 // save a list of the profile paths (which thankfully do not change) that |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1237 if (!current_entry) { | 1221 if (!current_entry) { |
| 1238 // The profile info is in the cache but its entry isn't created yet, insert | 1222 // The profile info is in the cache but its entry isn't created yet, insert |
| 1239 // it in the map. | 1223 // it in the map. |
| 1240 current_entry.reset(new ProfileAttributesEntry()); | 1224 current_entry.reset(new ProfileAttributesEntry()); |
| 1241 current_entry->Initialize(this, path); | 1225 current_entry->Initialize(this, path); |
| 1242 } | 1226 } |
| 1243 | 1227 |
| 1244 *entry = current_entry.get(); | 1228 *entry = current_entry.get(); |
| 1245 return true; | 1229 return true; |
| 1246 } | 1230 } |
| OLD | NEW |