Index: chrome/browser/jumplist_win.cc |
diff --git a/chrome/browser/jumplist_win.cc b/chrome/browser/jumplist_win.cc |
index 22a73e61f4f8b40c59006335369f5fbbd332b406..a8fd822f4fd6ad3a14b4fed5fc4d04402738d2df 100644 |
--- a/chrome/browser/jumplist_win.cc |
+++ b/chrome/browser/jumplist_win.cc |
@@ -46,6 +46,10 @@ using content::BrowserThread; |
namespace { |
+// Delay jumplist update tasks to allow collapsing of redundant |
+// update requests. |
+const int kDelayMSForJumplistUpdate = 1500; |
jochen (gone - plz use gerrit)
2015/03/31 10:28:52
nit. it's more common to have the unit last (kDela
brucedawson
2015/06/03 17:57:16
Done.
|
+ |
// Append the common switches to each shell link. |
void AppendCommonSwitches(ShellLinkItem* shell_link) { |
const char* kSwitchNames[] = { switches::kUserDataDir }; |
@@ -445,11 +449,20 @@ void JumpList::PostRunUpdate() { |
profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) |
: IncognitoModePrefs::ENABLED; |
- BrowserThread::PostTask( |
+ // Post the JumpListIcons update request with a brief delay. |
+ BrowserThread::PostDelayedTask( |
BrowserThread::FILE, FROM_HERE, |
base::Bind(&JumpList::RunUpdateOnFileThread, |
this, |
- incognito_availability)); |
+ incognito_availability), |
+ base::TimeDelta::FromMilliseconds(kDelayMSForJumplistUpdate)); |
+ |
+ { |
+ // Record the request time (after posting the task) to allow filtering |
+ // out redundant update requests. |
+ base::AutoLock auto_lock(list_lock_); |
+ lastUpdateRequested_ = base::TimeTicks::NowFromSystemTraceTime(); |
+ } |
} |
void JumpList::RunUpdateOnFileThread( |
@@ -464,6 +477,19 @@ void JumpList::RunUpdateOnFileThread( |
if (!icon_urls_.empty()) |
return; |
+ // If we get a storm of update requests then we can skip most of the |
+ // updates. Any update that starts after the last request will have |
+ // done all the necessary work. This addresses this scenario: |
+ // t=10.0: PostRunUpdate |
+ // t=10.1: PostRunUpdate |
+ // t=10.5: RunUpdateOnFileThread |
+ // t=10.6: RunUpdateOnFileThread -- no update necessary! |
+ // If the times are equal the meaning is ambiguous, so only return if |
+ // the update-start time is clearly greater. |
+ if (lastUpdateStarted_ > lastUpdateRequested_) |
+ return; |
+ lastUpdateStarted_ = base::TimeTicks::NowFromSystemTraceTime(); |
+ |
// Make local copies of lists so we can release the lock. |
local_most_visited_pages = most_visited_pages_; |
local_recently_closed_pages = recently_closed_pages_; |