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" | 11 #include "base/command_line.h" |
12 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "components/password_manager/core/common/password_manager_switches.h" | 15 #include "components/password_manager/core/common/password_manager_switches.h" |
16 #include "components/variations/variations_associated_data.h" | |
16 #include "net/base/escape.h" | 17 #include "net/base/escape.h" |
17 #include "url/third_party/mozilla/url_parse.h" | 18 #include "url/third_party/mozilla/url_parse.h" |
18 #include "url/url_canon_stdstring.h" | 19 #include "url/url_canon_stdstring.h" |
19 #include "url/url_util.h" | 20 #include "url/url_util.h" |
20 | 21 |
21 namespace password_manager { | 22 namespace password_manager { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 // The scheme used for identifying Android applications. | 26 // The scheme used for identifying Android applications. |
26 const char kAndroidAppScheme[] = "android"; | 27 const char kAndroidAppScheme[] = "android"; |
27 | 28 |
29 // The name of the field trial controlling affiliation-based matching. | |
30 const char kFieldTrialName[] = "AffiliationBasedMatching"; | |
31 | |
28 // Returns a StringPiece corresponding to |component| in |uri|, or the empty | 32 // Returns a StringPiece corresponding to |component| in |uri|, or the empty |
29 // string in case there is no such component. | 33 // string in case there is no such component. |
30 base::StringPiece ComponentString(const std::string& uri, | 34 base::StringPiece ComponentString(const std::string& uri, |
31 const url::Component& component) { | 35 const url::Component& component) { |
32 if (!component.is_valid()) | 36 if (!component.is_valid()) |
33 return base::StringPiece(); | 37 return base::StringPiece(); |
34 return base::StringPiece(uri.c_str() + component.begin, component.len); | 38 return base::StringPiece(uri.c_str() + component.begin, component.len); |
35 } | 39 } |
36 | 40 |
37 // Returns true if the passed ASCII |input| string contains nothing else than | 41 // Returns true if the passed ASCII |input| string contains nothing else than |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 std::vector<FacetURI> b_sorted(b.begin(), b.end()); | 289 std::vector<FacetURI> b_sorted(b.begin(), b.end()); |
286 std::sort(a_sorted.begin(), a_sorted.end()); | 290 std::sort(a_sorted.begin(), a_sorted.end()); |
287 std::sort(b_sorted.begin(), b_sorted.end()); | 291 std::sort(b_sorted.begin(), b_sorted.end()); |
288 return std::equal(a_sorted.begin(), a_sorted.end(), b_sorted.begin()); | 292 return std::equal(a_sorted.begin(), a_sorted.end(), b_sorted.begin()); |
289 } | 293 } |
290 | 294 |
291 bool IsAffiliationBasedMatchingEnabled(const base::CommandLine& command_line) { | 295 bool IsAffiliationBasedMatchingEnabled(const base::CommandLine& command_line) { |
292 // Note: It is important to always query the field trial state, to ensure that | 296 // Note: It is important to always query the field trial state, to ensure that |
293 // UMA reports the correct group. | 297 // UMA reports the correct group. |
294 const std::string group_name = | 298 const std::string group_name = |
295 base::FieldTrialList::FindFullName("AffiliationBasedMatching"); | 299 base::FieldTrialList::FindFullName(kFieldTrialName); |
296 | 300 |
297 if (command_line.HasSwitch(switches::kDisableAffiliationBasedMatching)) | 301 if (command_line.HasSwitch(switches::kDisableAffiliationBasedMatching)) |
298 return false; | 302 return false; |
299 if (command_line.HasSwitch(switches::kEnableAffiliationBasedMatching)) | 303 if (command_line.HasSwitch(switches::kEnableAffiliationBasedMatching)) |
300 return true; | 304 return true; |
301 return StartsWithASCII(group_name, "Enabled", /*case_sensitive=*/false); | 305 return StartsWithASCII(group_name, "Enabled", /*case_sensitive=*/false); |
302 } | 306 } |
303 | 307 |
308 bool IsPropagatingPasswordChangesToWebCredentialsEnabled( | |
309 const base::CommandLine& command_line) { | |
310 // Note: It is important to always query the field trial state, to ensure that | |
311 // UMA reports the correct group. | |
vasilii
2015/04/20 16:25:19
Can you elaborate?
engedy
2015/04/20 18:31:58
Done.
| |
312 const std::string update_enabled = variations::GetVariationParamValue( | |
313 kFieldTrialName, "propagate_password_changes_to_web"); | |
314 | |
315 if (command_line.HasSwitch(switches::kDisableAffiliationBasedMatching)) | |
316 return false; | |
317 if (command_line.HasSwitch(switches::kEnableAffiliationBasedMatching)) | |
318 return true; | |
319 return LowerCaseEqualsASCII(update_enabled, "enabled"); | |
320 } | |
321 | |
304 bool IsValidAndroidFacetURI(const std::string& url) { | 322 bool IsValidAndroidFacetURI(const std::string& url) { |
305 FacetURI facet = FacetURI::FromPotentiallyInvalidSpec(url); | 323 FacetURI facet = FacetURI::FromPotentiallyInvalidSpec(url); |
306 return facet.IsValidAndroidFacetURI(); | 324 return facet.IsValidAndroidFacetURI(); |
307 } | 325 } |
308 | 326 |
309 } // namespace password_manager | 327 } // namespace password_manager |
OLD | NEW |