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

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

Issue 8226007: WORK_IN_PROGRESS: Do effective TLD lookups using a suffix trie (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 9 years, 2 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 | « DEPS ('k') | net/net.gyp » ('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 30 matching lines...) Expand all
41 41
42 #include "base/logging.h" 42 #include "base/logging.h"
43 #include "base/memory/singleton.h" 43 #include "base/memory/singleton.h"
44 #include "base/string_util.h" 44 #include "base/string_util.h"
45 #include "base/utf_string_conversions.h" 45 #include "base/utf_string_conversions.h"
46 #include "googleurl/src/gurl.h" 46 #include "googleurl/src/gurl.h"
47 #include "googleurl/src/url_parse.h" 47 #include "googleurl/src/url_parse.h"
48 #include "net/base/net_module.h" 48 #include "net/base/net_module.h"
49 #include "net/base/net_util.h" 49 #include "net/base/net_util.h"
50 50
51 #if defined(USE_DOMAIN_SUFFIX_TRIE)
52 #include "third_party/domain-registry-provider/src/domain_registry/domain_regist ry.h"
53 #else
51 #include "effective_tld_names.cc" 54 #include "effective_tld_names.cc"
55 #endif
52 56
53 namespace net { 57 namespace net {
54 58
55 namespace { 59 namespace {
56 60
57 const int kExceptionRule = 1; 61 const int kExceptionRule = 1;
58 const int kWildcardRule = 2; 62 const int kWildcardRule = 2;
59 63
60 RegistryControlledDomainService* test_instance_; 64 RegistryControlledDomainService* test_instance_;
61 65
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 139
136 // static 140 // static
137 RegistryControlledDomainService* RegistryControlledDomainService::GetInstance() 141 RegistryControlledDomainService* RegistryControlledDomainService::GetInstance()
138 { 142 {
139 if (test_instance_) 143 if (test_instance_)
140 return test_instance_; 144 return test_instance_;
141 145
142 return Singleton<RegistryControlledDomainService>::get(); 146 return Singleton<RegistryControlledDomainService>::get();
143 } 147 }
144 148
149 #if defined(USE_DOMAIN_SUFFIX_TRIE)
145 RegistryControlledDomainService::RegistryControlledDomainService() 150 RegistryControlledDomainService::RegistryControlledDomainService()
146 : find_domain_function_(Perfect_Hash::FindDomain) { 151 : find_domain_function_(NULL) {
152 InitializeDomainRegistry();
147 } 153 }
154 #else
155 RegistryControlledDomainService::RegistryControlledDomainService()
156 : find_domain_function_() {
157 }
158 #endif
148 159
149 // static 160 // static
150 RegistryControlledDomainService* RegistryControlledDomainService::SetInstance( 161 RegistryControlledDomainService* RegistryControlledDomainService::SetInstance(
151 RegistryControlledDomainService* instance) { 162 RegistryControlledDomainService* instance) {
152 RegistryControlledDomainService* old_instance = test_instance_; 163 RegistryControlledDomainService* old_instance = test_instance_;
153 test_instance_ = instance; 164 test_instance_ = instance;
154 return old_instance; 165 return old_instance;
155 } 166 }
156 167
157 // static 168 // static
(...skipping 24 matching lines...) Expand all
182 193
183 // Move past the dot preceding the registry, and search for the next previous 194 // Move past the dot preceding the registry, and search for the next previous
184 // dot. Return the host from after that dot, or the whole host when there is 195 // dot. Return the host from after that dot, or the whole host when there is
185 // no dot. 196 // no dot.
186 const size_t dot = host.rfind('.', host.length() - registry_length - 2); 197 const size_t dot = host.rfind('.', host.length() - registry_length - 2);
187 if (dot == std::string::npos) 198 if (dot == std::string::npos)
188 return host; 199 return host;
189 return host.substr(dot + 1); 200 return host.substr(dot + 1);
190 } 201 }
191 202
203 #if defined(USE_DOMAIN_SUFFIX_TRIE)
192 size_t RegistryControlledDomainService::GetRegistryLengthImpl( 204 size_t RegistryControlledDomainService::GetRegistryLengthImpl(
193 const std::string& host, 205 const std::string& host,
194 bool allow_unknown_registries) { 206 bool allow_unknown_registries) {
207 DCHECK(!host.empty());
208 if (allow_unknown_registries)
209 return GetRegistryLengthAllowUnknownRegistries(host.c_str());
210 else
211 return ::GetRegistryLength(host.c_str());
212 }
213 #else
214 size_t RegistryControlledDomainService::GetRegistryLengthImpl(
215 const std::string& host,
216 bool allow_unknown_registries) {
195 DCHECK(!host.empty()); 217 DCHECK(!host.empty());
196 218
197 // Skip leading dots. 219 // Skip leading dots.
198 const size_t host_check_begin = host.find_first_not_of('.'); 220 const size_t host_check_begin = host.find_first_not_of('.');
199 if (host_check_begin == std::string::npos) 221 if (host_check_begin == std::string::npos)
200 return 0; // Host is only dots. 222 return 0; // Host is only dots.
201 223
202 // A single trailing dot isn't relevant in this determination, but does need 224 // A single trailing dot isn't relevant in this determination, but does need
203 // to be included in the final returned length. 225 // to be included in the final returned length.
204 size_t host_check_len = host.length(); 226 size_t host_check_len = host.length();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 prev_start = curr_start; 282 prev_start = curr_start;
261 curr_start = next_dot + 1; 283 curr_start = next_dot + 1;
262 next_dot = host.find('.', curr_start); 284 next_dot = host.find('.', curr_start);
263 } 285 }
264 286
265 // No rule found in the registry. curr_start now points to the first 287 // No rule found in the registry. curr_start now points to the first
266 // character of the last subcomponent of the host, so if we allow unknown 288 // character of the last subcomponent of the host, so if we allow unknown
267 // registries, return the length of this subcomponent. 289 // registries, return the length of this subcomponent.
268 return allow_unknown_registries ? (host.length() - curr_start) : 0; 290 return allow_unknown_registries ? (host.length() - curr_start) : 0;
269 } 291 }
292 #endif
270 293
271 } // namespace net 294 } // namespace net
OLDNEW
« no previous file with comments | « DEPS ('k') | net/net.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698