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 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/metrics/histogram_macros.h" | |
12 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
13 #include "base/threading/thread_checker.h" | 12 #include "base/threading/thread_checker.h" |
14 #include "base/time/clock.h" | 13 #include "base/time/clock.h" |
15 #include "base/time/tick_clock.h" | 14 #include "base/time/tick_clock.h" |
16 #include "base/time/time.h" | 15 #include "base/time/time.h" |
17 #include "components/password_manager/core/browser/affiliation_database.h" | 16 #include "components/password_manager/core/browser/affiliation_database.h" |
18 #include "components/password_manager/core/browser/affiliation_fetch_throttler.h
" | 17 #include "components/password_manager/core/browser/affiliation_fetch_throttler.h
" |
19 #include "components/password_manager/core/browser/affiliation_fetcher.h" | 18 #include "components/password_manager/core/browser/affiliation_fetcher.h" |
20 #include "components/password_manager/core/browser/facet_manager.h" | 19 #include "components/password_manager/core/browser/facet_manager.h" |
21 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
22 | 21 |
23 namespace password_manager { | 22 namespace password_manager { |
24 | 23 |
25 AffiliationBackend::AffiliationBackend( | 24 AffiliationBackend::AffiliationBackend( |
26 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, | 25 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, |
27 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 26 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
28 scoped_ptr<base::Clock> time_source, | 27 scoped_ptr<base::Clock> time_source, |
29 scoped_ptr<base::TickClock> time_tick_source) | 28 scoped_ptr<base::TickClock> time_tick_source) |
30 : request_context_getter_(request_context_getter), | 29 : request_context_getter_(request_context_getter), |
31 task_runner_(task_runner), | 30 task_runner_(task_runner), |
32 clock_(time_source.Pass()), | 31 clock_(time_source.Pass()), |
33 tick_clock_(time_tick_source.Pass()), | 32 tick_clock_(time_tick_source.Pass()), |
34 construction_time_(clock_->Now()), | |
35 weak_ptr_factory_(this) { | 33 weak_ptr_factory_(this) { |
36 DCHECK_LT(base::Time(), clock_->Now()); | 34 DCHECK_LT(base::Time(), clock_->Now()); |
37 } | 35 } |
38 | 36 |
39 AffiliationBackend::~AffiliationBackend() { | 37 AffiliationBackend::~AffiliationBackend() { |
40 } | 38 } |
41 | 39 |
42 void AffiliationBackend::Initialize(const base::FilePath& db_path) { | 40 void AffiliationBackend::Initialize(const base::FilePath& db_path) { |
43 thread_checker_.reset(new base::ThreadChecker); | 41 thread_checker_.reset(new base::ThreadChecker); |
44 | 42 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 requested_facet_uris.push_back(facet_manager_pair.first); | 218 requested_facet_uris.push_back(facet_manager_pair.first); |
221 } | 219 } |
222 | 220 |
223 // In case a request is no longer needed, return false to indicate this. | 221 // In case a request is no longer needed, return false to indicate this. |
224 if (requested_facet_uris.empty()) | 222 if (requested_facet_uris.empty()) |
225 return false; | 223 return false; |
226 | 224 |
227 fetcher_.reset(AffiliationFetcher::Create(request_context_getter_.get(), | 225 fetcher_.reset(AffiliationFetcher::Create(request_context_getter_.get(), |
228 requested_facet_uris, this)); | 226 requested_facet_uris, this)); |
229 fetcher_->StartRequest(); | 227 fetcher_->StartRequest(); |
230 ReportStatistics(requested_facet_uris.size()); | |
231 return true; | 228 return true; |
232 } | 229 } |
233 | 230 |
234 void AffiliationBackend::ReportStatistics(size_t requested_facet_uri_count) { | |
235 UMA_HISTOGRAM_COUNTS_100("PasswordManager.AffiliationBackend.FetchSize", | |
236 requested_facet_uri_count); | |
237 | |
238 if (last_request_time_.is_null()) { | |
239 base::TimeDelta delay = clock_->Now() - construction_time_; | |
240 UMA_HISTOGRAM_CUSTOM_TIMES( | |
241 "PasswordManager.AffiliationBackend.FirstFetchDelay", delay, | |
242 base::TimeDelta::FromSeconds(1), base::TimeDelta::FromDays(3), 50); | |
243 } else { | |
244 base::TimeDelta delay = clock_->Now() - last_request_time_; | |
245 UMA_HISTOGRAM_CUSTOM_TIMES( | |
246 "PasswordManager.AffiliationBackend.SubsequentFetchDelay", delay, | |
247 base::TimeDelta::FromSeconds(1), base::TimeDelta::FromDays(3), 50); | |
248 } | |
249 last_request_time_ = clock_->Now(); | |
250 } | |
251 | |
252 void AffiliationBackend::SetThrottlerForTesting( | 231 void AffiliationBackend::SetThrottlerForTesting( |
253 scoped_ptr<AffiliationFetchThrottler> throttler) { | 232 scoped_ptr<AffiliationFetchThrottler> throttler) { |
254 throttler_ = throttler.Pass(); | 233 throttler_ = throttler.Pass(); |
255 } | 234 } |
256 | 235 |
257 } // namespace password_manager | 236 } // namespace password_manager |
OLD | NEW |