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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 | 69 |
70 // The delay before updating the JumpList to prevent update storms. | 70 // The delay before updating the JumpList to prevent update storms. |
71 constexpr base::TimeDelta kDelayForJumplistUpdate = | 71 constexpr base::TimeDelta kDelayForJumplistUpdate = |
72 base::TimeDelta::FromMilliseconds(3500); | 72 base::TimeDelta::FromMilliseconds(3500); |
73 | 73 |
74 // The maximum allowed time for JumpListUpdater::BeginUpdate. Updates taking | 74 // The maximum allowed time for JumpListUpdater::BeginUpdate. Updates taking |
75 // longer than this are discarded to prevent bogging down slow machines. | 75 // longer than this are discarded to prevent bogging down slow machines. |
76 constexpr base::TimeDelta kTimeOutForJumplistBeginUpdate = | 76 constexpr base::TimeDelta kTimeOutForJumplistBeginUpdate = |
77 base::TimeDelta::FromMilliseconds(500); | 77 base::TimeDelta::FromMilliseconds(500); |
78 | 78 |
79 // The maximum allowed time for updating both "most visited" and "recently | 79 // The maximum allowed time for adding most visited pages custom category via |
80 // closed" categories via JumpListUpdater::AddCustomCategory. | 80 // JumpListUpdater::AddCustomCategory. |
81 constexpr base::TimeDelta kTimeOutForAddCustomCategory = | 81 constexpr base::TimeDelta kTimeOutForAddCustomCategory = |
82 base::TimeDelta::FromMilliseconds(500); | 82 base::TimeDelta::FromMilliseconds(300); |
83 | 83 |
84 // The maximum allowed time for JumpListUpdater::CommitUpdate. | 84 // The maximum allowed time for JumpListUpdater::CommitUpdate. |
85 constexpr base::TimeDelta kTimeOutForJumplistCommitUpdate = | 85 constexpr base::TimeDelta kTimeOutForJumplistCommitUpdate = |
86 base::TimeDelta::FromMilliseconds(1000); | 86 base::TimeDelta::FromMilliseconds(1000); |
87 | 87 |
88 // Appends the common switches to each shell link. | 88 // Appends the common switches to each shell link. |
89 void AppendCommonSwitches(ShellLinkItem* shell_link) { | 89 void AppendCommonSwitches(ShellLinkItem* shell_link) { |
90 const char* kSwitchNames[] = { switches::kUserDataDir }; | 90 const char* kSwitchNames[] = { switches::kUserDataDir }; |
91 const base::CommandLine& command_line = | 91 const base::CommandLine& command_line = |
92 *base::CommandLine::ForCurrentProcess(); | 92 *base::CommandLine::ForCurrentProcess(); |
(...skipping 20 matching lines...) Expand all Loading... | |
113 if (!base::CreateTemporaryFileInDir(icon_dir, &path)) | 113 if (!base::CreateTemporaryFileInDir(icon_dir, &path)) |
114 return false; | 114 return false; |
115 | 115 |
116 // Create an icon file from the favicon attached to the given |page|, and | 116 // Create an icon file from the favicon attached to the given |page|, and |
117 // save it as the temporary file. | 117 // save it as the temporary file. |
118 gfx::ImageFamily image_family; | 118 gfx::ImageFamily image_family; |
119 if (!image_skia.isNull()) { | 119 if (!image_skia.isNull()) { |
120 std::vector<float> supported_scales = image_skia.GetSupportedScales(); | 120 std::vector<float> supported_scales = image_skia.GetSupportedScales(); |
121 for (auto& scale : supported_scales) { | 121 for (auto& scale : supported_scales) { |
122 gfx::ImageSkiaRep image_skia_rep = image_skia.GetRepresentation(scale); | 122 gfx::ImageSkiaRep image_skia_rep = image_skia.GetRepresentation(scale); |
123 if (!image_skia_rep.is_null()) | 123 if (!image_skia_rep.is_null()) { |
124 image_family.Add( | 124 image_family.Add( |
125 gfx::Image::CreateFrom1xBitmap(image_skia_rep.sk_bitmap())); | 125 gfx::Image::CreateFrom1xBitmap(image_skia_rep.sk_bitmap())); |
126 } | |
126 } | 127 } |
127 } | 128 } |
128 | 129 |
129 if (!IconUtil::CreateIconFileFromImageFamily(image_family, path, | 130 if (!IconUtil::CreateIconFileFromImageFamily(image_family, path, |
130 IconUtil::NORMAL_WRITE)) { | 131 IconUtil::NORMAL_WRITE)) { |
131 // Delete the file created by CreateTemporaryFileInDir as it won't be used. | 132 // Delete the file created by CreateTemporaryFileInDir as it won't be used. |
132 base::DeleteFile(path, false); | 133 base::DeleteFile(path, false); |
133 return false; | 134 return false; |
134 } | 135 } |
135 | 136 |
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
697 bool most_visited_should_update, | 698 bool most_visited_should_update, |
698 bool recently_closed_should_update, | 699 bool recently_closed_should_update, |
699 IncognitoModePrefs::Availability incognito_availability, | 700 IncognitoModePrefs::Availability incognito_availability, |
700 UpdateTransaction* update_transaction) { | 701 UpdateTransaction* update_transaction) { |
701 DCHECK(update_transaction); | 702 DCHECK(update_transaction); |
702 | 703 |
703 JumpListUpdater jumplist_updater(app_id); | 704 JumpListUpdater jumplist_updater(app_id); |
704 | 705 |
705 base::ElapsedTimer begin_update_timer; | 706 base::ElapsedTimer begin_update_timer; |
706 | 707 |
707 if (!jumplist_updater.BeginUpdate()) | 708 bool begin_success = jumplist_updater.BeginUpdate(); |
708 return; | |
709 | 709 |
710 // Discard this JumpList update if JumpListUpdater::BeginUpdate takes longer | 710 // If JumpListUpdater::BeginUpdate takes longer than the maximum allowed time, |
711 // than the maximum allowed time, as it's very likely the following update | 711 // abort the current update as it's very likely the following steps will also |
712 // steps will also take a long time. | 712 // take a long time, and skip the next |kUpdatesToSkipUnderHeavyLoad| updates. |
713 if (begin_update_timer.Elapsed() >= kTimeOutForJumplistBeginUpdate) { | 713 if (begin_update_timer.Elapsed() >= kTimeOutForJumplistBeginUpdate) { |
714 update_transaction->update_timeout = true; | 714 update_transaction->update_timeout = true; |
715 return; | 715 return; |
716 } | 716 } |
717 | 717 |
718 if (!begin_success) | |
719 return; | |
720 | |
718 // Record the desired number of icons created in this JumpList update. | 721 // Record the desired number of icons created in this JumpList update. |
719 int icons_created = 0; | 722 int icons_created = 0; |
720 | 723 |
721 URLIconCache most_visited_icons_next; | 724 URLIconCache most_visited_icons_next; |
722 URLIconCache recently_closed_icons_next; | 725 URLIconCache recently_closed_icons_next; |
723 | 726 |
724 // Update the icons for "Most Visisted" category of the JumpList if needed. | 727 // Update the icons for "Most Visisted" category of the JumpList if needed. |
725 if (most_visited_should_update) { | 728 if (most_visited_should_update) { |
726 icons_created += UpdateIconFiles( | 729 icons_created += UpdateIconFiles( |
727 most_visited_icon_dir, most_visited_pages, kMostVisitedItems, | 730 most_visited_icon_dir, most_visited_pages, kMostVisitedItems, |
(...skipping 12 matching lines...) Expand all Loading... | |
740 UMA_HISTOGRAM_COUNTS_100("WinJumplist.CreateIconFilesCount", icons_created); | 743 UMA_HISTOGRAM_COUNTS_100("WinJumplist.CreateIconFilesCount", icons_created); |
741 | 744 |
742 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. | 745 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. |
743 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplist.UpdateJumpListDuration"); | 746 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplist.UpdateJumpListDuration"); |
744 | 747 |
745 base::ElapsedTimer add_custom_category_timer; | 748 base::ElapsedTimer add_custom_category_timer; |
746 | 749 |
747 // Update the "Most Visited" category of the JumpList if it exists. | 750 // Update the "Most Visited" category of the JumpList if it exists. |
748 // This update request is applied into the JumpList when we commit this | 751 // This update request is applied into the JumpList when we commit this |
749 // transaction. | 752 // transaction. |
750 if (!jumplist_updater.AddCustomCategory( | 753 bool add_category_success = jumplist_updater.AddCustomCategory( |
751 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED), | 754 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED), most_visited_pages, |
752 most_visited_pages, kMostVisitedItems)) { | 755 kMostVisitedItems); |
756 | |
757 // If AddCustomCategory takes longer than the maximum allowed time, abort the | |
758 // current update and skip the next |kUpdatesToSkipUnderHeavyLoad| updates. | |
759 // | |
760 // We only time adding custom category for most visited pages because | |
761 // 1. If processing the first category times out or fails, there is no need to | |
grt (UTC plus 2)
2017/07/03 06:24:15
i understand why it makes sense to consider this a
chengx
2017/07/09 23:08:49
To answer your question, I landed crrev/2964873002
| |
762 // process the second category. In this case, we are not able to time both | |
763 // categories. Then we need to select one category from the two. | |
764 // 2. Most visited category is selected because it always has 5 items, while | |
grt (UTC plus 2)
2017/07/03 06:24:15
why doesn't a newish user have fewer than 5?
to v
chengx
2017/07/09 23:08:49
It does have fewer than 5 items. Then it should ta
| |
765 // the number of items in recently closed category varies from 1 to 3. This | |
766 // means the runtime of AddCustomCategory API should be fixed for most | |
767 // visited category, but not for recently closed category. So a fixed | |
768 // timeout threshold is only valid for most visited category. | |
769 if (add_custom_category_timer.Elapsed() >= kTimeOutForAddCustomCategory) { | |
770 update_transaction->update_timeout = true; | |
753 return; | 771 return; |
754 } | 772 } |
755 | 773 |
774 if (!add_category_success) | |
775 return; | |
776 | |
756 // Update the "Recently Closed" category of the JumpList. | 777 // Update the "Recently Closed" category of the JumpList. |
757 if (!jumplist_updater.AddCustomCategory( | 778 if (!jumplist_updater.AddCustomCategory( |
758 l10n_util::GetStringUTF16(IDS_RECENTLY_CLOSED), recently_closed_pages, | 779 l10n_util::GetStringUTF16(IDS_RECENTLY_CLOSED), recently_closed_pages, |
759 kRecentlyClosedItems)) { | 780 kRecentlyClosedItems)) { |
760 return; | 781 return; |
761 } | 782 } |
762 | 783 |
763 // If AddCustomCategory takes longer than the maximum allowed time, abort the | |
764 // current update and skip the next |kUpdatesToSkipUnderHeavyLoad| updates. | |
765 if (add_custom_category_timer.Elapsed() >= kTimeOutForAddCustomCategory) { | |
766 update_transaction->update_timeout = true; | |
767 return; | |
768 } | |
769 | |
770 // Update the "Tasks" category of the JumpList. | 784 // Update the "Tasks" category of the JumpList. |
771 if (!UpdateTaskCategory(&jumplist_updater, incognito_availability)) | 785 if (!UpdateTaskCategory(&jumplist_updater, incognito_availability)) |
772 return; | 786 return; |
773 | 787 |
774 base::ElapsedTimer commit_update_timer; | 788 base::ElapsedTimer commit_update_timer; |
775 | 789 |
776 // Commit this transaction and send the updated JumpList to Windows. | 790 // Commit this transaction and send the updated JumpList to Windows. |
777 bool commit_success = jumplist_updater.CommitUpdate(); | 791 bool commit_success = jumplist_updater.CommitUpdate(); |
778 | 792 |
779 // If CommitUpdate call takes longer than the maximum allowed time, skip the | 793 // If CommitUpdate call takes longer than the maximum allowed time, skip the |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
863 const URLIconCache& icons_cache) { | 877 const URLIconCache& icons_cache) { |
864 // Put all cached icon file paths into a set. | 878 // Put all cached icon file paths into a set. |
865 base::flat_set<base::FilePath> cached_files; | 879 base::flat_set<base::FilePath> cached_files; |
866 cached_files.reserve(icons_cache.size()); | 880 cached_files.reserve(icons_cache.size()); |
867 | 881 |
868 for (const auto& url_path_pair : icons_cache) | 882 for (const auto& url_path_pair : icons_cache) |
869 cached_files.insert(url_path_pair.second); | 883 cached_files.insert(url_path_pair.second); |
870 | 884 |
871 DeleteNonCachedFiles(icon_dir, cached_files); | 885 DeleteNonCachedFiles(icon_dir, cached_files); |
872 } | 886 } |
OLD | NEW |