| 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" | 11 #include "base/metrics/field_trial.h" |
| 13 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
| 14 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 15 #include "components/autofill/core/common/password_form.h" | 14 #include "components/autofill/core/common/password_form.h" |
| 16 #include "components/password_manager/core/common/password_manager_switches.h" | 15 #include "components/password_manager/core/common/password_manager_features.h" |
| 17 #include "components/url_formatter/elide_url.h" | 16 #include "components/url_formatter/elide_url.h" |
| 18 #include "components/variations/variations_associated_data.h" | 17 #include "components/variations/variations_associated_data.h" |
| 19 #include "net/base/escape.h" | 18 #include "net/base/escape.h" |
| 20 #include "url/third_party/mozilla/url_parse.h" | 19 #include "url/third_party/mozilla/url_parse.h" |
| 21 #include "url/url_canon_stdstring.h" | 20 #include "url/url_canon_stdstring.h" |
| 22 | 21 |
| 23 namespace password_manager { | 22 namespace password_manager { |
| 24 | 23 |
| 25 namespace { | 24 namespace { |
| 26 | 25 |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 if (a.size() != b.size()) | 283 if (a.size() != b.size()) |
| 285 return false; | 284 return false; |
| 286 | 285 |
| 287 std::vector<FacetURI> a_sorted(a.begin(), a.end()); | 286 std::vector<FacetURI> a_sorted(a.begin(), a.end()); |
| 288 std::vector<FacetURI> b_sorted(b.begin(), b.end()); | 287 std::vector<FacetURI> b_sorted(b.begin(), b.end()); |
| 289 std::sort(a_sorted.begin(), a_sorted.end()); | 288 std::sort(a_sorted.begin(), a_sorted.end()); |
| 290 std::sort(b_sorted.begin(), b_sorted.end()); | 289 std::sort(b_sorted.begin(), b_sorted.end()); |
| 291 return std::equal(a_sorted.begin(), a_sorted.end(), b_sorted.begin()); | 290 return std::equal(a_sorted.begin(), a_sorted.end(), b_sorted.begin()); |
| 292 } | 291 } |
| 293 | 292 |
| 294 bool IsAffiliationBasedMatchingEnabled(const base::CommandLine& command_line) { | 293 bool IsAffiliationBasedMatchingEnabled() { |
| 295 // Note: It is important to always query the field trial state, to ensure that | 294 // Note: It is important to always query the field trial state, to ensure that |
| 296 // UMA reports the correct group. | 295 // UMA reports the correct group. |
| 297 const std::string group_name = | 296 const std::string group_name = |
| 298 base::FieldTrialList::FindFullName(kFieldTrialName); | 297 base::FieldTrialList::FindFullName(kFieldTrialName); |
| 299 | 298 |
| 300 if (command_line.HasSwitch(switches::kDisableAffiliationBasedMatching)) | 299 if (base::FeatureList::IsEnabled(features::kDisableAffiliationBasedMatching)) |
| 301 return false; | 300 return false; |
| 302 if (command_line.HasSwitch(switches::kEnableAffiliationBasedMatching)) | 301 if (base::FeatureList::IsEnabled(features::kEnableAffiliationBasedMatching)) |
| 303 return true; | 302 return true; |
| 304 return !base::StartsWith(group_name, "Disabled", | 303 return !base::StartsWith(group_name, "Disabled", |
| 305 base::CompareCase::INSENSITIVE_ASCII); | 304 base::CompareCase::INSENSITIVE_ASCII); |
| 306 } | 305 } |
| 307 | 306 |
| 308 bool IsPropagatingPasswordChangesToWebCredentialsEnabled( | 307 bool IsPropagatingPasswordChangesToWebCredentialsEnabled() { |
| 309 const base::CommandLine& command_line) { | |
| 310 // Note: It is important to always query the variation param first, which, in | 308 // Note: It is important to always query the variation param first, which, in |
| 311 // turn, queries the field trial state, which ensures that UMA reports the | 309 // turn, queries the field trial state, which ensures that UMA reports the |
| 312 // correct group if it is forced by a command line flag. | 310 // correct group if it is forced by a command line flag. |
| 313 const std::string update_enabled = variations::GetVariationParamValue( | 311 const std::string update_enabled = variations::GetVariationParamValue( |
| 314 kFieldTrialName, "propagate_password_changes_to_web"); | 312 kFieldTrialName, "propagate_password_changes_to_web"); |
| 315 | 313 |
| 316 if (command_line.HasSwitch(switches::kDisableAffiliationBasedMatching)) | 314 if (base::FeatureList::IsEnabled(features::kDisableAffiliationBasedMatching)) |
| 317 return false; | 315 return false; |
| 318 if (command_line.HasSwitch(switches::kEnableAffiliationBasedMatching)) | 316 if (base::FeatureList::IsEnabled(features::kEnableAffiliationBasedMatching)) |
| 319 return true; | 317 return true; |
| 320 return !base::LowerCaseEqualsASCII(update_enabled, "disabled"); | 318 return !base::LowerCaseEqualsASCII(update_enabled, "disabled"); |
| 321 } | 319 } |
| 322 | 320 |
| 323 bool IsValidAndroidFacetURI(const std::string& url) { | 321 bool IsValidAndroidFacetURI(const std::string& url) { |
| 324 FacetURI facet = FacetURI::FromPotentiallyInvalidSpec(url); | 322 FacetURI facet = FacetURI::FromPotentiallyInvalidSpec(url); |
| 325 return facet.IsValidAndroidFacetURI(); | 323 return facet.IsValidAndroidFacetURI(); |
| 326 } | 324 } |
| 327 | 325 |
| 328 std::string GetHumanReadableOrigin(const autofill::PasswordForm& password_form, | 326 std::string GetHumanReadableOrigin(const autofill::PasswordForm& password_form, |
| 329 const std::string& languages) { | 327 const std::string& languages) { |
| 330 FacetURI facet_uri = | 328 FacetURI facet_uri = |
| 331 FacetURI::FromPotentiallyInvalidSpec(password_form.signon_realm); | 329 FacetURI::FromPotentiallyInvalidSpec(password_form.signon_realm); |
| 332 if (facet_uri.IsValidAndroidFacetURI()) | 330 if (facet_uri.IsValidAndroidFacetURI()) |
| 333 return GetHumanReadableOriginForAndroidUri(facet_uri); | 331 return GetHumanReadableOriginForAndroidUri(facet_uri); |
| 334 | 332 |
| 335 return base::UTF16ToUTF8(url_formatter::FormatUrlForSecurityDisplay( | 333 return base::UTF16ToUTF8(url_formatter::FormatUrlForSecurityDisplay( |
| 336 password_form.origin, languages)); | 334 password_form.origin, languages)); |
| 337 } | 335 } |
| 338 | 336 |
| 339 std::string GetHumanReadableOriginForAndroidUri(const FacetURI facet_uri) { | 337 std::string GetHumanReadableOriginForAndroidUri(const FacetURI facet_uri) { |
| 340 DCHECK(facet_uri.IsValidAndroidFacetURI()); | 338 DCHECK(facet_uri.IsValidAndroidFacetURI()); |
| 341 return facet_uri.scheme() + "://" + facet_uri.android_package_name(); | 339 return facet_uri.scheme() + "://" + facet_uri.android_package_name(); |
| 342 } | 340 } |
| 343 | 341 |
| 344 } // namespace password_manager | 342 } // namespace password_manager |
| OLD | NEW |