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

Side by Side Diff: net/base/registry_controlled_domain.h

Issue 193072: Move StringPiece into the base namespace. It is colliding (Closed)
Patch Set: take 2 Created 11 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 | « net/base/net_util.cc ('k') | net/base/registry_controlled_domain.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 friend struct DefaultSingletonTraits<RegistryControlledDomainService>; 220 friend struct DefaultSingletonTraits<RegistryControlledDomainService>;
221 221
222 void Init(); 222 void Init();
223 223
224 // A DomainEntry is a combination of the domain name (as a StringPiece, so 224 // A DomainEntry is a combination of the domain name (as a StringPiece, so
225 // that we can reference external memory without copying), and two bits of 225 // that we can reference external memory without copying), and two bits of
226 // information, if it's an exception and/or wildcard entry. Note: we don't 226 // information, if it's an exception and/or wildcard entry. Note: we don't
227 // consider the attributes when doing comparisons, so as far as any data 227 // consider the attributes when doing comparisons, so as far as any data
228 // structures our concerned (ex our set), two DomainEntry's are equal as long 228 // structures our concerned (ex our set), two DomainEntry's are equal as long
229 // as their StringPiece (the domain) is equal. This is the behavior we want. 229 // as their StringPiece (the domain) is equal. This is the behavior we want.
230 class DomainEntry : public StringPiece { 230 class DomainEntry : public base::StringPiece {
231 public: 231 public:
232 struct DomainEntryAttributes { 232 struct DomainEntryAttributes {
233 DomainEntryAttributes() : exception(false), wildcard(false) { } 233 DomainEntryAttributes() : exception(false), wildcard(false) { }
234 ~DomainEntryAttributes() { } 234 ~DomainEntryAttributes() { }
235 235
236 void Combine(const DomainEntryAttributes& other) { 236 void Combine(const DomainEntryAttributes& other) {
237 if (other.exception) exception = true; 237 if (other.exception) exception = true;
238 if (other.wildcard) wildcard = true; 238 if (other.wildcard) wildcard = true;
239 } 239 }
240 240
241 bool exception; 241 bool exception;
242 bool wildcard; 242 bool wildcard;
243 }; 243 };
244 244
245 DomainEntry() : StringPiece() { } 245 DomainEntry() : base::StringPiece() { }
246 DomainEntry(const char* ptr, size_type size) : StringPiece(ptr, size) { } 246 DomainEntry(const char* ptr, size_type size)
247 : base::StringPiece(ptr, size) { }
247 ~DomainEntry() { } 248 ~DomainEntry() { }
248 249
249 // We override StringPiece's operator < to make it more efficent, since we 250 // We override StringPiece's operator < to make it more efficent, since we
250 // don't care that it's sorted lexigraphically and we want to ignore the 251 // don't care that it's sorted lexigraphically and we want to ignore the
251 // attributes when we are doing the comparisons. 252 // attributes when we are doing the comparisons.
252 bool operator<(const DomainEntry& other) const { 253 bool operator<(const DomainEntry& other) const {
253 // If we are the same size, call up to StringPiece's real less than. 254 // If we are the same size, call up to StringPiece's real less than.
254 if (size() == other.size()) 255 if (size() == other.size())
255 return *static_cast<const StringPiece*>(this) < other; 256 return *static_cast<const base::StringPiece*>(this) < other;
256 // Consider ourselves less if we are smaller 257 // Consider ourselves less if we are smaller
257 return size() < other.size(); 258 return size() < other.size();
258 } 259 }
259 260
260 DomainEntryAttributes attributes; 261 DomainEntryAttributes attributes;
261 }; 262 };
262 263
263 // An entry in the set of domain specifications, describing the properties 264 // An entry in the set of domain specifications, describing the properties
264 // that apply to that domain rule. 265 // that apply to that domain rule.
265 typedef std::set<DomainEntry> DomainSet; 266 typedef std::set<DomainEntry> DomainSet;
266 267
267 // Parses a list of effective-TLD rules, building the domain_set_. Rules are 268 // Parses a list of effective-TLD rules, building the domain_set_. Rules are
268 // assumed to be syntactically valid. We operate on a StringPiece. If we 269 // assumed to be syntactically valid. We operate on a StringPiece. If we
269 // were populated from an embedded resource, we will reference the embedded 270 // were populated from an embedded resource, we will reference the embedded
270 // resource directly. If we were populated through UseDomainData, then our 271 // resource directly. If we were populated through UseDomainData, then our
271 // StringPiece will reference our local copy in copied_domain_data_. 272 // StringPiece will reference our local copy in copied_domain_data_.
272 void ParseDomainData(const StringPiece& data); 273 void ParseDomainData(const base::StringPiece& data);
273 274
274 // Returns the singleton instance, after attempting to initialize it. 275 // Returns the singleton instance, after attempting to initialize it.
275 // NOTE that if the effective-TLD data resource can't be found, the instance 276 // NOTE that if the effective-TLD data resource can't be found, the instance
276 // will be initialized and continue operation with simple default TLD data. 277 // will be initialized and continue operation with simple default TLD data.
277 static RegistryControlledDomainService* GetInstance(); 278 static RegistryControlledDomainService* GetInstance();
278 279
279 // Adds one rule, assumed to be valid, to the domain_set_. 280 // Adds one rule, assumed to be valid, to the domain_set_.
280 void AddRule(const StringPiece& rule_str); 281 void AddRule(const base::StringPiece& rule_str);
281 282
282 // Internal workings of the static public methods. See above. 283 // Internal workings of the static public methods. See above.
283 static std::string GetDomainAndRegistryImpl(const std::string& host); 284 static std::string GetDomainAndRegistryImpl(const std::string& host);
284 size_t GetRegistryLengthImpl(const std::string& host, 285 size_t GetRegistryLengthImpl(const std::string& host,
285 bool allow_unknown_registries); 286 bool allow_unknown_registries);
286 287
287 // A set of our DomainEntry's. 288 // A set of our DomainEntry's.
288 DomainSet domain_set_; 289 DomainSet domain_set_;
289 290
290 // An optional copy of the full domain rule data. If we're loaded from a 291 // An optional copy of the full domain rule data. If we're loaded from a
291 // resource, then we just reference the resource directly without copying, 292 // resource, then we just reference the resource directly without copying,
292 // and copied_domain_data_ is not used. If we are populated through 293 // and copied_domain_data_ is not used. If we are populated through
293 // UseDomainData() then we copy that data here and reference it. 294 // UseDomainData() then we copy that data here and reference it.
294 std::string copied_domain_data_; 295 std::string copied_domain_data_;
295 296
296 // The actual domain data that we parse on startup. 297 // The actual domain data that we parse on startup.
297 static const char kDomainData[]; 298 static const char kDomainData[];
298 299
299 DISALLOW_COPY_AND_ASSIGN(RegistryControlledDomainService); 300 DISALLOW_COPY_AND_ASSIGN(RegistryControlledDomainService);
300 }; 301 };
301 302
302 } // namespace net 303 } // namespace net
303 304
304 #endif // NET_BASE_REGISTRY_CONTROLLED_DOMAIN_H_ 305 #endif // NET_BASE_REGISTRY_CONTROLLED_DOMAIN_H_
OLDNEW
« no previous file with comments | « net/base/net_util.cc ('k') | net/base/registry_controlled_domain.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698