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

Unified Diff: components/password_manager/core/browser/affiliation_backend.cc

Issue 1072413003: Add foundation for trimming the AffiliationDatabase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Keep noncontroversial parts. Created 5 years, 7 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/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 48301dbf24bca77b18b2b5a67b2d51509f16cfa3..fd4af44444e0ba4e7891d98e49332fd59d815667 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"
@@ -98,8 +99,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
+ // 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) {
+ 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]);
+ }
+ }
+}
+
+// static
+void AffiliationBackend::DeleteCache(const base::FilePath& db_path) {
+ AffiliationDatabase::Delete(db_path);
}
FacetManager* AffiliationBackend::GetOrCreateFacetManager(

Powered by Google App Engine
This is Rietveld 408576698