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

Unified Diff: components/ntp_snippets/remote/ntp_snippets_service.cc

Issue 2386103009: NTPSnippetsService: Garbage collect orphaned images at startup. (Closed)
Patch Set: patch restored Created 4 years, 2 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: components/ntp_snippets/remote/ntp_snippets_service.cc
diff --git a/components/ntp_snippets/remote/ntp_snippets_service.cc b/components/ntp_snippets/remote/ntp_snippets_service.cc
index 94a8f893a9ca5bc162fc147b7bb2bf45fd5fafa3..a73ce3898f8694c7145e5db4075146530f68f1be 100644
--- a/components/ntp_snippets/remote/ntp_snippets_service.cc
+++ b/components/ntp_snippets/remote/ntp_snippets_service.cc
@@ -10,6 +10,7 @@
#include "base/command_line.h"
#include "base/location.h"
+#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/sparse_histogram.h"
#include "base/path_service.h"
@@ -492,6 +493,9 @@ void NTPSnippetsService::OnDatabaseLoaded(NTPSnippet::PtrVector snippets) {
DCHECK_EQ(1u, categories_.size()); // Only articles category, so far.
DCHECK(categories_.find(articles_category_) != categories_.end());
+ ClearExpiredDismissedSnippets();
Marc Treib 2016/10/06 10:21:30 This won't do anything, since |categories_| is sti
tschumann 2016/10/06 10:56:11 are you sure? we have a DCHECK() above verifying i
Marc Treib 2016/10/06 11:37:20 Ah okay, correction: The category itself will be t
tschumann 2016/10/06 12:21:44 nope -- you're not :-) added a TODO() to increase
+ ClearOrphanedImages(snippets);
+
// TODO(sfiera): support non-article categories in database.
CategoryContent* content = &categories_[articles_category_];
for (std::unique_ptr<NTPSnippet>& snippet : snippets) {
@@ -507,8 +511,6 @@ void NTPSnippetsService::OnDatabaseLoaded(NTPSnippet::PtrVector snippets) {
return lhs->score() > rhs->score();
});
- ClearExpiredDismissedSnippets();
- ClearOrphanedImages();
FinishInitialization();
}
@@ -593,7 +595,6 @@ void NTPSnippetsService::OnFetchFinished(
UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.Snippets.NumArticlesFetched",
fetched_category.snippets.size());
}
-
ReplaceSnippets(category, std::move(fetched_category.snippets));
}
}
@@ -767,8 +768,13 @@ void NTPSnippetsService::ClearExpiredDismissedSnippets() {
}
}
-void NTPSnippetsService::ClearOrphanedImages() {
- // TODO(jkrcal): Implement. crbug.com/649009
+void NTPSnippetsService::ClearOrphanedImages(
+ const NTPSnippet::PtrVector& snippets) {
+ auto alive_snippets = base::MakeUnique<std::set<std::string>>();
+ for (const auto& snippet_ptr : snippets) {
+ alive_snippets->insert(snippet_ptr->id());
+ }
+ database_->GarbageCollectImages(std::move(alive_snippets));
}
void NTPSnippetsService::NukeAllSnippets() {

Powered by Google App Engine
This is Rietveld 408576698