| 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/login_database.h" | 5 #include "components/password_manager/core/browser/login_database.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 if (!domain_to_registry_controlled_domain.count(domain)) { | 230 if (!domain_to_registry_controlled_domain.count(domain)) { |
| 231 domain_to_registry_controlled_domain[domain] = | 231 domain_to_registry_controlled_domain[domain] = |
| 232 GetRegistryControlledDomain(signon_realm_url); | 232 GetRegistryControlledDomain(signon_realm_url); |
| 233 if (domain_to_registry_controlled_domain[domain].empty()) | 233 if (domain_to_registry_controlled_domain[domain].empty()) |
| 234 domain_to_registry_controlled_domain[domain] = domain; | 234 domain_to_registry_controlled_domain[domain] = domain; |
| 235 } | 235 } |
| 236 const std::string& registry_controlled_domain = | 236 const std::string& registry_controlled_domain = |
| 237 domain_to_registry_controlled_domain[domain]; | 237 domain_to_registry_controlled_domain[domain]; |
| 238 | 238 |
| 239 Scheme scheme = SCHEME_HTTP; | 239 Scheme scheme = SCHEME_HTTP; |
| 240 COMPILE_ASSERT(arraysize(kAllSchemes) == 2, "Update this logic"); | 240 static_assert(arraysize(kAllSchemes) == 2, "Update this logic"); |
| 241 if (signon_realm_url.SchemeIs(url::kHttpsScheme)) | 241 if (signon_realm_url.SchemeIs(url::kHttpsScheme)) |
| 242 scheme = SCHEME_HTTPS; | 242 scheme = SCHEME_HTTPS; |
| 243 else if (!signon_realm_url.SchemeIs(url::kHttpScheme)) | 243 else if (!signon_realm_url.SchemeIs(url::kHttpScheme)) |
| 244 continue; | 244 continue; |
| 245 | 245 |
| 246 statistics[scheme].num_accounts_per_domain[domain]++; | 246 statistics[scheme].num_accounts_per_domain[domain]++; |
| 247 statistics[scheme].num_accounts_per_registry_controlled_domain | 247 statistics[scheme].num_accounts_per_registry_controlled_domain |
| 248 [registry_controlled_domain]++; | 248 [registry_controlled_domain]++; |
| 249 statistics[scheme].num_total_accounts++; | 249 statistics[scheme].num_total_accounts++; |
| 250 } | 250 } |
| 251 | 251 |
| 252 // For each "source" account of either scheme, count the number of "target" | 252 // For each "source" account of either scheme, count the number of "target" |
| 253 // accounts reusing the same password (of either scheme). | 253 // accounts reusing the same password (of either scheme). |
| 254 for (const Scheme scheme : kAllSchemes) { | 254 for (const Scheme scheme : kAllSchemes) { |
| 255 for (const auto& kv : statistics[scheme].num_accounts_per_domain) { | 255 for (const auto& kv : statistics[scheme].num_accounts_per_domain) { |
| 256 const std::string& domain(kv.first); | 256 const std::string& domain(kv.first); |
| 257 const int num_accounts_per_domain(kv.second); | 257 const int num_accounts_per_domain(kv.second); |
| 258 const std::string& registry_controlled_domain = | 258 const std::string& registry_controlled_domain = |
| 259 domain_to_registry_controlled_domain[domain]; | 259 domain_to_registry_controlled_domain[domain]; |
| 260 | 260 |
| 261 Scheme other_scheme = scheme == SCHEME_HTTP ? SCHEME_HTTPS : SCHEME_HTTP; | 261 Scheme other_scheme = scheme == SCHEME_HTTP ? SCHEME_HTTPS : SCHEME_HTTP; |
| 262 COMPILE_ASSERT(arraysize(kAllSchemes) == 2, "Update |other_scheme|"); | 262 static_assert(arraysize(kAllSchemes) == 2, "Update |other_scheme|"); |
| 263 | 263 |
| 264 // Discount the account at hand from the number of accounts with the same | 264 // Discount the account at hand from the number of accounts with the same |
| 265 // domain and scheme. | 265 // domain and scheme. |
| 266 int num_accounts_for_same_domain[arraysize(kAllSchemes)] = {}; | 266 int num_accounts_for_same_domain[arraysize(kAllSchemes)] = {}; |
| 267 num_accounts_for_same_domain[scheme] = | 267 num_accounts_for_same_domain[scheme] = |
| 268 statistics[scheme].num_accounts_per_domain[domain] - 1; | 268 statistics[scheme].num_accounts_per_domain[domain] - 1; |
| 269 num_accounts_for_same_domain[other_scheme] = | 269 num_accounts_for_same_domain[other_scheme] = |
| 270 statistics[other_scheme].num_accounts_per_domain[domain]; | 270 statistics[other_scheme].num_accounts_per_domain[domain]; |
| 271 | 271 |
| 272 // By definition, a PSL match requires the scheme to be the same. | 272 // By definition, a PSL match requires the scheme to be the same. |
| 273 int num_psl_matching_accounts = | 273 int num_psl_matching_accounts = |
| 274 statistics[scheme].num_accounts_per_registry_controlled_domain | 274 statistics[scheme].num_accounts_per_registry_controlled_domain |
| 275 [registry_controlled_domain] - | 275 [registry_controlled_domain] - |
| 276 statistics[scheme].num_accounts_per_domain[domain]; | 276 statistics[scheme].num_accounts_per_domain[domain]; |
| 277 | 277 |
| 278 // Discount PSL matches from the number of accounts with different domains | 278 // Discount PSL matches from the number of accounts with different domains |
| 279 // but the same scheme. | 279 // but the same scheme. |
| 280 int num_accounts_for_different_domain[arraysize(kAllSchemes)] = {}; | 280 int num_accounts_for_different_domain[arraysize(kAllSchemes)] = {}; |
| 281 num_accounts_for_different_domain[scheme] = | 281 num_accounts_for_different_domain[scheme] = |
| 282 statistics[scheme].num_total_accounts - | 282 statistics[scheme].num_total_accounts - |
| 283 statistics[scheme].num_accounts_per_registry_controlled_domain | 283 statistics[scheme].num_accounts_per_registry_controlled_domain |
| 284 [registry_controlled_domain]; | 284 [registry_controlled_domain]; |
| 285 num_accounts_for_different_domain[other_scheme] = | 285 num_accounts_for_different_domain[other_scheme] = |
| 286 statistics[other_scheme].num_total_accounts - | 286 statistics[other_scheme].num_total_accounts - |
| 287 statistics[other_scheme].num_accounts_per_domain[domain]; | 287 statistics[other_scheme].num_accounts_per_domain[domain]; |
| 288 | 288 |
| 289 std::string source_realm_kind = | 289 std::string source_realm_kind = |
| 290 scheme == SCHEME_HTTP ? "FromHttpRealm" : "FromHttpsRealm"; | 290 scheme == SCHEME_HTTP ? "FromHttpRealm" : "FromHttpsRealm"; |
| 291 COMPILE_ASSERT(arraysize(kAllSchemes) == 2, "Update |source_realm_kind|"); | 291 static_assert(arraysize(kAllSchemes) == 2, "Update |source_realm_kind|"); |
| 292 | 292 |
| 293 // So far, the calculation has been carried out once per "source" domain, | 293 // So far, the calculation has been carried out once per "source" domain, |
| 294 // but the metrics need to be recorded on a per-account basis. The set of | 294 // but the metrics need to be recorded on a per-account basis. The set of |
| 295 // metrics are the same for all accounts for the same domain, so simply | 295 // metrics are the same for all accounts for the same domain, so simply |
| 296 // report them as many times as accounts. | 296 // report them as many times as accounts. |
| 297 for (int i = 0; i < num_accounts_per_domain; ++i) { | 297 for (int i = 0; i < num_accounts_per_domain; ++i) { |
| 298 LogNumberOfAccountsReusingPassword( | 298 LogNumberOfAccountsReusingPassword( |
| 299 source_realm_kind + ".OnHttpRealmWithSameHost", | 299 source_realm_kind + ".OnHttpRealmWithSameHost", |
| 300 num_accounts_for_same_domain[SCHEME_HTTP], HistogramSize::SMALL); | 300 num_accounts_for_same_domain[SCHEME_HTTP], HistogramSize::SMALL); |
| 301 LogNumberOfAccountsReusingPassword( | 301 LogNumberOfAccountsReusingPassword( |
| (...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1289 UMA_HISTOGRAM_ENUMERATION("PasswordManager.PslDomainMatchTriggering", | 1289 UMA_HISTOGRAM_ENUMERATION("PasswordManager.PslDomainMatchTriggering", |
| 1290 psl_domain_match_metric, PSL_DOMAIN_MATCH_COUNT); | 1290 psl_domain_match_metric, PSL_DOMAIN_MATCH_COUNT); |
| 1291 } | 1291 } |
| 1292 | 1292 |
| 1293 if (!statement->Succeeded()) | 1293 if (!statement->Succeeded()) |
| 1294 return false; | 1294 return false; |
| 1295 return true; | 1295 return true; |
| 1296 } | 1296 } |
| 1297 | 1297 |
| 1298 } // namespace password_manager | 1298 } // namespace password_manager |
| OLD | NEW |