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

Unified Diff: components/password_manager/core/browser/psl_matching_helper.cc

Issue 2899083004: Implement PasswordStore::GetLoginsForSameOrganizationName. (Closed)
Patch Set: Rebase. Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: components/password_manager/core/browser/psl_matching_helper.cc
diff --git a/components/password_manager/core/browser/psl_matching_helper.cc b/components/password_manager/core/browser/psl_matching_helper.cc
index b4c4bef165c9d022f57ded82296fe6f68a8b88a0..6cbb305c7645938e4d3249378d76395273d84e7d 100644
--- a/components/password_manager/core/browser/psl_matching_helper.cc
+++ b/components/password_manager/core/browser/psl_matching_helper.cc
@@ -116,4 +116,28 @@ std::string GetRegistryControlledDomain(const GURL& signon_realm) {
signon_realm,
net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
}
+
+std::string GetOrganizationIdentifyingName(const GURL& url) {
+ if (!url.is_valid())
+ return std::string();
+
+ const std::string organization_and_registrar =
+ net::registry_controlled_domains::GetDomainAndRegistry(
+ url, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
+ const size_t registrar_length =
+ net::registry_controlled_domains::GetRegistryLength(
+ url, net::registry_controlled_domains::INCLUDE_UNKNOWN_REGISTRIES,
+ net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
+
+ if (organization_and_registrar.empty() || !registrar_length ||
+ registrar_length == std::string::npos) {
+ return std::string();
+ }
+
+ // No CHECK, std::string::substr gracefully handles an underflow there.
+ DCHECK_LT(registrar_length, organization_and_registrar.size());
+ return organization_and_registrar.substr(
+ 0, organization_and_registrar.size() - registrar_length - 1);
+}
+
} // namespace password_manager

Powered by Google App Engine
This is Rietveld 408576698