Index: chrome/browser/win/jumplist.cc |
diff --git a/chrome/browser/win/jumplist.cc b/chrome/browser/win/jumplist.cc |
index 9054e20864d8e2a1c324c721d904440b9fabaf9f..d08ddb2ef38c6152daba414cd5d88f941000d1a7 100644 |
--- a/chrome/browser/win/jumplist.cc |
+++ b/chrome/browser/win/jumplist.cc |
@@ -221,12 +221,9 @@ JumpList::JumpList(Profile* profile) |
scoped_refptr<history::TopSites> top_sites = |
TopSitesFactory::GetForProfile(profile_); |
if (top_sites) { |
- // TopSites updates itself after a delay. This is especially noticable when |
- // your profile is empty. Ask TopSites to update itself when jumplist is |
- // initialized. |
- top_sites->SyncWithHistory(); |
// Register as TopSitesObserver so that we can update ourselves when the |
- // TopSites changes. |
+ // TopSites changes. TopSites updates itself after a delay. This is |
+ // especially noticable when your profile is empty. |
top_sites->AddObserver(this); |
} |
tab_restore_service->AddObserver(this); |
@@ -283,9 +280,9 @@ void JumpList::OnMostVisitedURLsAvailable( |
const history::MostVisitedURLList& urls) { |
DCHECK(CalledOnValidThread()); |
- // At most 9 JumpList items can be displayed for the "Most Visited" |
+ // At most 5 JumpList items can be displayed for the "Most Visited" |
// category. |
- const int kMostVistedCount = 9; |
+ const int kMostVistedCount = 5; |
{ |
JumpListData* data = &jumplist_data_->data; |
base::AutoLock auto_lock(data->list_lock_); |
@@ -532,6 +529,12 @@ void JumpList::DeferredTopSitesChanged() { |
return; |
} |
+ // Opening the first tab in one session triggers a TopSite history sync. |
+ // Delay this sync till the first tab is closed to allow the "recently closed" |
+ // category from last session stay longer. |
+ if (!has_tab_closed_) |
+ return; |
+ |
scoped_refptr<history::TopSites> top_sites = |
TopSitesFactory::GetForProfile(profile_); |
if (top_sites) { |
@@ -548,6 +551,15 @@ void JumpList::DeferredTabRestoreServiceChanged() { |
return; |
} |
+ // Force to do a TopSite history sync when closing a first tab in one session. |
grt (UTC plus 2)
2017/05/18 09:35:14
nit: "Force a TopSite..."
chengx
2017/05/19 02:11:58
Done.
|
+ if (!has_tab_closed_) { |
+ has_tab_closed_ = true; |
+ scoped_refptr<history::TopSites> top_sites = |
+ TopSitesFactory::GetForProfile(profile_); |
+ if (top_sites) |
+ top_sites->SyncWithHistory(); |
+ } |
+ |
// Create a list of ShellLinkItems from the "Recently Closed" pages. |
// As noted above, we create a ShellLinkItem objects with the following |
// parameters. |
@@ -642,34 +654,24 @@ bool JumpList::UpdateJumpList( |
// The default maximum number of items to display in JumpList is 10. |
// https://msdn.microsoft.com/library/windows/desktop/dd378398.aspx |
- // The "Most visited" category title always takes 1 of the JumpList slots if |
- // |most_visited_pages| isn't empty. |
- // The "Recently closed" category title will also take 1 if |
- // |recently_closed_pages| isn't empty. |
- // For the remaining slots, we allocate 5/8 (i.e., 5 slots if both categories |
- // present) to "most-visited" items and 3/8 (i.e., 3 slots if both categories |
- // present) to "recently-closed" items, respectively. |
- // Nevertheless, if there are not so many items in |recently_closed_pages|, |
- // we give the remaining slots to "most-visited" items. |
+ // The "Most visited" and "Recently closed" category titles always takes 2 of |
+ // the JumpList slots. For the remaining slots, we allocate 5/8 (i.e., 5 slots |
+ // by default) to "most-visited" items and 3/8 (i.e., 3 slots by default) to |
+ // "recently-closed" items, respectively. |
const int kMostVisited = 50; |
const int kRecentlyClosed = 30; |
const int kTotal = kMostVisited + kRecentlyClosed; |
- // Adjust the available jumplist slots to account for the category titles. |
- size_t user_max_items_adjusted = jumplist_updater.user_max_items(); |
- if (!most_visited_pages.empty()) |
- --user_max_items_adjusted; |
- if (!recently_closed_pages.empty()) |
- --user_max_items_adjusted; |
+ // Adjust the available jumplist slots to account for the two category titles. |
+ size_t user_max_items_adjusted = jumplist_updater.user_max_items() - 2; |
+ // Cap 5 items for "Most visited" category, and 3 items for "Recently closed" |
+ // category. |
+ user_max_items_adjusted = std::min((int)jumplist_updater.user_max_items(), 8); |
size_t most_visited_items = |
MulDiv(user_max_items_adjusted, kMostVisited, kTotal); |
size_t recently_closed_items = user_max_items_adjusted - most_visited_items; |
- if (recently_closed_pages.size() < recently_closed_items) { |
- most_visited_items += recently_closed_items - recently_closed_pages.size(); |
- recently_closed_items = recently_closed_pages.size(); |
- } |
// Record the desired number of icons to create in this JumpList update. |
int icons_to_create = 0; |