diff --git a/ios/chrome/browser/reading_list/reading_list_download_service.cc b/ios/chrome/browser/reading_list/reading_list_download_service.cc index c0b2cdf857f2e..f694449702732 100644 --- a/ios/chrome/browser/reading_list/reading_list_download_service.cc +++ b/ios/chrome/browser/reading_list/reading_list_download_service.cc @@ -40,6 +40,23 @@ const int kNumberOfFailsBeforeWifiOnly = 5; // Number of time the download must fail before we give up trying to download // it. const int kNumberOfFailsBeforeStop = 7; + +// Scans |root| directory and deletes all subdirectories not listed +// in |directories_to_keep|. +// Must be called on File thread. +void CleanUpFiles(base::FilePath root, + const std::set& processed_directories) { + base::ThreadRestrictions::AssertIOAllowed(); + base::FileEnumerator file_enumerator(root, false, + base::FileEnumerator::DIRECTORIES); + for (base::FilePath sub_directory = file_enumerator.Next(); + !sub_directory.empty(); sub_directory = file_enumerator.Next()) { + std::string directory_name = sub_directory.BaseName().value(); + if (!processed_directories.count(directory_name)) { + base::DeleteFile(sub_directory, true); + } + } +} } // namespace ReadingListDownloadService::ReadingListDownloadService( @@ -146,27 +163,14 @@ void ReadingListDownloadService::SyncWithModel() { } } base::PostTaskWithTraitsAndReply( - FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND}, - base::Bind(&ReadingListDownloadService::CleanUpFiles, - base::Unretained(this), processed_directories), + FROM_HERE, + {base::MayBlock(), base::TaskPriority::USER_VISIBLE, + base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}, + base::Bind(&::CleanUpFiles, OfflineRoot(), processed_directories), base::Bind(&ReadingListDownloadService::DownloadUnprocessedEntries, base::Unretained(this), unprocessed_entries)); } -void ReadingListDownloadService::CleanUpFiles( - const std::set& processed_directories) { - base::ThreadRestrictions::AssertIOAllowed(); - base::FileEnumerator file_enumerator(OfflineRoot(), false, - base::FileEnumerator::DIRECTORIES); - for (base::FilePath sub_directory = file_enumerator.Next(); - !sub_directory.empty(); sub_directory = file_enumerator.Next()) { - std::string directory_name = sub_directory.BaseName().value(); - if (!processed_directories.count(directory_name)) { - base::DeleteFile(sub_directory, true); - } - } -} - void ReadingListDownloadService::DownloadUnprocessedEntries( const std::set& unprocessed_entries) { for (const GURL& url : unprocessed_entries) { diff --git a/ios/chrome/browser/reading_list/reading_list_download_service.h b/ios/chrome/browser/reading_list/reading_list_download_service.h index 3276b7ad2257a..8210e41e25dac 100644 --- a/ios/chrome/browser/reading_list/reading_list_download_service.h +++ b/ios/chrome/browser/reading_list/reading_list_download_service.h @@ -70,10 +70,6 @@ class ReadingListDownloadService // not corresponding to a processed ReadingListEntry. // Schedules unprocessed entries for distillation. void SyncWithModel(); - // Scans |OfflineRoot()| directory and deletes all subdirectories not listed - // in |directories_to_keep|. - // Must be called on File thread. - void CleanUpFiles(const std::set& directories_to_keep); // Schedules all entries in |unprocessed_entries| for distillation. void DownloadUnprocessedEntries(const std::set& unprocessed_entries); // Processes a new entry and schedules a download if needed.