Chromium Code Reviews| 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( |
|
Marc Treib
2016/10/06 10:21:30
nit: Please match the order of methods in the head
tschumann
2016/10/06 10:56:10
Done.
|
| + std::unique_ptr<std::set<std::string>> references, |
| + bool success, |
| + std::unique_ptr<std::vector<std::string>> keys) { |
|
jkrcal
2016/10/06 10:12:47
Maybe |image_keys| to make it even clearer?
tschumann
2016/10/06 10:56:10
Done.
The context should already make 'keys' clear
|
| + 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) { |