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

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

Issue 2844463003: Fix the number of JumpList slots assigned to each JumpList category (Closed)
Patch Set: Created 3 years, 8 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 | « no previous file | 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 <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 200
201 JumpListUpdater jumplist_updater(app_id); 201 JumpListUpdater jumplist_updater(app_id);
202 if (!jumplist_updater.BeginUpdate()) 202 if (!jumplist_updater.BeginUpdate())
203 return; 203 return;
204 204
205 // Stops jumplist update if JumpListUpdater's start times out, as it's very 205 // Stops jumplist update if JumpListUpdater's start times out, as it's very
206 // likely the following update steps will also take a long time. 206 // likely the following update steps will also take a long time.
207 if (begin_update_timer.Elapsed() >= kTimeOutForJumplistUpdate) 207 if (begin_update_timer.Elapsed() >= kTimeOutForJumplistUpdate)
208 return; 208 return;
209 209
210 // We allocate 60% of the given JumpList slots to "most-visited" items
211 // and 40% to "recently-closed" items, respectively.
212 // Nevertheless, if there are not so many items in |recently_closed_pages|,
213 // we give the remaining slots to "most-visited" items.
214 // The default maximum number of items to display in JumpList is 10. 210 // The default maximum number of items to display in JumpList is 10.
215 // https://msdn.microsoft.com/en-us/library/windows/desktop/dd378398(v=vs.85). aspx 211 // https://msdn.microsoft.com/library/windows/desktop/dd378398.aspx
216 const int kMostVisited = 60; 212 // The "Most visited" category title always takes 1 of the JumpList slots if
217 const int kRecentlyClosed = 40; 213 // |most_visited_pages| isn't empty.
214 // The "Recently closed" category title will also take 1 if
215 // |recently_closed_pages| isn't empty.
216 // For the remaining slots, we allocate 5/8 (i.e., 5 slots if both categories
217 // present) to "most-visited" items and 3/8 (i.e., 3 slots if both categories
218 // present) to "recently-closed" items, respectively.
219
220 const int kMostVisited = 50;
221 const int kRecentlyClosed = 30;
218 const int kTotal = kMostVisited + kRecentlyClosed; 222 const int kTotal = kMostVisited + kRecentlyClosed;
223
224 // Adjust the available jumplist slots accordingly.
gab 2017/04/25 18:43:11 // Adjust the available jumplist slots to account
chengx 2017/04/25 19:36:59 Done.
225 size_t user_max_items_adjusted = jumplist_updater.user_max_items();
226 if (!most_visited_pages.empty())
227 user_max_items_adjusted--;
gab 2017/04/25 18:43:11 pre-decrement here and below --user_max_items_adj
chengx 2017/04/25 19:36:59 Done.
228 if (!recently_closed_pages.empty())
229 user_max_items_adjusted--;
230
219 size_t most_visited_items = 231 size_t most_visited_items =
220 MulDiv(jumplist_updater.user_max_items(), kMostVisited, kTotal); 232 MulDiv(user_max_items_adjusted, kMostVisited, kTotal);
221 size_t recently_closed_items = 233 size_t recently_closed_items = user_max_items_adjusted - most_visited_items;
222 jumplist_updater.user_max_items() - most_visited_items;
223 if (recently_closed_pages.size() < recently_closed_items) { 234 if (recently_closed_pages.size() < recently_closed_items) {
224 most_visited_items += recently_closed_items - recently_closed_pages.size(); 235 most_visited_items += recently_closed_items - recently_closed_pages.size();
225 recently_closed_items = recently_closed_pages.size(); 236 recently_closed_items = recently_closed_pages.size();
226 } 237 }
227 238
228 // Delete the content in JumpListIcons folder and log the results to UMA. 239 // Delete the content in JumpListIcons folder and log the results to UMA.
229 DeleteDirectoryContentAndLogResults(icon_dir, kFileDeleteLimit); 240 DeleteDirectoryContentAndLogResults(icon_dir, kFileDeleteLimit);
230 241
231 // If JumpListIcons directory doesn't exist (we have tried to create it 242 // If JumpListIcons directory doesn't exist (we have tried to create it
232 // already) or is not empty, skip updating the jumplist icons. The jumplist 243 // already) or is not empty, skip updating the jumplist icons. The jumplist
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 // As noted above, we create a ShellLinkItem objects with the following 445 // As noted above, we create a ShellLinkItem objects with the following
435 // parameters. 446 // parameters.
436 // * arguments 447 // * arguments
437 // The last URL of the tab object. 448 // The last URL of the tab object.
438 // * title 449 // * title
439 // The title of the last URL. 450 // The title of the last URL.
440 // * icon 451 // * icon
441 // An empty string. This value is to be updated in OnFaviconDataAvailable(). 452 // An empty string. This value is to be updated in OnFaviconDataAvailable().
442 // This code is copied from 453 // This code is copied from
443 // RecentlyClosedTabsHandler::TabRestoreServiceChanged() to emulate it. 454 // RecentlyClosedTabsHandler::TabRestoreServiceChanged() to emulate it.
444 const int kRecentlyClosedCount = 4; 455 const int kRecentlyClosedCount = 3;
445 sessions::TabRestoreService* tab_restore_service = 456 sessions::TabRestoreService* tab_restore_service =
446 TabRestoreServiceFactory::GetForProfile(profile_); 457 TabRestoreServiceFactory::GetForProfile(profile_);
447 for (const auto& entry : tab_restore_service->entries()) { 458 for (const auto& entry : tab_restore_service->entries()) {
448 switch (entry->type) { 459 switch (entry->type) {
449 case sessions::TabRestoreService::TAB: 460 case sessions::TabRestoreService::TAB:
450 AddTab(static_cast<const sessions::TabRestoreService::Tab&>(*entry), 461 AddTab(static_cast<const sessions::TabRestoreService::Tab&>(*entry),
451 &temp_list, kRecentlyClosedCount); 462 &temp_list, kRecentlyClosedCount);
452 break; 463 break;
453 case sessions::TabRestoreService::WINDOW: 464 case sessions::TabRestoreService::WINDOW:
454 AddWindow( 465 AddWindow(
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { 643 void JumpList::TopSitesLoaded(history::TopSites* top_sites) {
633 } 644 }
634 645
635 void JumpList::TopSitesChanged(history::TopSites* top_sites, 646 void JumpList::TopSitesChanged(history::TopSites* top_sites,
636 ChangeReason change_reason) { 647 ChangeReason change_reason) {
637 top_sites->GetMostVisitedURLs( 648 top_sites->GetMostVisitedURLs(
638 base::Bind(&JumpList::OnMostVisitedURLsAvailable, 649 base::Bind(&JumpList::OnMostVisitedURLsAvailable,
639 weak_ptr_factory_.GetWeakPtr()), 650 weak_ptr_factory_.GetWeakPtr()),
640 false); 651 false);
641 } 652 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698