diff options
author | hbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-18 08:32:35 +0000 |
---|---|---|
committer | hbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-18 08:32:35 +0000 |
commit | b703a4aa4d7f4674069b51e8cfae70ea7dc10a54 (patch) | |
tree | 488ec290cf09b00320c28505469a27e2c1e035fd /chrome/browser/jumplist.cc | |
parent | 9c214d9e2dcc0e2d4565fefb2702c194018e2b0d (diff) | |
download | chromium_src-b703a4aa4d7f4674069b51e8cfae70ea7dc10a54.zip chromium_src-b703a4aa4d7f4674069b51e8cfae70ea7dc10a54.tar.gz chromium_src-b703a4aa4d7f4674069b51e8cfae70ea7dc10a54.tar.bz2 |
A fix for Issue 18994.
This change retrieves the number of slots available for custom JumpList items to calculate the items for "Most Visited" items and for "Recently Closed" items.
As written in the MSDN doc, Windows 7 changes the number of JumpList slots at run time and it truncates the items from the bottom (i.e. "Recently Closed" items) if we add more items than available ones.
To fix this issue, this change assigned 60% of available JumpList slots to the "Most Visited" category and 40% to the "Recently Closed" category, respectively. (If there are not so many "Recently Closed" Items, this change increases the number of "Most Visited" items.)
Also, this change sets the AppID since <http://codereview.chromium.org/385120> changes it.
BUG=18994
TEST=Open a JumpList and see there are two or more "Recently Closed" items in it.
Review URL: http://codereview.chromium.org/399031
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32308 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/jumplist.cc')
-rw-r--r-- | chrome/browser/jumplist.cc | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/chrome/browser/jumplist.cc b/chrome/browser/jumplist.cc index 6a45201..03fab2f 100644 --- a/chrome/browser/jumplist.cc +++ b/chrome/browser/jumplist.cc @@ -34,6 +34,7 @@ #include "googleurl/src/gurl.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "grit/chromium_strings.h" #include "grit/generated_resources.h" namespace { @@ -280,11 +281,12 @@ HRESULT UpdateCategory(ScopedComPtr<ICustomDestinationList> list, int category_id, const std::wstring& application, const std::wstring& switches, - const ShellLinkItemList& data) { + const ShellLinkItemList& data, + int max_slots) { // Exit this function when the given vector does not contain any items // because an ICustomDestinationList::AppendCategory() call fails in this // case. - if (data.empty()) + if (data.empty() || !max_slots) return S_OK; std::wstring category = l10n_util::GetString(category_id); @@ -299,7 +301,7 @@ HRESULT UpdateCategory(ScopedComPtr<ICustomDestinationList> list, return false; for (ShellLinkItemList::const_iterator item = data.begin(); - item != data.end(); ++item) { + item != data.end() && max_slots > 0; ++item, --max_slots) { scoped_refptr<ShellLinkItem> link(*item); AddShellLink(collection, application, switches, link); } @@ -393,6 +395,9 @@ bool UpdateJumpList(const ShellLinkItemList& most_visited_pages, if (FAILED(result)) return false; + // Set the App ID for this JumpList. + destination_list->SetAppID(l10n_util::GetString(IDS_PRODUCT_NAME).c_str()); + // Start a transaction that updates the JumpList of this application. // This implementation just replaces the all items in this JumpList, so // we don't have to use the IObjectArray object returned from this call. @@ -413,17 +418,33 @@ bool UpdateJumpList(const ShellLinkItemList& most_visited_pages, // Retrieve the command-line switches of this process. std::wstring chrome_switches; + // We allocate 60% of the given JumpList slots to "most-visited" items + // and 40% 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. + const int kMostVisited = 60; + const int kRecentlyClosed = 40; + const int kTotal = kMostVisited + kRecentlyClosed; + size_t most_visited_items = MulDiv(max_slots, kMostVisited, kTotal); + size_t recently_closed_items = max_slots - 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(); + } + // Update the "Most Visited" category of the JumpList. // This update request is applied into the JumpList when we commit this // transaction. result = UpdateCategory(destination_list, IDS_NEW_TAB_MOST_VISITED, - chrome_path, chrome_switches, most_visited_pages); + chrome_path, chrome_switches, most_visited_pages, + most_visited_items); if (FAILED(result)) return false; // Update the "Recently Closed" category of the JumpList. result = UpdateCategory(destination_list, IDS_NEW_TAB_RECENTLY_CLOSED, - chrome_path, chrome_switches, recently_closed_pages); + chrome_path, chrome_switches, recently_closed_pages, + recently_closed_items); if (FAILED(result)) return false; @@ -690,6 +711,7 @@ void JumpList::OnSegmentUsageAvailable( // An empty string. This value is to be updated in OnFavIconDataAvailable(). // This code is copied from // RecentlyClosedTabsHandler::TabRestoreServiceChanged() to emulate it. + const int kRecentlyClosedCount = 4; recently_closed_pages_.clear(); TabRestoreService* tab_restore_service = profile_->GetTabRestoreService(); const TabRestoreService::Entries& entries = tab_restore_service->entries(); @@ -698,10 +720,10 @@ void JumpList::OnSegmentUsageAvailable( const TabRestoreService::Entry* entry = *it; if (entry->type == TabRestoreService::TAB) { AddTab(static_cast<const TabRestoreService::Tab*>(entry), - &recently_closed_pages_, 3); + &recently_closed_pages_, kRecentlyClosedCount); } else if (entry->type == TabRestoreService::WINDOW) { AddWindow(static_cast<const TabRestoreService::Window*>(entry), - &recently_closed_pages_, 3); + &recently_closed_pages_, kRecentlyClosedCount); } } |