OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "net/base/host_resolver_impl.h" | 5 #include "net/base/host_resolver_impl.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <Winsock2.h> | 8 #include <Winsock2.h> |
9 #elif defined(OS_POSIX) | 9 #elif defined(OS_POSIX) |
10 #include <netdb.h> | 10 #include <netdb.h> |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 AddressFamily address_family, | 168 AddressFamily address_family, |
169 HostResolverFlags host_resolver_flags, | 169 HostResolverFlags host_resolver_flags, |
170 AddressList* addr_list, | 170 AddressList* addr_list, |
171 int* os_error) OVERRIDE { | 171 int* os_error) OVERRIDE { |
172 return SystemHostResolverProc(hostname, | 172 return SystemHostResolverProc(hostname, |
173 address_family, | 173 address_family, |
174 host_resolver_flags, | 174 host_resolver_flags, |
175 addr_list, | 175 addr_list, |
176 os_error); | 176 os_error); |
177 } | 177 } |
| 178 |
| 179 private: |
| 180 virtual ~CallSystemHostResolverProc() {} |
178 }; | 181 }; |
179 | 182 |
180 // Extra parameters to attach to the NetLog when the resolve failed. | 183 // Extra parameters to attach to the NetLog when the resolve failed. |
181 class ProcTaskFailedParams : public NetLog::EventParameters { | 184 class ProcTaskFailedParams : public NetLog::EventParameters { |
182 public: | 185 public: |
183 ProcTaskFailedParams(uint32 attempt_number, int net_error, int os_error) | 186 ProcTaskFailedParams(uint32 attempt_number, int net_error, int os_error) |
184 : attempt_number_(attempt_number), | 187 : attempt_number_(attempt_number), |
185 net_error_(net_error), | 188 net_error_(net_error), |
186 os_error_(os_error) { | 189 os_error_(os_error) { |
187 } | 190 } |
(...skipping 22 matching lines...) Expand all Loading... |
210 0); // Arguments (unused). | 213 0); // Arguments (unused). |
211 dict->SetString("os_error_string", WideToUTF8(error_string)); | 214 dict->SetString("os_error_string", WideToUTF8(error_string)); |
212 LocalFree(error_string); | 215 LocalFree(error_string); |
213 #endif | 216 #endif |
214 } | 217 } |
215 | 218 |
216 return dict; | 219 return dict; |
217 } | 220 } |
218 | 221 |
219 private: | 222 private: |
| 223 virtual ~ProcTaskFailedParams() {} |
| 224 |
220 const uint32 attempt_number_; | 225 const uint32 attempt_number_; |
221 const int net_error_; | 226 const int net_error_; |
222 const int os_error_; | 227 const int os_error_; |
223 }; | 228 }; |
224 | 229 |
225 // Extra parameters to attach to the NetLog when the DnsTask failed. | 230 // Extra parameters to attach to the NetLog when the DnsTask failed. |
226 class DnsTaskFailedParams : public NetLog::EventParameters { | 231 class DnsTaskFailedParams : public NetLog::EventParameters { |
227 public: | 232 public: |
228 DnsTaskFailedParams(int net_error, int dns_error) | 233 DnsTaskFailedParams(int net_error, int dns_error) |
229 : net_error_(net_error), dns_error_(dns_error) { | 234 : net_error_(net_error), dns_error_(dns_error) { |
230 } | 235 } |
231 | 236 |
232 virtual Value* ToValue() const OVERRIDE { | 237 virtual Value* ToValue() const OVERRIDE { |
233 DictionaryValue* dict = new DictionaryValue(); | 238 DictionaryValue* dict = new DictionaryValue(); |
234 dict->SetInteger("net_error", net_error_); | 239 dict->SetInteger("net_error", net_error_); |
235 if (dns_error_) | 240 if (dns_error_) |
236 dict->SetInteger("dns_error", dns_error_); | 241 dict->SetInteger("dns_error", dns_error_); |
237 return dict; | 242 return dict; |
238 } | 243 } |
239 | 244 |
240 private: | 245 private: |
| 246 virtual ~DnsTaskFailedParams() {} |
| 247 |
241 const int net_error_; | 248 const int net_error_; |
242 const int dns_error_; | 249 const int dns_error_; |
243 }; | 250 }; |
244 | 251 |
245 // Parameters representing the information in a RequestInfo object, along with | 252 // Parameters representing the information in a RequestInfo object, along with |
246 // the associated NetLog::Source. | 253 // the associated NetLog::Source. |
247 class RequestInfoParameters : public NetLog::EventParameters { | 254 class RequestInfoParameters : public NetLog::EventParameters { |
248 public: | 255 public: |
249 RequestInfoParameters(const HostResolver::RequestInfo& info, | 256 RequestInfoParameters(const HostResolver::RequestInfo& info, |
250 const NetLog::Source& source) | 257 const NetLog::Source& source) |
251 : info_(info), source_(source) {} | 258 : info_(info), source_(source) {} |
252 | 259 |
253 virtual Value* ToValue() const OVERRIDE { | 260 virtual Value* ToValue() const OVERRIDE { |
254 DictionaryValue* dict = new DictionaryValue(); | 261 DictionaryValue* dict = new DictionaryValue(); |
255 dict->SetString("host", info_.host_port_pair().ToString()); | 262 dict->SetString("host", info_.host_port_pair().ToString()); |
256 dict->SetInteger("address_family", | 263 dict->SetInteger("address_family", |
257 static_cast<int>(info_.address_family())); | 264 static_cast<int>(info_.address_family())); |
258 dict->SetBoolean("allow_cached_response", info_.allow_cached_response()); | 265 dict->SetBoolean("allow_cached_response", info_.allow_cached_response()); |
259 dict->SetBoolean("is_speculative", info_.is_speculative()); | 266 dict->SetBoolean("is_speculative", info_.is_speculative()); |
260 dict->SetInteger("priority", info_.priority()); | 267 dict->SetInteger("priority", info_.priority()); |
261 | 268 |
262 if (source_.is_valid()) | 269 if (source_.is_valid()) |
263 dict->Set("source_dependency", source_.ToValue()); | 270 dict->Set("source_dependency", source_.ToValue()); |
264 | 271 |
265 return dict; | 272 return dict; |
266 } | 273 } |
267 | 274 |
268 private: | 275 private: |
| 276 virtual ~RequestInfoParameters() {} |
| 277 |
269 const HostResolver::RequestInfo info_; | 278 const HostResolver::RequestInfo info_; |
270 const NetLog::Source source_; | 279 const NetLog::Source source_; |
271 }; | 280 }; |
272 | 281 |
273 // Parameters associated with the creation of a HostResolverImpl::Job. | 282 // Parameters associated with the creation of a HostResolverImpl::Job. |
274 class JobCreationParameters : public NetLog::EventParameters { | 283 class JobCreationParameters : public NetLog::EventParameters { |
275 public: | 284 public: |
276 JobCreationParameters(const std::string& host, | 285 JobCreationParameters(const std::string& host, |
277 const NetLog::Source& source) | 286 const NetLog::Source& source) |
278 : host_(host), source_(source) {} | 287 : host_(host), source_(source) {} |
279 | 288 |
280 virtual Value* ToValue() const OVERRIDE { | 289 virtual Value* ToValue() const OVERRIDE { |
281 DictionaryValue* dict = new DictionaryValue(); | 290 DictionaryValue* dict = new DictionaryValue(); |
282 dict->SetString("host", host_); | 291 dict->SetString("host", host_); |
283 dict->Set("source_dependency", source_.ToValue()); | 292 dict->Set("source_dependency", source_.ToValue()); |
284 return dict; | 293 return dict; |
285 } | 294 } |
286 | 295 |
287 private: | 296 private: |
| 297 virtual ~JobCreationParameters() {} |
| 298 |
288 const std::string host_; | 299 const std::string host_; |
289 const NetLog::Source source_; | 300 const NetLog::Source source_; |
290 }; | 301 }; |
291 | 302 |
292 // Parameters of the HOST_RESOLVER_IMPL_JOB_ATTACH/DETACH event. | 303 // Parameters of the HOST_RESOLVER_IMPL_JOB_ATTACH/DETACH event. |
293 class JobAttachParameters : public NetLog::EventParameters { | 304 class JobAttachParameters : public NetLog::EventParameters { |
294 public: | 305 public: |
295 JobAttachParameters(const NetLog::Source& source, | 306 JobAttachParameters(const NetLog::Source& source, |
296 RequestPriority priority) | 307 RequestPriority priority) |
297 : source_(source), priority_(priority) {} | 308 : source_(source), priority_(priority) {} |
298 | 309 |
299 virtual Value* ToValue() const OVERRIDE { | 310 virtual Value* ToValue() const OVERRIDE { |
300 DictionaryValue* dict = new DictionaryValue(); | 311 DictionaryValue* dict = new DictionaryValue(); |
301 dict->Set("source_dependency", source_.ToValue()); | 312 dict->Set("source_dependency", source_.ToValue()); |
302 dict->SetInteger("priority", priority_); | 313 dict->SetInteger("priority", priority_); |
303 return dict; | 314 return dict; |
304 } | 315 } |
305 | 316 |
306 private: | 317 private: |
| 318 virtual ~JobAttachParameters() {} |
| 319 |
307 const NetLog::Source source_; | 320 const NetLog::Source source_; |
308 const RequestPriority priority_; | 321 const RequestPriority priority_; |
309 }; | 322 }; |
310 | 323 |
311 // Parameters of the DNS_CONFIG_CHANGED event. | 324 // Parameters of the DNS_CONFIG_CHANGED event. |
312 class DnsConfigParameters : public NetLog::EventParameters { | 325 class DnsConfigParameters : public NetLog::EventParameters { |
313 public: | 326 public: |
314 explicit DnsConfigParameters(const DnsConfig& config) | 327 explicit DnsConfigParameters(const DnsConfig& config) |
315 : num_hosts_(config.hosts.size()) { | 328 : num_hosts_(config.hosts.size()) { |
316 config_.CopyIgnoreHosts(config); | 329 config_.CopyIgnoreHosts(config); |
317 } | 330 } |
318 | 331 |
319 virtual Value* ToValue() const OVERRIDE { | 332 virtual Value* ToValue() const OVERRIDE { |
320 Value* value = config_.ToValue(); | 333 Value* value = config_.ToValue(); |
321 if (!value) | 334 if (!value) |
322 return NULL; | 335 return NULL; |
323 DictionaryValue* dict; | 336 DictionaryValue* dict; |
324 if (value->GetAsDictionary(&dict)) | 337 if (value->GetAsDictionary(&dict)) |
325 dict->SetInteger("num_hosts", num_hosts_); | 338 dict->SetInteger("num_hosts", num_hosts_); |
326 return value; | 339 return value; |
327 } | 340 } |
328 | 341 |
329 private: | 342 private: |
| 343 virtual ~DnsConfigParameters() {} |
| 344 |
330 DnsConfig config_; // Does not include DnsHosts to save memory and work. | 345 DnsConfig config_; // Does not include DnsHosts to save memory and work. |
331 const size_t num_hosts_; | 346 const size_t num_hosts_; |
332 }; | 347 }; |
333 | 348 |
334 // The logging routines are defined here because some requests are resolved | 349 // The logging routines are defined here because some requests are resolved |
335 // without a Request object. | 350 // without a Request object. |
336 | 351 |
337 // Logs when a request has just been started. | 352 // Logs when a request has just been started. |
338 void LogStartRequest(const BoundNetLog& source_net_log, | 353 void LogStartRequest(const BoundNetLog& source_net_log, |
339 const BoundNetLog& request_net_log, | 354 const BoundNetLog& request_net_log, |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 DCHECK(origin_loop_->BelongsToCurrentThread()); | 645 DCHECK(origin_loop_->BelongsToCurrentThread()); |
631 return callback_.is_null(); | 646 return callback_.is_null(); |
632 } | 647 } |
633 | 648 |
634 bool was_completed() const { | 649 bool was_completed() const { |
635 DCHECK(origin_loop_->BelongsToCurrentThread()); | 650 DCHECK(origin_loop_->BelongsToCurrentThread()); |
636 return completed_attempt_number_ > 0; | 651 return completed_attempt_number_ > 0; |
637 } | 652 } |
638 | 653 |
639 private: | 654 private: |
| 655 friend base::RefCountedThreadSafe<ProcTask>; |
| 656 virtual ~ProcTask() {} |
| 657 |
640 void StartLookupAttempt() { | 658 void StartLookupAttempt() { |
641 DCHECK(origin_loop_->BelongsToCurrentThread()); | 659 DCHECK(origin_loop_->BelongsToCurrentThread()); |
642 base::TimeTicks start_time = base::TimeTicks::Now(); | 660 base::TimeTicks start_time = base::TimeTicks::Now(); |
643 ++attempt_number_; | 661 ++attempt_number_; |
644 // Dispatch the lookup attempt to a worker thread. | 662 // Dispatch the lookup attempt to a worker thread. |
645 if (!base::WorkerPool::PostTask( | 663 if (!base::WorkerPool::PostTask( |
646 FROM_HERE, | 664 FROM_HERE, |
647 base::Bind(&ProcTask::DoLookup, this, start_time, attempt_number_), | 665 base::Bind(&ProcTask::DoLookup, this, start_time, attempt_number_), |
648 true)) { | 666 true)) { |
649 NOTREACHED(); | 667 NOTREACHED(); |
(...skipping 1303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1953 | 1971 |
1954 if (self && dns_config.IsValid()) | 1972 if (self && dns_config.IsValid()) |
1955 TryServingAllJobsFromHosts(); | 1973 TryServingAllJobsFromHosts(); |
1956 } | 1974 } |
1957 | 1975 |
1958 bool HostResolverImpl::HaveDnsConfig() const { | 1976 bool HostResolverImpl::HaveDnsConfig() const { |
1959 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL); | 1977 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL); |
1960 } | 1978 } |
1961 | 1979 |
1962 } // namespace net | 1980 } // namespace net |
OLD | NEW |