Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: chrome/browser/win/jumplist.cc

Issue 2898083003: Log the number of new icons created per jumplist update (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/win/jumplist.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 // Put all cached icon file paths into a set. 628 // Put all cached icon file paths into a set.
629 base::flat_set<base::FilePath> cached_files; 629 base::flat_set<base::FilePath> cached_files;
630 cached_files.reserve(source_map->size()); 630 cached_files.reserve(source_map->size());
631 631
632 for (const auto& url_path_pair : *source_map) 632 for (const auto& url_path_pair : *source_map)
633 cached_files.insert(url_path_pair.second); 633 cached_files.insert(url_path_pair.second);
634 634
635 DeleteNonCachedFiles(icon_dir, cached_files); 635 DeleteNonCachedFiles(icon_dir, cached_files);
636 } 636 }
637 637
638 void JumpList::CreateIconFiles(const base::FilePath& icon_dir, 638 int JumpList::CreateIconFiles(const base::FilePath& icon_dir,
639 const ShellLinkItemList& item_list, 639 const ShellLinkItemList& item_list,
640 size_t max_items, 640 size_t max_items,
641 JumpListCategory category) { 641 JumpListCategory category) {
642 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. 642 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407.
643 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplist.CreateIconFilesDuration"); 643 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplist.CreateIconFilesDuration");
644 644
645 int icons_created = 0;
646
645 // Reuse icons for urls that were already present in the jumplist for this 647 // Reuse icons for urls that were already present in the jumplist for this
646 // category. 648 // category.
647 649
648 base::flat_map<std::string, base::FilePath>* source_map = nullptr; 650 base::flat_map<std::string, base::FilePath>* source_map = nullptr;
649 switch (category) { 651 switch (category) {
650 case JumpListCategory::kMostVisited: 652 case JumpListCategory::kMostVisited:
651 source_map = &most_visited_icons_; 653 source_map = &most_visited_icons_;
652 break; 654 break;
653 case JumpListCategory::kRecentlyClosed: 655 case JumpListCategory::kRecentlyClosed:
654 source_map = &recently_closed_icons_; 656 source_map = &recently_closed_icons_;
655 break; 657 break;
656 } 658 }
657 659
658 base::flat_map<std::string, base::FilePath> updated_map; 660 base::flat_map<std::string, base::FilePath> updated_map;
659 661
660 for (ShellLinkItemList::const_iterator iter = item_list.begin(); 662 for (ShellLinkItemList::const_iterator iter = item_list.begin();
661 iter != item_list.end() && max_items > 0; ++iter, --max_items) { 663 iter != item_list.end() && max_items > 0; ++iter, --max_items) {
662 ShellLinkItem* item = iter->get(); 664 ShellLinkItem* item = iter->get();
663 auto cache_iter = source_map->find(item->url()); 665 auto cache_iter = source_map->find(item->url());
664 if (cache_iter != source_map->end()) { 666 if (cache_iter != source_map->end()) {
665 item->set_icon(cache_iter->second.value(), 0); 667 item->set_icon(cache_iter->second.value(), 0);
666 updated_map[item->url()] = cache_iter->second; 668 updated_map[item->url()] = cache_iter->second;
667 } else { 669 } else {
668 base::FilePath icon_path; 670 base::FilePath icon_path;
669 if (CreateIconFile(item->icon_image(), icon_dir, &icon_path)) { 671 if (CreateIconFile(item->icon_image(), icon_dir, &icon_path)) {
672 ++icons_created;
670 item->set_icon(icon_path.value(), 0); 673 item->set_icon(icon_path.value(), 0);
671 updated_map[item->url()] = icon_path; 674 updated_map[item->url()] = icon_path;
672 } 675 }
673 } 676 }
674 } 677 }
675 source_map->swap(updated_map); 678 source_map->swap(updated_map);
679
680 return icons_created;
676 } 681 }
677 682
678 void JumpList::UpdateIconFiles(const base::FilePath& icon_dir, 683 int JumpList::UpdateIconFiles(const base::FilePath& icon_dir,
679 const ShellLinkItemList& page_list, 684 const ShellLinkItemList& page_list,
680 size_t slot_limit, 685 size_t slot_limit,
681 JumpListCategory category) { 686 JumpListCategory category) {
687 int icons_created = 0;
688
682 // Maximum number of icon files that each JumpList icon folder may hold. 689 // Maximum number of icon files that each JumpList icon folder may hold.
683 size_t icon_limit = (category == JumpListCategory::kMostVisited) ? 10 : 6; 690 size_t icon_limit = (category == JumpListCategory::kMostVisited) ? 10 : 6;
684 691
685 // Clear the JumpList icon folder at |icon_dir| and the cache when 692 // Clear the JumpList icon folder at |icon_dir| and the cache when
686 // 1) "Most visited" category updates for the 1st time after Chrome is 693 // 1) "Most visited" category updates for the 1st time after Chrome is
687 // launched. This actually happens right after Chrome is launched. 694 // launched. This actually happens right after Chrome is launched.
688 // 2) "Recently closed" category updates for the 1st time after Chrome is 695 // 2) "Recently closed" category updates for the 1st time after Chrome is
689 // launched. 696 // launched.
690 // 3) The number of icons in |icon_dir| has exceeded the limit. 697 // 3) The number of icons in |icon_dir| has exceeded the limit.
691 if ((category == JumpListCategory::kMostVisited && 698 if ((category == JumpListCategory::kMostVisited &&
692 most_visited_icons_.empty()) || 699 most_visited_icons_.empty()) ||
693 (category == JumpListCategory::kRecentlyClosed && 700 (category == JumpListCategory::kRecentlyClosed &&
694 recently_closed_icons_.empty()) || 701 recently_closed_icons_.empty()) ||
695 FilesExceedLimitInDir(icon_dir, icon_limit)) { 702 FilesExceedLimitInDir(icon_dir, icon_limit)) {
696 DeleteDirectoryContentAndLogRuntime(icon_dir, kFileDeleteLimit); 703 DeleteDirectoryContentAndLogRuntime(icon_dir, kFileDeleteLimit);
697 most_visited_icons_.clear(); 704 most_visited_icons_.clear();
698 recently_closed_icons_.clear(); 705 recently_closed_icons_.clear();
699 // Create new icons only when the directory exists and is empty. 706 // Create new icons only when the directory exists and is empty.
700 if (base::CreateDirectory(icon_dir) && base::IsDirectoryEmpty(icon_dir)) 707 if (base::CreateDirectory(icon_dir) && base::IsDirectoryEmpty(icon_dir))
701 CreateIconFiles(icon_dir, page_list, slot_limit, category); 708 icons_created +=
709 CreateIconFiles(icon_dir, page_list, slot_limit, category);
702 } else if (base::CreateDirectory(icon_dir)) { 710 } else if (base::CreateDirectory(icon_dir)) {
703 CreateIconFiles(icon_dir, page_list, slot_limit, category); 711 icons_created += CreateIconFiles(icon_dir, page_list, slot_limit, category);
704 DeleteIconFiles(icon_dir, category); 712 DeleteIconFiles(icon_dir, category);
705 } 713 }
714
715 return icons_created;
706 } 716 }
707 717
708 bool JumpList::UpdateJumpList( 718 bool JumpList::UpdateJumpList(
709 const base::string16& app_id, 719 const base::string16& app_id,
710 const base::FilePath& profile_dir, 720 const base::FilePath& profile_dir,
711 const ShellLinkItemList& most_visited_pages, 721 const ShellLinkItemList& most_visited_pages,
712 const ShellLinkItemList& recently_closed_pages, 722 const ShellLinkItemList& recently_closed_pages,
713 bool most_visited_pages_have_updates, 723 bool most_visited_pages_have_updates,
714 bool recently_closed_pages_have_updates, 724 bool recently_closed_pages_have_updates,
715 IncognitoModePrefs::Availability incognito_availability) { 725 IncognitoModePrefs::Availability incognito_availability) {
716 if (!JumpListUpdater::IsEnabled()) 726 if (!JumpListUpdater::IsEnabled())
717 return true; 727 return true;
718 728
719 JumpListUpdater jumplist_updater(app_id); 729 JumpListUpdater jumplist_updater(app_id);
720 730
721 base::ElapsedTimer begin_update_timer; 731 base::ElapsedTimer begin_update_timer;
722 732
723 if (!jumplist_updater.BeginUpdate()) 733 if (!jumplist_updater.BeginUpdate())
724 return false; 734 return false;
725 735
726 // Discard this JumpList update if JumpListUpdater::BeginUpdate takes longer 736 // Discard this JumpList update if JumpListUpdater::BeginUpdate takes longer
727 // than the maximum allowed time, as it's very likely the following update 737 // than the maximum allowed time, as it's very likely the following update
728 // steps will also take a long time. As we've not updated the icons on the 738 // steps will also take a long time. As we've not updated the icons on the
729 // disk, discarding this update wont't affect the current JumpList used by OS. 739 // disk, discarding this update wont't affect the current JumpList used by OS.
730 if (begin_update_timer.Elapsed() >= kTimeOutForJumplistBeginUpdate) { 740 if (begin_update_timer.Elapsed() >= kTimeOutForJumplistBeginUpdate) {
731 updates_to_skip_ = kUpdatesToSkipUnderHeavyLoad; 741 updates_to_skip_ = kUpdatesToSkipUnderHeavyLoad;
732 return false; 742 return false;
733 } 743 }
734 744
735 // Record the desired number of icons to create in this JumpList update. 745 // Record the desired number of icons to create in this JumpList update.
grt (UTC plus 2) 2017/05/23 07:03:36 nit: update comment "Record the number of icons cr
chengx 2017/05/23 20:39:39 Done.
736 int icons_to_create = 0; 746 int icons_created = 0;
737 747
738 // Update the icons for "Most Visisted" category of the JumpList if needed. 748 // Update the icons for "Most Visisted" category of the JumpList if needed.
739 if (most_visited_pages_have_updates) { 749 if (most_visited_pages_have_updates) {
740 base::FilePath icon_dir_most_visited = GenerateJumplistIconDirName( 750 base::FilePath icon_dir_most_visited = GenerateJumplistIconDirName(
741 profile_dir, FILE_PATH_LITERAL("MostVisited")); 751 profile_dir, FILE_PATH_LITERAL("MostVisited"));
742 752
743 UpdateIconFiles(icon_dir_most_visited, most_visited_pages, 753 icons_created +=
744 kMostVisitedItems, JumpListCategory::kMostVisited); 754 UpdateIconFiles(icon_dir_most_visited, most_visited_pages,
745 755 kMostVisitedItems, JumpListCategory::kMostVisited);
746 icons_to_create += std::min(most_visited_pages.size(), kMostVisitedItems);
747 } 756 }
748 757
749 // Update the icons for "Recently Closed" category of the JumpList if needed. 758 // Update the icons for "Recently Closed" category of the JumpList if needed.
750 if (recently_closed_pages_have_updates) { 759 if (recently_closed_pages_have_updates) {
751 base::FilePath icon_dir_recent_closed = GenerateJumplistIconDirName( 760 base::FilePath icon_dir_recent_closed = GenerateJumplistIconDirName(
752 profile_dir, FILE_PATH_LITERAL("RecentClosed")); 761 profile_dir, FILE_PATH_LITERAL("RecentClosed"));
753 762
754 UpdateIconFiles(icon_dir_recent_closed, recently_closed_pages, 763 icons_created += UpdateIconFiles(
755 kRecentlyClosedItems, JumpListCategory::kRecentlyClosed); 764 icon_dir_recent_closed, recently_closed_pages, kRecentlyClosedItems,
756 765 JumpListCategory::kRecentlyClosed);
757 icons_to_create +=
758 std::min(recently_closed_pages.size(), kRecentlyClosedItems);
759 } 766 }
760 767
761 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. 768 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407.
762 UMA_HISTOGRAM_COUNTS_100("WinJumplist.CreateIconFilesCount", icons_to_create); 769 UMA_HISTOGRAM_COUNTS_100("WinJumplist.CreateIconFilesCount", icons_created);
763 770
764 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. 771 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407.
765 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplist.UpdateJumpListDuration"); 772 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplist.UpdateJumpListDuration");
766 773
767 base::ElapsedTimer add_custom_category_timer; 774 base::ElapsedTimer add_custom_category_timer;
768 775
769 // Update the "Most Visited" category of the JumpList if it exists. 776 // Update the "Most Visited" category of the JumpList if it exists.
770 // This update request is applied into the JumpList when we commit this 777 // This update request is applied into the JumpList when we commit this
771 // transaction. 778 // transaction.
772 if (!jumplist_updater.AddCustomCategory( 779 if (!jumplist_updater.AddCustomCategory(
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 app_id, profile_dir, local_most_visited_pages, 856 app_id, profile_dir, local_most_visited_pages,
850 local_recently_closed_pages, most_visited_pages_have_updates, 857 local_recently_closed_pages, most_visited_pages_have_updates,
851 recently_closed_pages_have_updates, incognito_availability)) { 858 recently_closed_pages_have_updates, incognito_availability)) {
852 base::AutoLock auto_lock(data->list_lock_); 859 base::AutoLock auto_lock(data->list_lock_);
853 if (most_visited_pages_have_updates) 860 if (most_visited_pages_have_updates)
854 data->most_visited_pages_have_updates_ = true; 861 data->most_visited_pages_have_updates_ = true;
855 if (recently_closed_pages_have_updates) 862 if (recently_closed_pages_have_updates)
856 data->recently_closed_pages_have_updates_ = true; 863 data->recently_closed_pages_have_updates_ = true;
857 } 864 }
858 } 865 }
OLDNEW
« no previous file with comments | « chrome/browser/win/jumplist.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698