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" |
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
" |
18 #include "components/password_manager/core/browser/affiliation_fetcher.h" | 19 #include "components/password_manager/core/browser/affiliation_fetcher.h" |
19 #include "components/password_manager/core/browser/facet_manager.h" | 20 #include "components/password_manager/core/browser/facet_manager.h" |
20 #include "net/url_request/url_request_context_getter.h" | 21 #include "net/url_request/url_request_context_getter.h" |
21 | 22 |
22 namespace password_manager { | 23 namespace password_manager { |
23 | 24 |
24 AffiliationBackend::AffiliationBackend( | 25 AffiliationBackend::AffiliationBackend( |
25 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, | 26 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, |
26 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 27 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
27 scoped_ptr<base::Clock> time_source, | 28 scoped_ptr<base::Clock> time_source, |
28 scoped_ptr<base::TickClock> time_tick_source) | 29 scoped_ptr<base::TickClock> time_tick_source) |
29 : request_context_getter_(request_context_getter), | 30 : request_context_getter_(request_context_getter), |
30 task_runner_(task_runner), | 31 task_runner_(task_runner), |
31 clock_(time_source.Pass()), | 32 clock_(time_source.Pass()), |
32 tick_clock_(time_tick_source.Pass()), | 33 tick_clock_(time_tick_source.Pass()), |
| 34 construction_time_(clock_->Now()), |
33 weak_ptr_factory_(this) { | 35 weak_ptr_factory_(this) { |
34 DCHECK_LT(base::Time(), clock_->Now()); | 36 DCHECK_LT(base::Time(), clock_->Now()); |
35 } | 37 } |
36 | 38 |
37 AffiliationBackend::~AffiliationBackend() { | 39 AffiliationBackend::~AffiliationBackend() { |
38 } | 40 } |
39 | 41 |
40 void AffiliationBackend::Initialize(const base::FilePath& db_path) { | 42 void AffiliationBackend::Initialize(const base::FilePath& db_path) { |
41 thread_checker_.reset(new base::ThreadChecker); | 43 thread_checker_.reset(new base::ThreadChecker); |
42 | 44 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 requested_facet_uris.push_back(facet_manager_pair.first); | 220 requested_facet_uris.push_back(facet_manager_pair.first); |
219 } | 221 } |
220 | 222 |
221 // In case a request is no longer needed, return false to indicate this. | 223 // In case a request is no longer needed, return false to indicate this. |
222 if (requested_facet_uris.empty()) | 224 if (requested_facet_uris.empty()) |
223 return false; | 225 return false; |
224 | 226 |
225 fetcher_.reset(AffiliationFetcher::Create(request_context_getter_.get(), | 227 fetcher_.reset(AffiliationFetcher::Create(request_context_getter_.get(), |
226 requested_facet_uris, this)); | 228 requested_facet_uris, this)); |
227 fetcher_->StartRequest(); | 229 fetcher_->StartRequest(); |
| 230 ReportStatistics(requested_facet_uris.size()); |
228 return true; | 231 return true; |
229 } | 232 } |
230 | 233 |
| 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 |
231 void AffiliationBackend::SetThrottlerForTesting( | 252 void AffiliationBackend::SetThrottlerForTesting( |
232 scoped_ptr<AffiliationFetchThrottler> throttler) { | 253 scoped_ptr<AffiliationFetchThrottler> throttler) { |
233 throttler_ = throttler.Pass(); | 254 throttler_ = throttler.Pass(); |
234 } | 255 } |
235 | 256 |
236 } // namespace password_manager | 257 } // namespace password_manager |
OLD | NEW |