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

Unified Diff: chrome/browser/win/jumplist.cc

Issue 2865133003: Defer syncing TopSites with history until the first tab closure (Closed)
Patch Set: Delay the history sync until 3 tabs are closed rather than 3 recently closed category updates are scheduled Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/win/jumplist.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/win/jumplist.cc
diff --git a/chrome/browser/win/jumplist.cc b/chrome/browser/win/jumplist.cc
index 24ac405c820d75e2c19b92784cc03fe21829bc8d..8e79909d34daad51f5bc05d60ceba9ab33b86d54 100644
--- a/chrome/browser/win/jumplist.cc
+++ b/chrome/browser/win/jumplist.cc
@@ -55,6 +55,10 @@ using JumpListData = JumpList::JumpListData;
namespace {
+// JumpList "Most Visited" category is forced to sync with the TopSites service
+// only after this number of tabs are closed after Chrome launches.
+constexpr int kTabClosedCountToDelayTopSitesSync = 3;
+
// The delay before updating the JumpList to prevent update storms.
constexpr base::TimeDelta kDelayForJumplistUpdate =
base::TimeDelta::FromMilliseconds(3500);
@@ -181,6 +185,8 @@ JumpList::JumpList(Profile* profile)
: RefcountedKeyedService(content::BrowserThread::GetTaskRunnerForThread(
content::BrowserThread::UI)),
profile_(profile),
+ tab_closed_count_(0),
+ initial_most_visited_update_done_(false),
jumplist_data_(new base::RefCountedData<JumpListData>),
task_id_(base::CancelableTaskTracker::kBadTaskId),
update_jumplist_task_runner_(base::CreateCOMSTATaskRunnerWithTraits(
@@ -208,12 +214,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);
@@ -270,9 +273,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_);
@@ -303,6 +306,8 @@ void JumpList::TabRestoreServiceChanged(sessions::TabRestoreService* service) {
// if we have a pending favicon request, cancel it here (it is out of date).
CancelPendingUpdate();
+ ++tab_closed_count_;
+
// Initialize the one-shot timer to update the the "Recently Closed" category
// in a while. If there is already a request queued then cancel it and post
// the new request. This ensures that JumpList update of the "Recently Closed"
@@ -514,6 +519,9 @@ void JumpList::TopSitesChanged(history::TopSites* top_sites,
}
void JumpList::DeferredTopSitesChanged() {
+ if (tab_closed_count_ < kTabClosedCountToDelayTopSitesSync)
+ return;
+
scoped_refptr<history::TopSites> top_sites =
TopSitesFactory::GetForProfile(profile_);
if (top_sites) {
@@ -525,6 +533,17 @@ void JumpList::DeferredTopSitesChanged() {
}
void JumpList::DeferredTabRestoreServiceChanged() {
+ if (tab_closed_count_ < kTabClosedCountToDelayTopSitesSync) {
+ return;
+ } else if (!initial_most_visited_update_done_) {
+ scoped_refptr<history::TopSites> top_sites =
+ TopSitesFactory::GetForProfile(profile_);
+ if (top_sites) {
+ top_sites->SyncWithHistory();
+ }
+ initial_most_visited_update_done_ = true;
+ }
+
// Create a list of ShellLinkItems from the "Recently Closed" pages.
// As noted above, we create a ShellLinkItem objects with the following
// parameters.
@@ -630,20 +649,12 @@ bool JumpList::UpdateJumpList(
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;
size_t most_visited_items =
MulDiv(user_max_items_adjusted, kMostVisited, kTotal);
gab 2017/05/12 18:13:35 Can we just make this 5 and recently closed 3. i.e
chengx 2017/05/18 00:51:00 I stopped load-balancing, and limited these two ca
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;
« no previous file with comments | « chrome/browser/win/jumplist.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698