Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(420)

Side by Side Diff: components/password_manager/core/browser/affiliated_match_helper.cc

Issue 2657013002: Introduce ThreadTaskRunnerHandle::OverrideForTesting and TestMockTimeTaskRunner::ScopedContext. (Closed)
Patch Set: fix RecentTabHelperTest crash? Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/affiliated_match_helper.h" 5 #include "components/password_manager/core/browser/affiliated_match_helper.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/barrier_closure.h" 9 #include "base/barrier_closure.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 15 matching lines...) Expand all
26 if (form.scheme != autofill::PasswordForm::SCHEME_HTML) 26 if (form.scheme != autofill::PasswordForm::SCHEME_HTML)
27 return false; 27 return false;
28 28
29 *facet_uri = FacetURI::FromPotentiallyInvalidSpec(form.signon_realm); 29 *facet_uri = FacetURI::FromPotentiallyInvalidSpec(form.signon_realm);
30 return facet_uri->IsValidAndroidFacetURI(); 30 return facet_uri->IsValidAndroidFacetURI();
31 } 31 }
32 32
33 } // namespace 33 } // namespace
34 34
35 // static 35 // static
36 const int64_t AffiliatedMatchHelper::kInitializationDelayOnStartupInSeconds; 36 constexpr base::TimeDelta AffiliatedMatchHelper::kInitializationDelayOnStartup;
37 37
38 AffiliatedMatchHelper::AffiliatedMatchHelper( 38 AffiliatedMatchHelper::AffiliatedMatchHelper(
39 PasswordStore* password_store, 39 PasswordStore* password_store,
40 std::unique_ptr<AffiliationService> affiliation_service) 40 std::unique_ptr<AffiliationService> affiliation_service)
41 : password_store_(password_store), 41 : password_store_(password_store),
42 task_runner_for_waiting_(base::ThreadTaskRunnerHandle::Get()),
43 affiliation_service_(std::move(affiliation_service)), 42 affiliation_service_(std::move(affiliation_service)),
44 weak_ptr_factory_(this) {} 43 weak_ptr_factory_(this) {}
45 44
46 AffiliatedMatchHelper::~AffiliatedMatchHelper() { 45 AffiliatedMatchHelper::~AffiliatedMatchHelper() {
47 if (password_store_) 46 if (password_store_)
48 password_store_->RemoveObserver(this); 47 password_store_->RemoveObserver(this);
49 } 48 }
50 49
51 void AffiliatedMatchHelper::Initialize() { 50 void AffiliatedMatchHelper::Initialize() {
52 DCHECK(password_store_); 51 DCHECK(password_store_);
53 DCHECK(affiliation_service_); 52 DCHECK(affiliation_service_);
54 task_runner_for_waiting_->PostDelayedTask( 53 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
55 FROM_HERE, base::Bind(&AffiliatedMatchHelper::DoDeferredInitialization, 54 FROM_HERE,
56 weak_ptr_factory_.GetWeakPtr()), 55 base::Bind(&AffiliatedMatchHelper::DoDeferredInitialization,
57 base::TimeDelta::FromSeconds(kInitializationDelayOnStartupInSeconds)); 56 weak_ptr_factory_.GetWeakPtr()),
57 kInitializationDelayOnStartup);
58 } 58 }
59 59
60 void AffiliatedMatchHelper::GetAffiliatedAndroidRealms( 60 void AffiliatedMatchHelper::GetAffiliatedAndroidRealms(
61 const PasswordStore::FormDigest& observed_form, 61 const PasswordStore::FormDigest& observed_form,
62 const AffiliatedRealmsCallback& result_callback) { 62 const AffiliatedRealmsCallback& result_callback) {
63 if (IsValidWebCredential(observed_form)) { 63 if (IsValidWebCredential(observed_form)) {
64 FacetURI facet_uri( 64 FacetURI facet_uri(
65 FacetURI::FromPotentiallyInvalidSpec(observed_form.signon_realm)); 65 FacetURI::FromPotentiallyInvalidSpec(observed_form.signon_realm));
66 affiliation_service_->GetAffiliations( 66 affiliation_service_->GetAffiliations(
67 facet_uri, AffiliationService::StrategyOnCacheMiss::FAIL, 67 facet_uri, AffiliationService::StrategyOnCacheMiss::FAIL,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 137 }
138 138
139 // static 139 // static
140 bool AffiliatedMatchHelper::IsValidWebCredential( 140 bool AffiliatedMatchHelper::IsValidWebCredential(
141 const PasswordStore::FormDigest& form) { 141 const PasswordStore::FormDigest& form) {
142 FacetURI facet_uri(FacetURI::FromPotentiallyInvalidSpec(form.signon_realm)); 142 FacetURI facet_uri(FacetURI::FromPotentiallyInvalidSpec(form.signon_realm));
143 return form.scheme == autofill::PasswordForm::SCHEME_HTML && 143 return form.scheme == autofill::PasswordForm::SCHEME_HTML &&
144 facet_uri.IsValidWebFacetURI(); 144 facet_uri.IsValidWebFacetURI();
145 } 145 }
146 146
147 void AffiliatedMatchHelper::SetTaskRunnerUsedForWaitingForTesting(
148 const scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
149 task_runner_for_waiting_ = task_runner;
150 }
151
152 void AffiliatedMatchHelper::DoDeferredInitialization() { 147 void AffiliatedMatchHelper::DoDeferredInitialization() {
153 // Must start observing for changes at the same time as when the snapshot is 148 // Must start observing for changes at the same time as when the snapshot is
154 // taken to avoid inconsistencies due to any changes taking place in-between. 149 // taken to avoid inconsistencies due to any changes taking place in-between.
155 password_store_->AddObserver(this); 150 password_store_->AddObserver(this);
156 password_store_->GetAutofillableLogins(this); 151 password_store_->GetAutofillableLogins(this);
157 password_store_->GetBlacklistLogins(this); 152 password_store_->GetBlacklistLogins(this);
158 } 153 }
159 154
160 void AffiliatedMatchHelper::CompleteGetAffiliatedAndroidRealms( 155 void AffiliatedMatchHelper::CompleteGetAffiliatedAndroidRealms(
161 const FacetURI& original_facet_uri, 156 const FacetURI& original_facet_uri,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 void AffiliatedMatchHelper::OnGetPasswordStoreResults( 214 void AffiliatedMatchHelper::OnGetPasswordStoreResults(
220 std::vector<std::unique_ptr<autofill::PasswordForm>> results) { 215 std::vector<std::unique_ptr<autofill::PasswordForm>> results) {
221 for (const auto& form : results) { 216 for (const auto& form : results) {
222 FacetURI facet_uri; 217 FacetURI facet_uri;
223 if (IsAndroidApplicationCredential(*form, &facet_uri)) 218 if (IsAndroidApplicationCredential(*form, &facet_uri))
224 affiliation_service_->Prefetch(facet_uri, base::Time::Max()); 219 affiliation_service_->Prefetch(facet_uri, base::Time::Max());
225 } 220 }
226 } 221 }
227 222
228 } // namespace password_manager 223 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698