| 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 #include <algorithm> |
| 9 #include <utility> |
| 9 | 10 |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/location.h" | 12 #include "base/location.h" |
| 12 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 14 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
| 15 #include "base/time/clock.h" | 16 #include "base/time/clock.h" |
| 16 #include "base/time/tick_clock.h" | 17 #include "base/time/tick_clock.h" |
| 17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 18 #include "components/password_manager/core/browser/affiliation_database.h" | 19 #include "components/password_manager/core/browser/affiliation_database.h" |
| 19 #include "components/password_manager/core/browser/affiliation_fetch_throttler.h
" | 20 #include "components/password_manager/core/browser/affiliation_fetch_throttler.h
" |
| 20 #include "components/password_manager/core/browser/affiliation_fetcher.h" | 21 #include "components/password_manager/core/browser/affiliation_fetcher.h" |
| 21 #include "components/password_manager/core/browser/facet_manager.h" | 22 #include "components/password_manager/core/browser/facet_manager.h" |
| 22 #include "net/url_request/url_request_context_getter.h" | 23 #include "net/url_request/url_request_context_getter.h" |
| 23 | 24 |
| 24 namespace password_manager { | 25 namespace password_manager { |
| 25 | 26 |
| 26 AffiliationBackend::AffiliationBackend( | 27 AffiliationBackend::AffiliationBackend( |
| 27 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, | 28 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, |
| 28 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 29 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 29 scoped_ptr<base::Clock> time_source, | 30 scoped_ptr<base::Clock> time_source, |
| 30 scoped_ptr<base::TickClock> time_tick_source) | 31 scoped_ptr<base::TickClock> time_tick_source) |
| 31 : request_context_getter_(request_context_getter), | 32 : request_context_getter_(request_context_getter), |
| 32 task_runner_(task_runner), | 33 task_runner_(task_runner), |
| 33 clock_(time_source.Pass()), | 34 clock_(std::move(time_source)), |
| 34 tick_clock_(time_tick_source.Pass()), | 35 tick_clock_(std::move(time_tick_source)), |
| 35 construction_time_(clock_->Now()), | 36 construction_time_(clock_->Now()), |
| 36 weak_ptr_factory_(this) { | 37 weak_ptr_factory_(this) { |
| 37 DCHECK_LT(base::Time(), clock_->Now()); | 38 DCHECK_LT(base::Time(), clock_->Now()); |
| 38 } | 39 } |
| 39 | 40 |
| 40 AffiliationBackend::~AffiliationBackend() { | 41 AffiliationBackend::~AffiliationBackend() { |
| 41 } | 42 } |
| 42 | 43 |
| 43 void AffiliationBackend::Initialize(const base::FilePath& db_path) { | 44 void AffiliationBackend::Initialize(const base::FilePath& db_path) { |
| 44 thread_checker_.reset(new base::ThreadChecker); | 45 thread_checker_.reset(new base::ThreadChecker); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 // static | 117 // static |
| 117 void AffiliationBackend::DeleteCache(const base::FilePath& db_path) { | 118 void AffiliationBackend::DeleteCache(const base::FilePath& db_path) { |
| 118 AffiliationDatabase::Delete(db_path); | 119 AffiliationDatabase::Delete(db_path); |
| 119 } | 120 } |
| 120 | 121 |
| 121 FacetManager* AffiliationBackend::GetOrCreateFacetManager( | 122 FacetManager* AffiliationBackend::GetOrCreateFacetManager( |
| 122 const FacetURI& facet_uri) { | 123 const FacetURI& facet_uri) { |
| 123 if (!facet_managers_.contains(facet_uri)) { | 124 if (!facet_managers_.contains(facet_uri)) { |
| 124 scoped_ptr<FacetManager> new_manager( | 125 scoped_ptr<FacetManager> new_manager( |
| 125 new FacetManager(facet_uri, this, clock_.get())); | 126 new FacetManager(facet_uri, this, clock_.get())); |
| 126 facet_managers_.add(facet_uri, new_manager.Pass()); | 127 facet_managers_.add(facet_uri, std::move(new_manager)); |
| 127 } | 128 } |
| 128 return facet_managers_.get(facet_uri); | 129 return facet_managers_.get(facet_uri); |
| 129 } | 130 } |
| 130 | 131 |
| 131 void AffiliationBackend::DiscardCachedDataIfNoLongerNeeded( | 132 void AffiliationBackend::DiscardCachedDataIfNoLongerNeeded( |
| 132 const AffiliatedFacets& affiliated_facets) { | 133 const AffiliatedFacets& affiliated_facets) { |
| 133 DCHECK(thread_checker_ && thread_checker_->CalledOnValidThread()); | 134 DCHECK(thread_checker_ && thread_checker_->CalledOnValidThread()); |
| 134 | 135 |
| 135 // Discard the equivalence class if there is no facet in the class whose | 136 // Discard the equivalence class if there is no facet in the class whose |
| 136 // FacetManager claims that it needs to keep the data. | 137 // FacetManager claims that it needs to keep the data. |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 base::TimeDelta delay = clock_->Now() - last_request_time_; | 277 base::TimeDelta delay = clock_->Now() - last_request_time_; |
| 277 UMA_HISTOGRAM_CUSTOM_TIMES( | 278 UMA_HISTOGRAM_CUSTOM_TIMES( |
| 278 "PasswordManager.AffiliationBackend.SubsequentFetchDelay", delay, | 279 "PasswordManager.AffiliationBackend.SubsequentFetchDelay", delay, |
| 279 base::TimeDelta::FromSeconds(1), base::TimeDelta::FromDays(3), 50); | 280 base::TimeDelta::FromSeconds(1), base::TimeDelta::FromDays(3), 50); |
| 280 } | 281 } |
| 281 last_request_time_ = clock_->Now(); | 282 last_request_time_ = clock_->Now(); |
| 282 } | 283 } |
| 283 | 284 |
| 284 void AffiliationBackend::SetThrottlerForTesting( | 285 void AffiliationBackend::SetThrottlerForTesting( |
| 285 scoped_ptr<AffiliationFetchThrottler> throttler) { | 286 scoped_ptr<AffiliationFetchThrottler> throttler) { |
| 286 throttler_ = throttler.Pass(); | 287 throttler_ = std::move(throttler); |
| 287 } | 288 } |
| 288 | 289 |
| 289 } // namespace password_manager | 290 } // namespace password_manager |
| OLD | NEW |