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

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

Issue 2868303003: Cancel the next 10 updates if there's a timeout in jumplist updater (Closed)
Patch Set: Change int/bool logic to int logic only 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 <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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 #include "ui/gfx/image/image_family.h" 57 #include "ui/gfx/image/image_family.h"
58 #include "ui/gfx/image/image_skia.h" 58 #include "ui/gfx/image/image_skia.h"
59 #include "ui/gfx/image/image_skia_rep.h" 59 #include "ui/gfx/image/image_skia_rep.h"
60 #include "url/gurl.h" 60 #include "url/gurl.h"
61 61
62 using content::BrowserThread; 62 using content::BrowserThread;
63 using JumpListData = JumpList::JumpListData; 63 using JumpListData = JumpList::JumpListData;
64 64
65 namespace { 65 namespace {
66 66
67 // The maximum allowed number of updates to skip to alleviate the machine when a
68 // previous update was too slow.
69 constexpr int kMaxUpdatesToSkip = 10;
gab 2017/05/12 18:59:59 kUpdatesToSkipUnderHeavyLoad (i.e. this isn't a "
chengx 2017/05/12 19:23:57 Agreed. Done.
70
67 // The delay before updating the JumpList to prevent update storms. 71 // The delay before updating the JumpList to prevent update storms.
68 constexpr base::TimeDelta kDelayForJumplistUpdate = 72 constexpr base::TimeDelta kDelayForJumplistUpdate =
69 base::TimeDelta::FromMilliseconds(3500); 73 base::TimeDelta::FromMilliseconds(3500);
70 74
71 // The maximum allowed time for JumpListUpdater::BeginUpdate. Updates taking 75 // The maximum allowed time for JumpListUpdater::BeginUpdate. Updates taking
72 // longer than this are discarded to prevent bogging down slow machines. 76 // longer than this are discarded to prevent bogging down slow machines.
73 constexpr base::TimeDelta kTimeOutForJumplistUpdate = 77 constexpr base::TimeDelta kTimeOutForJumplistBeginUpdate =
74 base::TimeDelta::FromMilliseconds(500); 78 base::TimeDelta::FromMilliseconds(500);
75 79
80 // The maximum allowed time for updating both "most visited" and "recently
81 // closed" categories via JumpListUpdater::AddCustomCategory.
82 constexpr base::TimeDelta kTimeOutForAddCustomCategory =
83 base::TimeDelta::FromMilliseconds(500);
84
85 // The maximum allowed time for JumpListUpdater::CommitUpdate.
86 constexpr base::TimeDelta kTimeOutForJumplistCommitUpdate =
87 base::TimeDelta::FromMilliseconds(1000);
88
76 // Appends the common switches to each shell link. 89 // Appends the common switches to each shell link.
77 void AppendCommonSwitches(ShellLinkItem* shell_link) { 90 void AppendCommonSwitches(ShellLinkItem* shell_link) {
78 const char* kSwitchNames[] = { switches::kUserDataDir }; 91 const char* kSwitchNames[] = { switches::kUserDataDir };
79 const base::CommandLine& command_line = 92 const base::CommandLine& command_line =
80 *base::CommandLine::ForCurrentProcess(); 93 *base::CommandLine::ForCurrentProcess();
81 shell_link->GetCommandLine()->CopySwitchesFrom(command_line, 94 shell_link->GetCommandLine()->CopySwitchesFrom(command_line,
82 kSwitchNames, 95 kSwitchNames,
83 arraysize(kSwitchNames)); 96 arraysize(kSwitchNames));
84 } 97 }
85 98
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 if (timer_most_visited_.IsRunning()) { 529 if (timer_most_visited_.IsRunning()) {
517 timer_most_visited_.Reset(); 530 timer_most_visited_.Reset();
518 } else { 531 } else {
519 timer_most_visited_.Start( 532 timer_most_visited_.Start(
520 FROM_HERE, kDelayForJumplistUpdate, 533 FROM_HERE, kDelayForJumplistUpdate,
521 base::Bind(&JumpList::DeferredTopSitesChanged, base::Unretained(this))); 534 base::Bind(&JumpList::DeferredTopSitesChanged, base::Unretained(this)));
522 } 535 }
523 } 536 }
524 537
525 void JumpList::DeferredTopSitesChanged() { 538 void JumpList::DeferredTopSitesChanged() {
539 if (updates_to_skip_ > 0) {
540 --updates_to_skip_;
541 return;
542 }
543
526 scoped_refptr<history::TopSites> top_sites = 544 scoped_refptr<history::TopSites> top_sites =
527 TopSitesFactory::GetForProfile(profile_); 545 TopSitesFactory::GetForProfile(profile_);
528 if (top_sites) { 546 if (top_sites) {
529 top_sites->GetMostVisitedURLs( 547 top_sites->GetMostVisitedURLs(
530 base::Bind(&JumpList::OnMostVisitedURLsAvailable, 548 base::Bind(&JumpList::OnMostVisitedURLsAvailable,
531 weak_ptr_factory_.GetWeakPtr()), 549 weak_ptr_factory_.GetWeakPtr()),
532 false); 550 false);
533 } 551 }
534 } 552 }
535 553
536 void JumpList::DeferredTabRestoreServiceChanged() { 554 void JumpList::DeferredTabRestoreServiceChanged() {
555 if (updates_to_skip_ > 0) {
556 --updates_to_skip_;
557 return;
558 }
559
537 // Create a list of ShellLinkItems from the "Recently Closed" pages. 560 // Create a list of ShellLinkItems from the "Recently Closed" pages.
538 // As noted above, we create a ShellLinkItem objects with the following 561 // As noted above, we create a ShellLinkItem objects with the following
539 // parameters. 562 // parameters.
540 // * arguments 563 // * arguments
541 // The last URL of the tab object. 564 // The last URL of the tab object.
542 // * title 565 // * title
543 // The title of the last URL. 566 // The title of the last URL.
544 // * icon 567 // * icon
545 // An empty string. This value is to be updated in OnFaviconDataAvailable(). 568 // An empty string. This value is to be updated in OnFaviconDataAvailable().
546 const int kRecentlyClosedCount = 3; 569 const int kRecentlyClosedCount = 3;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 JumpListUpdater jumplist_updater(app_id); 636 JumpListUpdater jumplist_updater(app_id);
614 637
615 base::ElapsedTimer begin_update_timer; 638 base::ElapsedTimer begin_update_timer;
616 639
617 if (!jumplist_updater.BeginUpdate()) 640 if (!jumplist_updater.BeginUpdate())
618 return false; 641 return false;
619 642
620 // Discard this JumpList update if JumpListUpdater::BeginUpdate takes longer 643 // Discard this JumpList update if JumpListUpdater::BeginUpdate takes longer
621 // than the maximum allowed time, as it's very likely the following update 644 // than the maximum allowed time, as it's very likely the following update
622 // steps will also take a long time. 645 // steps will also take a long time.
623 if (begin_update_timer.Elapsed() >= kTimeOutForJumplistUpdate) 646 if (begin_update_timer.Elapsed() >= kTimeOutForJumplistBeginUpdate) {
647 updates_to_skip_ = kMaxUpdatesToSkip;
624 return false; 648 return false;
649 }
625 650
626 // The default maximum number of items to display in JumpList is 10. 651 // The default maximum number of items to display in JumpList is 10.
627 // https://msdn.microsoft.com/library/windows/desktop/dd378398.aspx 652 // https://msdn.microsoft.com/library/windows/desktop/dd378398.aspx
628 // The "Most visited" category title always takes 1 of the JumpList slots if 653 // The "Most visited" category title always takes 1 of the JumpList slots if
629 // |most_visited_pages| isn't empty. 654 // |most_visited_pages| isn't empty.
630 // The "Recently closed" category title will also take 1 if 655 // The "Recently closed" category title will also take 1 if
631 // |recently_closed_pages| isn't empty. 656 // |recently_closed_pages| isn't empty.
632 // For the remaining slots, we allocate 5/8 (i.e., 5 slots if both categories 657 // For the remaining slots, we allocate 5/8 (i.e., 5 slots if both categories
633 // present) to "most-visited" items and 3/8 (i.e., 3 slots if both categories 658 // present) to "most-visited" items and 3/8 (i.e., 3 slots if both categories
634 // present) to "recently-closed" items, respectively. 659 // present) to "recently-closed" items, respectively.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 icons_to_create += 704 icons_to_create +=
680 std::min(recently_closed_pages.size(), recently_closed_items); 705 std::min(recently_closed_pages.size(), recently_closed_items);
681 } 706 }
682 707
683 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. 708 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407.
684 UMA_HISTOGRAM_COUNTS_100("WinJumplist.CreateIconFilesCount", icons_to_create); 709 UMA_HISTOGRAM_COUNTS_100("WinJumplist.CreateIconFilesCount", icons_to_create);
685 710
686 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. 711 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407.
687 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplist.UpdateJumpListDuration"); 712 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplist.UpdateJumpListDuration");
688 713
714 base::ElapsedTimer add_custom_category_timer;
715
689 // Update the "Most Visited" category of the JumpList if it exists. 716 // Update the "Most Visited" category of the JumpList if it exists.
690 // This update request is applied into the JumpList when we commit this 717 // This update request is applied into the JumpList when we commit this
691 // transaction. 718 // transaction.
692 if (!jumplist_updater.AddCustomCategory( 719 if (!jumplist_updater.AddCustomCategory(
693 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED), 720 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED),
694 most_visited_pages, most_visited_items)) { 721 most_visited_pages, most_visited_items)) {
695 return false; 722 return false;
696 } 723 }
697 724
698 // Update the "Recently Closed" category of the JumpList. 725 // Update the "Recently Closed" category of the JumpList.
699 if (!jumplist_updater.AddCustomCategory( 726 if (!jumplist_updater.AddCustomCategory(
700 l10n_util::GetStringUTF16(IDS_RECENTLY_CLOSED), recently_closed_pages, 727 l10n_util::GetStringUTF16(IDS_RECENTLY_CLOSED), recently_closed_pages,
701 recently_closed_items)) { 728 recently_closed_items)) {
702 return false; 729 return false;
703 } 730 }
704 731
732 // If JumpListUpdater::AddCustomCategory takes longer than the maximum allowed
733 // time, mark the flag but continue with this update.
gab 2017/05/12 19:00:00 Explain why you continue with the update in this c
chengx 2017/05/12 19:23:57 I've updated the comments to explain why this upda
734 if (add_custom_category_timer.Elapsed() >= kTimeOutForAddCustomCategory)
735 updates_to_skip_ = kMaxUpdatesToSkip;
736
705 // Update the "Tasks" category of the JumpList. 737 // Update the "Tasks" category of the JumpList.
706 if (!UpdateTaskCategory(&jumplist_updater, incognito_availability)) 738 if (!UpdateTaskCategory(&jumplist_updater, incognito_availability))
707 return false; 739 return false;
708 740
741 base::ElapsedTimer commit_update_timer;
742
709 // Commit this transaction and send the updated JumpList to Windows. 743 // Commit this transaction and send the updated JumpList to Windows.
710 return jumplist_updater.CommitUpdate(); 744 bool commit_result = jumplist_updater.CommitUpdate();
745
746 // If JumpListUpdater::CommitUpdate takes longer than the maximum allowed
747 // time, mark the flag but continue with this update.
gab 2017/05/12 19:00:00 ditto
chengx 2017/05/12 19:23:58 Done.
748 if (commit_update_timer.Elapsed() >= kTimeOutForJumplistCommitUpdate)
749 updates_to_skip_ = kMaxUpdatesToSkip;
750
751 return commit_result;
711 } 752 }
712 753
713 void JumpList::RunUpdateJumpList( 754 void JumpList::RunUpdateJumpList(
714 IncognitoModePrefs::Availability incognito_availability, 755 IncognitoModePrefs::Availability incognito_availability,
715 const base::string16& app_id, 756 const base::string16& app_id,
716 const base::FilePath& profile_dir, 757 const base::FilePath& profile_dir,
717 base::RefCountedData<JumpListData>* ref_counted_data) { 758 base::RefCountedData<JumpListData>* ref_counted_data) {
718 JumpListData* data = &ref_counted_data->data; 759 JumpListData* data = &ref_counted_data->data;
719 ShellLinkItemList local_most_visited_pages; 760 ShellLinkItemList local_most_visited_pages;
720 ShellLinkItemList local_recently_closed_pages; 761 ShellLinkItemList local_recently_closed_pages;
(...skipping 30 matching lines...) Expand all
751 app_id, profile_dir, local_most_visited_pages, 792 app_id, profile_dir, local_most_visited_pages,
752 local_recently_closed_pages, most_visited_pages_have_updates, 793 local_recently_closed_pages, most_visited_pages_have_updates,
753 recently_closed_pages_have_updates, incognito_availability)) { 794 recently_closed_pages_have_updates, incognito_availability)) {
754 base::AutoLock auto_lock(data->list_lock_); 795 base::AutoLock auto_lock(data->list_lock_);
755 if (most_visited_pages_have_updates) 796 if (most_visited_pages_have_updates)
756 data->most_visited_pages_have_updates_ = true; 797 data->most_visited_pages_have_updates_ = true;
757 if (recently_closed_pages_have_updates) 798 if (recently_closed_pages_have_updates)
758 data->recently_closed_pages_have_updates_ = true; 799 data->recently_closed_pages_have_updates_ = true;
759 } 800 }
760 } 801 }
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