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

Side by Side Diff: extensions/common/permissions/permission_message_util.cc

Issue 591313004: Reusing base::StringPairs in src/extentions/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "extensions/common/permissions/permission_message_util.h" 5 #include "extensions/common/permissions/permission_message_util.h"
6 6
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "extensions/common/permissions/permission_message.h" 9 #include "extensions/common/permissions/permission_message.h"
10 #include "extensions/common/permissions/permission_set.h" 10 #include "extensions/common/permissions/permission_set.h"
11 #include "extensions/common/url_pattern_set.h" 11 #include "extensions/common/url_pattern_set.h"
12 #include "grit/extensions_strings.h" 12 #include "grit/extensions_strings.h"
13 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 13 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
14 #include "ui/base/l10n/l10n_util.h" 14 #include "ui/base/l10n/l10n_util.h"
15 #include "url/url_constants.h" 15 #include "url/url_constants.h"
16 #include "base/strings/string_split.h"
16 17
17 using extensions::PermissionMessage; 18 using extensions::PermissionMessage;
18 using extensions::PermissionSet; 19 using extensions::PermissionSet;
19 using extensions::URLPatternSet; 20 using extensions::URLPatternSet;
20 21
21 namespace { 22 namespace {
22 23
23 // Helper for GetDistinctHosts(): com > net > org > everything else. 24 // Helper for GetDistinctHosts(): com > net > org > everything else.
24 bool RcdBetterThan(const std::string& a, const std::string& b) { 25 bool RcdBetterThan(const std::string& a, const std::string& b) {
25 if (a == b) 26 if (a == b)
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 kMessagesList[arraysize(kMessagesList) - 1].second), 86 kMessagesList[arraysize(kMessagesList) - 1].second),
86 details); 87 details);
87 } 88 }
88 89
89 std::set<std::string> GetDistinctHosts(const URLPatternSet& host_patterns, 90 std::set<std::string> GetDistinctHosts(const URLPatternSet& host_patterns,
90 bool include_rcd, 91 bool include_rcd,
91 bool exclude_file_scheme) { 92 bool exclude_file_scheme) {
92 // Use a vector to preserve order (also faster than a map on small sets). 93 // Use a vector to preserve order (also faster than a map on small sets).
93 // Each item is a host split into two parts: host without RCDs and 94 // Each item is a host split into two parts: host without RCDs and
94 // current best RCD. 95 // current best RCD.
95 typedef std::vector<std::pair<std::string, std::string> > HostVector; 96 typedef base::StringPairs HostVector;
96 HostVector hosts_best_rcd; 97 HostVector hosts_best_rcd;
97 for (URLPatternSet::const_iterator i = host_patterns.begin(); 98 for (URLPatternSet::const_iterator i = host_patterns.begin();
98 i != host_patterns.end(); 99 i != host_patterns.end();
99 ++i) { 100 ++i) {
100 if (exclude_file_scheme && i->scheme() == url::kFileScheme) 101 if (exclude_file_scheme && i->scheme() == url::kFileScheme)
101 continue; 102 continue;
102 103
103 std::string host = i->host(); 104 std::string host = i->host();
104 105
105 // Add the subdomain wildcard back to the host, if necessary. 106 // Add the subdomain wildcard back to the host, if necessary.
(...skipping 30 matching lines...) Expand all
136 // Build up the final vector by concatenating hosts and RCDs. 137 // Build up the final vector by concatenating hosts and RCDs.
137 std::set<std::string> distinct_hosts; 138 std::set<std::string> distinct_hosts;
138 for (HostVector::iterator it = hosts_best_rcd.begin(); 139 for (HostVector::iterator it = hosts_best_rcd.begin();
139 it != hosts_best_rcd.end(); 140 it != hosts_best_rcd.end();
140 ++it) 141 ++it)
141 distinct_hosts.insert(it->first + it->second); 142 distinct_hosts.insert(it->first + it->second);
142 return distinct_hosts; 143 return distinct_hosts;
143 } 144 }
144 145
145 } // namespace permission_message_util 146 } // namespace permission_message_util
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698