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

Side by Side Diff: components/policy/core/browser/url_blacklist_manager.cc

Issue 1485853003: Revert of Remove kuint16max. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kint2
Patch Set: Created 5 years 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 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 "components/policy/core/browser/url_blacklist_manager.h" 5 #include "components/policy/core/browser/url_blacklist_manager.h"
6 6
7 #include <stdint.h>
8
9 #include <limits>
10
11 #include "base/bind.h" 7 #include "base/bind.h"
12 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
13 #include "base/location.h" 9 #include "base/location.h"
14 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
15 #include "base/sequenced_task_runner.h" 11 #include "base/sequenced_task_runner.h"
16 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
17 #include "base/stl_util.h" 13 #include "base/stl_util.h"
18 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
19 #include "base/task_runner_util.h" 15 #include "base/task_runner_util.h"
20 #include "base/thread_task_runner_handle.h" 16 #include "base/thread_task_runner_handle.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 130
135 // Returns true if |this| represents the "*" filter in the blacklist. 131 // Returns true if |this| represents the "*" filter in the blacklist.
136 bool IsBlacklistWildcard() const { 132 bool IsBlacklistWildcard() const {
137 return !allow && host.empty() && scheme.empty() && path.empty() && 133 return !allow && host.empty() && scheme.empty() && path.empty() &&
138 query.empty() && port == 0 && number_of_key_value_pairs == 0 && 134 query.empty() && port == 0 && number_of_key_value_pairs == 0 &&
139 match_subdomains; 135 match_subdomains;
140 } 136 }
141 137
142 std::string scheme; 138 std::string scheme;
143 std::string host; 139 std::string host;
144 uint16_t port; 140 uint16 port;
145 std::string path; 141 std::string path;
146 std::string query; 142 std::string query;
147 int number_of_key_value_pairs; 143 int number_of_key_value_pairs;
148 bool match_subdomains; 144 bool match_subdomains;
149 bool allow; 145 bool allow;
150 }; 146 };
151 147
152 URLBlacklist::URLBlacklist(SegmentURLCallback segment_url) 148 URLBlacklist::URLBlacklist(SegmentURLCallback segment_url)
153 : segment_url_(segment_url), id_(0), url_matcher_(new URLMatcher) {} 149 : segment_url_(segment_url), id_(0), url_matcher_(new URLMatcher) {}
154 150
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 size_t URLBlacklist::Size() const { 228 size_t URLBlacklist::Size() const {
233 return filters_.size(); 229 return filters_.size();
234 } 230 }
235 231
236 // static 232 // static
237 bool URLBlacklist::FilterToComponents(SegmentURLCallback segment_url, 233 bool URLBlacklist::FilterToComponents(SegmentURLCallback segment_url,
238 const std::string& filter, 234 const std::string& filter,
239 std::string* scheme, 235 std::string* scheme,
240 std::string* host, 236 std::string* host,
241 bool* match_subdomains, 237 bool* match_subdomains,
242 uint16_t* port, 238 uint16* port,
243 std::string* path, 239 std::string* path,
244 std::string* query) { 240 std::string* query) {
245 url::Parsed parsed; 241 url::Parsed parsed;
246 242
247 if (segment_url(filter, &parsed) == url::kFileScheme) { 243 if (segment_url(filter, &parsed) == url::kFileScheme) {
248 base::FilePath file_path; 244 base::FilePath file_path;
249 if (!net::FileURLToFilePath(GURL(filter), &file_path)) 245 if (!net::FileURLToFilePath(GURL(filter), &file_path))
250 return false; 246 return false;
251 247
252 *scheme = url::kFileScheme; 248 *scheme = url::kFileScheme;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 *match_subdomains = false; 291 *match_subdomains = false;
296 } 292 }
297 } 293 }
298 294
299 if (parsed.port.is_nonempty()) { 295 if (parsed.port.is_nonempty()) {
300 int int_port; 296 int int_port;
301 if (!base::StringToInt(filter.substr(parsed.port.begin, parsed.port.len), 297 if (!base::StringToInt(filter.substr(parsed.port.begin, parsed.port.len),
302 &int_port)) { 298 &int_port)) {
303 return false; 299 return false;
304 } 300 }
305 if (int_port <= 0 || int_port > std::numeric_limits<uint16_t>::max()) 301 if (int_port <= 0 || int_port > kuint16max)
306 return false; 302 return false;
307 *port = int_port; 303 *port = int_port;
308 } else { 304 } else {
309 // Match any port. 305 // Match any port.
310 *port = 0; 306 *port = 0;
311 } 307 }
312 308
313 if (parsed.path.is_nonempty()) 309 if (parsed.path.is_nonempty())
314 path->assign(filter, parsed.path.begin, parsed.path.len); 310 path->assign(filter, parsed.path.begin, parsed.path.len);
315 else 311 else
316 path->clear(); 312 path->clear();
317 313
318 if (query) { 314 if (query) {
319 if (parsed.query.is_nonempty()) 315 if (parsed.query.is_nonempty())
320 query->assign(filter, parsed.query.begin, parsed.query.len); 316 query->assign(filter, parsed.query.begin, parsed.query.len);
321 else 317 else
322 query->clear(); 318 query->clear();
323 } 319 }
324 320
325 return true; 321 return true;
326 } 322 }
327 323
328 // static 324 // static
329 scoped_refptr<URLMatcherConditionSet> URLBlacklist::CreateConditionSet( 325 scoped_refptr<URLMatcherConditionSet> URLBlacklist::CreateConditionSet(
330 URLMatcher* url_matcher, 326 URLMatcher* url_matcher,
331 int id, 327 int id,
332 const std::string& scheme, 328 const std::string& scheme,
333 const std::string& host, 329 const std::string& host,
334 bool match_subdomains, 330 bool match_subdomains,
335 uint16_t port, 331 uint16 port,
336 const std::string& path, 332 const std::string& path,
337 const std::string& query, 333 const std::string& query,
338 bool allow) { 334 bool allow) {
339 URLMatcherConditionFactory* condition_factory = 335 URLMatcherConditionFactory* condition_factory =
340 url_matcher->condition_factory(); 336 url_matcher->condition_factory();
341 std::set<URLMatcherCondition> conditions; 337 std::set<URLMatcherCondition> conditions;
342 conditions.insert(match_subdomains ? 338 conditions.insert(match_subdomains ?
343 condition_factory->CreateHostSuffixPathPrefixCondition(host, path) : 339 condition_factory->CreateHostSuffixPathPrefixCondition(host, path) :
344 condition_factory->CreateHostEqualsPathPrefixCondition(host, path)); 340 condition_factory->CreateHostEqualsPathPrefixCondition(host, path));
345 341
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 } 501 }
506 502
507 // static 503 // static
508 void URLBlacklistManager::RegisterProfilePrefs( 504 void URLBlacklistManager::RegisterProfilePrefs(
509 user_prefs::PrefRegistrySyncable* registry) { 505 user_prefs::PrefRegistrySyncable* registry) {
510 registry->RegisterListPref(policy_prefs::kUrlBlacklist); 506 registry->RegisterListPref(policy_prefs::kUrlBlacklist);
511 registry->RegisterListPref(policy_prefs::kUrlWhitelist); 507 registry->RegisterListPref(policy_prefs::kUrlWhitelist);
512 } 508 }
513 509
514 } // namespace policy 510 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/sync/test/integration/sync_test.cc ('k') | extensions/common/permissions/usb_device_permission_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698