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

Side by Side Diff: components/content_settings/core/common/content_settings_pattern.cc

Issue 2250713003: Add metrics for schemes of content setting exceptions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/content_settings/core/common/content_settings_pattern.h" 5 #include "components/content_settings/core/common/content_settings_pattern.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "components/content_settings/core/common/content_settings_pattern_parse r.h" 15 #include "components/content_settings/core/common/content_settings_pattern_parse r.h"
16 #include "net/base/url_util.h" 16 #include "net/base/url_util.h"
17 #include "url/gurl.h" 17 #include "url/gurl.h"
18 18
19 namespace { 19 namespace {
20 20
21 // The component supports only one scheme for simplicity. 21 // The component supports only one scheme for simplicity.
22 const char* non_port_non_domain_wildcard_scheme = NULL; 22 const char* non_port_non_domain_wildcard_scheme = NULL;
23 23
24 // Keep it consistent with enum SchemeType in content_settings_pattern.h.
25 const char* const kSchemeNames[] = {
26 "wildcard",
27 "other",
28 url::kHttpScheme,
29 url::kHttpsScheme,
30 url::kFileScheme,
31 "chrome-extension",
32 };
33
34 static_assert(arraysize(kSchemeNames) == ContentSettingsPattern::SCHEME_MAX,
35 "kSchemeNames should have SCHEME_MAX elements");
36
24 std::string GetDefaultPort(const std::string& scheme) { 37 std::string GetDefaultPort(const std::string& scheme) {
25 if (scheme == url::kHttpScheme) 38 if (scheme == url::kHttpScheme)
26 return "80"; 39 return "80";
27 if (scheme == url::kHttpsScheme) 40 if (scheme == url::kHttpsScheme)
28 return "443"; 41 return "443";
29 return std::string(); 42 return std::string();
30 } 43 }
31 44
32 // Returns true if |sub_domain| is a sub domain or equls |domain|. E.g. 45 // Returns true if |sub_domain| is a sub domain or equls |domain|. E.g.
33 // "mail.google.com" is a sub domain of "google.com" but "evilhost.com" is not a 46 // "mail.google.com" is a sub domain of "google.com" but "evilhost.com" is not a
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 return parts_.has_domain_wildcard && parts_.host.empty(); 542 return parts_.has_domain_wildcard && parts_.host.empty();
530 } 543 }
531 544
532 std::string ContentSettingsPattern::ToString() const { 545 std::string ContentSettingsPattern::ToString() const {
533 if (IsValid()) 546 if (IsValid())
534 return content_settings::PatternParser::ToString(parts_); 547 return content_settings::PatternParser::ToString(parts_);
535 else 548 else
536 return std::string(); 549 return std::string();
537 } 550 }
538 551
552 ContentSettingsPattern::SchemeType ContentSettingsPattern::GetScheme() const {
553 if (parts_.is_scheme_wildcard)
554 return SCHEME_WILDCARD;
555
556 for (size_t i = 2; i < arraysize(kSchemeNames); ++i) {
557 if (parts_.scheme == kSchemeNames[i])
558 return static_cast<SchemeType>(i);
559 }
560 return SCHEME_OTHER;
561 }
562
539 ContentSettingsPattern::Relation ContentSettingsPattern::Compare( 563 ContentSettingsPattern::Relation ContentSettingsPattern::Compare(
540 const ContentSettingsPattern& other) const { 564 const ContentSettingsPattern& other) const {
541 // Two invalid patterns are identical in the way they behave. They don't match 565 // Two invalid patterns are identical in the way they behave. They don't match
542 // anything and are represented as an empty string. So it's fair to treat them 566 // anything and are represented as an empty string. So it's fair to treat them
543 // as identical. 567 // as identical.
544 if ((this == &other) || 568 if ((this == &other) ||
545 (!is_valid_ && !other.is_valid_)) 569 (!is_valid_ && !other.is_valid_))
546 return IDENTITY; 570 return IDENTITY;
547 571
548 if (!is_valid_ && other.is_valid_) 572 if (!is_valid_ && other.is_valid_)
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 if (!parts.is_path_wildcard && other_parts.is_path_wildcard) 761 if (!parts.is_path_wildcard && other_parts.is_path_wildcard)
738 return ContentSettingsPattern::PREDECESSOR; 762 return ContentSettingsPattern::PREDECESSOR;
739 763
740 int result = parts.path.compare(other_parts.path); 764 int result = parts.path.compare(other_parts.path);
741 if (result == 0) 765 if (result == 0)
742 return ContentSettingsPattern::IDENTITY; 766 return ContentSettingsPattern::IDENTITY;
743 if (result > 0) 767 if (result > 0)
744 return ContentSettingsPattern::DISJOINT_ORDER_PRE; 768 return ContentSettingsPattern::DISJOINT_ORDER_PRE;
745 return ContentSettingsPattern::DISJOINT_ORDER_POST; 769 return ContentSettingsPattern::DISJOINT_ORDER_POST;
746 } 770 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698