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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 #include "base/string_util.h" | 44 #include "base/string_util.h" |
45 #include "googleurl/src/gurl.h" | 45 #include "googleurl/src/gurl.h" |
46 #include "googleurl/src/url_parse.h" | 46 #include "googleurl/src/url_parse.h" |
47 #include "net/base/net_module.h" | 47 #include "net/base/net_module.h" |
48 #include "net/base/net_util.h" | 48 #include "net/base/net_util.h" |
49 | 49 |
50 #include "effective_tld_names.cc" | 50 #include "effective_tld_names.cc" |
51 | 51 |
52 namespace net { | 52 namespace net { |
53 | 53 |
54 static const int kExceptionRule = 1; | 54 namespace { |
55 static const int kWildcardRule = 2; | |
56 | 55 |
57 RegistryControlledDomainService::RegistryControlledDomainService() | 56 const int kExceptionRule = 1; |
58 : find_domain_function_(Perfect_Hash::FindDomain) { | 57 const int kWildcardRule = 2; |
59 } | 58 |
| 59 RegistryControlledDomainService* test_instance_; |
| 60 |
| 61 } // namespace |
60 | 62 |
61 // static | 63 // static |
62 std::string RegistryControlledDomainService::GetDomainAndRegistry( | 64 std::string RegistryControlledDomainService::GetDomainAndRegistry( |
63 const GURL& gurl) { | 65 const GURL& gurl) { |
64 const url_parse::Component host = | 66 const url_parse::Component host = |
65 gurl.parsed_for_possibly_invalid_spec().host; | 67 gurl.parsed_for_possibly_invalid_spec().host; |
66 if ((host.len <= 0) || gurl.HostIsIPAddress()) | 68 if ((host.len <= 0) || gurl.HostIsIPAddress()) |
67 return std::string(); | 69 return std::string(); |
68 return GetDomainAndRegistryImpl(std::string( | 70 return GetDomainAndRegistryImpl(std::string( |
69 gurl.possibly_invalid_spec().data() + host.begin, host.len)); | 71 gurl.possibly_invalid_spec().data() + host.begin, host.len)); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 const std::string canon_host(net::CanonicalizeHost(host, &host_info)); | 150 const std::string canon_host(net::CanonicalizeHost(host, &host_info)); |
149 if (canon_host.empty()) | 151 if (canon_host.empty()) |
150 return std::string::npos; | 152 return std::string::npos; |
151 if (host_info.IsIPAddress()) | 153 if (host_info.IsIPAddress()) |
152 return 0; | 154 return 0; |
153 return GetInstance()->GetRegistryLengthImpl(canon_host, | 155 return GetInstance()->GetRegistryLengthImpl(canon_host, |
154 allow_unknown_registries); | 156 allow_unknown_registries); |
155 } | 157 } |
156 | 158 |
157 // static | 159 // static |
| 160 RegistryControlledDomainService* RegistryControlledDomainService::GetInstance() |
| 161 { |
| 162 if (test_instance_) |
| 163 return test_instance_; |
| 164 |
| 165 return Singleton<RegistryControlledDomainService>::get(); |
| 166 } |
| 167 |
| 168 RegistryControlledDomainService::RegistryControlledDomainService() |
| 169 : find_domain_function_(Perfect_Hash::FindDomain) { |
| 170 } |
| 171 |
| 172 // static |
| 173 RegistryControlledDomainService* RegistryControlledDomainService::SetInstance( |
| 174 RegistryControlledDomainService* instance) { |
| 175 RegistryControlledDomainService* old_instance = test_instance_; |
| 176 test_instance_ = instance; |
| 177 return old_instance; |
| 178 } |
| 179 |
| 180 // static |
| 181 void RegistryControlledDomainService::UseFindDomainFunction( |
| 182 FindDomainPtr function) { |
| 183 RegistryControlledDomainService* instance = GetInstance(); |
| 184 instance->find_domain_function_ = function; |
| 185 } |
| 186 |
| 187 // static |
158 std::string RegistryControlledDomainService::GetDomainAndRegistryImpl( | 188 std::string RegistryControlledDomainService::GetDomainAndRegistryImpl( |
159 const std::string& host) { | 189 const std::string& host) { |
160 DCHECK(!host.empty()); | 190 DCHECK(!host.empty()); |
161 | 191 |
162 // Find the length of the registry for this host. | 192 // Find the length of the registry for this host. |
163 const size_t registry_length = | 193 const size_t registry_length = |
164 GetInstance()->GetRegistryLengthImpl(host, true); | 194 GetInstance()->GetRegistryLengthImpl(host, true); |
165 if ((registry_length == std::string::npos) || (registry_length == 0)) | 195 if ((registry_length == std::string::npos) || (registry_length == 0)) |
166 return std::string(); // No registry. | 196 return std::string(); // No registry. |
167 // The "2" in this next line is 1 for the dot, plus a 1-char minimum preceding | 197 // The "2" in this next line is 1 for the dot, plus a 1-char minimum preceding |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 curr_start = next_dot + 1; | 284 curr_start = next_dot + 1; |
255 next_dot = host.find('.', curr_start); | 285 next_dot = host.find('.', curr_start); |
256 } | 286 } |
257 | 287 |
258 // No rule found in the registry. curr_start now points to the first | 288 // No rule found in the registry. curr_start now points to the first |
259 // character of the last subcomponent of the host, so if we allow unknown | 289 // character of the last subcomponent of the host, so if we allow unknown |
260 // registries, return the length of this subcomponent. | 290 // registries, return the length of this subcomponent. |
261 return allow_unknown_registries ? (host.length() - curr_start) : 0; | 291 return allow_unknown_registries ? (host.length() - curr_start) : 0; |
262 } | 292 } |
263 | 293 |
264 static RegistryControlledDomainService* test_instance_; | |
265 | |
266 // static | |
267 RegistryControlledDomainService* RegistryControlledDomainService::SetInstance( | |
268 RegistryControlledDomainService* instance) { | |
269 RegistryControlledDomainService* old_instance = test_instance_; | |
270 test_instance_ = instance; | |
271 return old_instance; | |
272 } | |
273 | |
274 // static | |
275 RegistryControlledDomainService* RegistryControlledDomainService::GetInstance() | |
276 { | |
277 if (test_instance_) | |
278 return test_instance_; | |
279 | |
280 return Singleton<RegistryControlledDomainService>::get(); | |
281 } | |
282 | |
283 // static | |
284 void RegistryControlledDomainService::UseFindDomainFunction( | |
285 FindDomainPtr function) { | |
286 RegistryControlledDomainService* instance = GetInstance(); | |
287 instance->find_domain_function_ = function; | |
288 } | |
289 | |
290 } // namespace net | 294 } // namespace net |
OLD | NEW |