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

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

Issue 2379113002: Extended the ProtoDatabase to provide LoadKeys() functionality. (Closed)
Patch Set: Garbage Collect orphaned images on service start-up. 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_database.cc
diff --git a/components/ntp_snippets/remote/ntp_snippets_database.cc b/components/ntp_snippets/remote/ntp_snippets_database.cc
index 5ded341343d74ca9813d4f1ead438928cdd52e88..41498820e306410985565ca27354dae0afda5cc7 100644
--- a/components/ntp_snippets/remote/ntp_snippets_database.cc
+++ b/components/ntp_snippets/remote/ntp_snippets_database.cc
@@ -133,6 +133,32 @@ void NTPSnippetsDatabase::DeleteImages(const NTPSnippet::PtrVector& snippets) {
DeleteImagesImpl(std::move(keys_to_remove));
}
+void NTPSnippetsDatabase::DeleteUnreferencedImages(
+ std::unique_ptr<std::set<std::string>> references,
+ bool success,
+ std::unique_ptr<std::vector<std::string>> keys) {
+ if (!success) {
+ DVLOG(1) << "NTPSnippetsDatabase garbage collection failed.";
+ OnDatabaseError();
+ return;
+ }
+ auto keys_to_remove = base::MakeUnique<std::vector<std::string>>();
+ for (const std::string& key : *keys) {
+ if (references->count(key) == 0) {
+ keys_to_remove->emplace_back(key);
+ }
+ }
+ DeleteImagesImpl(std::move(keys_to_remove));
+}
+
+void NTPSnippetsDatabase::GarbageCollectImages(
+ std::unique_ptr<std::set<std::string>> alive_snippets) {
+ DCHECK(image_database_initialized_);
+ image_database_->LoadKeys(base::Bind(
+ &NTPSnippetsDatabase::DeleteUnreferencedImages,
+ weak_ptr_factory_.GetWeakPtr(), base::Passed(std::move(alive_snippets))));
+}
+
void NTPSnippetsDatabase::OnDatabaseInited(bool success) {
DCHECK(!database_initialized_);
if (!success) {

Powered by Google App Engine
This is Rietveld 408576698