OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_utils.h" | 5 #include "components/password_manager/core/browser/affiliation_utils.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <ostream> | 8 #include <ostream> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
11 #include "base/command_line.h" | |
12 #include "base/metrics/field_trial.h" | |
13 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
14 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
15 #include "components/autofill/core/common/password_form.h" | 13 #include "components/autofill/core/common/password_form.h" |
16 #include "components/password_manager/core/common/password_manager_switches.h" | |
17 #include "components/url_formatter/elide_url.h" | 14 #include "components/url_formatter/elide_url.h" |
18 #include "components/variations/variations_associated_data.h" | 15 #include "components/variations/variations_associated_data.h" |
19 #include "net/base/escape.h" | 16 #include "net/base/escape.h" |
20 #include "url/third_party/mozilla/url_parse.h" | 17 #include "url/third_party/mozilla/url_parse.h" |
21 #include "url/url_canon_stdstring.h" | 18 #include "url/url_canon_stdstring.h" |
22 | 19 |
23 namespace password_manager { | 20 namespace password_manager { |
24 | 21 |
25 namespace { | 22 namespace { |
26 | 23 |
27 // The scheme used for identifying Android applications. | 24 // The scheme used for identifying Android applications. |
28 const char kAndroidAppScheme[] = "android"; | 25 const char kAndroidAppScheme[] = "android"; |
29 | 26 |
30 // The name of the field trial controlling affiliation-based matching. | |
31 const char kFieldTrialName[] = "AffiliationBasedMatching"; | |
32 | |
33 // Returns a StringPiece corresponding to |component| in |uri|, or the empty | 27 // Returns a StringPiece corresponding to |component| in |uri|, or the empty |
34 // string in case there is no such component. | 28 // string in case there is no such component. |
35 base::StringPiece ComponentString(const std::string& uri, | 29 base::StringPiece ComponentString(const std::string& uri, |
36 const url::Component& component) { | 30 const url::Component& component) { |
37 if (!component.is_valid()) | 31 if (!component.is_valid()) |
38 return base::StringPiece(); | 32 return base::StringPiece(); |
39 return base::StringPiece(uri.c_str() + component.begin, component.len); | 33 return base::StringPiece(uri.c_str() + component.begin, component.len); |
40 } | 34 } |
41 | 35 |
42 // Returns true if the passed ASCII |input| string contains nothing else than | 36 // Returns true if the passed ASCII |input| string contains nothing else than |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 if (a.size() != b.size()) | 281 if (a.size() != b.size()) |
288 return false; | 282 return false; |
289 | 283 |
290 std::vector<FacetURI> a_sorted(a.begin(), a.end()); | 284 std::vector<FacetURI> a_sorted(a.begin(), a.end()); |
291 std::vector<FacetURI> b_sorted(b.begin(), b.end()); | 285 std::vector<FacetURI> b_sorted(b.begin(), b.end()); |
292 std::sort(a_sorted.begin(), a_sorted.end()); | 286 std::sort(a_sorted.begin(), a_sorted.end()); |
293 std::sort(b_sorted.begin(), b_sorted.end()); | 287 std::sort(b_sorted.begin(), b_sorted.end()); |
294 return std::equal(a_sorted.begin(), a_sorted.end(), b_sorted.begin()); | 288 return std::equal(a_sorted.begin(), a_sorted.end(), b_sorted.begin()); |
295 } | 289 } |
296 | 290 |
297 bool IsAffiliationBasedMatchingEnabled(const base::CommandLine& command_line) { | |
298 // Note: It is important to always query the field trial state, to ensure that | |
299 // UMA reports the correct group. | |
300 const std::string group_name = | |
301 base::FieldTrialList::FindFullName(kFieldTrialName); | |
302 | |
303 if (command_line.HasSwitch(switches::kDisableAffiliationBasedMatching)) | |
304 return false; | |
305 if (command_line.HasSwitch(switches::kEnableAffiliationBasedMatching)) | |
306 return true; | |
307 return !base::StartsWith(group_name, "Disabled", | |
308 base::CompareCase::INSENSITIVE_ASCII); | |
309 } | |
310 | |
311 bool IsPropagatingPasswordChangesToWebCredentialsEnabled( | |
312 const base::CommandLine& command_line) { | |
313 // Note: It is important to always query the variation param first, which, in | |
314 // turn, queries the field trial state, which ensures that UMA reports the | |
315 // correct group if it is forced by a command line flag. | |
316 const std::string update_enabled = variations::GetVariationParamValue( | |
317 kFieldTrialName, "propagate_password_changes_to_web"); | |
318 | |
319 if (command_line.HasSwitch(switches::kDisableAffiliationBasedMatching)) | |
320 return false; | |
321 if (command_line.HasSwitch(switches::kEnableAffiliationBasedMatching)) | |
322 return true; | |
323 return !base::LowerCaseEqualsASCII(update_enabled, "disabled"); | |
324 } | |
325 | |
326 bool IsValidAndroidFacetURI(const std::string& url) { | 291 bool IsValidAndroidFacetURI(const std::string& url) { |
327 FacetURI facet = FacetURI::FromPotentiallyInvalidSpec(url); | 292 FacetURI facet = FacetURI::FromPotentiallyInvalidSpec(url); |
328 return facet.IsValidAndroidFacetURI(); | 293 return facet.IsValidAndroidFacetURI(); |
329 } | 294 } |
330 | 295 |
331 std::string GetHumanReadableOrigin(const autofill::PasswordForm& password_form, | 296 std::string GetHumanReadableOrigin(const autofill::PasswordForm& password_form, |
332 const std::string& languages) { | 297 const std::string& languages) { |
333 FacetURI facet_uri = | 298 FacetURI facet_uri = |
334 FacetURI::FromPotentiallyInvalidSpec(password_form.signon_realm); | 299 FacetURI::FromPotentiallyInvalidSpec(password_form.signon_realm); |
335 if (facet_uri.IsValidAndroidFacetURI()) | 300 if (facet_uri.IsValidAndroidFacetURI()) |
336 return GetHumanReadableOriginForAndroidUri(facet_uri); | 301 return GetHumanReadableOriginForAndroidUri(facet_uri); |
337 | 302 |
338 return base::UTF16ToUTF8(url_formatter::FormatUrlForSecurityDisplay( | 303 return base::UTF16ToUTF8(url_formatter::FormatUrlForSecurityDisplay( |
339 password_form.origin, languages)); | 304 password_form.origin, languages)); |
340 } | 305 } |
341 | 306 |
342 std::string GetHumanReadableOriginForAndroidUri(const FacetURI facet_uri) { | 307 std::string GetHumanReadableOriginForAndroidUri(const FacetURI facet_uri) { |
343 DCHECK(facet_uri.IsValidAndroidFacetURI()); | 308 DCHECK(facet_uri.IsValidAndroidFacetURI()); |
344 return facet_uri.scheme() + "://" + facet_uri.android_package_name(); | 309 return facet_uri.scheme() + "://" + facet_uri.android_package_name(); |
345 } | 310 } |
346 | 311 |
347 } // namespace password_manager | 312 } // namespace password_manager |
OLD | NEW |