| 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 return false; | 224 return false; |
| 225 | 225 |
| 226 // Commit this transaction and send the updated JumpList to Windows. | 226 // Commit this transaction and send the updated JumpList to Windows. |
| 227 if (!jumplist_updater.CommitUpdate()) | 227 if (!jumplist_updater.CommitUpdate()) |
| 228 return false; | 228 return false; |
| 229 | 229 |
| 230 return true; | 230 return true; |
| 231 } | 231 } |
| 232 | 232 |
| 233 // Updates the jumplist, once all the data has been fetched. | 233 // Updates the jumplist, once all the data has been fetched. |
| 234 void RunUpdateJumpListUserVisiblePriority( | 234 void RunUpdateJumpList(IncognitoModePrefs::Availability incognito_availability, |
| 235 IncognitoModePrefs::Availability incognito_availability, | 235 const std::wstring& app_id, |
| 236 const std::wstring& app_id, | 236 const base::FilePath& icon_dir, |
| 237 const base::FilePath& icon_dir, | 237 base::RefCountedData<JumpListData>* ref_counted_data) { |
| 238 base::RefCountedData<JumpListData>* ref_counted_data) { | |
| 239 JumpListData* data = &ref_counted_data->data; | 238 JumpListData* data = &ref_counted_data->data; |
| 240 ShellLinkItemList local_most_visited_pages; | 239 ShellLinkItemList local_most_visited_pages; |
| 241 ShellLinkItemList local_recently_closed_pages; | 240 ShellLinkItemList local_recently_closed_pages; |
| 242 | 241 |
| 243 { | 242 { |
| 244 base::AutoLock auto_lock(data->list_lock_); | 243 base::AutoLock auto_lock(data->list_lock_); |
| 245 // Make sure we are not out of date: if icon_urls_ is not empty, then | 244 // Make sure we are not out of date: if icon_urls_ is not empty, then |
| 246 // another notification has been received since we processed this one | 245 // another notification has been received since we processed this one |
| 247 if (!data->icon_urls_.empty()) | 246 if (!data->icon_urls_.empty()) |
| 248 return; | 247 return; |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 waiting_for_icons = !data->icon_urls_.empty(); | 500 waiting_for_icons = !data->icon_urls_.empty(); |
| 502 if (waiting_for_icons) { | 501 if (waiting_for_icons) { |
| 503 // Ask FaviconService if it has a favicon of a URL. | 502 // Ask FaviconService if it has a favicon of a URL. |
| 504 // When FaviconService has one, it will call OnFaviconDataAvailable(). | 503 // When FaviconService has one, it will call OnFaviconDataAvailable(). |
| 505 url = GURL(data->icon_urls_.front().first); | 504 url = GURL(data->icon_urls_.front().first); |
| 506 } | 505 } |
| 507 } | 506 } |
| 508 | 507 |
| 509 if (!waiting_for_icons) { | 508 if (!waiting_for_icons) { |
| 510 // No more favicons are needed by the application JumpList. Schedule a | 509 // No more favicons are needed by the application JumpList. Schedule a |
| 511 // RunUpdateJumpListUserVisiblePriority call. | 510 // RunUpdateJumpList call. |
| 512 PostRunUpdate(); | 511 PostRunUpdate(); |
| 513 return; | 512 return; |
| 514 } | 513 } |
| 515 | 514 |
| 516 favicon::FaviconService* favicon_service = | 515 favicon::FaviconService* favicon_service = |
| 517 FaviconServiceFactory::GetForProfile(profile_, | 516 FaviconServiceFactory::GetForProfile(profile_, |
| 518 ServiceAccessType::EXPLICIT_ACCESS); | 517 ServiceAccessType::EXPLICIT_ACCESS); |
| 519 task_id_ = favicon_service->GetFaviconImageForPageURL( | 518 task_id_ = favicon_service->GetFaviconImageForPageURL( |
| 520 url, | 519 url, |
| 521 base::Bind(&JumpList::OnFaviconDataAvailable, base::Unretained(this)), | 520 base::Bind(&JumpList::OnFaviconDataAvailable, base::Unretained(this)), |
| 522 &cancelable_task_tracker_); | 521 &cancelable_task_tracker_); |
| 523 } | 522 } |
| 524 | 523 |
| 525 void JumpList::OnFaviconDataAvailable( | 524 void JumpList::OnFaviconDataAvailable( |
| 526 const favicon_base::FaviconImageResult& image_result) { | 525 const favicon_base::FaviconImageResult& image_result) { |
| 527 DCHECK(CalledOnValidThread()); | 526 DCHECK(CalledOnValidThread()); |
| 528 | 527 |
| 529 // If there is currently a favicon request in progress, it is now outdated, | 528 // If there is currently a favicon request in progress, it is now outdated, |
| 530 // as we have received another, so nullify the handle from the old request. | 529 // as we have received another, so nullify the handle from the old request. |
| 531 task_id_ = base::CancelableTaskTracker::kBadTaskId; | 530 task_id_ = base::CancelableTaskTracker::kBadTaskId; |
| 532 // Lock the list to set icon data and pop the url. | 531 // Lock the list to set icon data and pop the url. |
| 533 { | 532 { |
| 534 JumpListData* data = &jumplist_data_->data; | 533 JumpListData* data = &jumplist_data_->data; |
| 535 base::AutoLock auto_lock(data->list_lock_); | 534 base::AutoLock auto_lock(data->list_lock_); |
| 536 // Attach the received data to the ShellLinkItem object. | 535 // Attach the received data to the ShellLinkItem object. |
| 537 // This data will be decoded by the RunUpdateJumpListUserVisiblePriority | 536 // This data will be decoded by the RunUpdateJumpList |
| 538 // method. | 537 // method. |
| 539 if (!image_result.image.IsEmpty() && !data->icon_urls_.empty() && | 538 if (!image_result.image.IsEmpty() && !data->icon_urls_.empty() && |
| 540 data->icon_urls_.front().second.get()) { | 539 data->icon_urls_.front().second.get()) { |
| 541 gfx::ImageSkia image_skia = image_result.image.AsImageSkia(); | 540 gfx::ImageSkia image_skia = image_result.image.AsImageSkia(); |
| 542 image_skia.EnsureRepsForSupportedScales(); | 541 image_skia.EnsureRepsForSupportedScales(); |
| 543 std::unique_ptr<gfx::ImageSkia> deep_copy(image_skia.DeepCopy()); | 542 std::unique_ptr<gfx::ImageSkia> deep_copy(image_skia.DeepCopy()); |
| 544 data->icon_urls_.front().second->set_icon_image(*deep_copy); | 543 data->icon_urls_.front().second->set_icon_image(*deep_copy); |
| 545 } | 544 } |
| 546 | 545 |
| 547 if (!data->icon_urls_.empty()) | 546 if (!data->icon_urls_.empty()) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 | 588 |
| 590 TRACE_EVENT0("browser", "JumpList::DeferredRunUpdate"); | 589 TRACE_EVENT0("browser", "JumpList::DeferredRunUpdate"); |
| 591 // Check if incognito windows (or normal windows) are disabled by policy. | 590 // Check if incognito windows (or normal windows) are disabled by policy. |
| 592 IncognitoModePrefs::Availability incognito_availability = | 591 IncognitoModePrefs::Availability incognito_availability = |
| 593 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) | 592 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) |
| 594 : IncognitoModePrefs::ENABLED; | 593 : IncognitoModePrefs::ENABLED; |
| 595 | 594 |
| 596 // Post a task to delete the content in JumpListIcons folder and log the | 595 // Post a task to delete the content in JumpListIcons folder and log the |
| 597 // results to UMA. | 596 // results to UMA. |
| 598 update_jumplisticons_task_runner_->PostTask( | 597 update_jumplisticons_task_runner_->PostTask( |
| 599 FROM_HERE, | 598 FROM_HERE, base::Bind(&DeleteDirectoryContentAndLogResults, icon_dir_, |
| 600 base::Bind(&DeleteDirectoryContentAndLogResultsUserVisiblePriority, | 599 kFileDeleteLimit)); |
| 601 icon_dir_, kFileDeleteLimit)); | |
| 602 | 600 |
| 603 // Post a task to update the jumplist used by the shell. | 601 // Post a task to update the jumplist used by the shell. |
| 604 update_jumplisticons_task_runner_->PostTask( | 602 update_jumplisticons_task_runner_->PostTask( |
| 605 FROM_HERE, | 603 FROM_HERE, base::Bind(&RunUpdateJumpList, incognito_availability, app_id_, |
| 606 base::Bind(&RunUpdateJumpListUserVisiblePriority, incognito_availability, | 604 icon_dir_, base::RetainedRef(jumplist_data_))); |
| 607 app_id_, icon_dir_, base::RetainedRef(jumplist_data_))); | |
| 608 | 605 |
| 609 // Post a task to delete JumpListIconsOld folder and log the results to UMA. | 606 // Post a task to delete JumpListIconsOld folder and log the results to UMA. |
| 610 base::FilePath icon_dir_old = icon_dir_.DirName().Append( | 607 base::FilePath icon_dir_old = icon_dir_.DirName().Append( |
| 611 icon_dir_.BaseName().value() + FILE_PATH_LITERAL("Old")); | 608 icon_dir_.BaseName().value() + FILE_PATH_LITERAL("Old")); |
| 612 | 609 |
| 613 delete_jumplisticonsold_task_runner_->PostTask( | 610 delete_jumplisticonsold_task_runner_->PostTask( |
| 614 FROM_HERE, base::Bind(&DeleteDirectoryAndLogResults, | 611 FROM_HERE, base::Bind(&DeleteDirectoryAndLogResults, |
| 615 std::move(icon_dir_old), kFileDeleteLimit)); | 612 std::move(icon_dir_old), kFileDeleteLimit)); |
| 616 } | 613 } |
| 617 | 614 |
| 618 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { | 615 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { |
| 619 } | 616 } |
| 620 | 617 |
| 621 void JumpList::TopSitesChanged(history::TopSites* top_sites, | 618 void JumpList::TopSitesChanged(history::TopSites* top_sites, |
| 622 ChangeReason change_reason) { | 619 ChangeReason change_reason) { |
| 623 top_sites->GetMostVisitedURLs( | 620 top_sites->GetMostVisitedURLs( |
| 624 base::Bind(&JumpList::OnMostVisitedURLsAvailable, | 621 base::Bind(&JumpList::OnMostVisitedURLsAvailable, |
| 625 weak_ptr_factory_.GetWeakPtr()), | 622 weak_ptr_factory_.GetWeakPtr()), |
| 626 false); | 623 false); |
| 627 } | 624 } |
| OLD | NEW |