| 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 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 | 573 |
| 574 for (const auto& tab : window.tabs) { | 574 for (const auto& tab : window.tabs) { |
| 575 if (!AddTab(*tab, max_items, data)) | 575 if (!AddTab(*tab, max_items, data)) |
| 576 return; | 576 return; |
| 577 } | 577 } |
| 578 } | 578 } |
| 579 | 579 |
| 580 void JumpList::StartLoadingFavicon() { | 580 void JumpList::StartLoadingFavicon() { |
| 581 DCHECK(CalledOnValidThread()); | 581 DCHECK(CalledOnValidThread()); |
| 582 | 582 |
| 583 base::ElapsedTimer timer; |
| 584 |
| 583 GURL url; | 585 GURL url; |
| 584 bool waiting_for_icons = true; | 586 bool waiting_for_icons = true; |
| 585 { | 587 { |
| 586 JumpListData* data = &jumplist_data_->data; | 588 JumpListData* data = &jumplist_data_->data; |
| 587 base::AutoLock auto_lock(data->list_lock_); | 589 base::AutoLock auto_lock(data->list_lock_); |
| 588 waiting_for_icons = !data->icon_urls_.empty(); | 590 waiting_for_icons = !data->icon_urls_.empty(); |
| 589 if (waiting_for_icons) { | 591 if (waiting_for_icons) { |
| 590 // Ask FaviconService if it has a favicon of a URL. | 592 // Ask FaviconService if it has a favicon of a URL. |
| 591 // When FaviconService has one, it will call OnFaviconDataAvailable(). | 593 // When FaviconService has one, it will call OnFaviconDataAvailable(). |
| 592 url = GURL(data->icon_urls_.front().first); | 594 url = GURL(data->icon_urls_.front().first); |
| 593 } | 595 } |
| 594 } | 596 } |
| 595 | 597 |
| 596 if (!waiting_for_icons) { | 598 if (!waiting_for_icons) { |
| 597 // No more favicons are needed by the application JumpList. Schedule a | 599 // No more favicons are needed by the application JumpList. Schedule a |
| 598 // RunUpdateJumpList call. | 600 // RunUpdateJumpList call. |
| 599 PostRunUpdate(); | 601 PostRunUpdate(); |
| 600 return; | 602 return; |
| 601 } | 603 } |
| 602 | 604 |
| 603 favicon::FaviconService* favicon_service = | 605 favicon::FaviconService* favicon_service = |
| 604 FaviconServiceFactory::GetForProfile(profile_, | 606 FaviconServiceFactory::GetForProfile(profile_, |
| 605 ServiceAccessType::EXPLICIT_ACCESS); | 607 ServiceAccessType::EXPLICIT_ACCESS); |
| 606 task_id_ = favicon_service->GetFaviconImageForPageURL( | 608 task_id_ = favicon_service->GetFaviconImageForPageURL( |
| 607 url, | 609 url, |
| 608 base::Bind(&JumpList::OnFaviconDataAvailable, base::Unretained(this)), | 610 base::Bind(&JumpList::OnFaviconDataAvailable, base::Unretained(this)), |
| 609 &cancelable_task_tracker_); | 611 &cancelable_task_tracker_); |
| 612 |
| 613 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/717236 |
| 614 UMA_HISTOGRAM_TIMES("WinJumplist.StartLoadingFaviconDuration", |
| 615 timer.Elapsed()); |
| 610 } | 616 } |
| 611 | 617 |
| 612 void JumpList::OnFaviconDataAvailable( | 618 void JumpList::OnFaviconDataAvailable( |
| 613 const favicon_base::FaviconImageResult& image_result) { | 619 const favicon_base::FaviconImageResult& image_result) { |
| 614 DCHECK(CalledOnValidThread()); | 620 DCHECK(CalledOnValidThread()); |
| 615 | 621 |
| 622 base::ElapsedTimer timer; |
| 623 |
| 616 // If there is currently a favicon request in progress, it is now outdated, | 624 // If there is currently a favicon request in progress, it is now outdated, |
| 617 // as we have received another, so nullify the handle from the old request. | 625 // as we have received another, so nullify the handle from the old request. |
| 618 task_id_ = base::CancelableTaskTracker::kBadTaskId; | 626 task_id_ = base::CancelableTaskTracker::kBadTaskId; |
| 619 // Lock the list to set icon data and pop the url. | 627 // Lock the list to set icon data and pop the url. |
| 620 { | 628 { |
| 621 JumpListData* data = &jumplist_data_->data; | 629 JumpListData* data = &jumplist_data_->data; |
| 622 base::AutoLock auto_lock(data->list_lock_); | 630 base::AutoLock auto_lock(data->list_lock_); |
| 623 // Attach the received data to the ShellLinkItem object. | 631 // Attach the received data to the ShellLinkItem object. |
| 624 // This data will be decoded by the RunUpdateJumpList | 632 // This data will be decoded by the RunUpdateJumpList |
| 625 // method. | 633 // method. |
| 626 if (!image_result.image.IsEmpty() && !data->icon_urls_.empty() && | 634 if (!image_result.image.IsEmpty() && !data->icon_urls_.empty() && |
| 627 data->icon_urls_.front().second.get()) { | 635 data->icon_urls_.front().second.get()) { |
| 628 gfx::ImageSkia image_skia = image_result.image.AsImageSkia(); | 636 gfx::ImageSkia image_skia = image_result.image.AsImageSkia(); |
| 629 image_skia.EnsureRepsForSupportedScales(); | 637 image_skia.EnsureRepsForSupportedScales(); |
| 630 std::unique_ptr<gfx::ImageSkia> deep_copy(image_skia.DeepCopy()); | 638 std::unique_ptr<gfx::ImageSkia> deep_copy(image_skia.DeepCopy()); |
| 631 data->icon_urls_.front().second->set_icon_image(*deep_copy); | 639 data->icon_urls_.front().second->set_icon_image(*deep_copy); |
| 632 } | 640 } |
| 633 | 641 |
| 634 if (!data->icon_urls_.empty()) | 642 if (!data->icon_urls_.empty()) |
| 635 data->icon_urls_.pop_front(); | 643 data->icon_urls_.pop_front(); |
| 636 } | 644 } |
| 645 |
| 646 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/717236 |
| 647 UMA_HISTOGRAM_TIMES("WinJumplist.OnFaviconDataAvailableDuration", |
| 648 timer.Elapsed()); |
| 649 |
| 637 // Check whether we need to load more favicons. | 650 // Check whether we need to load more favicons. |
| 638 StartLoadingFavicon(); | 651 StartLoadingFavicon(); |
| 639 } | 652 } |
| 640 | 653 |
| 641 void JumpList::OnIncognitoAvailabilityChanged() { | 654 void JumpList::OnIncognitoAvailabilityChanged() { |
| 642 DCHECK(CalledOnValidThread()); | 655 DCHECK(CalledOnValidThread()); |
| 643 | 656 |
| 644 bool waiting_for_icons = true; | 657 bool waiting_for_icons = true; |
| 645 { | 658 { |
| 646 JumpListData* data = &jumplist_data_->data; | 659 JumpListData* data = &jumplist_data_->data; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { | 717 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { |
| 705 } | 718 } |
| 706 | 719 |
| 707 void JumpList::TopSitesChanged(history::TopSites* top_sites, | 720 void JumpList::TopSitesChanged(history::TopSites* top_sites, |
| 708 ChangeReason change_reason) { | 721 ChangeReason change_reason) { |
| 709 top_sites->GetMostVisitedURLs( | 722 top_sites->GetMostVisitedURLs( |
| 710 base::Bind(&JumpList::OnMostVisitedURLsAvailable, | 723 base::Bind(&JumpList::OnMostVisitedURLsAvailable, |
| 711 weak_ptr_factory_.GetWeakPtr()), | 724 weak_ptr_factory_.GetWeakPtr()), |
| 712 false); | 725 false); |
| 713 } | 726 } |
| OLD | NEW |