Index: chrome/browser/win/jumplist.cc |
diff --git a/chrome/browser/win/jumplist.cc b/chrome/browser/win/jumplist.cc |
index 7f8ecf1257bda62023d10ea3bf2b181b72fe7a6c..33cf249633debfaaefc272506d95e2ccb1291a34 100644 |
--- a/chrome/browser/win/jumplist.cc |
+++ b/chrome/browser/win/jumplist.cc |
@@ -4,6 +4,9 @@ |
#include "chrome/browser/win/jumplist.h" |
+#include <algorithm> |
+#include <iterator> |
+ |
#include "base/base_paths.h" |
#include "base/bind.h" |
#include "base/bind_helpers.h" |
@@ -193,6 +196,25 @@ base::FilePath GenerateJumplistIconDirName( |
return profile_dir.Append(dir_name); |
} |
+// Checks if the urls stored in |items| have new ones coming from |urls|. |
+bool HasNewMostVisitedItems(const ShellLinkItemList& items, |
+ const history::MostVisitedURLList& urls) { |
+ // If the number of the top sites going to be displayed is larger than the |
+ // current one, or if the available urls from TopSites are fewer than the ones |
+ // currenlty in display, we consider there are new most visited items. |
+ // Otherwise, check if the current urls stored in |items| are different from |
+ // |urls| to determine if there are new items. |
+ |
+ size_t topsites_count_updated = std::min(urls.size(), kMostVisitedItems); |
+ if (topsites_count_updated > items.size() || urls.size() < items.size()) |
+ return true; |
+ |
+ return std::equal(std::begin(items), std::end(items), std::begin(urls), |
grt (UTC plus 2)
2017/05/29 07:14:44
shouldn't this return false if the ranges are equa
chengx
2017/05/30 02:56:44
You're right. I've fixed this in the new patch set
|
+ [](const auto& item_ptr, const auto& most_visited_url) { |
+ return item_ptr->url() == most_visited_url.url.spec(); |
+ }); |
+} |
+ |
} // namespace |
JumpList::JumpListData::JumpListData() {} |
@@ -292,6 +314,12 @@ void JumpList::OnMostVisitedURLsAvailable( |
{ |
JumpListData* data = &jumplist_data_->data; |
base::AutoLock auto_lock(data->list_lock_); |
+ |
+ // There is no need to update the JumpList if the top most visited sites in |
+ // display have not changed. |
+ if (!HasNewMostVisitedItems(data->most_visited_pages_, urls)) |
+ return; |
+ |
data->most_visited_pages_.clear(); |
for (size_t i = 0; i < urls.size() && i < kMostVisitedItems; i++) { |