Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(403)

Unified Diff: ios/chrome/browser/reading_list/reading_list_download_service.cc

Issue 2650753003: [ReadingList iOS] Cleanup Offline directory on startup (Closed)
Patch Set: cleanup Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/reading_list/reading_list_download_service.cc
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 6cc7c6c8e7230752d7cf331adb992a57bfbaf1b7..ffa5513dec27ec7a47c79e229e6a713597b1877b 100644
--- a/ios/chrome/browser/reading_list/reading_list_download_service.cc
+++ b/ios/chrome/browser/reading_list/reading_list_download_service.cc
@@ -7,7 +7,9 @@
#include <utility>
#include "base/bind.h"
+#include "base/files/file_enumerator.h"
#include "base/files/file_path.h"
+#include "base/files/file_util.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "components/reading_list/ios/offline_url_utils.h"
@@ -117,9 +119,43 @@ void ReadingListDownloadService::ProcessNewEntry(const GURL& url) {
}
}
-void ReadingListDownloadService::DownloadAllEntries() {
+void ReadingListDownloadService::SyncWithModel() {
DCHECK(reading_list_model_->loaded());
+ std::set<std::string> processed_directories;
+ std::set<GURL> unprocessed_entries;
for (const auto& url : reading_list_model_->Keys()) {
+ const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url);
+ if (entry->DistilledState() == ReadingListEntry::PROCESSED) {
jif 2017/01/25 09:15:51 You know the drill. Can you do a: switch (entry->
Olivier 2017/01/25 12:25:30 Done.
+ std::string directory_name = reading_list::OfflineURLDirectoryID(url);
+ processed_directories.insert(directory_name);
jif 2017/01/25 09:15:51 can you do: processed_directories.insert(reading_
Olivier 2017/01/25 12:25:30 Done.
+ } else if (entry->DistilledState() != ReadingListEntry::ERROR) {
+ unprocessed_entries.insert(url);
+ }
+ }
+ web::WebThread::PostTaskAndReply(
+ web::WebThread::FILE, FROM_HERE,
+ base::Bind(&ReadingListDownloadService::CleanUpFiles,
+ base::Unretained(this), processed_directories),
+ base::Bind(&ReadingListDownloadService::DownloadUnprocessedEntries,
+ base::Unretained(this), unprocessed_entries));
+}
+
+void ReadingListDownloadService::CleanUpFiles(
+ const std::set<std::string>& processed_directories) {
+ 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) {
this->ScheduleDownloadEntry(url);
}
}

Powered by Google App Engine
This is Rietveld 408576698