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 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 RunUpdateJumpList(IncognitoModePrefs::Availability incognito_availability, | 234 void RunUpdateJumpListUserVisiblePriority( |
|
gab
2017/04/11 20:25:31
Don't rename methods just for this (same for other
chengx
2017/04/11 21:09:28
This CL will be included in the Canary build tomor
gab
2017/04/12 19:25:47
I disagree.
1) UMA has version filters, you shoul
| |
| 235 const std::wstring& app_id, | 235 IncognitoModePrefs::Availability incognito_availability, |
| 236 const base::FilePath& icon_dir, | 236 const std::wstring& app_id, |
| 237 base::RefCountedData<JumpListData>* ref_counted_data) { | 237 const base::FilePath& icon_dir, |
| 238 base::RefCountedData<JumpListData>* ref_counted_data) { | |
| 238 JumpListData* data = &ref_counted_data->data; | 239 JumpListData* data = &ref_counted_data->data; |
| 239 ShellLinkItemList local_most_visited_pages; | 240 ShellLinkItemList local_most_visited_pages; |
| 240 ShellLinkItemList local_recently_closed_pages; | 241 ShellLinkItemList local_recently_closed_pages; |
| 241 | 242 |
| 242 { | 243 { |
| 243 base::AutoLock auto_lock(data->list_lock_); | 244 base::AutoLock auto_lock(data->list_lock_); |
| 244 // Make sure we are not out of date: if icon_urls_ is not empty, then | 245 // Make sure we are not out of date: if icon_urls_ is not empty, then |
| 245 // another notification has been received since we processed this one | 246 // another notification has been received since we processed this one |
| 246 if (!data->icon_urls_.empty()) | 247 if (!data->icon_urls_.empty()) |
| 247 return; | 248 return; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 277 JumpList::JumpListData::~JumpListData() {} | 278 JumpList::JumpListData::~JumpListData() {} |
| 278 | 279 |
| 279 JumpList::JumpList(Profile* profile) | 280 JumpList::JumpList(Profile* profile) |
| 280 : RefcountedKeyedService(content::BrowserThread::GetTaskRunnerForThread( | 281 : RefcountedKeyedService(content::BrowserThread::GetTaskRunnerForThread( |
| 281 content::BrowserThread::UI)), | 282 content::BrowserThread::UI)), |
| 282 profile_(profile), | 283 profile_(profile), |
| 283 jumplist_data_(new base::RefCountedData<JumpListData>), | 284 jumplist_data_(new base::RefCountedData<JumpListData>), |
| 284 task_id_(base::CancelableTaskTracker::kBadTaskId), | 285 task_id_(base::CancelableTaskTracker::kBadTaskId), |
| 285 update_jumplisticons_task_runner_(base::CreateCOMSTATaskRunnerWithTraits( | 286 update_jumplisticons_task_runner_(base::CreateCOMSTATaskRunnerWithTraits( |
| 286 base::TaskTraits() | 287 base::TaskTraits() |
| 287 .WithPriority(base::TaskPriority::BACKGROUND) | 288 .WithPriority(base::TaskPriority::USER_VISIBLE) |
| 288 .WithShutdownBehavior( | 289 .WithShutdownBehavior( |
| 289 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) | 290 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
| 290 .MayBlock())), | 291 .MayBlock())), |
| 291 delete_jumplisticonsold_task_runner_( | 292 delete_jumplisticonsold_task_runner_( |
| 292 base::CreateSequencedTaskRunnerWithTraits( | 293 base::CreateSequencedTaskRunnerWithTraits( |
| 293 base::TaskTraits() | 294 base::TaskTraits() |
| 294 .WithPriority(base::TaskPriority::BACKGROUND) | 295 .WithPriority(base::TaskPriority::BACKGROUND) |
| 295 .WithShutdownBehavior( | 296 .WithShutdownBehavior( |
| 296 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) | 297 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
| 297 .MayBlock())), | 298 .MayBlock())), |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 500 waiting_for_icons = !data->icon_urls_.empty(); | 501 waiting_for_icons = !data->icon_urls_.empty(); |
| 501 if (waiting_for_icons) { | 502 if (waiting_for_icons) { |
| 502 // Ask FaviconService if it has a favicon of a URL. | 503 // Ask FaviconService if it has a favicon of a URL. |
| 503 // When FaviconService has one, it will call OnFaviconDataAvailable(). | 504 // When FaviconService has one, it will call OnFaviconDataAvailable(). |
| 504 url = GURL(data->icon_urls_.front().first); | 505 url = GURL(data->icon_urls_.front().first); |
| 505 } | 506 } |
| 506 } | 507 } |
| 507 | 508 |
| 508 if (!waiting_for_icons) { | 509 if (!waiting_for_icons) { |
| 509 // No more favicons are needed by the application JumpList. Schedule a | 510 // No more favicons are needed by the application JumpList. Schedule a |
| 510 // RunUpdateJumpList call. | 511 // RunUpdateJumpListUserVisiblePriority call. |
| 511 PostRunUpdate(); | 512 PostRunUpdate(); |
| 512 return; | 513 return; |
| 513 } | 514 } |
| 514 | 515 |
| 515 favicon::FaviconService* favicon_service = | 516 favicon::FaviconService* favicon_service = |
| 516 FaviconServiceFactory::GetForProfile(profile_, | 517 FaviconServiceFactory::GetForProfile(profile_, |
| 517 ServiceAccessType::EXPLICIT_ACCESS); | 518 ServiceAccessType::EXPLICIT_ACCESS); |
| 518 task_id_ = favicon_service->GetFaviconImageForPageURL( | 519 task_id_ = favicon_service->GetFaviconImageForPageURL( |
| 519 url, | 520 url, |
| 520 base::Bind(&JumpList::OnFaviconDataAvailable, base::Unretained(this)), | 521 base::Bind(&JumpList::OnFaviconDataAvailable, base::Unretained(this)), |
| 521 &cancelable_task_tracker_); | 522 &cancelable_task_tracker_); |
| 522 } | 523 } |
| 523 | 524 |
| 524 void JumpList::OnFaviconDataAvailable( | 525 void JumpList::OnFaviconDataAvailable( |
| 525 const favicon_base::FaviconImageResult& image_result) { | 526 const favicon_base::FaviconImageResult& image_result) { |
| 526 DCHECK(CalledOnValidThread()); | 527 DCHECK(CalledOnValidThread()); |
| 527 | 528 |
| 528 // If there is currently a favicon request in progress, it is now outdated, | 529 // If there is currently a favicon request in progress, it is now outdated, |
| 529 // as we have received another, so nullify the handle from the old request. | 530 // as we have received another, so nullify the handle from the old request. |
| 530 task_id_ = base::CancelableTaskTracker::kBadTaskId; | 531 task_id_ = base::CancelableTaskTracker::kBadTaskId; |
| 531 // Lock the list to set icon data and pop the url. | 532 // Lock the list to set icon data and pop the url. |
| 532 { | 533 { |
| 533 JumpListData* data = &jumplist_data_->data; | 534 JumpListData* data = &jumplist_data_->data; |
| 534 base::AutoLock auto_lock(data->list_lock_); | 535 base::AutoLock auto_lock(data->list_lock_); |
| 535 // Attach the received data to the ShellLinkItem object. | 536 // Attach the received data to the ShellLinkItem object. |
| 536 // This data will be decoded by the RunUpdateJumpList method. | 537 // This data will be decoded by the RunUpdateJumpListUserVisiblePriority |
| 538 // method. | |
| 537 if (!image_result.image.IsEmpty() && !data->icon_urls_.empty() && | 539 if (!image_result.image.IsEmpty() && !data->icon_urls_.empty() && |
| 538 data->icon_urls_.front().second.get()) { | 540 data->icon_urls_.front().second.get()) { |
| 539 gfx::ImageSkia image_skia = image_result.image.AsImageSkia(); | 541 gfx::ImageSkia image_skia = image_result.image.AsImageSkia(); |
| 540 image_skia.EnsureRepsForSupportedScales(); | 542 image_skia.EnsureRepsForSupportedScales(); |
| 541 std::unique_ptr<gfx::ImageSkia> deep_copy(image_skia.DeepCopy()); | 543 std::unique_ptr<gfx::ImageSkia> deep_copy(image_skia.DeepCopy()); |
| 542 data->icon_urls_.front().second->set_icon_image(*deep_copy); | 544 data->icon_urls_.front().second->set_icon_image(*deep_copy); |
| 543 } | 545 } |
| 544 | 546 |
| 545 if (!data->icon_urls_.empty()) | 547 if (!data->icon_urls_.empty()) |
| 546 data->icon_urls_.pop_front(); | 548 data->icon_urls_.pop_front(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 587 | 589 |
| 588 TRACE_EVENT0("browser", "JumpList::DeferredRunUpdate"); | 590 TRACE_EVENT0("browser", "JumpList::DeferredRunUpdate"); |
| 589 // Check if incognito windows (or normal windows) are disabled by policy. | 591 // Check if incognito windows (or normal windows) are disabled by policy. |
| 590 IncognitoModePrefs::Availability incognito_availability = | 592 IncognitoModePrefs::Availability incognito_availability = |
| 591 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) | 593 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) |
| 592 : IncognitoModePrefs::ENABLED; | 594 : IncognitoModePrefs::ENABLED; |
| 593 | 595 |
| 594 // Post a task to delete the content in JumpListIcons folder and log the | 596 // Post a task to delete the content in JumpListIcons folder and log the |
| 595 // results to UMA. | 597 // results to UMA. |
| 596 update_jumplisticons_task_runner_->PostTask( | 598 update_jumplisticons_task_runner_->PostTask( |
| 597 FROM_HERE, base::Bind(&DeleteDirectoryContentAndLogResults, icon_dir_, | 599 FROM_HERE, |
| 598 kFileDeleteLimit)); | 600 base::Bind(&DeleteDirectoryContentAndLogResultsUserVisiblePriority, |
| 601 icon_dir_, kFileDeleteLimit)); | |
| 599 | 602 |
| 600 // Post a task to update the jumplist used by the shell. | 603 // Post a task to update the jumplist used by the shell. |
| 601 update_jumplisticons_task_runner_->PostTask( | 604 update_jumplisticons_task_runner_->PostTask( |
| 602 FROM_HERE, base::Bind(&RunUpdateJumpList, incognito_availability, app_id_, | 605 FROM_HERE, |
| 603 icon_dir_, base::RetainedRef(jumplist_data_))); | 606 base::Bind(&RunUpdateJumpListUserVisiblePriority, incognito_availability, |
| 607 app_id_, icon_dir_, base::RetainedRef(jumplist_data_))); | |
| 604 | 608 |
| 605 // Post a task to delete JumpListIconsOld folder and log the results to UMA. | 609 // Post a task to delete JumpListIconsOld folder and log the results to UMA. |
| 606 base::FilePath icon_dir_old = icon_dir_.DirName().Append( | 610 base::FilePath icon_dir_old = icon_dir_.DirName().Append( |
| 607 icon_dir_.BaseName().value() + FILE_PATH_LITERAL("Old")); | 611 icon_dir_.BaseName().value() + FILE_PATH_LITERAL("Old")); |
| 608 | 612 |
| 609 delete_jumplisticonsold_task_runner_->PostTask( | 613 delete_jumplisticonsold_task_runner_->PostTask( |
| 610 FROM_HERE, base::Bind(&DeleteDirectoryAndLogResults, | 614 FROM_HERE, base::Bind(&DeleteDirectoryAndLogResults, |
| 611 std::move(icon_dir_old), kFileDeleteLimit)); | 615 std::move(icon_dir_old), kFileDeleteLimit)); |
| 612 } | 616 } |
| 613 | 617 |
| 614 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { | 618 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { |
| 615 } | 619 } |
| 616 | 620 |
| 617 void JumpList::TopSitesChanged(history::TopSites* top_sites, | 621 void JumpList::TopSitesChanged(history::TopSites* top_sites, |
| 618 ChangeReason change_reason) { | 622 ChangeReason change_reason) { |
| 619 top_sites->GetMostVisitedURLs( | 623 top_sites->GetMostVisitedURLs( |
| 620 base::Bind(&JumpList::OnMostVisitedURLsAvailable, | 624 base::Bind(&JumpList::OnMostVisitedURLsAvailable, |
| 621 weak_ptr_factory_.GetWeakPtr()), | 625 weak_ptr_factory_.GetWeakPtr()), |
| 622 false); | 626 false); |
| 623 } | 627 } |
| OLD | NEW |