| OLD | NEW |
| 1 //* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | 1 //* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 /* ***** BEGIN LICENSE BLOCK ***** | 2 /* ***** BEGIN LICENSE BLOCK ***** |
| 3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 4 * | 4 * |
| 5 * The contents of this file are subject to the Mozilla Public License Version | 5 * The contents of this file are subject to the Mozilla Public License Version |
| 6 * 1.1 (the "License"); you may not use this file except in compliance with | 6 * 1.1 (the "License"); you may not use this file except in compliance with |
| 7 * the License. You may obtain a copy of the License at | 7 * the License. You may obtain a copy of the License at |
| 8 * http://www.mozilla.org/MPL/ | 8 * http://www.mozilla.org/MPL/ |
| 9 * | 9 * |
| 10 * Software distributed under the License is distributed on an "AS IS" basis, | 10 * Software distributed under the License is distributed on an "AS IS" basis, |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 void RegistryControlledDomainService::UseDomainData(const std::string& data) { | 269 void RegistryControlledDomainService::UseDomainData(const std::string& data) { |
| 270 RegistryControlledDomainService* instance = GetInstance(); | 270 RegistryControlledDomainService* instance = GetInstance(); |
| 271 instance->copied_domain_data_ = data; | 271 instance->copied_domain_data_ = data; |
| 272 instance->ParseDomainData(instance->copied_domain_data_); | 272 instance->ParseDomainData(instance->copied_domain_data_); |
| 273 } | 273 } |
| 274 | 274 |
| 275 void RegistryControlledDomainService::Init() { | 275 void RegistryControlledDomainService::Init() { |
| 276 ParseDomainData(kDomainData); | 276 ParseDomainData(kDomainData); |
| 277 } | 277 } |
| 278 | 278 |
| 279 void RegistryControlledDomainService::ParseDomainData(const StringPiece& data) { | 279 void RegistryControlledDomainService::ParseDomainData( |
| 280 const base::StringPiece& data) { |
| 280 domain_set_.clear(); | 281 domain_set_.clear(); |
| 281 | 282 |
| 282 size_t line_end = 0; | 283 size_t line_end = 0; |
| 283 size_t line_start = 0; | 284 size_t line_start = 0; |
| 284 while (line_start < data.size()) { | 285 while (line_start < data.size()) { |
| 285 line_end = data.find('\n', line_start); | 286 line_end = data.find('\n', line_start); |
| 286 if (line_end == StringPiece::npos) | 287 if (line_end == base::StringPiece::npos) |
| 287 line_end = data.size(); | 288 line_end = data.size(); |
| 288 AddRule(StringPiece(data.data() + line_start, line_end - line_start)); | 289 AddRule(base::StringPiece(data.data() + line_start, line_end - line_start)); |
| 289 line_start = line_end + 1; | 290 line_start = line_end + 1; |
| 290 } | 291 } |
| 291 } | 292 } |
| 292 | 293 |
| 293 void RegistryControlledDomainService::AddRule(const StringPiece& rule_str) { | 294 void RegistryControlledDomainService::AddRule( |
| 295 const base::StringPiece& rule_str) { |
| 294 DomainEntry rule(rule_str.data(), rule_str.size()); | 296 DomainEntry rule(rule_str.data(), rule_str.size()); |
| 295 | 297 |
| 296 // Valid rules may be either wild or exceptions, but not both. | 298 // Valid rules may be either wild or exceptions, but not both. |
| 297 if (rule.starts_with("!")) { | 299 if (rule.starts_with("!")) { |
| 298 rule.remove_prefix(1); | 300 rule.remove_prefix(1); |
| 299 rule.attributes.exception = true; | 301 rule.attributes.exception = true; |
| 300 } else if (rule.starts_with("*.")) { | 302 } else if (rule.starts_with("*.")) { |
| 301 rule.remove_prefix(2); | 303 rule.remove_prefix(2); |
| 302 rule.attributes.wildcard = true; | 304 rule.attributes.wildcard = true; |
| 303 } | 305 } |
| 304 | 306 |
| 305 DomainSet::iterator prev_rule = domain_set_.find(rule); | 307 DomainSet::iterator prev_rule = domain_set_.find(rule); |
| 306 if (prev_rule != domain_set_.end()) { | 308 if (prev_rule != domain_set_.end()) { |
| 307 // We found a rule with the same domain, combine the attributes. | 309 // We found a rule with the same domain, combine the attributes. |
| 308 // This could happen for example when a domain is both a wildcard | 310 // This could happen for example when a domain is both a wildcard |
| 309 // and an exception (ex *.google.com and !google.com). Sets are immutable, | 311 // and an exception (ex *.google.com and !google.com). Sets are immutable, |
| 310 // we'll erase the old one, and insert a new one with the new attributes. | 312 // we'll erase the old one, and insert a new one with the new attributes. |
| 311 rule.attributes.Combine(prev_rule->attributes); | 313 rule.attributes.Combine(prev_rule->attributes); |
| 312 domain_set_.erase(prev_rule); | 314 domain_set_.erase(prev_rule); |
| 313 } | 315 } |
| 314 | 316 |
| 315 domain_set_.insert(rule); | 317 domain_set_.insert(rule); |
| 316 } | 318 } |
| 317 | 319 |
| 318 } // namespace net | 320 } // namespace net |
| OLD | NEW |