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 2865133003: Defer syncing TopSites with history until the first tab closure (Closed)
Patch Set: Address comments from grt@ 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/win/jumplist.h ('k') | 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 "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 TabRestoreServiceFactory::GetForProfile(profile_); 214 TabRestoreServiceFactory::GetForProfile(profile_);
215 if (!tab_restore_service) 215 if (!tab_restore_service)
216 return; 216 return;
217 217
218 app_id_ = 218 app_id_ =
219 shell_integration::win::GetChromiumModelIdForProfile(profile_->GetPath()); 219 shell_integration::win::GetChromiumModelIdForProfile(profile_->GetPath());
220 220
221 scoped_refptr<history::TopSites> top_sites = 221 scoped_refptr<history::TopSites> top_sites =
222 TopSitesFactory::GetForProfile(profile_); 222 TopSitesFactory::GetForProfile(profile_);
223 if (top_sites) { 223 if (top_sites) {
224 // TopSites updates itself after a delay. This is especially noticable when
225 // your profile is empty. Ask TopSites to update itself when jumplist is
226 // initialized.
227 top_sites->SyncWithHistory();
228 // Register as TopSitesObserver so that we can update ourselves when the 224 // Register as TopSitesObserver so that we can update ourselves when the
229 // TopSites changes. 225 // TopSites changes. TopSites updates itself after a delay. This is
226 // especially noticable when your profile is empty.
230 top_sites->AddObserver(this); 227 top_sites->AddObserver(this);
231 } 228 }
232 tab_restore_service->AddObserver(this); 229 tab_restore_service->AddObserver(this);
233 pref_change_registrar_.reset(new PrefChangeRegistrar); 230 pref_change_registrar_.reset(new PrefChangeRegistrar);
234 pref_change_registrar_->Init(profile_->GetPrefs()); 231 pref_change_registrar_->Init(profile_->GetPrefs());
235 pref_change_registrar_->Add( 232 pref_change_registrar_->Add(
236 prefs::kIncognitoModeAvailability, 233 prefs::kIncognitoModeAvailability,
237 base::Bind(&JumpList::OnIncognitoAvailabilityChanged, this)); 234 base::Bind(&JumpList::OnIncognitoAvailabilityChanged, this));
238 } 235 }
239 236
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 273
277 void JumpList::ShutdownOnUIThread() { 274 void JumpList::ShutdownOnUIThread() {
278 DCHECK(CalledOnValidThread()); 275 DCHECK(CalledOnValidThread());
279 Terminate(); 276 Terminate();
280 } 277 }
281 278
282 void JumpList::OnMostVisitedURLsAvailable( 279 void JumpList::OnMostVisitedURLsAvailable(
283 const history::MostVisitedURLList& urls) { 280 const history::MostVisitedURLList& urls) {
284 DCHECK(CalledOnValidThread()); 281 DCHECK(CalledOnValidThread());
285 282
286 // At most 9 JumpList items can be displayed for the "Most Visited" 283 // At most 5 JumpList items can be displayed for the "Most Visited"
287 // category. 284 // category.
288 const int kMostVistedCount = 9; 285 const int kMostVistedCount = 5;
289 { 286 {
290 JumpListData* data = &jumplist_data_->data; 287 JumpListData* data = &jumplist_data_->data;
291 base::AutoLock auto_lock(data->list_lock_); 288 base::AutoLock auto_lock(data->list_lock_);
292 data->most_visited_pages_.clear(); 289 data->most_visited_pages_.clear();
293 290
294 for (size_t i = 0; i < urls.size() && i < kMostVistedCount; i++) { 291 for (size_t i = 0; i < urls.size() && i < kMostVistedCount; i++) {
295 const history::MostVisitedURL& url = urls[i]; 292 const history::MostVisitedURL& url = urls[i];
296 scoped_refptr<ShellLinkItem> link = CreateShellLink(); 293 scoped_refptr<ShellLinkItem> link = CreateShellLink();
297 std::string url_string = url.url.spec(); 294 std::string url_string = url.url.spec();
298 base::string16 url_string_wide = base::UTF8ToUTF16(url_string); 295 base::string16 url_string_wide = base::UTF8ToUTF16(url_string);
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 if (timer_most_visited_.IsRunning()) { 517 if (timer_most_visited_.IsRunning()) {
521 timer_most_visited_.Reset(); 518 timer_most_visited_.Reset();
522 } else { 519 } else {
523 timer_most_visited_.Start( 520 timer_most_visited_.Start(
524 FROM_HERE, kDelayForJumplistUpdate, 521 FROM_HERE, kDelayForJumplistUpdate,
525 base::Bind(&JumpList::DeferredTopSitesChanged, base::Unretained(this))); 522 base::Bind(&JumpList::DeferredTopSitesChanged, base::Unretained(this)));
526 } 523 }
527 } 524 }
528 525
529 void JumpList::DeferredTopSitesChanged() { 526 void JumpList::DeferredTopSitesChanged() {
527 DCHECK(CalledOnValidThread());
528
530 if (updates_to_skip_ > 0) { 529 if (updates_to_skip_ > 0) {
531 --updates_to_skip_; 530 --updates_to_skip_;
532 return; 531 return;
533 } 532 }
534 533
534 // Opening the first tab in one session triggers a TopSite history sync.
535 // Delay this sync till the first tab is closed to allow the "recently closed"
536 // category from last session stay longer.
gab 2017/05/19 15:13:26 s/stay/to stay/
chengx 2017/05/22 23:36:00 Done.
537 if (!has_tab_closed_)
538 return;
539
535 scoped_refptr<history::TopSites> top_sites = 540 scoped_refptr<history::TopSites> top_sites =
536 TopSitesFactory::GetForProfile(profile_); 541 TopSitesFactory::GetForProfile(profile_);
537 if (top_sites) { 542 if (top_sites) {
538 top_sites->GetMostVisitedURLs( 543 top_sites->GetMostVisitedURLs(
539 base::Bind(&JumpList::OnMostVisitedURLsAvailable, 544 base::Bind(&JumpList::OnMostVisitedURLsAvailable,
540 weak_ptr_factory_.GetWeakPtr()), 545 weak_ptr_factory_.GetWeakPtr()),
541 false); 546 false);
542 } 547 }
543 } 548 }
544 549
545 void JumpList::DeferredTabRestoreServiceChanged() { 550 void JumpList::DeferredTabRestoreServiceChanged() {
551 DCHECK(CalledOnValidThread());
552
546 if (updates_to_skip_ > 0) { 553 if (updates_to_skip_ > 0) {
547 --updates_to_skip_; 554 --updates_to_skip_;
548 return; 555 return;
549 } 556 }
550 557
558 // Force a TopSite history sync when closing a first tab in one session.
559 if (!has_tab_closed_) {
560 has_tab_closed_ = true;
561 scoped_refptr<history::TopSites> top_sites =
562 TopSitesFactory::GetForProfile(profile_);
563 if (top_sites)
564 top_sites->SyncWithHistory();
565 }
566
551 // Create a list of ShellLinkItems from the "Recently Closed" pages. 567 // Create a list of ShellLinkItems from the "Recently Closed" pages.
552 // As noted above, we create a ShellLinkItem objects with the following 568 // As noted above, we create a ShellLinkItem objects with the following
553 // parameters. 569 // parameters.
554 // * arguments 570 // * arguments
555 // The last URL of the tab object. 571 // The last URL of the tab object.
556 // * title 572 // * title
557 // The title of the last URL. 573 // The title of the last URL.
558 // * icon 574 // * icon
559 // An empty string. This value is to be updated in OnFaviconDataAvailable(). 575 // An empty string. This value is to be updated in OnFaviconDataAvailable().
560 const int kRecentlyClosedCount = 3; 576 const int kRecentlyClosedCount = 3;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 // than the maximum allowed time, as it's very likely the following update 651 // than the maximum allowed time, as it's very likely the following update
636 // steps will also take a long time. As we've not updated the icons on the 652 // steps will also take a long time. As we've not updated the icons on the
637 // disk, discarding this update wont't affect the current JumpList used by OS. 653 // disk, discarding this update wont't affect the current JumpList used by OS.
638 if (begin_update_timer.Elapsed() >= kTimeOutForJumplistBeginUpdate) { 654 if (begin_update_timer.Elapsed() >= kTimeOutForJumplistBeginUpdate) {
639 updates_to_skip_ = kUpdatesToSkipUnderHeavyLoad; 655 updates_to_skip_ = kUpdatesToSkipUnderHeavyLoad;
640 return false; 656 return false;
641 } 657 }
642 658
643 // The default maximum number of items to display in JumpList is 10. 659 // The default maximum number of items to display in JumpList is 10.
644 // https://msdn.microsoft.com/library/windows/desktop/dd378398.aspx 660 // https://msdn.microsoft.com/library/windows/desktop/dd378398.aspx
645 // The "Most visited" category title always takes 1 of the JumpList slots if 661 // The "Most visited" and "Recently closed" category titles always takes 2 of
646 // |most_visited_pages| isn't empty. 662 // the JumpList slots. For the remaining slots, we allocate 5/8 (i.e., 5 slots
647 // The "Recently closed" category title will also take 1 if 663 // by default) to "most-visited" items and 3/8 (i.e., 3 slots by default) to
648 // |recently_closed_pages| isn't empty. 664 // "recently-closed" items, respectively.
649 // For the remaining slots, we allocate 5/8 (i.e., 5 slots if both categories
650 // present) to "most-visited" items and 3/8 (i.e., 3 slots if both categories
651 // present) to "recently-closed" items, respectively.
652 // Nevertheless, if there are not so many items in |recently_closed_pages|,
653 // we give the remaining slots to "most-visited" items.
654 665
655 const int kMostVisited = 50; 666 const int kMostVisited = 50;
656 const int kRecentlyClosed = 30; 667 const int kRecentlyClosed = 30;
657 const int kTotal = kMostVisited + kRecentlyClosed; 668 const int kTotal = kMostVisited + kRecentlyClosed;
658 669
659 // Adjust the available jumplist slots to account for the category titles. 670 // Adjust the available jumplist slots to account for the two category titles.
660 size_t user_max_items_adjusted = jumplist_updater.user_max_items(); 671 size_t user_max_items_adjusted = jumplist_updater.user_max_items() - 2;
661 if (!most_visited_pages.empty())
662 --user_max_items_adjusted;
663 if (!recently_closed_pages.empty())
664 --user_max_items_adjusted;
665 672
673 // Cap 5 items for "Most visited" category, and 3 items for "Recently closed"
674 // category.
gab 2017/05/19 15:13:27 I think we should just do 5/3 always, no MulDiv ei
chengx 2017/05/22 23:36:00 Done. I also made some other changes accordingly.
675 user_max_items_adjusted = std::min((int)jumplist_updater.user_max_items(), 8);
666 size_t most_visited_items = 676 size_t most_visited_items =
667 MulDiv(user_max_items_adjusted, kMostVisited, kTotal); 677 MulDiv(user_max_items_adjusted, kMostVisited, kTotal);
668 size_t recently_closed_items = user_max_items_adjusted - most_visited_items; 678 size_t recently_closed_items = user_max_items_adjusted - most_visited_items;
669 if (recently_closed_pages.size() < recently_closed_items) {
670 most_visited_items += recently_closed_items - recently_closed_pages.size();
671 recently_closed_items = recently_closed_pages.size();
672 }
673 679
674 // Record the desired number of icons to create in this JumpList update. 680 // Record the desired number of icons to create in this JumpList update.
675 int icons_to_create = 0; 681 int icons_to_create = 0;
676 682
677 // Update the icons for "Most Visisted" category of the JumpList if needed. 683 // Update the icons for "Most Visisted" category of the JumpList if needed.
678 if (most_visited_pages_have_updates) { 684 if (most_visited_pages_have_updates) {
679 base::FilePath icon_dir_most_visited = GenerateJumplistIconDirName( 685 base::FilePath icon_dir_most_visited = GenerateJumplistIconDirName(
680 profile_dir, FILE_PATH_LITERAL("MostVisited")); 686 profile_dir, FILE_PATH_LITERAL("MostVisited"));
681 687
682 UpdateIconFiles(icon_dir_most_visited, most_visited_pages, 688 UpdateIconFiles(icon_dir_most_visited, most_visited_pages,
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 app_id, profile_dir, local_most_visited_pages, 794 app_id, profile_dir, local_most_visited_pages,
789 local_recently_closed_pages, most_visited_pages_have_updates, 795 local_recently_closed_pages, most_visited_pages_have_updates,
790 recently_closed_pages_have_updates, incognito_availability)) { 796 recently_closed_pages_have_updates, incognito_availability)) {
791 base::AutoLock auto_lock(data->list_lock_); 797 base::AutoLock auto_lock(data->list_lock_);
792 if (most_visited_pages_have_updates) 798 if (most_visited_pages_have_updates)
793 data->most_visited_pages_have_updates_ = true; 799 data->most_visited_pages_have_updates_ = true;
794 if (recently_closed_pages_have_updates) 800 if (recently_closed_pages_have_updates)
795 data->recently_closed_pages_have_updates_ = true; 801 data->recently_closed_pages_have_updates_ = true;
796 } 802 }
797 } 803 }
OLDNEW
« 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