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/credential_manager_pending_re quest_task.h" | 5 #include "components/password_manager/core/browser/credential_manager_pending_re quest_task.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <map> | 9 #include <map> |
10 #include <utility> | 10 #include <utility> |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 size_before = forms->size(); | 106 size_before = forms->size(); |
107 FilterDuplicates(forms); | 107 FilterDuplicates(forms); |
108 *has_duplicates = (size_before != forms->size()); | 108 *has_duplicates = (size_before != forms->size()); |
109 } | 109 } |
110 | 110 |
111 } // namespace | 111 } // namespace |
112 | 112 |
113 CredentialManagerPendingRequestTask::CredentialManagerPendingRequestTask( | 113 CredentialManagerPendingRequestTask::CredentialManagerPendingRequestTask( |
114 CredentialManagerPendingRequestTaskDelegate* delegate, | 114 CredentialManagerPendingRequestTaskDelegate* delegate, |
115 const SendCredentialCallback& callback, | 115 const SendCredentialCallback& callback, |
116 bool request_zero_click_only, | 116 CredentialMediationRequirement mediation, |
117 bool include_passwords, | 117 bool include_passwords, |
118 const std::vector<GURL>& request_federations) | 118 const std::vector<GURL>& request_federations) |
119 : delegate_(delegate), | 119 : delegate_(delegate), |
120 send_callback_(callback), | 120 send_callback_(callback), |
121 zero_click_only_(request_zero_click_only), | 121 mediation_(mediation), |
122 origin_(delegate_->GetOrigin()), | 122 origin_(delegate_->GetOrigin()), |
123 include_passwords_(include_passwords) { | 123 include_passwords_(include_passwords) { |
124 CHECK(!delegate_->client()->DidLastPageLoadEncounterSSLErrors()); | 124 CHECK(!delegate_->client()->DidLastPageLoadEncounterSSLErrors()); |
125 for (const GURL& federation : request_federations) | 125 for (const GURL& federation : request_federations) |
126 federations_.insert(url::Origin(federation.GetOrigin()).Serialize()); | 126 federations_.insert(url::Origin(federation.GetOrigin()).Serialize()); |
127 } | 127 } |
128 | 128 |
129 CredentialManagerPendingRequestTask::~CredentialManagerPendingRequestTask() = | 129 CredentialManagerPendingRequestTask::~CredentialManagerPendingRequestTask() = |
130 default; | 130 default; |
131 | 131 |
(...skipping 10 matching lines...) Expand all Loading... | |
142 } | 142 } |
143 | 143 |
144 void CredentialManagerPendingRequestTask::ProcessMigratedForms( | 144 void CredentialManagerPendingRequestTask::ProcessMigratedForms( |
145 std::vector<std::unique_ptr<autofill::PasswordForm>> forms) { | 145 std::vector<std::unique_ptr<autofill::PasswordForm>> forms) { |
146 ProcessForms(std::move(forms)); | 146 ProcessForms(std::move(forms)); |
147 } | 147 } |
148 | 148 |
149 void CredentialManagerPendingRequestTask::ProcessForms( | 149 void CredentialManagerPendingRequestTask::ProcessForms( |
150 std::vector<std::unique_ptr<autofill::PasswordForm>> results) { | 150 std::vector<std::unique_ptr<autofill::PasswordForm>> results) { |
151 using metrics_util::LogCredentialManagerGetResult; | 151 using metrics_util::LogCredentialManagerGetResult; |
152 metrics_util::CredentialManagerGetMediation mediation_status = | |
153 zero_click_only_ ? metrics_util::CREDENTIAL_MANAGER_GET_UNMEDIATED | |
154 : metrics_util::CREDENTIAL_MANAGER_GET_MEDIATED; | |
155 if (delegate_->GetOrigin() != origin_) { | 152 if (delegate_->GetOrigin() != origin_) { |
156 LogCredentialManagerGetResult(metrics_util::CREDENTIAL_MANAGER_GET_NONE, | 153 LogCredentialManagerGetResult(metrics_util::CREDENTIAL_MANAGER_GET_NONE, |
157 mediation_status); | 154 mediation_); |
158 delegate_->SendCredential(send_callback_, CredentialInfo()); | 155 delegate_->SendCredential(send_callback_, CredentialInfo()); |
159 return; | 156 return; |
160 } | 157 } |
161 | 158 |
162 std::vector<std::unique_ptr<autofill::PasswordForm>> local_results; | 159 std::vector<std::unique_ptr<autofill::PasswordForm>> local_results; |
163 std::vector<std::unique_ptr<autofill::PasswordForm>> psl_results; | 160 std::vector<std::unique_ptr<autofill::PasswordForm>> psl_results; |
164 for (auto& form : results) { | 161 for (auto& form : results) { |
165 // Ensure that the form we're looking at matches the password and | 162 // Ensure that the form we're looking at matches the password and |
166 // federation filters provided. | 163 // federation filters provided. |
167 if (!((form->federation_origin.unique() && include_passwords_) || | 164 if (!((form->federation_origin.unique() && include_passwords_) || |
(...skipping 13 matching lines...) Expand all Loading... | |
181 psl_results.push_back(std::move(form)); | 178 psl_results.push_back(std::move(form)); |
182 } | 179 } |
183 } | 180 } |
184 | 181 |
185 bool has_empty_username = false; | 182 bool has_empty_username = false; |
186 bool has_duplicates = false; | 183 bool has_duplicates = false; |
187 FilterDuplicatesAndEmptyUsername(&local_results, &has_empty_username, | 184 FilterDuplicatesAndEmptyUsername(&local_results, &has_empty_username, |
188 &has_duplicates); | 185 &has_duplicates); |
189 | 186 |
190 // We only perform zero-click sign-in when the result is completely | 187 // We only perform zero-click sign-in when the result is completely |
191 // unambigious. If there is one and only one entry, and zero-click is | 188 // unambigious and zero-click sign-in is not forbidden via the mediation |
189 // requirement. If there is one and only one entry, and zero-click is | |
192 // enabled for that entry, return it. | 190 // enabled for that entry, return it. |
193 // | 191 // |
194 // Moreover, we only return such a credential if the user has opted-in via the | 192 // Moreover, we only return such a credential if the user has opted-in via the |
195 // first-run experience. | 193 // first-run experience. |
196 const bool can_use_autosignin = | 194 const bool can_use_autosignin = |
197 local_results.size() == 1u && delegate_->IsZeroClickAllowed(); | 195 local_results.size() == 1u && delegate_->IsZeroClickAllowed() && |
vasilii
2017/05/18 12:34:03
I think the class should not ask the delegate unne
jdoerrie
2017/05/18 14:57:24
Done.
| |
196 mediation_ != CredentialMediationRequirement::REQUIRED; | |
198 if (can_use_autosignin && !local_results[0]->skip_zero_click && | 197 if (can_use_autosignin && !local_results[0]->skip_zero_click && |
199 !password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience( | 198 !password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience( |
200 delegate_->client()->GetPrefs())) { | 199 delegate_->client()->GetPrefs())) { |
201 CredentialInfo info(*local_results[0], | 200 CredentialInfo info(*local_results[0], |
202 local_results[0]->federation_origin.unique() | 201 local_results[0]->federation_origin.unique() |
203 ? CredentialType::CREDENTIAL_TYPE_PASSWORD | 202 ? CredentialType::CREDENTIAL_TYPE_PASSWORD |
204 : CredentialType::CREDENTIAL_TYPE_FEDERATED); | 203 : CredentialType::CREDENTIAL_TYPE_FEDERATED); |
205 delegate_->client()->NotifyUserAutoSignin(std::move(local_results), | 204 delegate_->client()->NotifyUserAutoSignin(std::move(local_results), |
206 origin_); | 205 origin_); |
207 base::RecordAction(base::UserMetricsAction("CredentialManager_Autosignin")); | 206 base::RecordAction(base::UserMetricsAction("CredentialManager_Autosignin")); |
208 LogCredentialManagerGetResult( | 207 LogCredentialManagerGetResult( |
209 metrics_util::CREDENTIAL_MANAGER_GET_AUTOSIGNIN, mediation_status); | 208 metrics_util::CREDENTIAL_MANAGER_GET_AUTOSIGNIN, mediation_); |
210 delegate_->SendCredential(send_callback_, info); | 209 delegate_->SendCredential(send_callback_, info); |
211 return; | 210 return; |
212 } | 211 } |
213 | 212 |
214 if (zero_click_only_) { | 213 if (mediation_ == CredentialMediationRequirement::SILENT) { |
215 metrics_util::CredentialManagerGetResult get_result; | 214 metrics_util::CredentialManagerGetResult get_result; |
216 if (local_results.empty()) | 215 if (local_results.empty()) |
217 get_result = metrics_util::CREDENTIAL_MANAGER_GET_NONE_EMPTY_STORE; | 216 get_result = metrics_util::CREDENTIAL_MANAGER_GET_NONE_EMPTY_STORE; |
218 else if (!can_use_autosignin) | 217 else if (!can_use_autosignin) |
219 get_result = metrics_util::CREDENTIAL_MANAGER_GET_NONE_MANY_CREDENTIALS; | 218 get_result = metrics_util::CREDENTIAL_MANAGER_GET_NONE_MANY_CREDENTIALS; |
220 else if (local_results[0]->skip_zero_click) | 219 else if (local_results[0]->skip_zero_click) |
221 get_result = metrics_util::CREDENTIAL_MANAGER_GET_NONE_SIGNED_OUT; | 220 get_result = metrics_util::CREDENTIAL_MANAGER_GET_NONE_SIGNED_OUT; |
222 else | 221 else |
223 get_result = metrics_util::CREDENTIAL_MANAGER_GET_NONE_FIRST_RUN; | 222 get_result = metrics_util::CREDENTIAL_MANAGER_GET_NONE_FIRST_RUN; |
224 | 223 |
225 if (can_use_autosignin) { | 224 if (can_use_autosignin) { |
226 // The user had credentials, but either chose not to share them with the | 225 // The user had credentials, but either chose not to share them with the |
227 // site, or was prevented from doing so by lack of zero-click (or the | 226 // site, or was prevented from doing so by lack of zero-click (or the |
228 // first-run experience). So, notify the client that we could potentially | 227 // first-run experience). So, notify the client that we could potentially |
229 // have used zero-click. | 228 // have used zero-click. |
230 delegate_->client()->NotifyUserCouldBeAutoSignedIn( | 229 delegate_->client()->NotifyUserCouldBeAutoSignedIn( |
231 std::move(local_results[0])); | 230 std::move(local_results[0])); |
232 } | 231 } |
233 | 232 |
234 LogCredentialManagerGetResult(get_result, mediation_status); | 233 LogCredentialManagerGetResult(get_result, mediation_); |
235 delegate_->SendCredential(send_callback_, CredentialInfo()); | 234 delegate_->SendCredential(send_callback_, CredentialInfo()); |
236 return; | 235 return; |
237 } | 236 } |
238 | 237 |
239 // Time to show the account chooser. If |local_results| is empty then it | 238 // Time to show the account chooser. If |local_results| is empty then it |
240 // should list the PSL matches. | 239 // should list the PSL matches. |
241 if (local_results.empty()) { | 240 if (local_results.empty()) { |
242 local_results = std::move(psl_results); | 241 local_results = std::move(psl_results); |
243 FilterDuplicatesAndEmptyUsername(&local_results, &has_empty_username, | 242 FilterDuplicatesAndEmptyUsername(&local_results, &has_empty_username, |
244 &has_duplicates); | 243 &has_duplicates); |
245 } | 244 } |
246 | 245 |
247 if (local_results.empty()) { | 246 if (local_results.empty()) { |
248 LogCredentialManagerGetResult( | 247 LogCredentialManagerGetResult( |
249 metrics_util::CREDENTIAL_MANAGER_GET_NONE_EMPTY_STORE, | 248 metrics_util::CREDENTIAL_MANAGER_GET_NONE_EMPTY_STORE, mediation_); |
250 mediation_status); | |
251 delegate_->SendCredential(send_callback_, CredentialInfo()); | 249 delegate_->SendCredential(send_callback_, CredentialInfo()); |
252 return; | 250 return; |
253 } | 251 } |
254 | 252 |
255 ReportAccountChooserUsabilityMetrics(local_results, has_duplicates, | 253 ReportAccountChooserUsabilityMetrics(local_results, has_duplicates, |
256 has_empty_username); | 254 has_empty_username); |
257 if (!delegate_->client()->PromptUserToChooseCredentials( | 255 if (!delegate_->client()->PromptUserToChooseCredentials( |
258 std::move(local_results), origin_, | 256 std::move(local_results), origin_, |
259 base::Bind( | 257 base::Bind( |
260 &CredentialManagerPendingRequestTaskDelegate::SendPasswordForm, | 258 &CredentialManagerPendingRequestTaskDelegate::SendPasswordForm, |
261 base::Unretained(delegate_), send_callback_))) { | 259 base::Unretained(delegate_), send_callback_))) { |
262 LogCredentialManagerGetResult(metrics_util::CREDENTIAL_MANAGER_GET_NONE, | 260 LogCredentialManagerGetResult(metrics_util::CREDENTIAL_MANAGER_GET_NONE, |
263 mediation_status); | 261 mediation_); |
264 delegate_->SendCredential(send_callback_, CredentialInfo()); | 262 delegate_->SendCredential(send_callback_, CredentialInfo()); |
265 } | 263 } |
266 } | 264 } |
267 | 265 |
268 } // namespace password_manager | 266 } // namespace password_manager |
OLD | NEW |