Skip to content

Commit a8778d0

Browse files
author
Olivier Robin
committed
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 a859436) Bug: 762577 Change-Id: I05acf8e58b4dcdf9d21d5ee7e3f352d48f76f699 Reviewed-on: https://chromium-review.googlesource.com/654860 Commit-Queue: Olivier Robin <olivierrobin@chromium.org> Reviewed-by: Sylvain Defresne <sdefresne@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#500592} Reviewed-on: https://chromium-review.googlesource.com/668539 Reviewed-by: Olivier Robin <olivierrobin@chromium.org> Cr-Commit-Position: refs/branch-heads/3202@{crosswalk-project#249} Cr-Branched-From: fa6a5d8-refs/heads/master@{#499098}
1 parent 65e8108 commit a8778d0

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

ios/chrome/browser/reading_list/reading_list_download_service.cc

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@ const int kNumberOfFailsBeforeWifiOnly = 5;
4040
// Number of time the download must fail before we give up trying to download
4141
// it.
4242
const int kNumberOfFailsBeforeStop = 7;
43+
44+
// Scans |root| directory and deletes all subdirectories not listed
45+
// in |directories_to_keep|.
46+
// Must be called on File thread.
47+
void CleanUpFiles(base::FilePath root,
48+
const std::set<std::string>& processed_directories) {
49+
base::ThreadRestrictions::AssertIOAllowed();
50+
base::FileEnumerator file_enumerator(root, false,
51+
base::FileEnumerator::DIRECTORIES);
52+
for (base::FilePath sub_directory = file_enumerator.Next();
53+
!sub_directory.empty(); sub_directory = file_enumerator.Next()) {
54+
std::string directory_name = sub_directory.BaseName().value();
55+
if (!processed_directories.count(directory_name)) {
56+
base::DeleteFile(sub_directory, true);
57+
}
58+
}
59+
}
4360
} // namespace
4461

4562
ReadingListDownloadService::ReadingListDownloadService(
@@ -146,27 +163,14 @@ void ReadingListDownloadService::SyncWithModel() {
146163
}
147164
}
148165
base::PostTaskWithTraitsAndReply(
149-
FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND},
150-
base::Bind(&ReadingListDownloadService::CleanUpFiles,
151-
base::Unretained(this), processed_directories),
166+
FROM_HERE,
167+
{base::MayBlock(), base::TaskPriority::USER_VISIBLE,
168+
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN},
169+
base::Bind(&::CleanUpFiles, OfflineRoot(), processed_directories),
152170
base::Bind(&ReadingListDownloadService::DownloadUnprocessedEntries,
153171
base::Unretained(this), unprocessed_entries));
154172
}
155173

156-
void ReadingListDownloadService::CleanUpFiles(
157-
const std::set<std::string>& processed_directories) {
158-
base::ThreadRestrictions::AssertIOAllowed();
159-
base::FileEnumerator file_enumerator(OfflineRoot(), false,
160-
base::FileEnumerator::DIRECTORIES);
161-
for (base::FilePath sub_directory = file_enumerator.Next();
162-
!sub_directory.empty(); sub_directory = file_enumerator.Next()) {
163-
std::string directory_name = sub_directory.BaseName().value();
164-
if (!processed_directories.count(directory_name)) {
165-
base::DeleteFile(sub_directory, true);
166-
}
167-
}
168-
}
169-
170174
void ReadingListDownloadService::DownloadUnprocessedEntries(
171175
const std::set<GURL>& unprocessed_entries) {
172176
for (const GURL& url : unprocessed_entries) {

ios/chrome/browser/reading_list/reading_list_download_service.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ class ReadingListDownloadService
7070
// not corresponding to a processed ReadingListEntry.
7171
// Schedules unprocessed entries for distillation.
7272
void SyncWithModel();
73-
// Scans |OfflineRoot()| directory and deletes all subdirectories not listed
74-
// in |directories_to_keep|.
75-
// Must be called on File thread.
76-
void CleanUpFiles(const std::set<std::string>& directories_to_keep);
7773
// Schedules all entries in |unprocessed_entries| for distillation.
7874
void DownloadUnprocessedEntries(const std::set<GURL>& unprocessed_entries);
7975
// Processes a new entry and schedules a download if needed.

0 commit comments

Comments
 (0)