OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // NB: Modelled after Mozilla's code (originally written by Pamela Greene, | 5 // NB: Modelled after Mozilla's code (originally written by Pamela Greene, |
6 // later modified by others), but almost entirely rewritten for Chrome. | 6 // later modified by others), but almost entirely rewritten for Chrome. |
7 // (netwerk/dns/src/nsEffectiveTLDService.cpp) | 7 // (netwerk/dns/src/nsEffectiveTLDService.cpp) |
8 /* ***** BEGIN LICENSE BLOCK ***** | 8 /* ***** BEGIN LICENSE BLOCK ***** |
9 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 9 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
10 * | 10 * |
(...skipping 28 matching lines...) Expand all Loading... |
39 * decision by deleting the provisions above and replace them with the notice | 39 * decision by deleting the provisions above and replace them with the notice |
40 * and other provisions required by the GPL or the LGPL. If you do not delete | 40 * and other provisions required by the GPL or the LGPL. If you do not delete |
41 * the provisions above, a recipient may use your version of this file under | 41 * the provisions above, a recipient may use your version of this file under |
42 * the terms of any one of the MPL, the GPL or the LGPL. | 42 * the terms of any one of the MPL, the GPL or the LGPL. |
43 * | 43 * |
44 * ***** END LICENSE BLOCK ***** */ | 44 * ***** END LICENSE BLOCK ***** */ |
45 | 45 |
46 #include "net/base/registry_controlled_domain.h" | 46 #include "net/base/registry_controlled_domain.h" |
47 | 47 |
48 #include "base/logging.h" | 48 #include "base/logging.h" |
49 #include "base/memory/singleton.h" | |
50 #include "base/string_util.h" | 49 #include "base/string_util.h" |
51 #include "base/utf_string_conversions.h" | 50 #include "base/utf_string_conversions.h" |
52 #include "googleurl/src/gurl.h" | 51 #include "googleurl/src/gurl.h" |
53 #include "googleurl/src/url_parse.h" | 52 #include "googleurl/src/url_parse.h" |
54 #include "net/base/net_module.h" | 53 #include "net/base/net_module.h" |
55 #include "net/base/net_util.h" | 54 #include "net/base/net_util.h" |
56 | 55 |
57 #include "effective_tld_names.cc" | 56 #include "effective_tld_names.cc" |
58 | 57 |
59 namespace net { | 58 namespace net { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 if (canon_host.empty()) | 135 if (canon_host.empty()) |
137 return std::string::npos; | 136 return std::string::npos; |
138 if (host_info.IsIPAddress()) | 137 if (host_info.IsIPAddress()) |
139 return 0; | 138 return 0; |
140 return GetRegistryLengthImpl(canon_host, allow_unknown_registries); | 139 return GetRegistryLengthImpl(canon_host, allow_unknown_registries); |
141 } | 140 } |
142 | 141 |
143 // static | 142 // static |
144 void RegistryControlledDomainService::UseFindDomainFunction( | 143 void RegistryControlledDomainService::UseFindDomainFunction( |
145 FindDomainPtr function) { | 144 FindDomainPtr function) { |
146 if (function) { | 145 find_domain_function_ = function ? function : Perfect_Hash::FindDomain; |
147 find_domain_function_ = function; | |
148 } else { | |
149 find_domain_function_ = Perfect_Hash::FindDomain; | |
150 } | |
151 } | 146 } |
152 | 147 |
153 // static | 148 // static |
154 std::string RegistryControlledDomainService::GetDomainAndRegistryImpl( | 149 std::string RegistryControlledDomainService::GetDomainAndRegistryImpl( |
155 const std::string& host) { | 150 const std::string& host) { |
156 DCHECK(!host.empty()); | 151 DCHECK(!host.empty()); |
157 | 152 |
158 // Find the length of the registry for this host. | 153 // Find the length of the registry for this host. |
159 const size_t registry_length = GetRegistryLengthImpl(host, true); | 154 const size_t registry_length = GetRegistryLengthImpl(host, true); |
160 if ((registry_length == std::string::npos) || (registry_length == 0)) | 155 if ((registry_length == std::string::npos) || (registry_length == 0)) |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 next_dot = host.find('.', curr_start); | 245 next_dot = host.find('.', curr_start); |
251 } | 246 } |
252 | 247 |
253 // No rule found in the registry. curr_start now points to the first | 248 // No rule found in the registry. curr_start now points to the first |
254 // character of the last subcomponent of the host, so if we allow unknown | 249 // character of the last subcomponent of the host, so if we allow unknown |
255 // registries, return the length of this subcomponent. | 250 // registries, return the length of this subcomponent. |
256 return allow_unknown_registries ? (host.length() - curr_start) : 0; | 251 return allow_unknown_registries ? (host.length() - curr_start) : 0; |
257 } | 252 } |
258 | 253 |
259 } // namespace net | 254 } // namespace net |
OLD | NEW |