OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/password_manager/core/browser/affiliation_backend.h" | 5 #include "components/password_manager/core/browser/affiliation_backend.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <algorithm> | |
8 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/location.h" | 11 #include "base/location.h" |
11 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
12 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
13 #include "base/time/clock.h" | 14 #include "base/time/clock.h" |
14 #include "base/time/tick_clock.h" | 15 #include "base/time/tick_clock.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
16 #include "components/password_manager/core/browser/affiliation_database.h" | 17 #include "components/password_manager/core/browser/affiliation_database.h" |
17 #include "components/password_manager/core/browser/affiliation_fetch_throttler.h " | 18 #include "components/password_manager/core/browser/affiliation_fetch_throttler.h " |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 return; | 90 return; |
90 facet_manager->CancelPrefetch(keep_fresh_until); | 91 facet_manager->CancelPrefetch(keep_fresh_until); |
91 | 92 |
92 if (facet_manager->CanBeDiscarded()) | 93 if (facet_manager->CanBeDiscarded()) |
93 facet_managers_.erase(facet_uri); | 94 facet_managers_.erase(facet_uri); |
94 } | 95 } |
95 | 96 |
96 void AffiliationBackend::TrimCache() { | 97 void AffiliationBackend::TrimCache() { |
97 DCHECK(thread_checker_ && thread_checker_->CalledOnValidThread()); | 98 DCHECK(thread_checker_ && thread_checker_->CalledOnValidThread()); |
98 | 99 |
99 // TODO(engedy): Implement this. crbug.com/437865. | 100 // Discard all equivalence classes except those that contain >= 1 facet for |
vasilii
2015/04/23 13:16:35
... contain at least one facet ....
| |
100 NOTIMPLEMENTED(); | 101 // which there is a FacetManager claiming that it needs to keep the data. |
102 std::vector<AffiliatedFacetsWithUpdateTime> all_affiliations; | |
103 cache_->GetAllAffiliations(&all_affiliations); | |
104 for (const auto& affiliation : all_affiliations) { | |
105 bool can_discard = true; | |
106 for (const auto& facet_uri : affiliation.facets) { | |
vasilii
2015/04/23 13:16:35
const FacetURI&
| |
107 FacetManager* facet_manager = facet_managers_.get(facet_uri); | |
108 if (facet_manager && !facet_manager->CanCachedDataBeDiscarded()) { | |
109 can_discard = false; | |
110 break; | |
111 } | |
112 } | |
113 if (can_discard) { | |
114 // The database should not be serving empty equivalence classes. | |
115 CHECK(affiliation.facets.size()); | |
116 cache_->DeleteAffiliationsForFacet(affiliation.facets[0]); | |
vasilii
2015/04/23 13:16:35
Should you delete FacetManager?
| |
117 } | |
118 } | |
119 } | |
120 | |
121 // static | |
122 void AffiliationBackend::DeleteCache(const base::FilePath& db_path) { | |
123 AffiliationDatabase::Delete(db_path); | |
101 } | 124 } |
102 | 125 |
103 FacetManager* AffiliationBackend::GetOrCreateFacetManager( | 126 FacetManager* AffiliationBackend::GetOrCreateFacetManager( |
104 const FacetURI& facet_uri) { | 127 const FacetURI& facet_uri) { |
105 if (!facet_managers_.contains(facet_uri)) { | 128 if (!facet_managers_.contains(facet_uri)) { |
106 scoped_ptr<FacetManager> new_manager( | 129 scoped_ptr<FacetManager> new_manager( |
107 new FacetManager(facet_uri, this, clock_.get())); | 130 new FacetManager(facet_uri, this, clock_.get())); |
108 facet_managers_.add(facet_uri, new_manager.Pass()); | 131 facet_managers_.add(facet_uri, new_manager.Pass()); |
109 } | 132 } |
110 return facet_managers_.get(facet_uri); | 133 return facet_managers_.get(facet_uri); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 fetcher_->StartRequest(); | 250 fetcher_->StartRequest(); |
228 return true; | 251 return true; |
229 } | 252 } |
230 | 253 |
231 void AffiliationBackend::SetThrottlerForTesting( | 254 void AffiliationBackend::SetThrottlerForTesting( |
232 scoped_ptr<AffiliationFetchThrottler> throttler) { | 255 scoped_ptr<AffiliationFetchThrottler> throttler) { |
233 throttler_ = throttler.Pass(); | 256 throttler_ = throttler.Pass(); |
234 } | 257 } |
235 | 258 |
236 } // namespace password_manager | 259 } // namespace password_manager |
OLD | NEW |