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

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

Issue 1668523002: [Password Manager] Switch password manager code to use the Feature framework. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes to fieldtrial_testing_config_*.json Created 4 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 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" 14 #include "components/password_manager/core/browser/password_manager_util.h"
vabr (Chromium) 2016/02/26 09:43:41 It looks like you can remove this header -- it was
Pritam Nikam 2016/02/26 12:42:23 Done.
17 #include "components/url_formatter/elide_url.h" 15 #include "components/url_formatter/elide_url.h"
18 #include "components/variations/variations_associated_data.h" 16 #include "components/variations/variations_associated_data.h"
19 #include "net/base/escape.h" 17 #include "net/base/escape.h"
20 #include "url/third_party/mozilla/url_parse.h" 18 #include "url/third_party/mozilla/url_parse.h"
21 #include "url/url_canon_stdstring.h" 19 #include "url/url_canon_stdstring.h"
22 20
23 namespace password_manager { 21 namespace password_manager {
24 22
25 namespace { 23 namespace {
26 24
27 // The scheme used for identifying Android applications. 25 // The scheme used for identifying Android applications.
28 const char kAndroidAppScheme[] = "android"; 26 const char kAndroidAppScheme[] = "android";
29 27
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 28 // Returns a StringPiece corresponding to |component| in |uri|, or the empty
34 // string in case there is no such component. 29 // string in case there is no such component.
35 base::StringPiece ComponentString(const std::string& uri, 30 base::StringPiece ComponentString(const std::string& uri,
36 const url::Component& component) { 31 const url::Component& component) {
37 if (!component.is_valid()) 32 if (!component.is_valid())
38 return base::StringPiece(); 33 return base::StringPiece();
39 return base::StringPiece(uri.c_str() + component.begin, component.len); 34 return base::StringPiece(uri.c_str() + component.begin, component.len);
40 } 35 }
41 36
42 // Returns true if the passed ASCII |input| string contains nothing else than 37 // Returns true if the passed ASCII |input| string contains nothing else than
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 if (a.size() != b.size()) 279 if (a.size() != b.size())
285 return false; 280 return false;
286 281
287 std::vector<FacetURI> a_sorted(a.begin(), a.end()); 282 std::vector<FacetURI> a_sorted(a.begin(), a.end());
288 std::vector<FacetURI> b_sorted(b.begin(), b.end()); 283 std::vector<FacetURI> b_sorted(b.begin(), b.end());
289 std::sort(a_sorted.begin(), a_sorted.end()); 284 std::sort(a_sorted.begin(), a_sorted.end());
290 std::sort(b_sorted.begin(), b_sorted.end()); 285 std::sort(b_sorted.begin(), b_sorted.end());
291 return std::equal(a_sorted.begin(), a_sorted.end(), b_sorted.begin()); 286 return std::equal(a_sorted.begin(), a_sorted.end(), b_sorted.begin());
292 } 287 }
293 288
294 bool IsAffiliationBasedMatchingEnabled(const base::CommandLine& command_line) {
295 // Note: It is important to always query the field trial state, to ensure that
296 // UMA reports the correct group.
297 const std::string group_name =
298 base::FieldTrialList::FindFullName(kFieldTrialName);
299
300 if (command_line.HasSwitch(switches::kDisableAffiliationBasedMatching))
301 return false;
302 if (command_line.HasSwitch(switches::kEnableAffiliationBasedMatching))
303 return true;
304 return !base::StartsWith(group_name, "Disabled",
305 base::CompareCase::INSENSITIVE_ASCII);
306 }
307
308 bool IsPropagatingPasswordChangesToWebCredentialsEnabled(
309 const base::CommandLine& command_line) {
310 // 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
312 // correct group if it is forced by a command line flag.
313 const std::string update_enabled = variations::GetVariationParamValue(
314 kFieldTrialName, "propagate_password_changes_to_web");
315
316 if (command_line.HasSwitch(switches::kDisableAffiliationBasedMatching))
317 return false;
318 if (command_line.HasSwitch(switches::kEnableAffiliationBasedMatching))
319 return true;
320 return !base::LowerCaseEqualsASCII(update_enabled, "disabled");
321 }
322
323 bool IsValidAndroidFacetURI(const std::string& url) { 289 bool IsValidAndroidFacetURI(const std::string& url) {
324 FacetURI facet = FacetURI::FromPotentiallyInvalidSpec(url); 290 FacetURI facet = FacetURI::FromPotentiallyInvalidSpec(url);
325 return facet.IsValidAndroidFacetURI(); 291 return facet.IsValidAndroidFacetURI();
326 } 292 }
327 293
328 std::string GetHumanReadableOrigin(const autofill::PasswordForm& password_form, 294 std::string GetHumanReadableOrigin(const autofill::PasswordForm& password_form,
329 const std::string& languages) { 295 const std::string& languages) {
330 FacetURI facet_uri = 296 FacetURI facet_uri =
331 FacetURI::FromPotentiallyInvalidSpec(password_form.signon_realm); 297 FacetURI::FromPotentiallyInvalidSpec(password_form.signon_realm);
332 if (facet_uri.IsValidAndroidFacetURI()) 298 if (facet_uri.IsValidAndroidFacetURI())
333 return GetHumanReadableOriginForAndroidUri(facet_uri); 299 return GetHumanReadableOriginForAndroidUri(facet_uri);
334 300
335 return base::UTF16ToUTF8(url_formatter::FormatUrlForSecurityDisplay( 301 return base::UTF16ToUTF8(url_formatter::FormatUrlForSecurityDisplay(
336 password_form.origin, languages)); 302 password_form.origin, languages));
337 } 303 }
338 304
339 std::string GetHumanReadableOriginForAndroidUri(const FacetURI facet_uri) { 305 std::string GetHumanReadableOriginForAndroidUri(const FacetURI facet_uri) {
340 DCHECK(facet_uri.IsValidAndroidFacetURI()); 306 DCHECK(facet_uri.IsValidAndroidFacetURI());
341 return facet_uri.scheme() + "://" + facet_uri.android_package_name(); 307 return facet_uri.scheme() + "://" + facet_uri.android_package_name();
342 } 308 }
343 309
344 } // namespace password_manager 310 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698