Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/jumplist_win.h" | 5 #include "chrome/browser/jumplist_win.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 #include "ui/gfx/codec/png_codec.h" | 39 #include "ui/gfx/codec/png_codec.h" |
| 40 #include "ui/gfx/favicon_size.h" | 40 #include "ui/gfx/favicon_size.h" |
| 41 #include "ui/gfx/icon_util.h" | 41 #include "ui/gfx/icon_util.h" |
| 42 #include "ui/gfx/image/image_family.h" | 42 #include "ui/gfx/image/image_family.h" |
| 43 #include "url/gurl.h" | 43 #include "url/gurl.h" |
| 44 | 44 |
| 45 using content::BrowserThread; | 45 using content::BrowserThread; |
| 46 | 46 |
| 47 namespace { | 47 namespace { |
| 48 | 48 |
| 49 // Delay jumplist update tasks to allow collapsing of redundant | |
| 50 // update requests. | |
| 51 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.
| |
| 52 | |
| 49 // Append the common switches to each shell link. | 53 // Append the common switches to each shell link. |
| 50 void AppendCommonSwitches(ShellLinkItem* shell_link) { | 54 void AppendCommonSwitches(ShellLinkItem* shell_link) { |
| 51 const char* kSwitchNames[] = { switches::kUserDataDir }; | 55 const char* kSwitchNames[] = { switches::kUserDataDir }; |
| 52 const base::CommandLine& command_line = | 56 const base::CommandLine& command_line = |
| 53 *base::CommandLine::ForCurrentProcess(); | 57 *base::CommandLine::ForCurrentProcess(); |
| 54 shell_link->GetCommandLine()->CopySwitchesFrom(command_line, | 58 shell_link->GetCommandLine()->CopySwitchesFrom(command_line, |
| 55 kSwitchNames, | 59 kSwitchNames, |
| 56 arraysize(kSwitchNames)); | 60 arraysize(kSwitchNames)); |
| 57 } | 61 } |
| 58 | 62 |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 438 // If |icon_urls_| isn't empty then OnFaviconDataAvailable will eventually | 442 // If |icon_urls_| isn't empty then OnFaviconDataAvailable will eventually |
| 439 // call PostRunUpdate(). | 443 // call PostRunUpdate(). |
| 440 } | 444 } |
| 441 | 445 |
| 442 void JumpList::PostRunUpdate() { | 446 void JumpList::PostRunUpdate() { |
| 443 // Check if incognito windows (or normal windows) are disabled by policy. | 447 // Check if incognito windows (or normal windows) are disabled by policy. |
| 444 IncognitoModePrefs::Availability incognito_availability = | 448 IncognitoModePrefs::Availability incognito_availability = |
| 445 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) | 449 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) |
| 446 : IncognitoModePrefs::ENABLED; | 450 : IncognitoModePrefs::ENABLED; |
| 447 | 451 |
| 448 BrowserThread::PostTask( | 452 // Post the JumpListIcons update request with a brief delay. |
| 453 BrowserThread::PostDelayedTask( | |
| 449 BrowserThread::FILE, FROM_HERE, | 454 BrowserThread::FILE, FROM_HERE, |
| 450 base::Bind(&JumpList::RunUpdateOnFileThread, | 455 base::Bind(&JumpList::RunUpdateOnFileThread, |
| 451 this, | 456 this, |
| 452 incognito_availability)); | 457 incognito_availability), |
| 458 base::TimeDelta::FromMilliseconds(kDelayMSForJumplistUpdate)); | |
| 459 | |
| 460 { | |
| 461 // Record the request time (after posting the task) to allow filtering | |
| 462 // out redundant update requests. | |
| 463 base::AutoLock auto_lock(list_lock_); | |
| 464 lastUpdateRequested_ = base::TimeTicks::NowFromSystemTraceTime(); | |
| 465 } | |
| 453 } | 466 } |
| 454 | 467 |
| 455 void JumpList::RunUpdateOnFileThread( | 468 void JumpList::RunUpdateOnFileThread( |
| 456 IncognitoModePrefs::Availability incognito_availability) { | 469 IncognitoModePrefs::Availability incognito_availability) { |
| 457 ShellLinkItemList local_most_visited_pages; | 470 ShellLinkItemList local_most_visited_pages; |
| 458 ShellLinkItemList local_recently_closed_pages; | 471 ShellLinkItemList local_recently_closed_pages; |
| 459 | 472 |
| 460 { | 473 { |
| 461 base::AutoLock auto_lock(list_lock_); | 474 base::AutoLock auto_lock(list_lock_); |
| 462 // Make sure we are not out of date: if icon_urls_ is not empty, then | 475 // Make sure we are not out of date: if icon_urls_ is not empty, then |
| 463 // another notification has been received since we processed this one | 476 // another notification has been received since we processed this one |
| 464 if (!icon_urls_.empty()) | 477 if (!icon_urls_.empty()) |
| 465 return; | 478 return; |
| 466 | 479 |
| 480 // If we get a storm of update requests then we can skip most of the | |
| 481 // updates. Any update that starts after the last request will have | |
| 482 // done all the necessary work. This addresses this scenario: | |
| 483 // t=10.0: PostRunUpdate | |
| 484 // t=10.1: PostRunUpdate | |
| 485 // t=10.5: RunUpdateOnFileThread | |
| 486 // t=10.6: RunUpdateOnFileThread -- no update necessary! | |
| 487 // If the times are equal the meaning is ambiguous, so only return if | |
| 488 // the update-start time is clearly greater. | |
| 489 if (lastUpdateStarted_ > lastUpdateRequested_) | |
| 490 return; | |
| 491 lastUpdateStarted_ = base::TimeTicks::NowFromSystemTraceTime(); | |
| 492 | |
| 467 // Make local copies of lists so we can release the lock. | 493 // Make local copies of lists so we can release the lock. |
| 468 local_most_visited_pages = most_visited_pages_; | 494 local_most_visited_pages = most_visited_pages_; |
| 469 local_recently_closed_pages = recently_closed_pages_; | 495 local_recently_closed_pages = recently_closed_pages_; |
| 470 } | 496 } |
| 471 | 497 |
| 472 // Delete the directory which contains old icon files, rename the current | 498 // Delete the directory which contains old icon files, rename the current |
| 473 // icon directory, and create a new directory which contains new JumpList | 499 // icon directory, and create a new directory which contains new JumpList |
| 474 // icon files. | 500 // icon files. |
| 475 base::FilePath icon_dir_old(icon_dir_.value() + L"Old"); | 501 base::FilePath icon_dir_old(icon_dir_.value() + L"Old"); |
| 476 if (base::PathExists(icon_dir_old)) | 502 if (base::PathExists(icon_dir_old)) |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 505 | 531 |
| 506 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { | 532 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { |
| 507 } | 533 } |
| 508 | 534 |
| 509 void JumpList::TopSitesChanged(history::TopSites* top_sites) { | 535 void JumpList::TopSitesChanged(history::TopSites* top_sites) { |
| 510 top_sites->GetMostVisitedURLs( | 536 top_sites->GetMostVisitedURLs( |
| 511 base::Bind(&JumpList::OnMostVisitedURLsAvailable, | 537 base::Bind(&JumpList::OnMostVisitedURLsAvailable, |
| 512 weak_ptr_factory_.GetWeakPtr()), | 538 weak_ptr_factory_.GetWeakPtr()), |
| 513 false); | 539 false); |
| 514 } | 540 } |
| OLD | NEW |