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/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 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 432 } | 432 } |
| 433 | 433 |
| 434 void JumpList::CancelPendingUpdate() { | 434 void JumpList::CancelPendingUpdate() { |
| 435 DCHECK(CalledOnValidThread()); | 435 DCHECK(CalledOnValidThread()); |
| 436 if (task_id_ != base::CancelableTaskTracker::kBadTaskId) { | 436 if (task_id_ != base::CancelableTaskTracker::kBadTaskId) { |
| 437 cancelable_task_tracker_.TryCancel(task_id_); | 437 cancelable_task_tracker_.TryCancel(task_id_); |
| 438 task_id_ = base::CancelableTaskTracker::kBadTaskId; | 438 task_id_ = base::CancelableTaskTracker::kBadTaskId; |
| 439 } | 439 } |
| 440 } | 440 } |
| 441 | 441 |
| 442 void JumpList::Terminate() { | 442 void JumpList::Terminate() { |
|
grt (UTC plus 2)
2017/05/03 10:51:48
stop the timers in here, no?
chengx
2017/05/03 20:45:14
Done. They should be stopped.
| |
| 443 DCHECK(CalledOnValidThread()); | 443 DCHECK(CalledOnValidThread()); |
| 444 CancelPendingUpdate(); | 444 CancelPendingUpdate(); |
| 445 if (profile_) { | 445 if (profile_) { |
| 446 sessions::TabRestoreService* tab_restore_service = | 446 sessions::TabRestoreService* tab_restore_service = |
| 447 TabRestoreServiceFactory::GetForProfile(profile_); | 447 TabRestoreServiceFactory::GetForProfile(profile_); |
| 448 if (tab_restore_service) | 448 if (tab_restore_service) |
| 449 tab_restore_service->RemoveObserver(this); | 449 tab_restore_service->RemoveObserver(this); |
| 450 scoped_refptr<history::TopSites> top_sites = | 450 scoped_refptr<history::TopSites> top_sites = |
| 451 TopSitesFactory::GetForProfile(profile_); | 451 TopSitesFactory::GetForProfile(profile_); |
| 452 if (top_sites) | 452 if (top_sites) |
| 453 top_sites->RemoveObserver(this); | 453 top_sites->RemoveObserver(this); |
| 454 pref_change_registrar_.reset(); | 454 pref_change_registrar_.reset(); |
| 455 } | 455 } |
| 456 profile_ = NULL; | 456 profile_ = NULL; |
| 457 } | 457 } |
| 458 | 458 |
| 459 void JumpList::ShutdownOnUIThread() { | 459 void JumpList::ShutdownOnUIThread() { |
| 460 DCHECK(CalledOnValidThread()); | 460 DCHECK(CalledOnValidThread()); |
| 461 Terminate(); | 461 Terminate(); |
| 462 } | 462 } |
| 463 | 463 |
| 464 void JumpList::OnMostVisitedURLsAvailable( | 464 void JumpList::OnMostVisitedURLsAvailable( |
| 465 const history::MostVisitedURLList& urls) { | 465 const history::MostVisitedURLList& urls) { |
| 466 DCHECK(CalledOnValidThread()); | 466 DCHECK(CalledOnValidThread()); |
| 467 // If we have a pending favicon request, cancel it here (it is out of date). | 467 // If we have a pending favicon request, cancel it here (it is out of date). |
| 468 CancelPendingUpdate(); | 468 CancelPendingUpdate(); |
| 469 | 469 |
| 470 // There're at most 9 JumpList items can be displayed for the "Most Visited" | |
|
grt (UTC plus 2)
2017/05/03 10:51:48
nit: "At most 9..."
chengx
2017/05/03 20:45:14
Done.
| |
| 471 // category. | |
| 472 const int kMostVistedCount = 9; | |
| 470 { | 473 { |
| 471 JumpListData* data = &jumplist_data_->data; | 474 JumpListData* data = &jumplist_data_->data; |
| 472 base::AutoLock auto_lock(data->list_lock_); | 475 base::AutoLock auto_lock(data->list_lock_); |
| 473 data->most_visited_pages_.clear(); | 476 data->most_visited_pages_.clear(); |
| 474 for (size_t i = 0; i < urls.size(); i++) { | 477 |
| 478 for (size_t i = 0; i < urls.size() && i < kMostVistedCount; i++) { | |
| 475 const history::MostVisitedURL& url = urls[i]; | 479 const history::MostVisitedURL& url = urls[i]; |
| 476 scoped_refptr<ShellLinkItem> link = CreateShellLink(); | 480 scoped_refptr<ShellLinkItem> link = CreateShellLink(); |
| 477 std::string url_string = url.url.spec(); | 481 std::string url_string = url.url.spec(); |
| 478 std::wstring url_string_wide = base::UTF8ToWide(url_string); | 482 std::wstring url_string_wide = base::UTF8ToWide(url_string); |
| 479 link->GetCommandLine()->AppendArgNative(url_string_wide); | 483 link->GetCommandLine()->AppendArgNative(url_string_wide); |
| 480 link->GetCommandLine()->AppendSwitchASCII( | 484 link->GetCommandLine()->AppendSwitchASCII( |
| 481 switches::kWinJumplistAction, jumplist::kMostVisitedCategory); | 485 switches::kWinJumplistAction, jumplist::kMostVisitedCategory); |
| 482 link->set_title(!url.title.empty() ? url.title : url_string_wide); | 486 link->set_title(!url.title.empty() ? url.title : url_string_wide); |
| 483 data->most_visited_pages_.push_back(link); | 487 data->most_visited_pages_.push_back(link); |
| 484 data->icon_urls_.push_back(std::make_pair(url_string, link)); | 488 data->icon_urls_.push_back(std::make_pair(url_string, link)); |
| 485 } | 489 } |
| 486 data->most_visited_pages_have_updates_ = true; | 490 data->most_visited_pages_have_updates_ = true; |
| 487 } | 491 } |
| 488 | 492 |
| 489 // Send a query that retrieves the first favicon. | 493 // Send a query that retrieves the first favicon. |
| 490 StartLoadingFavicon(); | 494 StartLoadingFavicon(); |
| 491 } | 495 } |
| 492 | 496 |
| 493 void JumpList::TabRestoreServiceChanged(sessions::TabRestoreService* service) { | 497 void JumpList::TabRestoreServiceChanged(sessions::TabRestoreService* service) { |
| 494 DCHECK(CalledOnValidThread()); | 498 DCHECK(CalledOnValidThread()); |
| 499 | |
| 500 // Initialize the one-shot timer to update the the "Recently Closed" category | |
| 501 // in a while. If there is already a request queued then cancel it and post | |
| 502 // the new request. This ensures that JumpList update of the "Recently Closed" | |
| 503 // category won't happen until there has been a brief quiet period, thus | |
| 504 // avoiding update storms. | |
| 505 if (timer_recently_closed_.IsRunning()) { | |
| 506 timer_recently_closed_.Reset(); | |
| 507 } else { | |
| 508 timer_recently_closed_.Start(FROM_HERE, kDelayForJumplistUpdate, this, | |
|
grt (UTC plus 2)
2017/05/03 10:51:48
i suggest making the bind explicit so that you're
chengx
2017/05/03 20:45:14
Done.
| |
| 509 &JumpList::DeferredTabRestoreServiceChanged); | |
| 510 } | |
| 511 } | |
| 512 | |
| 513 void JumpList::DeferredTabRestoreServiceChanged() { | |
| 495 // if we have a pending favicon request, cancel it here (it is out of date). | 514 // if we have a pending favicon request, cancel it here (it is out of date). |
| 496 CancelPendingUpdate(); | 515 CancelPendingUpdate(); |
| 497 | 516 |
| 498 // Create a list of ShellLinkItems from the "Recently Closed" pages. | 517 // Create a list of ShellLinkItems from the "Recently Closed" pages. |
| 499 // As noted above, we create a ShellLinkItem objects with the following | 518 // As noted above, we create a ShellLinkItem objects with the following |
| 500 // parameters. | 519 // parameters. |
| 501 // * arguments | 520 // * arguments |
| 502 // The last URL of the tab object. | 521 // The last URL of the tab object. |
| 503 // * title | 522 // * title |
| 504 // The title of the last URL. | 523 // The title of the last URL. |
| 505 // * icon | 524 // * icon |
| 506 // An empty string. This value is to be updated in OnFaviconDataAvailable(). | 525 // An empty string. This value is to be updated in OnFaviconDataAvailable(). |
| 507 // This code is copied from | 526 // This code is copied from |
| 508 // RecentlyClosedTabsHandler::TabRestoreServiceChanged() to emulate it. | 527 // RecentlyClosedTabsHandler::TabRestoreServiceChanged() to emulate it. |
| 509 const int kRecentlyClosedCount = 3; | 528 const int kRecentlyClosedCount = 3; |
| 510 sessions::TabRestoreService* tab_restore_service = | 529 sessions::TabRestoreService* tab_restore_service = |
| 511 TabRestoreServiceFactory::GetForProfile(profile_); | 530 TabRestoreServiceFactory::GetForProfile(profile_); |
| 512 | 531 |
| 513 { | 532 { |
| 514 JumpListData* data = &jumplist_data_->data; | 533 JumpListData* data = &jumplist_data_->data; |
| 515 base::AutoLock auto_lock(data->list_lock_); | 534 base::AutoLock auto_lock(data->list_lock_); |
| 516 data->recently_closed_pages_.clear(); | 535 data->recently_closed_pages_.clear(); |
| 517 | 536 |
| 518 for (const auto& entry : tab_restore_service->entries()) { | 537 for (const auto& entry : tab_restore_service->entries()) { |
|
grt (UTC plus 2)
2017/05/03 10:51:48
should this loop terminate early if recently_close
chengx
2017/05/03 20:45:14
Yes, it should. Early return is enabled in both Ad
| |
| 519 switch (entry->type) { | 538 switch (entry->type) { |
| 520 case sessions::TabRestoreService::TAB: | 539 case sessions::TabRestoreService::TAB: |
| 521 AddTab(static_cast<const sessions::TabRestoreService::Tab&>(*entry), | 540 AddTab(static_cast<const sessions::TabRestoreService::Tab&>(*entry), |
| 522 kRecentlyClosedCount, data); | 541 kRecentlyClosedCount, data); |
| 523 break; | 542 break; |
| 524 case sessions::TabRestoreService::WINDOW: | 543 case sessions::TabRestoreService::WINDOW: |
| 525 AddWindow( | 544 AddWindow( |
| 526 static_cast<const sessions::TabRestoreService::Window&>(*entry), | 545 static_cast<const sessions::TabRestoreService::Window&>(*entry), |
| 527 kRecentlyClosedCount, data); | 546 kRecentlyClosedCount, data); |
| 528 break; | 547 break; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 654 // category changes, mark the flags so that icon files for those categories | 673 // category changes, mark the flags so that icon files for those categories |
| 655 // won't be updated later on. | 674 // won't be updated later on. |
| 656 if (!waiting_for_icons) | 675 if (!waiting_for_icons) |
| 657 PostRunUpdate(); | 676 PostRunUpdate(); |
| 658 } | 677 } |
| 659 | 678 |
| 660 void JumpList::PostRunUpdate() { | 679 void JumpList::PostRunUpdate() { |
| 661 DCHECK(CalledOnValidThread()); | 680 DCHECK(CalledOnValidThread()); |
| 662 | 681 |
| 663 TRACE_EVENT0("browser", "JumpList::PostRunUpdate"); | 682 TRACE_EVENT0("browser", "JumpList::PostRunUpdate"); |
| 664 // Initialize the one-shot timer to update the jumplists in a while. | |
| 665 // If there is already a request queued then cancel it and post the new | |
| 666 // request. This ensures that JumpListUpdates won't happen until there has | |
| 667 // been a brief quiet period, thus avoiding update storms. | |
| 668 if (timer_.IsRunning()) { | |
| 669 timer_.Reset(); | |
| 670 } else { | |
| 671 timer_.Start(FROM_HERE, kDelayForJumplistUpdate, this, | |
| 672 &JumpList::DeferredRunUpdate); | |
| 673 } | |
| 674 } | |
| 675 | |
| 676 void JumpList::DeferredRunUpdate() { | |
| 677 DCHECK(CalledOnValidThread()); | |
| 678 | |
| 679 TRACE_EVENT0("browser", "JumpList::DeferredRunUpdate"); | |
| 680 // Check if incognito windows (or normal windows) are disabled by policy. | 683 // Check if incognito windows (or normal windows) are disabled by policy. |
| 681 IncognitoModePrefs::Availability incognito_availability = | 684 IncognitoModePrefs::Availability incognito_availability = |
| 682 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) | 685 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) |
| 683 : IncognitoModePrefs::ENABLED; | 686 : IncognitoModePrefs::ENABLED; |
| 684 | 687 |
| 685 // Post a task to update the JumpList, which consists of 1) delete old icons, | 688 // Post a task to update the JumpList, which consists of 1) delete old icons, |
| 686 // 2) create new icons, 3) notify the OS. | 689 // 2) create new icons, 3) notify the OS. |
| 687 update_jumplist_task_runner_->PostTask( | 690 update_jumplist_task_runner_->PostTask( |
| 688 FROM_HERE, base::Bind(&RunUpdateJumpList, incognito_availability, app_id_, | 691 FROM_HERE, base::Bind(&RunUpdateJumpList, incognito_availability, app_id_, |
| 689 icon_dir_, base::RetainedRef(jumplist_data_))); | 692 icon_dir_, base::RetainedRef(jumplist_data_))); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 701 delete_jumplisticons_task_runner_->PostTask( | 704 delete_jumplisticons_task_runner_->PostTask( |
| 702 FROM_HERE, | 705 FROM_HERE, |
| 703 base::Bind(&DeleteDirectory, std::move(icon_dir_old), kFileDeleteLimit)); | 706 base::Bind(&DeleteDirectory, std::move(icon_dir_old), kFileDeleteLimit)); |
| 704 } | 707 } |
| 705 | 708 |
| 706 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { | 709 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { |
| 707 } | 710 } |
| 708 | 711 |
| 709 void JumpList::TopSitesChanged(history::TopSites* top_sites, | 712 void JumpList::TopSitesChanged(history::TopSites* top_sites, |
| 710 ChangeReason change_reason) { | 713 ChangeReason change_reason) { |
| 714 // Initialize the one-shot timer to update the the "Most visited" category in | |
|
grt (UTC plus 2)
2017/05/03 10:51:48
CancelPendingUpdate here, or is there a reason to
chengx
2017/05/03 20:45:14
Yes, it should be called here. I've made the updat
| |
| 715 // a while. If there is already a request queued then cancel it and post the | |
| 716 // new request. This ensures that JumpList update of the "Most visited" | |
| 717 // category won't happen until there has been a brief quiet period, thus | |
| 718 // avoiding update storms. | |
| 719 if (timer_most_visited_.IsRunning()) { | |
| 720 timer_most_visited_.Reset(); | |
| 721 } else { | |
| 722 timer_most_visited_.Start(FROM_HERE, kDelayForJumplistUpdate, | |
| 723 base::Bind(&JumpList::DeferredTopSitesChanged, | |
| 724 base::Unretained(this), top_sites)); | |
|
grt (UTC plus 2)
2017/05/03 10:51:48
rather than holding a reference to TopSites throug
chengx
2017/05/03 20:45:14
Done.
| |
| 725 } | |
| 726 } | |
| 727 | |
| 728 void JumpList::DeferredTopSitesChanged(history::TopSites* top_sites) { | |
| 711 top_sites->GetMostVisitedURLs( | 729 top_sites->GetMostVisitedURLs( |
| 712 base::Bind(&JumpList::OnMostVisitedURLsAvailable, | 730 base::Bind(&JumpList::OnMostVisitedURLsAvailable, |
| 713 weak_ptr_factory_.GetWeakPtr()), | 731 weak_ptr_factory_.GetWeakPtr()), |
| 714 false); | 732 false); |
| 715 } | 733 } |
| OLD | NEW |