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/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
12 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
13 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
14 #include "base/time/clock.h" | 15 #include "base/time/clock.h" |
15 #include "base/time/tick_clock.h" | 16 #include "base/time/tick_clock.h" |
16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
17 #include "components/password_manager/core/browser/affiliation_database.h" | 18 #include "components/password_manager/core/browser/affiliation_database.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 return; | 92 return; |
92 facet_manager->CancelPrefetch(keep_fresh_until); | 93 facet_manager->CancelPrefetch(keep_fresh_until); |
93 | 94 |
94 if (facet_manager->CanBeDiscarded()) | 95 if (facet_manager->CanBeDiscarded()) |
95 facet_managers_.erase(facet_uri); | 96 facet_managers_.erase(facet_uri); |
96 } | 97 } |
97 | 98 |
98 void AffiliationBackend::TrimCache() { | 99 void AffiliationBackend::TrimCache() { |
99 DCHECK(thread_checker_ && thread_checker_->CalledOnValidThread()); | 100 DCHECK(thread_checker_ && thread_checker_->CalledOnValidThread()); |
100 | 101 |
101 // TODO(engedy): Implement this. crbug.com/437865. | 102 // Discard all equivalence classes except those that contain >= 1 facet for |
102 NOTIMPLEMENTED(); | 103 // which there is a FacetManager claiming that it needs to keep the data. |
| 104 std::vector<AffiliatedFacetsWithUpdateTime> all_affiliations; |
| 105 cache_->GetAllAffiliations(&all_affiliations); |
| 106 for (const auto& affiliation : all_affiliations) { |
| 107 bool can_discard = true; |
| 108 for (const auto& facet_uri : affiliation.facets) { |
| 109 FacetManager* facet_manager = facet_managers_.get(facet_uri); |
| 110 if (facet_manager && !facet_manager->CanCachedDataBeDiscarded()) { |
| 111 can_discard = false; |
| 112 break; |
| 113 } |
| 114 } |
| 115 if (can_discard) { |
| 116 // The database should not be serving empty equivalence classes. |
| 117 CHECK(affiliation.facets.size()); |
| 118 cache_->DeleteAffiliationsForFacet(affiliation.facets[0]); |
| 119 } |
| 120 } |
| 121 } |
| 122 |
| 123 // static |
| 124 void AffiliationBackend::DeleteCache(const base::FilePath& db_path) { |
| 125 AffiliationDatabase::Delete(db_path); |
103 } | 126 } |
104 | 127 |
105 FacetManager* AffiliationBackend::GetOrCreateFacetManager( | 128 FacetManager* AffiliationBackend::GetOrCreateFacetManager( |
106 const FacetURI& facet_uri) { | 129 const FacetURI& facet_uri) { |
107 if (!facet_managers_.contains(facet_uri)) { | 130 if (!facet_managers_.contains(facet_uri)) { |
108 scoped_ptr<FacetManager> new_manager( | 131 scoped_ptr<FacetManager> new_manager( |
109 new FacetManager(facet_uri, this, clock_.get())); | 132 new FacetManager(facet_uri, this, clock_.get())); |
110 facet_managers_.add(facet_uri, new_manager.Pass()); | 133 facet_managers_.add(facet_uri, new_manager.Pass()); |
111 } | 134 } |
112 return facet_managers_.get(facet_uri); | 135 return facet_managers_.get(facet_uri); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 } | 271 } |
249 last_request_time_ = clock_->Now(); | 272 last_request_time_ = clock_->Now(); |
250 } | 273 } |
251 | 274 |
252 void AffiliationBackend::SetThrottlerForTesting( | 275 void AffiliationBackend::SetThrottlerForTesting( |
253 scoped_ptr<AffiliationFetchThrottler> throttler) { | 276 scoped_ptr<AffiliationFetchThrottler> throttler) { |
254 throttler_ = throttler.Pass(); | 277 throttler_ = throttler.Pass(); |
255 } | 278 } |
256 | 279 |
257 } // namespace password_manager | 280 } // namespace password_manager |
OLD | NEW |