Chromium Code Reviews| 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 requested_facet_uris.push_back(facet_manager_pair.first); | 215 requested_facet_uris.push_back(facet_manager_pair.first); |
| 214 } | 216 } |
| 215 | 217 |
| 216 // In case a request is no longer needed, return false to indicate this. | 218 // In case a request is no longer needed, return false to indicate this. |
| 217 if (requested_facet_uris.empty()) | 219 if (requested_facet_uris.empty()) |
| 218 return false; | 220 return false; |
| 219 | 221 |
| 220 fetcher_.reset(AffiliationFetcher::Create(request_context_getter_.get(), | 222 fetcher_.reset(AffiliationFetcher::Create(request_context_getter_.get(), |
| 221 requested_facet_uris, this)); | 223 requested_facet_uris, this)); |
| 222 fetcher_->StartRequest(); | 224 fetcher_->StartRequest(); |
| 225 ReportStatistics(requested_facet_uris.size()); | |
| 223 return true; | 226 return true; |
| 224 } | 227 } |
| 225 | 228 |
| 229 void AffiliationBackend::ReportStatistics(size_t requested_facet_uri_count) { | |
| 230 UMA_HISTOGRAM_COUNTS_100("AffiliationService.FetchSize", | |
| 231 requested_facet_uri_count); | |
| 232 | |
| 233 if (last_request_time_.is_null()) { | |
| 234 base::TimeDelta delay = clock_->Now() - construction_time_; | |
| 235 UMA_HISTOGRAM_CUSTOM_TIMES("AffiliationService.FirstFetchDelay", delay, | |
| 236 base::TimeDelta::FromMicroseconds(1), | |
| 237 base::TimeDelta::FromDays(7), 100); | |
|
Ilya Sherman
2015/04/21 00:38:05
Hmm, do you really need such a large range?
engedy
2015/04/21 18:29:07
I need quite a large range, but on second though,
| |
| 238 } else { | |
| 239 base::TimeDelta delay = clock_->Now() - construction_time_; | |
| 240 UMA_HISTOGRAM_CUSTOM_TIMES("AffiliationService.SubsequentFetchDelay", delay, | |
| 241 base::TimeDelta::FromMicroseconds(1), | |
| 242 base::TimeDelta::FromDays(7), 100); | |
| 243 } | |
| 244 last_request_time_ = clock_->Now(); | |
| 245 } | |
| 246 | |
| 226 void AffiliationBackend::SetThrottlerForTesting( | 247 void AffiliationBackend::SetThrottlerForTesting( |
| 227 scoped_ptr<AffiliationFetchThrottler> throttler) { | 248 scoped_ptr<AffiliationFetchThrottler> throttler) { |
| 228 throttler_ = throttler.Pass(); | 249 throttler_ = throttler.Pass(); |
| 229 } | 250 } |
| 230 | 251 |
| 231 } // namespace password_manager | 252 } // namespace password_manager |
| OLD | NEW |