| Index: ios/chrome/browser/snapshots/snapshot_cache.mm
|
| diff --git a/ios/chrome/browser/snapshots/snapshot_cache.mm b/ios/chrome/browser/snapshots/snapshot_cache.mm
|
| index 7fb720d8c21ab9c55791dd7c850208a8d56a891a..612dc57e046e3a40fc50afe8e6b9917b34309fb2 100644
|
| --- a/ios/chrome/browser/snapshots/snapshot_cache.mm
|
| +++ b/ios/chrome/browser/snapshots/snapshot_cache.mm
|
| @@ -10,6 +10,7 @@
|
| #include "base/files/file_enumerator.h"
|
| #include "base/files/file_path.h"
|
| #include "base/files/file_util.h"
|
| +#include "base/lazy_instance.h"
|
| #include "base/location.h"
|
| #include "base/logging.h"
|
| #include "base/mac/bind_objc_block.h"
|
| @@ -18,6 +19,7 @@
|
| #include "base/mac/scoped_nsobject.h"
|
| #include "base/strings/sys_string_conversions.h"
|
| #include "base/task_runner_util.h"
|
| +#include "base/task_scheduler/post_task.h"
|
| #include "base/threading/thread_restrictions.h"
|
| #include "ios/chrome/browser/experimental_flags.h"
|
| #import "ios/chrome/browser/snapshots/lru_cache.h"
|
| @@ -52,12 +54,20 @@ static NSArray* const kSnapshotCacheDirectory = @[ @"Chromium", @"Snapshots" ];
|
| const NSUInteger kCacheInitialCapacity = 100;
|
| const NSUInteger kGreyInitialCapacity = 8;
|
| const CGFloat kJPEGImageQuality = 1.0; // Highest quality. No compression.
|
| -// Sequence token to make sure creation/deletion of snapshots don't overlap.
|
| -const char kSequenceToken[] = "SnapshotCacheSequenceToken";
|
| // Maximum size in number of elements that the LRU cache can hold before
|
| // starting to evict elements.
|
| const NSUInteger kLRUCacheMaxCapacity = 6;
|
|
|
| +struct SnapshotTaskRunner {
|
| + const scoped_refptr<base::SequencedTaskRunner> task_runner =
|
| + base::CreateSequencedTaskRunnerWithTraits(
|
| + {base::MayBlock(), base::TaskPriority::USER_VISIBLE});
|
| +};
|
| +
|
| +// Sequence token to make sure creation/deletion of snapshots don't overlap.
|
| +base::LazyInstance<SnapshotTaskRunner>::Leaky g_snapshot_task_runner =
|
| + LAZY_INSTANCE_INITIALIZER;
|
| +
|
| // The paths of the images saved to disk, given a cache directory.
|
| base::FilePath FilePathForSessionID(NSString* sessionID,
|
| const base::FilePath& directory) {
|
| @@ -275,9 +285,8 @@ void ConvertAndSaveGreyImage(
|
| [imageDictionary_ setObject:img forKey:sessionID];
|
|
|
| // Save the image to disk.
|
| - web::WebThread::PostBlockingPoolSequencedTask(
|
| - kSequenceToken, FROM_HERE,
|
| - base::BindBlock(^{
|
| + g_snapshot_task_runner.Get().task_runner->PostTask(
|
| + FROM_HERE, base::BindBlock(^{
|
| base::scoped_nsobject<UIImage> image([img retain]);
|
| WriteImageToDisk(image,
|
| [SnapshotCache imagePathForSessionID:sessionID]);
|
| @@ -291,9 +300,8 @@ void ConvertAndSaveGreyImage(
|
| else
|
| [imageDictionary_ removeObjectForKey:sessionID];
|
|
|
| - web::WebThread::PostBlockingPoolSequencedTask(
|
| - kSequenceToken, FROM_HERE,
|
| - base::BindBlock(^{
|
| + g_snapshot_task_runner.Get().task_runner->PostTask(
|
| + FROM_HERE, base::BindBlock(^{
|
| base::FilePath imagePath =
|
| [SnapshotCache imagePathForSessionID:sessionID];
|
| base::DeleteFile(imagePath, false);
|
| @@ -357,9 +365,8 @@ void ConvertAndSaveGreyImage(
|
| DCHECK_CURRENTLY_ON(web::WebThread::UI);
|
| // Copying the date, as the block must copy the value, not the reference.
|
| const base::Time dateCopy = date;
|
| - web::WebThread::PostBlockingPoolSequencedTask(
|
| - kSequenceToken, FROM_HERE,
|
| - base::BindBlock(^{
|
| + g_snapshot_task_runner.Get().task_runner->PostTask(
|
| + FROM_HERE, base::BindBlock(^{
|
| std::set<base::FilePath> filesToKeep;
|
| for (NSString* sessionID : liveSessionIds) {
|
| base::FilePath curImagePath =
|
| @@ -574,9 +581,10 @@ void ConvertAndSaveGreyImage(
|
| }
|
| }
|
|
|
| - web::WebThread::PostBlockingPoolTask(
|
| - FROM_HERE, base::Bind(&ConvertAndSaveGreyImage, colorImagePath,
|
| - greyImagePath, backgroundingColorImage_));
|
| + base::PostTaskWithTraits(
|
| + FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE},
|
| + base::BindOnce(&ConvertAndSaveGreyImage, colorImagePath, greyImagePath,
|
| + backgroundingColorImage_));
|
| }
|
|
|
| @end
|
|
|