From a8778d0b946d36fae921b4740e63d537ef01df4b Mon Sep 17 00:00:00 2001 From: Olivier Robin Date: Fri, 15 Sep 2017 15:36:03 +0000 Subject: [PATCH] Fix call to ReadingListDownloadService::CleanUpFiles. If the application is shutting down, the task may run on a shutdowned service. Make the call static (so it does not need the service) and mark it SKIP_ON_SHUTDOWN. Also mark it USER_VISIBLE as it delays the offline feature of ReadingList. TBR=olivierrobin@chromium.org (cherry picked from commit a859436434e4b45c9dacc9e5f0bd56c8616dba9e) Bug: 762577 Change-Id: I05acf8e58b4dcdf9d21d5ee7e3f352d48f76f699 Reviewed-on: https://chromium-review.googlesource.com/654860 Commit-Queue: Olivier Robin Reviewed-by: Sylvain Defresne Cr-Original-Commit-Position: refs/heads/master@{#500592} Reviewed-on: https://chromium-review.googlesource.com/668539 Reviewed-by: Olivier Robin Cr-Commit-Position: refs/branch-heads/3202@{#249} Cr-Branched-From: fa6a5d87adff761bc16afc5498c3f5944c1daa68-refs/heads/master@{#499098} --- .../reading_list_download_service.cc | 38 ++++++++++--------- .../reading_list_download_service.h | 4 -- 2 files changed, 21 insertions(+), 21 deletions(-) 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.