| 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 info->SetString(kAvatarIconKey, | 194 info->SetString(kAvatarIconKey, |
| 195 profiles::GetDefaultAvatarIconUrl(icon_index)); | 195 profiles::GetDefaultAvatarIconUrl(icon_index)); |
| 196 // Default value for whether background apps are running is false. | 196 // Default value for whether background apps are running is false. |
| 197 info->SetBoolean(kBackgroundAppsKey, false); | 197 info->SetBoolean(kBackgroundAppsKey, false); |
| 198 info->SetString(kSupervisedUserId, supervised_user_id); | 198 info->SetString(kSupervisedUserId, supervised_user_id); |
| 199 info->SetBoolean(kIsOmittedFromProfileListKey, !supervised_user_id.empty()); | 199 info->SetBoolean(kIsOmittedFromProfileListKey, !supervised_user_id.empty()); |
| 200 info->SetBoolean(kProfileIsEphemeral, false); | 200 info->SetBoolean(kProfileIsEphemeral, false); |
| 201 info->SetBoolean(kIsUsingDefaultNameKey, IsDefaultProfileName(name)); | 201 info->SetBoolean(kIsUsingDefaultNameKey, IsDefaultProfileName(name)); |
| 202 // Assume newly created profiles use a default avatar. | 202 // Assume newly created profiles use a default avatar. |
| 203 info->SetBoolean(kIsUsingDefaultAvatarKey, true); | 203 info->SetBoolean(kIsUsingDefaultAvatarKey, true); |
| 204 cache->SetWithoutPathExpansion(key, info.release()); | 204 cache->SetWithoutPathExpansion(key, std::move(info)); |
| 205 | 205 |
| 206 sorted_keys_.insert(FindPositionForProfile(key, name), key); | 206 sorted_keys_.insert(FindPositionForProfile(key, name), key); |
| 207 profile_attributes_entries_[user_data_dir_.AppendASCII(key).value()] = | 207 profile_attributes_entries_[user_data_dir_.AppendASCII(key).value()] = |
| 208 std::unique_ptr<ProfileAttributesEntry>(); | 208 std::unique_ptr<ProfileAttributesEntry>(); |
| 209 | 209 |
| 210 if (!disable_avatar_download_for_testing_) | 210 if (!disable_avatar_download_for_testing_) |
| 211 DownloadHighResAvatarIfNeeded(icon_index, profile_path); | 211 DownloadHighResAvatarIfNeeded(icon_index, profile_path); |
| 212 | 212 |
| 213 for (auto& observer : observer_list_) | 213 for (auto& observer : observer_list_) |
| 214 observer.OnProfileAdded(profile_path); | 214 observer.OnProfileAdded(profile_path); |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 | 529 |
| 530 void ProfileInfoCache::SetProfileActiveTimeAtIndex(size_t index) { | 530 void ProfileInfoCache::SetProfileActiveTimeAtIndex(size_t index) { |
| 531 if (base::Time::Now() - GetProfileActiveTimeAtIndex(index) < | 531 if (base::Time::Now() - GetProfileActiveTimeAtIndex(index) < |
| 532 base::TimeDelta::FromHours(1)) { | 532 base::TimeDelta::FromHours(1)) { |
| 533 return; | 533 return; |
| 534 } | 534 } |
| 535 | 535 |
| 536 std::unique_ptr<base::DictionaryValue> info( | 536 std::unique_ptr<base::DictionaryValue> info( |
| 537 GetInfoForProfileAtIndex(index)->DeepCopy()); | 537 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 538 info->SetDouble(kActiveTimeKey, base::Time::Now().ToDoubleT()); | 538 info->SetDouble(kActiveTimeKey, base::Time::Now().ToDoubleT()); |
| 539 // This takes ownership of |info|. | 539 SetInfoForProfileAtIndex(index, std::move(info)); |
| 540 SetInfoForProfileAtIndex(index, info.release()); | |
| 541 } | 540 } |
| 542 | 541 |
| 543 void ProfileInfoCache::SetNameOfProfileAtIndex(size_t index, | 542 void ProfileInfoCache::SetNameOfProfileAtIndex(size_t index, |
| 544 const base::string16& name) { | 543 const base::string16& name) { |
| 545 std::unique_ptr<base::DictionaryValue> info( | 544 std::unique_ptr<base::DictionaryValue> info( |
| 546 GetInfoForProfileAtIndex(index)->DeepCopy()); | 545 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 547 base::string16 current_name; | 546 base::string16 current_name; |
| 548 info->GetString(kNameKey, ¤t_name); | 547 info->GetString(kNameKey, ¤t_name); |
| 549 if (name == current_name) | 548 if (name == current_name) |
| 550 return; | 549 return; |
| 551 | 550 |
| 552 base::string16 old_display_name = GetNameOfProfileAtIndex(index); | 551 base::string16 old_display_name = GetNameOfProfileAtIndex(index); |
| 553 info->SetString(kNameKey, name); | 552 info->SetString(kNameKey, name); |
| 554 | 553 |
| 555 // This takes ownership of |info|. | 554 SetInfoForProfileAtIndex(index, std::move(info)); |
| 556 SetInfoForProfileAtIndex(index, info.release()); | |
| 557 | 555 |
| 558 base::string16 new_display_name = GetNameOfProfileAtIndex(index); | 556 base::string16 new_display_name = GetNameOfProfileAtIndex(index); |
| 559 base::FilePath profile_path = GetPathOfProfileAtIndex(index); | 557 base::FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 560 UpdateSortForProfileIndex(index); | 558 UpdateSortForProfileIndex(index); |
| 561 | 559 |
| 562 if (old_display_name != new_display_name) { | 560 if (old_display_name != new_display_name) { |
| 563 for (auto& observer : observer_list_) | 561 for (auto& observer : observer_list_) |
| 564 observer.OnProfileNameChanged(profile_path, old_display_name); | 562 observer.OnProfileNameChanged(profile_path, old_display_name); |
| 565 } | 563 } |
| 566 } | 564 } |
| 567 | 565 |
| 568 void ProfileInfoCache::SetShortcutNameOfProfileAtIndex( | 566 void ProfileInfoCache::SetShortcutNameOfProfileAtIndex( |
| 569 size_t index, | 567 size_t index, |
| 570 const base::string16& shortcut_name) { | 568 const base::string16& shortcut_name) { |
| 571 if (shortcut_name == GetShortcutNameOfProfileAtIndex(index)) | 569 if (shortcut_name == GetShortcutNameOfProfileAtIndex(index)) |
| 572 return; | 570 return; |
| 573 std::unique_ptr<base::DictionaryValue> info( | 571 std::unique_ptr<base::DictionaryValue> info( |
| 574 GetInfoForProfileAtIndex(index)->DeepCopy()); | 572 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 575 info->SetString(kShortcutNameKey, shortcut_name); | 573 info->SetString(kShortcutNameKey, shortcut_name); |
| 576 // This takes ownership of |info|. | 574 SetInfoForProfileAtIndex(index, std::move(info)); |
| 577 SetInfoForProfileAtIndex(index, info.release()); | |
| 578 } | 575 } |
| 579 | 576 |
| 580 void ProfileInfoCache::SetAuthInfoOfProfileAtIndex( | 577 void ProfileInfoCache::SetAuthInfoOfProfileAtIndex( |
| 581 size_t index, | 578 size_t index, |
| 582 const std::string& gaia_id, | 579 const std::string& gaia_id, |
| 583 const base::string16& user_name) { | 580 const base::string16& user_name) { |
| 584 // If both gaia_id and username are unchanged, abort early. | 581 // If both gaia_id and username are unchanged, abort early. |
| 585 if (gaia_id == GetGAIAIdOfProfileAtIndex(index) && | 582 if (gaia_id == GetGAIAIdOfProfileAtIndex(index) && |
| 586 user_name == GetUserNameOfProfileAtIndex(index)) { | 583 user_name == GetUserNameOfProfileAtIndex(index)) { |
| 587 return; | 584 return; |
| 588 } | 585 } |
| 589 | 586 |
| 590 std::unique_ptr<base::DictionaryValue> info( | 587 std::unique_ptr<base::DictionaryValue> info( |
| 591 GetInfoForProfileAtIndex(index)->DeepCopy()); | 588 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 592 | 589 |
| 593 info->SetString(kGAIAIdKey, gaia_id); | 590 info->SetString(kGAIAIdKey, gaia_id); |
| 594 info->SetString(kUserNameKey, user_name); | 591 info->SetString(kUserNameKey, user_name); |
| 595 | 592 |
| 596 // This takes ownership of |info|. | 593 SetInfoForProfileAtIndex(index, std::move(info)); |
| 597 SetInfoForProfileAtIndex(index, info.release()); | |
| 598 | 594 |
| 599 base::FilePath profile_path = GetPathOfProfileAtIndex(index); | 595 base::FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 600 for (auto& observer : observer_list_) | 596 for (auto& observer : observer_list_) |
| 601 observer.OnProfileAuthInfoChanged(profile_path); | 597 observer.OnProfileAuthInfoChanged(profile_path); |
| 602 } | 598 } |
| 603 | 599 |
| 604 void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index, | 600 void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index, |
| 605 size_t icon_index) { | 601 size_t icon_index) { |
| 606 if (!profiles::IsDefaultAvatarIconIndex(icon_index)) { | 602 if (!profiles::IsDefaultAvatarIconIndex(icon_index)) { |
| 607 DLOG(WARNING) << "Unknown avatar icon index: " << icon_index; | 603 DLOG(WARNING) << "Unknown avatar icon index: " << icon_index; |
| 608 // switch to generic avatar | 604 // switch to generic avatar |
| 609 icon_index = 0; | 605 icon_index = 0; |
| 610 } | 606 } |
| 611 std::unique_ptr<base::DictionaryValue> info( | 607 std::unique_ptr<base::DictionaryValue> info( |
| 612 GetInfoForProfileAtIndex(index)->DeepCopy()); | 608 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 613 info->SetString(kAvatarIconKey, | 609 info->SetString(kAvatarIconKey, |
| 614 profiles::GetDefaultAvatarIconUrl(icon_index)); | 610 profiles::GetDefaultAvatarIconUrl(icon_index)); |
| 615 // This takes ownership of |info|. | 611 SetInfoForProfileAtIndex(index, std::move(info)); |
| 616 SetInfoForProfileAtIndex(index, info.release()); | |
| 617 | 612 |
| 618 base::FilePath profile_path = GetPathOfProfileAtIndex(index); | 613 base::FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 619 | 614 |
| 620 if (!disable_avatar_download_for_testing_) | 615 if (!disable_avatar_download_for_testing_) |
| 621 DownloadHighResAvatarIfNeeded(icon_index, profile_path); | 616 DownloadHighResAvatarIfNeeded(icon_index, profile_path); |
| 622 | 617 |
| 623 for (auto& observer : observer_list_) | 618 for (auto& observer : observer_list_) |
| 624 observer.OnProfileAvatarChanged(profile_path); | 619 observer.OnProfileAvatarChanged(profile_path); |
| 625 } | 620 } |
| 626 | 621 |
| 627 void ProfileInfoCache::SetIsOmittedProfileAtIndex(size_t index, | 622 void ProfileInfoCache::SetIsOmittedProfileAtIndex(size_t index, |
| 628 bool is_omitted) { | 623 bool is_omitted) { |
| 629 if (IsOmittedProfileAtIndex(index) == is_omitted) | 624 if (IsOmittedProfileAtIndex(index) == is_omitted) |
| 630 return; | 625 return; |
| 631 std::unique_ptr<base::DictionaryValue> info( | 626 std::unique_ptr<base::DictionaryValue> info( |
| 632 GetInfoForProfileAtIndex(index)->DeepCopy()); | 627 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 633 info->SetBoolean(kIsOmittedFromProfileListKey, is_omitted); | 628 info->SetBoolean(kIsOmittedFromProfileListKey, is_omitted); |
| 634 // This takes ownership of |info|. | 629 SetInfoForProfileAtIndex(index, std::move(info)); |
| 635 SetInfoForProfileAtIndex(index, info.release()); | |
| 636 | 630 |
| 637 base::FilePath profile_path = GetPathOfProfileAtIndex(index); | 631 base::FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 638 for (auto& observer : observer_list_) | 632 for (auto& observer : observer_list_) |
| 639 observer.OnProfileIsOmittedChanged(profile_path); | 633 observer.OnProfileIsOmittedChanged(profile_path); |
| 640 } | 634 } |
| 641 | 635 |
| 642 void ProfileInfoCache::SetSupervisedUserIdOfProfileAtIndex( | 636 void ProfileInfoCache::SetSupervisedUserIdOfProfileAtIndex( |
| 643 size_t index, | 637 size_t index, |
| 644 const std::string& id) { | 638 const std::string& id) { |
| 645 if (GetSupervisedUserIdOfProfileAtIndex(index) == id) | 639 if (GetSupervisedUserIdOfProfileAtIndex(index) == id) |
| 646 return; | 640 return; |
| 647 std::unique_ptr<base::DictionaryValue> info( | 641 std::unique_ptr<base::DictionaryValue> info( |
| 648 GetInfoForProfileAtIndex(index)->DeepCopy()); | 642 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 649 info->SetString(kSupervisedUserId, id); | 643 info->SetString(kSupervisedUserId, id); |
| 650 // This takes ownership of |info|. | 644 SetInfoForProfileAtIndex(index, std::move(info)); |
| 651 SetInfoForProfileAtIndex(index, info.release()); | |
| 652 | 645 |
| 653 base::FilePath profile_path = GetPathOfProfileAtIndex(index); | 646 base::FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 654 for (auto& observer : observer_list_) | 647 for (auto& observer : observer_list_) |
| 655 observer.OnProfileSupervisedUserIdChanged(profile_path); | 648 observer.OnProfileSupervisedUserIdChanged(profile_path); |
| 656 } | 649 } |
| 657 | 650 |
| 658 void ProfileInfoCache::SetLocalAuthCredentialsOfProfileAtIndex( | 651 void ProfileInfoCache::SetLocalAuthCredentialsOfProfileAtIndex( |
| 659 size_t index, | 652 size_t index, |
| 660 const std::string& credentials) { | 653 const std::string& credentials) { |
| 661 std::unique_ptr<base::DictionaryValue> info( | 654 std::unique_ptr<base::DictionaryValue> info( |
| 662 GetInfoForProfileAtIndex(index)->DeepCopy()); | 655 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 663 info->SetString(kAuthCredentialsKey, credentials); | 656 info->SetString(kAuthCredentialsKey, credentials); |
| 664 // This takes ownership of |info|. | 657 SetInfoForProfileAtIndex(index, std::move(info)); |
| 665 SetInfoForProfileAtIndex(index, info.release()); | |
| 666 } | 658 } |
| 667 | 659 |
| 668 void ProfileInfoCache::SetPasswordChangeDetectionTokenAtIndex( | 660 void ProfileInfoCache::SetPasswordChangeDetectionTokenAtIndex( |
| 669 size_t index, | 661 size_t index, |
| 670 const std::string& token) { | 662 const std::string& token) { |
| 671 std::unique_ptr<base::DictionaryValue> info( | 663 std::unique_ptr<base::DictionaryValue> info( |
| 672 GetInfoForProfileAtIndex(index)->DeepCopy()); | 664 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 673 info->SetString(kPasswordTokenKey, token); | 665 info->SetString(kPasswordTokenKey, token); |
| 674 // This takes ownership of |info|. | 666 SetInfoForProfileAtIndex(index, std::move(info)); |
| 675 SetInfoForProfileAtIndex(index, info.release()); | |
| 676 } | 667 } |
| 677 | 668 |
| 678 void ProfileInfoCache::SetBackgroundStatusOfProfileAtIndex( | 669 void ProfileInfoCache::SetBackgroundStatusOfProfileAtIndex( |
| 679 size_t index, | 670 size_t index, |
| 680 bool running_background_apps) { | 671 bool running_background_apps) { |
| 681 if (GetBackgroundStatusOfProfileAtIndex(index) == running_background_apps) | 672 if (GetBackgroundStatusOfProfileAtIndex(index) == running_background_apps) |
| 682 return; | 673 return; |
| 683 std::unique_ptr<base::DictionaryValue> info( | 674 std::unique_ptr<base::DictionaryValue> info( |
| 684 GetInfoForProfileAtIndex(index)->DeepCopy()); | 675 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 685 info->SetBoolean(kBackgroundAppsKey, running_background_apps); | 676 info->SetBoolean(kBackgroundAppsKey, running_background_apps); |
| 686 // This takes ownership of |info|. | 677 SetInfoForProfileAtIndex(index, std::move(info)); |
| 687 SetInfoForProfileAtIndex(index, info.release()); | |
| 688 } | 678 } |
| 689 | 679 |
| 690 void ProfileInfoCache::SetGAIANameOfProfileAtIndex(size_t index, | 680 void ProfileInfoCache::SetGAIANameOfProfileAtIndex(size_t index, |
| 691 const base::string16& name) { | 681 const base::string16& name) { |
| 692 if (name == GetGAIANameOfProfileAtIndex(index)) | 682 if (name == GetGAIANameOfProfileAtIndex(index)) |
| 693 return; | 683 return; |
| 694 | 684 |
| 695 base::string16 old_display_name = GetNameOfProfileAtIndex(index); | 685 base::string16 old_display_name = GetNameOfProfileAtIndex(index); |
| 696 std::unique_ptr<base::DictionaryValue> info( | 686 std::unique_ptr<base::DictionaryValue> info( |
| 697 GetInfoForProfileAtIndex(index)->DeepCopy()); | 687 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 698 info->SetString(kGAIANameKey, name); | 688 info->SetString(kGAIANameKey, name); |
| 699 // This takes ownership of |info|. | 689 SetInfoForProfileAtIndex(index, std::move(info)); |
| 700 SetInfoForProfileAtIndex(index, info.release()); | |
| 701 base::string16 new_display_name = GetNameOfProfileAtIndex(index); | 690 base::string16 new_display_name = GetNameOfProfileAtIndex(index); |
| 702 base::FilePath profile_path = GetPathOfProfileAtIndex(index); | 691 base::FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 703 UpdateSortForProfileIndex(index); | 692 UpdateSortForProfileIndex(index); |
| 704 | 693 |
| 705 if (old_display_name != new_display_name) { | 694 if (old_display_name != new_display_name) { |
| 706 for (auto& observer : observer_list_) | 695 for (auto& observer : observer_list_) |
| 707 observer.OnProfileNameChanged(profile_path, old_display_name); | 696 observer.OnProfileNameChanged(profile_path, old_display_name); |
| 708 } | 697 } |
| 709 } | 698 } |
| 710 | 699 |
| 711 void ProfileInfoCache::SetGAIAGivenNameOfProfileAtIndex( | 700 void ProfileInfoCache::SetGAIAGivenNameOfProfileAtIndex( |
| 712 size_t index, | 701 size_t index, |
| 713 const base::string16& name) { | 702 const base::string16& name) { |
| 714 if (name == GetGAIAGivenNameOfProfileAtIndex(index)) | 703 if (name == GetGAIAGivenNameOfProfileAtIndex(index)) |
| 715 return; | 704 return; |
| 716 | 705 |
| 717 base::string16 old_display_name = GetNameOfProfileAtIndex(index); | 706 base::string16 old_display_name = GetNameOfProfileAtIndex(index); |
| 718 std::unique_ptr<base::DictionaryValue> info( | 707 std::unique_ptr<base::DictionaryValue> info( |
| 719 GetInfoForProfileAtIndex(index)->DeepCopy()); | 708 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 720 info->SetString(kGAIAGivenNameKey, name); | 709 info->SetString(kGAIAGivenNameKey, name); |
| 721 // This takes ownership of |info|. | 710 SetInfoForProfileAtIndex(index, std::move(info)); |
| 722 SetInfoForProfileAtIndex(index, info.release()); | |
| 723 base::string16 new_display_name = GetNameOfProfileAtIndex(index); | 711 base::string16 new_display_name = GetNameOfProfileAtIndex(index); |
| 724 base::FilePath profile_path = GetPathOfProfileAtIndex(index); | 712 base::FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 725 UpdateSortForProfileIndex(index); | 713 UpdateSortForProfileIndex(index); |
| 726 | 714 |
| 727 if (old_display_name != new_display_name) { | 715 if (old_display_name != new_display_name) { |
| 728 for (auto& observer : observer_list_) | 716 for (auto& observer : observer_list_) |
| 729 observer.OnProfileNameChanged(profile_path, old_display_name); | 717 observer.OnProfileNameChanged(profile_path, old_display_name); |
| 730 } | 718 } |
| 731 } | 719 } |
| 732 | 720 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 755 new_file_name = | 743 new_file_name = |
| 756 old_file_name.empty() ? profiles::kGAIAPictureFileName : old_file_name; | 744 old_file_name.empty() ? profiles::kGAIAPictureFileName : old_file_name; |
| 757 base::FilePath image_path = path.AppendASCII(new_file_name); | 745 base::FilePath image_path = path.AppendASCII(new_file_name); |
| 758 SaveAvatarImageAtPath( | 746 SaveAvatarImageAtPath( |
| 759 GetPathOfProfileAtIndex(index), image, key, image_path); | 747 GetPathOfProfileAtIndex(index), image, key, image_path); |
| 760 } | 748 } |
| 761 | 749 |
| 762 std::unique_ptr<base::DictionaryValue> info( | 750 std::unique_ptr<base::DictionaryValue> info( |
| 763 GetInfoForProfileAtIndex(index)->DeepCopy()); | 751 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 764 info->SetString(kGAIAPictureFileNameKey, new_file_name); | 752 info->SetString(kGAIAPictureFileNameKey, new_file_name); |
| 765 // This takes ownership of |info|. | 753 SetInfoForProfileAtIndex(index, std::move(info)); |
| 766 SetInfoForProfileAtIndex(index, info.release()); | |
| 767 | 754 |
| 768 for (auto& observer : observer_list_) | 755 for (auto& observer : observer_list_) |
| 769 observer.OnProfileAvatarChanged(path); | 756 observer.OnProfileAvatarChanged(path); |
| 770 } | 757 } |
| 771 | 758 |
| 772 void ProfileInfoCache::SetIsUsingGAIAPictureOfProfileAtIndex(size_t index, | 759 void ProfileInfoCache::SetIsUsingGAIAPictureOfProfileAtIndex(size_t index, |
| 773 bool value) { | 760 bool value) { |
| 774 std::unique_ptr<base::DictionaryValue> info( | 761 std::unique_ptr<base::DictionaryValue> info( |
| 775 GetInfoForProfileAtIndex(index)->DeepCopy()); | 762 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 776 info->SetBoolean(kUseGAIAPictureKey, value); | 763 info->SetBoolean(kUseGAIAPictureKey, value); |
| 777 // This takes ownership of |info|. | 764 SetInfoForProfileAtIndex(index, std::move(info)); |
| 778 SetInfoForProfileAtIndex(index, info.release()); | |
| 779 | 765 |
| 780 base::FilePath profile_path = GetPathOfProfileAtIndex(index); | 766 base::FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 781 for (auto& observer : observer_list_) | 767 for (auto& observer : observer_list_) |
| 782 observer.OnProfileAvatarChanged(profile_path); | 768 observer.OnProfileAvatarChanged(profile_path); |
| 783 } | 769 } |
| 784 | 770 |
| 785 void ProfileInfoCache::SetProfileSigninRequiredAtIndex(size_t index, | 771 void ProfileInfoCache::SetProfileSigninRequiredAtIndex(size_t index, |
| 786 bool value) { | 772 bool value) { |
| 787 if (value == ProfileIsSigninRequiredAtIndex(index)) | 773 if (value == ProfileIsSigninRequiredAtIndex(index)) |
| 788 return; | 774 return; |
| 789 | 775 |
| 790 std::unique_ptr<base::DictionaryValue> info( | 776 std::unique_ptr<base::DictionaryValue> info( |
| 791 GetInfoForProfileAtIndex(index)->DeepCopy()); | 777 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 792 info->SetBoolean(kSigninRequiredKey, value); | 778 info->SetBoolean(kSigninRequiredKey, value); |
| 793 // This takes ownership of |info|. | 779 SetInfoForProfileAtIndex(index, std::move(info)); |
| 794 SetInfoForProfileAtIndex(index, info.release()); | |
| 795 NotifyIsSigninRequiredChanged(GetPathOfProfileAtIndex(index)); | 780 NotifyIsSigninRequiredChanged(GetPathOfProfileAtIndex(index)); |
| 796 } | 781 } |
| 797 | 782 |
| 798 void ProfileInfoCache::SetProfileIsEphemeralAtIndex(size_t index, bool value) { | 783 void ProfileInfoCache::SetProfileIsEphemeralAtIndex(size_t index, bool value) { |
| 799 if (value == ProfileIsEphemeralAtIndex(index)) | 784 if (value == ProfileIsEphemeralAtIndex(index)) |
| 800 return; | 785 return; |
| 801 | 786 |
| 802 std::unique_ptr<base::DictionaryValue> info( | 787 std::unique_ptr<base::DictionaryValue> info( |
| 803 GetInfoForProfileAtIndex(index)->DeepCopy()); | 788 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 804 info->SetBoolean(kProfileIsEphemeral, value); | 789 info->SetBoolean(kProfileIsEphemeral, value); |
| 805 // This takes ownership of |info|. | 790 SetInfoForProfileAtIndex(index, std::move(info)); |
| 806 SetInfoForProfileAtIndex(index, info.release()); | |
| 807 } | 791 } |
| 808 | 792 |
| 809 void ProfileInfoCache::SetProfileIsUsingDefaultNameAtIndex( | 793 void ProfileInfoCache::SetProfileIsUsingDefaultNameAtIndex( |
| 810 size_t index, bool value) { | 794 size_t index, bool value) { |
| 811 if (value == ProfileIsUsingDefaultNameAtIndex(index)) | 795 if (value == ProfileIsUsingDefaultNameAtIndex(index)) |
| 812 return; | 796 return; |
| 813 | 797 |
| 814 base::string16 old_display_name = GetNameOfProfileAtIndex(index); | 798 base::string16 old_display_name = GetNameOfProfileAtIndex(index); |
| 815 | 799 |
| 816 std::unique_ptr<base::DictionaryValue> info( | 800 std::unique_ptr<base::DictionaryValue> info( |
| 817 GetInfoForProfileAtIndex(index)->DeepCopy()); | 801 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 818 info->SetBoolean(kIsUsingDefaultNameKey, value); | 802 info->SetBoolean(kIsUsingDefaultNameKey, value); |
| 819 // This takes ownership of |info|. | 803 SetInfoForProfileAtIndex(index, std::move(info)); |
| 820 SetInfoForProfileAtIndex(index, info.release()); | |
| 821 | 804 |
| 822 base::string16 new_display_name = GetNameOfProfileAtIndex(index); | 805 base::string16 new_display_name = GetNameOfProfileAtIndex(index); |
| 823 const base::FilePath profile_path = GetPathOfProfileAtIndex(index); | 806 const base::FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 824 | 807 |
| 825 if (old_display_name != new_display_name) { | 808 if (old_display_name != new_display_name) { |
| 826 for (auto& observer : observer_list_) | 809 for (auto& observer : observer_list_) |
| 827 observer.OnProfileNameChanged(profile_path, old_display_name); | 810 observer.OnProfileNameChanged(profile_path, old_display_name); |
| 828 } | 811 } |
| 829 } | 812 } |
| 830 | 813 |
| 831 void ProfileInfoCache::SetProfileIsUsingDefaultAvatarAtIndex( | 814 void ProfileInfoCache::SetProfileIsUsingDefaultAvatarAtIndex( |
| 832 size_t index, bool value) { | 815 size_t index, bool value) { |
| 833 if (value == ProfileIsUsingDefaultAvatarAtIndex(index)) | 816 if (value == ProfileIsUsingDefaultAvatarAtIndex(index)) |
| 834 return; | 817 return; |
| 835 | 818 |
| 836 std::unique_ptr<base::DictionaryValue> info( | 819 std::unique_ptr<base::DictionaryValue> info( |
| 837 GetInfoForProfileAtIndex(index)->DeepCopy()); | 820 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 838 info->SetBoolean(kIsUsingDefaultAvatarKey, value); | 821 info->SetBoolean(kIsUsingDefaultAvatarKey, value); |
| 839 // This takes ownership of |info|. | 822 SetInfoForProfileAtIndex(index, std::move(info)); |
| 840 SetInfoForProfileAtIndex(index, info.release()); | |
| 841 } | 823 } |
| 842 | 824 |
| 843 void ProfileInfoCache::SetProfileIsAuthErrorAtIndex(size_t index, bool value) { | 825 void ProfileInfoCache::SetProfileIsAuthErrorAtIndex(size_t index, bool value) { |
| 844 if (value == ProfileIsAuthErrorAtIndex(index)) | 826 if (value == ProfileIsAuthErrorAtIndex(index)) |
| 845 return; | 827 return; |
| 846 | 828 |
| 847 std::unique_ptr<base::DictionaryValue> info( | 829 std::unique_ptr<base::DictionaryValue> info( |
| 848 GetInfoForProfileAtIndex(index)->DeepCopy()); | 830 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 849 info->SetBoolean(kIsAuthErrorKey, value); | 831 info->SetBoolean(kIsAuthErrorKey, value); |
| 850 // This takes ownership of |info|. | 832 SetInfoForProfileAtIndex(index, std::move(info)); |
| 851 SetInfoForProfileAtIndex(index, info.release()); | |
| 852 } | 833 } |
| 853 | 834 |
| 854 void ProfileInfoCache::SetStatsBrowsingHistoryOfProfileAtIndex(size_t index, | 835 void ProfileInfoCache::SetStatsBrowsingHistoryOfProfileAtIndex(size_t index, |
| 855 int value) { | 836 int value) { |
| 856 std::unique_ptr<base::DictionaryValue> info( | 837 std::unique_ptr<base::DictionaryValue> info( |
| 857 GetInfoForProfileAtIndex(index)->DeepCopy()); | 838 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 858 info->SetInteger(kStatsBrowsingHistoryKey, value); | 839 info->SetInteger(kStatsBrowsingHistoryKey, value); |
| 859 // This takes ownership of |info|. | 840 SetInfoForProfileAtIndex(index, std::move(info)); |
| 860 SetInfoForProfileAtIndex(index, info.release()); | |
| 861 } | 841 } |
| 862 | 842 |
| 863 void ProfileInfoCache::SetStatsPasswordsOfProfileAtIndex(size_t index, | 843 void ProfileInfoCache::SetStatsPasswordsOfProfileAtIndex(size_t index, |
| 864 int value) { | 844 int value) { |
| 865 std::unique_ptr<base::DictionaryValue> info( | 845 std::unique_ptr<base::DictionaryValue> info( |
| 866 GetInfoForProfileAtIndex(index)->DeepCopy()); | 846 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 867 info->SetInteger(kStatsPasswordsKey, value); | 847 info->SetInteger(kStatsPasswordsKey, value); |
| 868 // This takes ownership of |info|. | 848 SetInfoForProfileAtIndex(index, std::move(info)); |
| 869 SetInfoForProfileAtIndex(index, info.release()); | |
| 870 } | 849 } |
| 871 | 850 |
| 872 void ProfileInfoCache::SetStatsBookmarksOfProfileAtIndex(size_t index, | 851 void ProfileInfoCache::SetStatsBookmarksOfProfileAtIndex(size_t index, |
| 873 int value) { | 852 int value) { |
| 874 std::unique_ptr<base::DictionaryValue> info( | 853 std::unique_ptr<base::DictionaryValue> info( |
| 875 GetInfoForProfileAtIndex(index)->DeepCopy()); | 854 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 876 info->SetInteger(kStatsBookmarksKey, value); | 855 info->SetInteger(kStatsBookmarksKey, value); |
| 877 // This takes ownership of |info|. | 856 SetInfoForProfileAtIndex(index, std::move(info)); |
| 878 SetInfoForProfileAtIndex(index, info.release()); | |
| 879 } | 857 } |
| 880 | 858 |
| 881 void ProfileInfoCache::SetStatsSettingsOfProfileAtIndex(size_t index, | 859 void ProfileInfoCache::SetStatsSettingsOfProfileAtIndex(size_t index, |
| 882 int value) { | 860 int value) { |
| 883 std::unique_ptr<base::DictionaryValue> info( | 861 std::unique_ptr<base::DictionaryValue> info( |
| 884 GetInfoForProfileAtIndex(index)->DeepCopy()); | 862 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 885 info->SetInteger(kStatsSettingsKey, value); | 863 info->SetInteger(kStatsSettingsKey, value); |
| 886 // This takes ownership of |info|. | 864 SetInfoForProfileAtIndex(index, std::move(info)); |
| 887 SetInfoForProfileAtIndex(index, info.release()); | |
| 888 } | 865 } |
| 889 | 866 |
| 890 void ProfileInfoCache::NotifyIsSigninRequiredChanged( | 867 void ProfileInfoCache::NotifyIsSigninRequiredChanged( |
| 891 const base::FilePath& profile_path) { | 868 const base::FilePath& profile_path) { |
| 892 for (auto& observer : observer_list_) | 869 for (auto& observer : observer_list_) |
| 893 observer.OnProfileSigninRequiredChanged(profile_path); | 870 observer.OnProfileSigninRequiredChanged(profile_path); |
| 894 } | 871 } |
| 895 | 872 |
| 896 const base::FilePath& ProfileInfoCache::GetUserDataDir() const { | 873 const base::FilePath& ProfileInfoCache::GetUserDataDir() const { |
| 897 return user_data_dir_; | 874 return user_data_dir_; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 const base::DictionaryValue* ProfileInfoCache::GetInfoForProfileAtIndex( | 942 const base::DictionaryValue* ProfileInfoCache::GetInfoForProfileAtIndex( |
| 966 size_t index) const { | 943 size_t index) const { |
| 967 DCHECK_LT(index, GetNumberOfProfiles()); | 944 DCHECK_LT(index, GetNumberOfProfiles()); |
| 968 const base::DictionaryValue* cache = | 945 const base::DictionaryValue* cache = |
| 969 prefs_->GetDictionary(prefs::kProfileInfoCache); | 946 prefs_->GetDictionary(prefs::kProfileInfoCache); |
| 970 const base::DictionaryValue* info = NULL; | 947 const base::DictionaryValue* info = NULL; |
| 971 cache->GetDictionaryWithoutPathExpansion(sorted_keys_[index], &info); | 948 cache->GetDictionaryWithoutPathExpansion(sorted_keys_[index], &info); |
| 972 return info; | 949 return info; |
| 973 } | 950 } |
| 974 | 951 |
| 975 void ProfileInfoCache::SetInfoForProfileAtIndex(size_t index, | 952 void ProfileInfoCache::SetInfoForProfileAtIndex( |
| 976 base::DictionaryValue* info) { | 953 size_t index, |
| 954 std::unique_ptr<base::DictionaryValue> info) { |
| 977 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); | 955 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); |
| 978 base::DictionaryValue* cache = update.Get(); | 956 base::DictionaryValue* cache = update.Get(); |
| 979 cache->SetWithoutPathExpansion(sorted_keys_[index], info); | 957 cache->SetWithoutPathExpansion(sorted_keys_[index], std::move(info)); |
| 980 } | 958 } |
| 981 | 959 |
| 982 std::string ProfileInfoCache::CacheKeyFromProfilePath( | 960 std::string ProfileInfoCache::CacheKeyFromProfilePath( |
| 983 const base::FilePath& profile_path) const { | 961 const base::FilePath& profile_path) const { |
| 984 DCHECK(user_data_dir_ == profile_path.DirName()); | 962 DCHECK(user_data_dir_ == profile_path.DirName()); |
| 985 base::FilePath base_name = profile_path.BaseName(); | 963 base::FilePath base_name = profile_path.BaseName(); |
| 986 return base_name.MaybeAsASCII(); | 964 return base_name.MaybeAsASCII(); |
| 987 } | 965 } |
| 988 | 966 |
| 989 std::vector<std::string>::iterator ProfileInfoCache::FindPositionForProfile( | 967 std::vector<std::string>::iterator ProfileInfoCache::FindPositionForProfile( |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1233 if (!current_entry) { | 1211 if (!current_entry) { |
| 1234 // The profile info is in the cache but its entry isn't created yet, insert | 1212 // The profile info is in the cache but its entry isn't created yet, insert |
| 1235 // it in the map. | 1213 // it in the map. |
| 1236 current_entry.reset(new ProfileAttributesEntry()); | 1214 current_entry.reset(new ProfileAttributesEntry()); |
| 1237 current_entry->Initialize(this, path); | 1215 current_entry->Initialize(this, path); |
| 1238 } | 1216 } |
| 1239 | 1217 |
| 1240 *entry = current_entry.get(); | 1218 *entry = current_entry.get(); |
| 1241 return true; | 1219 return true; |
| 1242 } | 1220 } |
| OLD | NEW |