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

Side by Side 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 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 const char* const kSchemeNames[] = {
25 "wildcard",
26 url::kHttpScheme,
27 url::kHttpsScheme,
28 url::kFileScheme,
29 "chrome-extension",
30 "other",
31 };
32
24 std::string GetDefaultPort(const std::string& scheme) { 33 std::string GetDefaultPort(const std::string& scheme) {
25 if (scheme == url::kHttpScheme) 34 if (scheme == url::kHttpScheme)
26 return "80"; 35 return "80";
27 if (scheme == url::kHttpsScheme) 36 if (scheme == url::kHttpsScheme)
28 return "443"; 37 return "443";
29 return std::string(); 38 return std::string();
30 } 39 }
31 40
32 // Returns true if |sub_domain| is a sub domain or equals |domain|. E.g. 41 // Returns true if |sub_domain| is a sub domain or equals |domain|. E.g.
33 // "mail.google.com" is a sub domain of "google.com" but "evilhost.com" is not a 42 // "mail.google.com" is a sub domain of "google.com" but "evilhost.com" is not a
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 return parts_.has_domain_wildcard && parts_.host.empty(); 592 return parts_.has_domain_wildcard && parts_.host.empty();
584 } 593 }
585 594
586 std::string ContentSettingsPattern::ToString() const { 595 std::string ContentSettingsPattern::ToString() const {
587 if (IsValid()) 596 if (IsValid())
588 return content_settings::PatternParser::ToString(parts_); 597 return content_settings::PatternParser::ToString(parts_);
589 else 598 else
590 return std::string(); 599 return std::string();
591 } 600 }
592 601
602 ContentSettingsPattern::SchemeType ContentSettingsPattern::GetScheme() const {
603 if (parts_.is_scheme_wildcard)
604 return SCHEME_WILDCARD;
605
606 for (int i = 1; i < SCHEME_MAX - 1; ++i) {
msramek 2016/08/09 10:47:43 We're iterating over kSchemeNames, so I would spec
lshang 2016/08/10 04:32:35 Done. Good advice!
607 if (parts_.scheme == kSchemeNames[i]) {
msramek 2016/08/09 10:47:43 nit: No braces needed for a one-line for() :)
lshang 2016/08/10 04:32:35 Done.
608 return static_cast<SchemeType>(i);
609 }
610 }
611 return SCHEME_OTHER;
612 }
613
593 ContentSettingsPattern::Relation ContentSettingsPattern::Compare( 614 ContentSettingsPattern::Relation ContentSettingsPattern::Compare(
594 const ContentSettingsPattern& other) const { 615 const ContentSettingsPattern& other) const {
595 // Two invalid patterns are identical in the way they behave. They don't match 616 // Two invalid patterns are identical in the way they behave. They don't match
596 // anything and are represented as an empty string. So it's fair to treat them 617 // anything and are represented as an empty string. So it's fair to treat them
597 // as identical. 618 // as identical.
598 if ((this == &other) || 619 if ((this == &other) ||
599 (!is_valid_ && !other.is_valid_)) 620 (!is_valid_ && !other.is_valid_))
600 return IDENTITY; 621 return IDENTITY;
601 622
602 if (!is_valid_ && other.is_valid_) 623 if (!is_valid_ && other.is_valid_)
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 if (!parts.is_path_wildcard && other_parts.is_path_wildcard) 812 if (!parts.is_path_wildcard && other_parts.is_path_wildcard)
792 return ContentSettingsPattern::PREDECESSOR; 813 return ContentSettingsPattern::PREDECESSOR;
793 814
794 int result = parts.path.compare(other_parts.path); 815 int result = parts.path.compare(other_parts.path);
795 if (result == 0) 816 if (result == 0)
796 return ContentSettingsPattern::IDENTITY; 817 return ContentSettingsPattern::IDENTITY;
797 if (result > 0) 818 if (result > 0)
798 return ContentSettingsPattern::DISJOINT_ORDER_PRE; 819 return ContentSettingsPattern::DISJOINT_ORDER_PRE;
799 return ContentSettingsPattern::DISJOINT_ORDER_POST; 820 return ContentSettingsPattern::DISJOINT_ORDER_POST;
800 } 821 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698