OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/win/jumplist.h" | 5 #include "chrome/browser/win/jumplist.h" |
6 | 6 |
7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 base::FilePath GenerateJumplistIconDirName( | 187 base::FilePath GenerateJumplistIconDirName( |
188 const base::FilePath& profile_dir, | 188 const base::FilePath& profile_dir, |
189 const base::FilePath::StringPieceType& suffix) { | 189 const base::FilePath::StringPieceType& suffix) { |
190 base::FilePath::StringType dir_name(chrome::kJumpListIconDirname); | 190 base::FilePath::StringType dir_name(chrome::kJumpListIconDirname); |
191 suffix.AppendToString(&dir_name); | 191 suffix.AppendToString(&dir_name); |
192 return profile_dir.Append(dir_name); | 192 return profile_dir.Append(dir_name); |
193 } | 193 } |
194 | 194 |
195 } // namespace | 195 } // namespace |
196 | 196 |
197 JumpList::UpdateResults::UpdateResults() {} | 197 JumpList::UpdateTransaction::UpdateTransaction() {} |
198 | 198 |
199 JumpList::UpdateResults::~UpdateResults() {} | 199 JumpList::UpdateTransaction::~UpdateTransaction() {} |
200 | 200 |
201 // static | 201 // static |
202 bool JumpList::Enabled() { | 202 bool JumpList::Enabled() { |
203 return JumpListUpdater::IsEnabled(); | 203 return JumpListUpdater::IsEnabled(); |
204 } | 204 } |
205 | 205 |
206 void JumpList::Shutdown() { | 206 void JumpList::Shutdown() { |
207 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 207 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
208 Terminate(); | 208 Terminate(); |
209 } | 209 } |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
545 | 545 |
546 base::FilePath profile_dir = profile_->GetPath(); | 546 base::FilePath profile_dir = profile_->GetPath(); |
547 | 547 |
548 // Check if incognito windows (or normal windows) are disabled by policy. | 548 // Check if incognito windows (or normal windows) are disabled by policy. |
549 IncognitoModePrefs::Availability incognito_availability = | 549 IncognitoModePrefs::Availability incognito_availability = |
550 IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); | 550 IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); |
551 | 551 |
552 // Make local copies of JumpList member variables and use them for an update. | 552 // Make local copies of JumpList member variables and use them for an update. |
553 ShellLinkItemList local_most_visited_pages = most_visited_pages_; | 553 ShellLinkItemList local_most_visited_pages = most_visited_pages_; |
554 ShellLinkItemList local_recently_closed_pages = recently_closed_pages_; | 554 ShellLinkItemList local_recently_closed_pages = recently_closed_pages_; |
555 | |
556 bool most_visited_should_update = most_visited_should_update_; | 555 bool most_visited_should_update = most_visited_should_update_; |
557 bool recently_closed_should_update = recently_closed_should_update_; | 556 bool recently_closed_should_update = recently_closed_should_update_; |
558 | 557 |
559 auto update_results = base::MakeUnique<UpdateResults>(); | 558 auto update_results = base::MakeUnique<UpdateTransaction>(); |
560 update_results->most_visited_icons_in_update = most_visited_icons_; | 559 update_results->most_visited_icons = most_visited_icons_; |
561 update_results->recently_closed_icons_in_update = recently_closed_icons_; | 560 update_results->recently_closed_icons = recently_closed_icons_; |
562 | 561 |
563 // Parameter evaluation order is unspecified in C++. Ensure the pointer value | 562 // Parameter evaluation order is unspecified in C++. Do the first bind and |
564 // is obtained before base::Passed() is called. | 563 // then move it into PostTaskAndReply to ensure the pointer value is obtained |
565 auto* update_results_raw = update_results.get(); | 564 // before base::Passed() is called. |
565 auto run_update = | |
566 base::Bind(&JumpList::RunUpdateJumpList, app_id_, profile_dir, | |
567 local_most_visited_pages, local_recently_closed_pages, | |
568 most_visited_should_update, recently_closed_should_update, | |
grt (UTC plus 2)
2017/06/23 09:36:14
is it possible for either this->*_should_update_ t
chengx
2017/06/23 18:52:38
You are right. There is no need to bind these two
| |
569 incognito_availability, update_results.get()); | |
566 | 570 |
567 // Post a task to update the JumpList, which consists of 1) create new icons, | 571 // Post a task to update the JumpList, which consists of 1) create new icons, |
568 // 2) delete old icons, 3) notify the OS. | 572 // 2) notify the OS, 3) delete old icons. |
569 if (!update_jumplist_task_runner_->PostTaskAndReply( | 573 if (!update_jumplist_task_runner_->PostTaskAndReply( |
570 FROM_HERE, | 574 FROM_HERE, std::move(run_update), |
571 base::Bind(&JumpList::RunUpdateJumpList, app_id_, profile_dir, | 575 base::Bind( |
572 local_most_visited_pages, local_recently_closed_pages, | 576 &JumpList::OnRunUpdateCompletion, weak_ptr_factory_.GetWeakPtr(), |
573 most_visited_should_update, recently_closed_should_update, | 577 base::Passed(std::move(update_results)), |
574 incognito_availability, update_results_raw), | 578 most_visited_should_update, recently_closed_should_update))) { |
575 base::Bind(&JumpList::OnRunUpdateCompletion, | 579 OnRunUpdateCompletion(base::MakeUnique<UpdateTransaction>(), false, false); |
576 weak_ptr_factory_.GetWeakPtr(), | |
577 base::Passed(std::move(update_results))))) { | |
578 OnRunUpdateCompletion(base::MakeUnique<UpdateResults>()); | |
579 } | 580 } |
580 } | 581 } |
581 | 582 |
582 void JumpList::OnRunUpdateCompletion( | 583 void JumpList::OnRunUpdateCompletion( |
583 std::unique_ptr<UpdateResults> update_results) { | 584 std::unique_ptr<UpdateTransaction> update_results, |
585 bool most_visited_should_update, | |
586 bool recently_closed_should_update) { | |
584 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 587 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
585 | 588 |
586 // Update JumpList member variables based on the results from the update run | 589 // Update JumpList member variables based on the results from the update run |
587 // just finished. | 590 // just finished. |
588 if (update_results->update_timeout) | 591 if (update_results->update_timeout) |
589 updates_to_skip_ = kUpdatesToSkipUnderHeavyLoad; | 592 updates_to_skip_ = kUpdatesToSkipUnderHeavyLoad; |
590 | 593 |
591 if (update_results->update_success) { | 594 if (update_results->update_success) { |
592 most_visited_icons_.swap(update_results->most_visited_icons_in_update); | 595 if (most_visited_should_update) { |
593 recently_closed_icons_.swap( | 596 most_visited_icons_.swap(update_results->most_visited_icons); |
grt (UTC plus 2)
2017/06/23 09:36:14
nit: swap() used to be the efficient way to move s
chengx
2017/06/23 18:52:38
Done. I think std::move better conveys the intent
| |
594 update_results->recently_closed_icons_in_update); | 597 most_visited_should_update_ = false; |
595 most_visited_should_update_ = false; | 598 } |
596 recently_closed_should_update_ = false; | 599 if (recently_closed_should_update) { |
600 recently_closed_icons_.swap(update_results->recently_closed_icons); | |
601 recently_closed_should_update_ = false; | |
602 } | |
597 } | 603 } |
598 | 604 |
599 update_in_progress_ = false; | 605 update_in_progress_ = false; |
600 | 606 |
601 // If there is any new notification during the update run just finished, start | 607 // If there is any new notification during the update run just finished, start |
602 // another JumpList update. | 608 // another JumpList update. |
603 // Otherwise, post tasks to delete the JumpListIcons and JumpListIconsOld | 609 // Otherwise, post tasks to delete the JumpListIcons and JumpListIconsOld |
604 // folders as they are no longer needed. Now we have the | 610 // folders as they are no longer needed. Now we have the |
605 // JumpListIcons{MostVisited, RecentClosed} folders instead. | 611 // JumpListIcons{MostVisited, RecentClosed} folders instead. |
606 if (top_sites_has_pending_notification_ || | 612 if (top_sites_has_pending_notification_ || |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
648 scoped_refptr<history::TopSites> top_sites = | 654 scoped_refptr<history::TopSites> top_sites = |
649 TopSitesFactory::GetForProfile(profile_); | 655 TopSitesFactory::GetForProfile(profile_); |
650 if (top_sites) | 656 if (top_sites) |
651 top_sites->RemoveObserver(this); | 657 top_sites->RemoveObserver(this); |
652 pref_change_registrar_.reset(); | 658 pref_change_registrar_.reset(); |
653 } | 659 } |
654 profile_ = nullptr; | 660 profile_ = nullptr; |
655 } | 661 } |
656 | 662 |
657 // static | 663 // static |
658 void JumpList::RunUpdateJumpList( | 664 void JumpList::CreateNewJumpListAndNotifyOS( |
659 const base::string16& app_id, | 665 const base::string16& app_id, |
660 const base::FilePath& profile_dir, | 666 const base::FilePath& most_visited_icon_dir, |
667 const base::FilePath& recently_closed_icon_dir, | |
661 const ShellLinkItemList& most_visited_pages, | 668 const ShellLinkItemList& most_visited_pages, |
662 const ShellLinkItemList& recently_closed_pages, | 669 const ShellLinkItemList& recently_closed_pages, |
663 bool most_visited_should_update, | 670 bool most_visited_should_update, |
664 bool recently_closed_should_update, | 671 bool recently_closed_should_update, |
665 IncognitoModePrefs::Availability incognito_availability, | 672 IncognitoModePrefs::Availability incognito_availability, |
666 UpdateResults* update_results) { | 673 UpdateTransaction* update_results) { |
667 if (!JumpListUpdater::IsEnabled()) | |
668 return; | |
669 | |
670 DCHECK(update_results); | 674 DCHECK(update_results); |
671 | 675 |
672 JumpListUpdater jumplist_updater(app_id); | 676 JumpListUpdater jumplist_updater(app_id); |
673 | 677 |
674 base::ElapsedTimer begin_update_timer; | 678 base::ElapsedTimer begin_update_timer; |
675 | 679 |
676 if (!jumplist_updater.BeginUpdate()) | 680 if (!jumplist_updater.BeginUpdate()) |
677 return; | 681 return; |
678 | 682 |
679 // Discard this JumpList update if JumpListUpdater::BeginUpdate takes longer | 683 // Discard this JumpList update if JumpListUpdater::BeginUpdate takes longer |
680 // than the maximum allowed time, as it's very likely the following update | 684 // than the maximum allowed time, as it's very likely the following update |
681 // steps will also take a long time. As we've not updated the icons on the | 685 // steps will also take a long time. |
682 // disk, discarding this update wont't affect the current JumpList used by OS. | |
683 if (begin_update_timer.Elapsed() >= kTimeOutForJumplistBeginUpdate) { | 686 if (begin_update_timer.Elapsed() >= kTimeOutForJumplistBeginUpdate) { |
684 update_results->update_timeout = true; | 687 update_results->update_timeout = true; |
685 return; | 688 return; |
686 } | 689 } |
687 | 690 |
688 // Record the desired number of icons created in this JumpList update. | 691 // Record the desired number of icons created in this JumpList update. |
689 int icons_created = 0; | 692 int icons_created = 0; |
690 | 693 |
694 URLIconCache most_visited_icons_next; | |
695 URLIconCache recently_closed_icons_next; | |
696 | |
691 // Update the icons for "Most Visisted" category of the JumpList if needed. | 697 // Update the icons for "Most Visisted" category of the JumpList if needed. |
692 if (most_visited_should_update) { | 698 if (most_visited_should_update) { |
693 base::FilePath icon_dir_most_visited = GenerateJumplistIconDirName( | |
694 profile_dir, FILE_PATH_LITERAL("MostVisited")); | |
695 | |
696 icons_created += UpdateIconFiles( | 699 icons_created += UpdateIconFiles( |
697 icon_dir_most_visited, most_visited_pages, kMostVisitedItems, | 700 most_visited_icon_dir, most_visited_pages, kMostVisitedItems, |
698 &update_results->most_visited_icons_in_update); | 701 &update_results->most_visited_icons, &most_visited_icons_next); |
699 } | 702 } |
700 | 703 |
701 // Update the icons for "Recently Closed" category of the JumpList if needed. | 704 // Update the icons for "Recently Closed" category of the JumpList if needed. |
702 if (recently_closed_should_update) { | 705 if (recently_closed_should_update) { |
703 base::FilePath icon_dir_recent_closed = GenerateJumplistIconDirName( | |
704 profile_dir, FILE_PATH_LITERAL("RecentClosed")); | |
705 | |
706 icons_created += UpdateIconFiles( | 706 icons_created += UpdateIconFiles( |
707 icon_dir_recent_closed, recently_closed_pages, kRecentlyClosedItems, | 707 recently_closed_icon_dir, recently_closed_pages, kRecentlyClosedItems, |
708 &update_results->recently_closed_icons_in_update); | 708 &update_results->recently_closed_icons, &recently_closed_icons_next); |
709 } | 709 } |
710 | 710 |
711 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. | 711 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. |
712 UMA_HISTOGRAM_COUNTS_100("WinJumplist.CreateIconFilesCount", icons_created); | 712 UMA_HISTOGRAM_COUNTS_100("WinJumplist.CreateIconFilesCount", icons_created); |
713 | 713 |
714 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. | 714 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. |
715 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplist.UpdateJumpListDuration"); | 715 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplist.UpdateJumpListDuration"); |
716 | 716 |
717 base::ElapsedTimer add_custom_category_timer; | 717 base::ElapsedTimer add_custom_category_timer; |
718 | 718 |
719 // Update the "Most Visited" category of the JumpList if it exists. | 719 // Update the "Most Visited" category of the JumpList if it exists. |
720 // This update request is applied into the JumpList when we commit this | 720 // This update request is applied into the JumpList when we commit this |
721 // transaction. | 721 // transaction. |
722 if (!jumplist_updater.AddCustomCategory( | 722 if (!jumplist_updater.AddCustomCategory( |
723 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED), | 723 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED), |
724 most_visited_pages, kMostVisitedItems)) { | 724 most_visited_pages, kMostVisitedItems)) { |
725 return; | 725 return; |
726 } | 726 } |
727 | 727 |
728 // Update the "Recently Closed" category of the JumpList. | 728 // Update the "Recently Closed" category of the JumpList. |
729 if (!jumplist_updater.AddCustomCategory( | 729 if (!jumplist_updater.AddCustomCategory( |
730 l10n_util::GetStringUTF16(IDS_RECENTLY_CLOSED), recently_closed_pages, | 730 l10n_util::GetStringUTF16(IDS_RECENTLY_CLOSED), recently_closed_pages, |
731 kRecentlyClosedItems)) { | 731 kRecentlyClosedItems)) { |
732 return; | 732 return; |
733 } | 733 } |
734 | 734 |
735 // If JumpListUpdater::AddCustomCategory or JumpListUpdater::CommitUpdate | 735 // If AddCustomCategory call takes longer than the maximum allowed time, abort |
736 // takes longer than the maximum allowed time, skip the next | 736 // the current update and skip the next |kUpdatesToSkipUnderHeavyLoad| |
737 // |kUpdatesToSkipUnderHeavyLoad| updates. This update should be finished | 737 // updates. |
738 // because we've already updated the icons on the disk. If discarding this | 738 if (add_custom_category_timer.Elapsed() >= kTimeOutForAddCustomCategory) { |
739 // update from here, some items in the current JumpList may not have icons | |
740 // as they've been delete from the disk. In this case, the background color of | |
741 // the JumpList panel is used instead, which doesn't look nice. | |
742 | |
743 if (add_custom_category_timer.Elapsed() >= kTimeOutForAddCustomCategory) | |
744 update_results->update_timeout = true; | 739 update_results->update_timeout = true; |
740 return; | |
741 } | |
745 | 742 |
746 // Update the "Tasks" category of the JumpList. | 743 // Update the "Tasks" category of the JumpList. |
747 if (!UpdateTaskCategory(&jumplist_updater, incognito_availability)) | 744 if (!UpdateTaskCategory(&jumplist_updater, incognito_availability)) |
748 return; | 745 return; |
749 | 746 |
750 base::ElapsedTimer commit_update_timer; | 747 base::ElapsedTimer commit_update_timer; |
751 | 748 |
752 // Commit this transaction and send the updated JumpList to Windows. | 749 // Commit this transaction and send the updated JumpList to Windows. |
753 if (jumplist_updater.CommitUpdate()) | 750 bool commit_success = jumplist_updater.CommitUpdate(); |
754 update_results->update_success = true; | |
755 | 751 |
752 // If CommitUpdate call takes longer than the maximum allowed time, abort the | |
753 // current update and skip the next |kUpdatesToSkipUnderHeavyLoad| updates. | |
grt (UTC plus 2)
2017/06/23 09:36:14
this doesn't abort the current update, as the curr
chengx
2017/06/23 18:52:38
Done.
| |
756 if (commit_update_timer.Elapsed() >= kTimeOutForJumplistCommitUpdate) | 754 if (commit_update_timer.Elapsed() >= kTimeOutForJumplistCommitUpdate) |
757 update_results->update_timeout = true; | 755 update_results->update_timeout = true; |
756 | |
757 if (commit_success) { | |
758 update_results->update_success = true; | |
759 // The swaps below ensure update_results always has the icons to keep. | |
760 if (most_visited_should_update) | |
761 update_results->most_visited_icons.swap(most_visited_icons_next); | |
762 if (recently_closed_should_update) | |
763 update_results->recently_closed_icons.swap(recently_closed_icons_next); | |
764 } | |
765 } | |
766 | |
767 // static | |
768 void JumpList::RunUpdateJumpList( | |
grt (UTC plus 2)
2017/06/23 09:36:14
nit: move this above CreateNewJumpListAndNotifyOS?
chengx
2017/06/23 18:52:38
Done.
| |
769 const base::string16& app_id, | |
770 const base::FilePath& profile_dir, | |
771 const ShellLinkItemList& most_visited_pages, | |
772 const ShellLinkItemList& recently_closed_pages, | |
773 bool most_visited_should_update, | |
774 bool recently_closed_should_update, | |
775 IncognitoModePrefs::Availability incognito_availability, | |
776 UpdateTransaction* update_results) { | |
777 if (!JumpListUpdater::IsEnabled()) | |
grt (UTC plus 2)
2017/06/23 09:36:14
is this needed? can IsEnabled() change from true t
chengx
2017/06/23 18:52:38
I think it should be moved to the very beginning o
| |
778 return; | |
779 | |
780 DCHECK(update_results); | |
781 | |
782 base::FilePath most_visited_icon_dir = GenerateJumplistIconDirName( | |
783 profile_dir, FILE_PATH_LITERAL("MostVisited")); | |
784 base::FilePath recently_closed_icon_dir = GenerateJumplistIconDirName( | |
785 profile_dir, FILE_PATH_LITERAL("RecentClosed")); | |
786 | |
787 CreateNewJumpListAndNotifyOS( | |
788 app_id, most_visited_icon_dir, recently_closed_icon_dir, | |
789 most_visited_pages, recently_closed_pages, most_visited_should_update, | |
790 recently_closed_should_update, incognito_availability, update_results); | |
791 | |
792 // Delete any obsolete icon files. | |
793 if (most_visited_should_update) | |
794 DeleteIconFiles(most_visited_icon_dir, update_results->most_visited_icons); | |
795 if (recently_closed_should_update) { | |
796 DeleteIconFiles(recently_closed_icon_dir, | |
797 update_results->recently_closed_icons); | |
798 } | |
758 } | 799 } |
759 | 800 |
760 // static | 801 // static |
761 int JumpList::UpdateIconFiles(const base::FilePath& icon_dir, | 802 int JumpList::UpdateIconFiles(const base::FilePath& icon_dir, |
762 const ShellLinkItemList& page_list, | 803 const ShellLinkItemList& page_list, |
763 size_t slot_limit, | 804 size_t slot_limit, |
764 URLIconCache* icon_cache) { | 805 URLIconCache* icon_cur, |
806 URLIconCache* icon_next) { | |
807 DCHECK(icon_cur); | |
808 DCHECK(icon_next); | |
809 | |
765 int icons_created = 0; | 810 int icons_created = 0; |
grt (UTC plus 2)
2017/06/23 09:36:14
nit: how about cleaning this up a tiny bit:
//
chengx
2017/06/23 18:52:38
Done. Thanks for the suggestion!
| |
766 | 811 |
767 // Clear the JumpList icon folder at |icon_dir| and the cache when | 812 // Clear the JumpList icon folder at |icon_dir| and the caches when |
768 // 1) |icon_cache| is empty. This happens when "Most visited" or "Recently | 813 // 1) |icon_cur| is empty. This happens when "Most visited" or "Recently |
769 // closed" category updates for the 1st time after Chrome is launched. | 814 // closed" category updates for the 1st time after Chrome is launched. |
770 // 2) The number of icons in |icon_dir| has exceeded the limit. | 815 // 2) The number of icons in |icon_dir| has exceeded the limit. |
771 if (icon_cache->empty() || FilesExceedLimitInDir(icon_dir, slot_limit * 2)) { | 816 if (icon_cur->empty() || FilesExceedLimitInDir(icon_dir, slot_limit * 2)) { |
772 DeleteDirectoryContentAndLogRuntime(icon_dir, kFileDeleteLimit); | 817 DeleteDirectoryContentAndLogRuntime(icon_dir, kFileDeleteLimit); |
773 icon_cache->clear(); | 818 icon_cur->clear(); |
819 icon_next->clear(); | |
820 | |
774 // Create new icons only when the directory exists and is empty. | 821 // Create new icons only when the directory exists and is empty. |
775 if (base::CreateDirectory(icon_dir) && base::IsDirectoryEmpty(icon_dir)) | 822 if (base::CreateDirectory(icon_dir) && base::IsDirectoryEmpty(icon_dir)) { |
776 icons_created += | 823 icons_created += |
777 CreateIconFiles(icon_dir, page_list, slot_limit, icon_cache); | 824 CreateIconFiles(icon_dir, page_list, slot_limit, icon_cur, icon_next); |
825 } | |
778 } else if (base::CreateDirectory(icon_dir)) { | 826 } else if (base::CreateDirectory(icon_dir)) { |
779 icons_created += | 827 icons_created += |
780 CreateIconFiles(icon_dir, page_list, slot_limit, icon_cache); | 828 CreateIconFiles(icon_dir, page_list, slot_limit, icon_cur, icon_next); |
781 DeleteIconFiles(icon_dir, icon_cache); | |
782 } | 829 } |
783 | 830 |
784 return icons_created; | 831 return icons_created; |
785 } | 832 } |
786 | 833 |
787 // static | 834 // static |
788 int JumpList::CreateIconFiles(const base::FilePath& icon_dir, | 835 int JumpList::CreateIconFiles(const base::FilePath& icon_dir, |
789 const ShellLinkItemList& item_list, | 836 const ShellLinkItemList& item_list, |
790 size_t max_items, | 837 size_t max_items, |
791 URLIconCache* icon_cache) { | 838 URLIconCache* icon_cur, |
grt (UTC plus 2)
2017/06/23 09:36:14
nit: pass |icon_cur| by constref
chengx
2017/06/23 18:52:38
Done.
| |
839 URLIconCache* icon_next) { | |
840 DCHECK(icon_cur); | |
841 DCHECK(icon_next); | |
842 | |
792 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. | 843 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. |
793 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplist.CreateIconFilesDuration"); | 844 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplist.CreateIconFilesDuration"); |
794 | 845 |
795 int icons_created = 0; | 846 int icons_created = 0; |
796 | 847 |
797 // Reuse icons for urls that already present in the current JumpList. | 848 // Reuse icons for urls that already present in the current JumpList. |
798 URLIconCache updated_map; | |
799 for (ShellLinkItemList::const_iterator iter = item_list.begin(); | 849 for (ShellLinkItemList::const_iterator iter = item_list.begin(); |
800 iter != item_list.end() && max_items > 0; ++iter, --max_items) { | 850 iter != item_list.end() && max_items > 0; ++iter, --max_items) { |
801 ShellLinkItem* item = iter->get(); | 851 ShellLinkItem* item = iter->get(); |
802 auto cache_iter = icon_cache->find(item->url()); | 852 auto cache_iter = icon_cur->find(item->url()); |
803 if (cache_iter != icon_cache->end()) { | 853 if (cache_iter != icon_cur->end()) { |
804 item->set_icon(cache_iter->second.value(), 0); | 854 item->set_icon(cache_iter->second.value(), 0); |
805 updated_map[item->url()] = cache_iter->second; | 855 (*icon_next)[item->url()] = cache_iter->second; |
806 } else { | 856 } else { |
807 base::FilePath icon_path; | 857 base::FilePath icon_path; |
808 if (CreateIconFile(item->icon_image(), icon_dir, &icon_path)) { | 858 if (CreateIconFile(item->icon_image(), icon_dir, &icon_path)) { |
809 ++icons_created; | 859 ++icons_created; |
810 item->set_icon(icon_path.value(), 0); | 860 item->set_icon(icon_path.value(), 0); |
811 updated_map[item->url()] = icon_path; | 861 (*icon_next)[item->url()] = icon_path; |
812 } | 862 } |
813 } | 863 } |
814 } | 864 } |
815 icon_cache->swap(updated_map); | |
816 | 865 |
817 return icons_created; | 866 return icons_created; |
818 } | 867 } |
819 | 868 |
820 // static | 869 // static |
821 void JumpList::DeleteIconFiles(const base::FilePath& icon_dir, | 870 void JumpList::DeleteIconFiles(const base::FilePath& icon_dir, |
822 URLIconCache* icon_cache) { | 871 const URLIconCache& icons_cache) { |
823 // Put all cached icon file paths into a set. | 872 // Put all cached icon file paths into a set. |
824 base::flat_set<base::FilePath> cached_files; | 873 base::flat_set<base::FilePath> cached_files; |
825 cached_files.reserve(icon_cache->size()); | 874 cached_files.reserve(icons_cache.size()); |
826 | 875 |
827 for (const auto& url_path_pair : *icon_cache) | 876 for (const auto& url_path_pair : icons_cache) |
828 cached_files.insert(url_path_pair.second); | 877 cached_files.insert(url_path_pair.second); |
829 | 878 |
830 DeleteNonCachedFiles(icon_dir, cached_files); | 879 DeleteNonCachedFiles(icon_dir, cached_files); |
831 } | 880 } |
OLD | NEW |