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

Unified Diff: components/content_settings/core/common/content_settings_pattern.cc

Issue 2226643002: Add metrics for schemes of content setting exceptions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review comments Created 4 years, 4 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/content_settings/core/common/content_settings_pattern.cc
diff --git a/components/content_settings/core/common/content_settings_pattern.cc b/components/content_settings/core/common/content_settings_pattern.cc
index aa895948153c07fa1536be3d9346c80c9a2462c3..348892e5d1523be701aa21a356b6aab3c60cb8c3 100644
--- a/components/content_settings/core/common/content_settings_pattern.cc
+++ b/components/content_settings/core/common/content_settings_pattern.cc
@@ -21,6 +21,19 @@ namespace {
// The component supports only one scheme for simplicity.
const char* non_port_non_domain_wildcard_scheme = NULL;
+// Keep it consistent with enum SchemeType in content_settings_pattern.h.
+const char* const kSchemeNames[] = {
+ "wildcard",
+ "other",
+ url::kHttpScheme,
+ url::kHttpsScheme,
+ url::kFileScheme,
+ "chrome-extension",
+};
+
+static_assert(arraysize(kSchemeNames) == ContentSettingsPattern::SCHEME_MAX,
+ "kSchemeNames should have SCHEME_MAX elements");
+
std::string GetDefaultPort(const std::string& scheme) {
if (scheme == url::kHttpScheme)
return "80";
@@ -590,6 +603,17 @@ std::string ContentSettingsPattern::ToString() const {
return std::string();
}
+ContentSettingsPattern::SchemeType ContentSettingsPattern::GetScheme() const {
+ if (parts_.is_scheme_wildcard)
+ return SCHEME_WILDCARD;
+
+ for (size_t i = 2; i < arraysize(kSchemeNames); ++i) {
+ if (parts_.scheme == kSchemeNames[i])
+ return static_cast<SchemeType>(i);
+ }
+ return SCHEME_OTHER;
+}
+
ContentSettingsPattern::Relation ContentSettingsPattern::Compare(
const ContentSettingsPattern& other) const {
// Two invalid patterns are identical in the way they behave. They don't match

Powered by Google App Engine
This is Rietveld 408576698