Chromium Code Reviews| Index: components/password_manager/core/browser/affiliation_backend.cc |
| diff --git a/components/password_manager/core/browser/affiliation_backend.cc b/components/password_manager/core/browser/affiliation_backend.cc |
| index fe7e31d8bfabf869508c8668dd0324927bc83a63..d18aa759bef6c4b946a8aed74296d3d04713d7f4 100644 |
| --- a/components/password_manager/core/browser/affiliation_backend.cc |
| +++ b/components/password_manager/core/browser/affiliation_backend.cc |
| @@ -5,6 +5,7 @@ |
| #include "components/password_manager/core/browser/affiliation_backend.h" |
| #include <stdint.h> |
| +#include <algorithm> |
| #include "base/bind.h" |
| #include "base/location.h" |
| @@ -96,8 +97,30 @@ void AffiliationBackend::CancelPrefetch(const FacetURI& facet_uri, |
| void AffiliationBackend::TrimCache() { |
| DCHECK(thread_checker_ && thread_checker_->CalledOnValidThread()); |
| - // TODO(engedy): Implement this. crbug.com/437865. |
| - NOTIMPLEMENTED(); |
| + // Discard all equivalence classes except those that contain >= 1 facet for |
|
vasilii
2015/04/23 13:16:35
... contain at least one facet ....
|
| + // which there is a FacetManager claiming that it needs to keep the data. |
| + std::vector<AffiliatedFacetsWithUpdateTime> all_affiliations; |
| + cache_->GetAllAffiliations(&all_affiliations); |
| + for (const auto& affiliation : all_affiliations) { |
| + bool can_discard = true; |
| + for (const auto& facet_uri : affiliation.facets) { |
|
vasilii
2015/04/23 13:16:35
const FacetURI&
|
| + FacetManager* facet_manager = facet_managers_.get(facet_uri); |
| + if (facet_manager && !facet_manager->CanCachedDataBeDiscarded()) { |
| + can_discard = false; |
| + break; |
| + } |
| + } |
| + if (can_discard) { |
| + // The database should not be serving empty equivalence classes. |
| + CHECK(affiliation.facets.size()); |
| + cache_->DeleteAffiliationsForFacet(affiliation.facets[0]); |
|
vasilii
2015/04/23 13:16:35
Should you delete FacetManager?
|
| + } |
| + } |
| +} |
| + |
| +// static |
| +void AffiliationBackend::DeleteCache(const base::FilePath& db_path) { |
| + AffiliationDatabase::Delete(db_path); |
| } |
| FacetManager* AffiliationBackend::GetOrCreateFacetManager( |