cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / components / password_manager / core / browser / affiliation_service.cc
blob3d55d5f6abec58dc116553cab2afb2e9b5f5e289
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
3 // found in the LICENSE file.
5 #include "components/password_manager/core/browser/affiliation_service.h"
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/files/file_path.h"
10 #include "base/location.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/thread_task_runner_handle.h"
13 #include "base/time/default_clock.h"
14 #include "base/time/default_tick_clock.h"
15 #include "components/password_manager/core/browser/affiliation_backend.h"
16 #include "net/url_request/url_request_context_getter.h"
18 namespace password_manager {
20 AffiliationService::AffiliationService(
21 scoped_refptr<base::SingleThreadTaskRunner> backend_task_runner)
22 : backend_(nullptr),
23 backend_task_runner_(backend_task_runner),
24 weak_ptr_factory_(this) {
27 AffiliationService::~AffiliationService() {
28 DCHECK(thread_checker_.CalledOnValidThread());
29 if (backend_) {
30 backend_task_runner_->DeleteSoon(FROM_HERE, backend_);
31 backend_ = nullptr;
35 void AffiliationService::Initialize(
36 net::URLRequestContextGetter* request_context_getter,
37 const base::FilePath& db_path) {
38 DCHECK(thread_checker_.CalledOnValidThread());
39 DCHECK(!backend_);
40 backend_ =
41 new AffiliationBackend(request_context_getter, backend_task_runner_,
42 make_scoped_ptr(new base::DefaultClock),
43 make_scoped_ptr(new base::DefaultTickClock));
45 scoped_ptr<base::TickClock> tick_clock(new base::DefaultTickClock);
46 backend_task_runner_->PostTask(
47 FROM_HERE, base::Bind(&AffiliationBackend::Initialize,
48 base::Unretained(backend_), db_path));
51 void AffiliationService::GetAffiliations(
52 const FacetURI& facet_uri,
53 StrategyOnCacheMiss cache_miss_strategy,
54 const ResultCallback& result_callback) {
55 DCHECK(thread_checker_.CalledOnValidThread());
56 DCHECK(backend_);
57 backend_task_runner_->PostTask(
58 FROM_HERE,
59 base::Bind(&AffiliationBackend::GetAffiliations,
60 base::Unretained(backend_), facet_uri, cache_miss_strategy,
61 result_callback, base::ThreadTaskRunnerHandle::Get()));
64 void AffiliationService::Prefetch(const FacetURI& facet_uri,
65 const base::Time& keep_fresh_until) {
66 DCHECK(thread_checker_.CalledOnValidThread());
67 DCHECK(backend_);
68 backend_task_runner_->PostTask(
69 FROM_HERE,
70 base::Bind(&AffiliationBackend::Prefetch, base::Unretained(backend_),
71 facet_uri, keep_fresh_until));
74 void AffiliationService::CancelPrefetch(const FacetURI& facet_uri,
75 const base::Time& keep_fresh_until) {
76 DCHECK(thread_checker_.CalledOnValidThread());
77 DCHECK(backend_);
78 backend_task_runner_->PostTask(
79 FROM_HERE,
80 base::Bind(&AffiliationBackend::CancelPrefetch,
81 base::Unretained(backend_), facet_uri, keep_fresh_until));
84 void AffiliationService::TrimCache() {
85 DCHECK(thread_checker_.CalledOnValidThread());
86 DCHECK(backend_);
87 backend_task_runner_->PostTask(
88 FROM_HERE,
89 base::Bind(&AffiliationBackend::TrimCache, base::Unretained(backend_)));
92 void AffiliationService::TrimCacheForFacet(const FacetURI& facet_uri) {
93 DCHECK(thread_checker_.CalledOnValidThread());
94 DCHECK(backend_);
95 backend_task_runner_->PostTask(
96 FROM_HERE, base::Bind(&AffiliationBackend::TrimCacheForFacet,
97 base::Unretained(backend_), facet_uri));
100 // static
101 void AffiliationService::DeleteCache(
102 const base::FilePath& db_path,
103 base::SingleThreadTaskRunner* backend_task_runner) {
104 backend_task_runner->PostTask(
105 FROM_HERE, base::Bind(&AffiliationBackend::DeleteCache, db_path));
108 } // namespace password_manager