Skip to content

Commit

Permalink
Fix call to ReadingListDownloadService::CleanUpFiles.
Browse files Browse the repository at this point in the history
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.

[email protected]

(cherry picked from commit a859436)

Bug: 762577
Change-Id: I05acf8e58b4dcdf9d21d5ee7e3f352d48f76f699
Reviewed-on: https://chromium-review.googlesource.com/654860
Commit-Queue: Olivier Robin <[email protected]>
Reviewed-by: Sylvain Defresne <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#500592}
Reviewed-on: https://chromium-review.googlesource.com/668539
Reviewed-by: Olivier Robin <[email protected]>
Cr-Commit-Position: refs/branch-heads/3202@{crosswalk-project#249}
Cr-Branched-From: fa6a5d8-refs/heads/master@{#499098}
  • Loading branch information
Olivier Robin committed Sep 15, 2017
1 parent 65e8108 commit a8778d0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
38 changes: 21 additions & 17 deletions ios/chrome/browser/reading_list/reading_list_download_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>& 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(
Expand Down Expand Up @@ -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<std::string>& 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<GURL>& unprocessed_entries) {
for (const GURL& url : unprocessed_entries) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>& directories_to_keep);
// Schedules all entries in |unprocessed_entries| for distillation.
void DownloadUnprocessedEntries(const std::set<GURL>& unprocessed_entries);
// Processes a new entry and schedules a download if needed.
Expand Down

0 comments on commit a8778d0

Please sign in to comment.