OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "components/password_manager/core/browser/affiliation_service.h" |
| 6 |
| 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/memory/ptr_util.h" |
| 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "base/time/default_clock.h" |
| 15 #include "base/time/default_tick_clock.h" |
| 16 #include "components/password_manager/core/browser/affiliation_backend.h" |
| 17 #include "net/url_request/url_request_context_getter.h" |
| 18 |
| 19 namespace password_manager { |
| 20 |
| 21 AffiliationService::AffiliationService( |
| 22 scoped_refptr<base::SingleThreadTaskRunner> backend_task_runner) |
| 23 : backend_(nullptr), |
| 24 backend_task_runner_(backend_task_runner), |
| 25 weak_ptr_factory_(this) { |
| 26 } |
| 27 |
| 28 AffiliationService::~AffiliationService() { |
| 29 DCHECK(thread_checker_.CalledOnValidThread()); |
| 30 if (backend_) { |
| 31 backend_task_runner_->DeleteSoon(FROM_HERE, backend_); |
| 32 backend_ = nullptr; |
| 33 } |
| 34 } |
| 35 |
| 36 void AffiliationService::Initialize( |
| 37 net::URLRequestContextGetter* request_context_getter, |
| 38 const base::FilePath& db_path) { |
| 39 DCHECK(thread_checker_.CalledOnValidThread()); |
| 40 DCHECK(!backend_); |
| 41 backend_ = |
| 42 new AffiliationBackend(request_context_getter, backend_task_runner_, |
| 43 base::WrapUnique(new base::DefaultClock), |
| 44 base::WrapUnique(new base::DefaultTickClock)); |
| 45 |
| 46 std::unique_ptr<base::TickClock> tick_clock(new base::DefaultTickClock); |
| 47 backend_task_runner_->PostTask( |
| 48 FROM_HERE, base::Bind(&AffiliationBackend::Initialize, |
| 49 base::Unretained(backend_), db_path)); |
| 50 } |
| 51 |
| 52 void AffiliationService::GetAffiliations( |
| 53 const FacetURI& facet_uri, |
| 54 StrategyOnCacheMiss cache_miss_strategy, |
| 55 const ResultCallback& result_callback) { |
| 56 DCHECK(thread_checker_.CalledOnValidThread()); |
| 57 DCHECK(backend_); |
| 58 backend_task_runner_->PostTask( |
| 59 FROM_HERE, |
| 60 base::Bind(&AffiliationBackend::GetAffiliations, |
| 61 base::Unretained(backend_), facet_uri, cache_miss_strategy, |
| 62 result_callback, base::ThreadTaskRunnerHandle::Get())); |
| 63 } |
| 64 |
| 65 void AffiliationService::Prefetch(const FacetURI& facet_uri, |
| 66 const base::Time& keep_fresh_until) { |
| 67 DCHECK(thread_checker_.CalledOnValidThread()); |
| 68 DCHECK(backend_); |
| 69 backend_task_runner_->PostTask( |
| 70 FROM_HERE, |
| 71 base::Bind(&AffiliationBackend::Prefetch, base::Unretained(backend_), |
| 72 facet_uri, keep_fresh_until)); |
| 73 } |
| 74 |
| 75 void AffiliationService::CancelPrefetch(const FacetURI& facet_uri, |
| 76 const base::Time& keep_fresh_until) { |
| 77 DCHECK(thread_checker_.CalledOnValidThread()); |
| 78 DCHECK(backend_); |
| 79 backend_task_runner_->PostTask( |
| 80 FROM_HERE, |
| 81 base::Bind(&AffiliationBackend::CancelPrefetch, |
| 82 base::Unretained(backend_), facet_uri, keep_fresh_until)); |
| 83 } |
| 84 |
| 85 void AffiliationService::TrimCache() { |
| 86 DCHECK(thread_checker_.CalledOnValidThread()); |
| 87 DCHECK(backend_); |
| 88 backend_task_runner_->PostTask( |
| 89 FROM_HERE, |
| 90 base::Bind(&AffiliationBackend::TrimCache, base::Unretained(backend_))); |
| 91 } |
| 92 |
| 93 void AffiliationService::TrimCacheForFacet(const FacetURI& facet_uri) { |
| 94 DCHECK(thread_checker_.CalledOnValidThread()); |
| 95 DCHECK(backend_); |
| 96 backend_task_runner_->PostTask( |
| 97 FROM_HERE, base::Bind(&AffiliationBackend::TrimCacheForFacet, |
| 98 base::Unretained(backend_), facet_uri)); |
| 99 } |
| 100 |
| 101 // static |
| 102 void AffiliationService::DeleteCache( |
| 103 const base::FilePath& db_path, |
| 104 base::SingleThreadTaskRunner* backend_task_runner) { |
| 105 backend_task_runner->PostTask( |
| 106 FROM_HERE, base::Bind(&AffiliationBackend::DeleteCache, db_path)); |
| 107 } |
| 108 |
| 109 } // namespace password_manager |
OLD | NEW |