| 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/dns/host_resolver_impl.h" | 5 #include "net/dns/host_resolver_impl.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
| 8 #include <Winsock2.h> | 10 #include <Winsock2.h> |
| 9 #elif defined(OS_POSIX) | 11 #elif defined(OS_POSIX) |
| 10 #include <netdb.h> | 12 #include <netdb.h> |
| 11 #endif | 13 #endif |
| 12 | 14 |
| 13 #include <cmath> | 15 #include <cmath> |
| 14 #include <utility> | 16 #include <utility> |
| 15 #include <vector> | 17 #include <vector> |
| 16 | 18 |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 os_error, | 339 os_error, |
| 338 0, // Use default language. | 340 0, // Use default language. |
| 339 (LPWSTR)&error_string, | 341 (LPWSTR)&error_string, |
| 340 0, // Buffer size. | 342 0, // Buffer size. |
| 341 0); // Arguments (unused). | 343 0); // Arguments (unused). |
| 342 dict->SetString("os_error_string", base::WideToUTF8(error_string)); | 344 dict->SetString("os_error_string", base::WideToUTF8(error_string)); |
| 343 LocalFree(error_string); | 345 LocalFree(error_string); |
| 344 #endif | 346 #endif |
| 345 } | 347 } |
| 346 | 348 |
| 347 return dict.Pass(); | 349 return std::move(dict); |
| 348 } | 350 } |
| 349 | 351 |
| 350 // Creates NetLog parameters when the DnsTask failed. | 352 // Creates NetLog parameters when the DnsTask failed. |
| 351 scoped_ptr<base::Value> NetLogDnsTaskFailedCallback( | 353 scoped_ptr<base::Value> NetLogDnsTaskFailedCallback( |
| 352 int net_error, | 354 int net_error, |
| 353 int dns_error, | 355 int dns_error, |
| 354 NetLogCaptureMode /* capture_mode */) { | 356 NetLogCaptureMode /* capture_mode */) { |
| 355 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 357 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 356 dict->SetInteger("net_error", net_error); | 358 dict->SetInteger("net_error", net_error); |
| 357 if (dns_error) | 359 if (dns_error) |
| 358 dict->SetInteger("dns_error", dns_error); | 360 dict->SetInteger("dns_error", dns_error); |
| 359 return dict.Pass(); | 361 return std::move(dict); |
| 360 }; | 362 }; |
| 361 | 363 |
| 362 // Creates NetLog parameters containing the information in a RequestInfo object, | 364 // Creates NetLog parameters containing the information in a RequestInfo object, |
| 363 // along with the associated NetLog::Source. | 365 // along with the associated NetLog::Source. |
| 364 scoped_ptr<base::Value> NetLogRequestInfoCallback( | 366 scoped_ptr<base::Value> NetLogRequestInfoCallback( |
| 365 const HostResolver::RequestInfo* info, | 367 const HostResolver::RequestInfo* info, |
| 366 NetLogCaptureMode /* capture_mode */) { | 368 NetLogCaptureMode /* capture_mode */) { |
| 367 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 369 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 368 | 370 |
| 369 dict->SetString("host", info->host_port_pair().ToString()); | 371 dict->SetString("host", info->host_port_pair().ToString()); |
| 370 dict->SetInteger("address_family", | 372 dict->SetInteger("address_family", |
| 371 static_cast<int>(info->address_family())); | 373 static_cast<int>(info->address_family())); |
| 372 dict->SetBoolean("allow_cached_response", info->allow_cached_response()); | 374 dict->SetBoolean("allow_cached_response", info->allow_cached_response()); |
| 373 dict->SetBoolean("is_speculative", info->is_speculative()); | 375 dict->SetBoolean("is_speculative", info->is_speculative()); |
| 374 return dict.Pass(); | 376 return std::move(dict); |
| 375 } | 377 } |
| 376 | 378 |
| 377 // Creates NetLog parameters for the creation of a HostResolverImpl::Job. | 379 // Creates NetLog parameters for the creation of a HostResolverImpl::Job. |
| 378 scoped_ptr<base::Value> NetLogJobCreationCallback( | 380 scoped_ptr<base::Value> NetLogJobCreationCallback( |
| 379 const NetLog::Source& source, | 381 const NetLog::Source& source, |
| 380 const std::string* host, | 382 const std::string* host, |
| 381 NetLogCaptureMode /* capture_mode */) { | 383 NetLogCaptureMode /* capture_mode */) { |
| 382 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 384 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 383 source.AddToEventParameters(dict.get()); | 385 source.AddToEventParameters(dict.get()); |
| 384 dict->SetString("host", *host); | 386 dict->SetString("host", *host); |
| 385 return dict.Pass(); | 387 return std::move(dict); |
| 386 } | 388 } |
| 387 | 389 |
| 388 // Creates NetLog parameters for HOST_RESOLVER_IMPL_JOB_ATTACH/DETACH events. | 390 // Creates NetLog parameters for HOST_RESOLVER_IMPL_JOB_ATTACH/DETACH events. |
| 389 scoped_ptr<base::Value> NetLogJobAttachCallback( | 391 scoped_ptr<base::Value> NetLogJobAttachCallback( |
| 390 const NetLog::Source& source, | 392 const NetLog::Source& source, |
| 391 RequestPriority priority, | 393 RequestPriority priority, |
| 392 NetLogCaptureMode /* capture_mode */) { | 394 NetLogCaptureMode /* capture_mode */) { |
| 393 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 395 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 394 source.AddToEventParameters(dict.get()); | 396 source.AddToEventParameters(dict.get()); |
| 395 dict->SetString("priority", RequestPriorityToString(priority)); | 397 dict->SetString("priority", RequestPriorityToString(priority)); |
| 396 return dict.Pass(); | 398 return std::move(dict); |
| 397 } | 399 } |
| 398 | 400 |
| 399 // Creates NetLog parameters for the DNS_CONFIG_CHANGED event. | 401 // Creates NetLog parameters for the DNS_CONFIG_CHANGED event. |
| 400 scoped_ptr<base::Value> NetLogDnsConfigCallback( | 402 scoped_ptr<base::Value> NetLogDnsConfigCallback( |
| 401 const DnsConfig* config, | 403 const DnsConfig* config, |
| 402 NetLogCaptureMode /* capture_mode */) { | 404 NetLogCaptureMode /* capture_mode */) { |
| 403 return make_scoped_ptr(config->ToValue()); | 405 return make_scoped_ptr(config->ToValue()); |
| 404 } | 406 } |
| 405 | 407 |
| 406 scoped_ptr<base::Value> NetLogIPv6AvailableCallback( | 408 scoped_ptr<base::Value> NetLogIPv6AvailableCallback( |
| 407 bool ipv6_available, | 409 bool ipv6_available, |
| 408 bool cached, | 410 bool cached, |
| 409 NetLogCaptureMode /* capture_mode */) { | 411 NetLogCaptureMode /* capture_mode */) { |
| 410 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 412 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 411 dict->SetBoolean("ipv6_available", ipv6_available); | 413 dict->SetBoolean("ipv6_available", ipv6_available); |
| 412 dict->SetBoolean("cached", cached); | 414 dict->SetBoolean("cached", cached); |
| 413 return dict.Pass(); | 415 return std::move(dict); |
| 414 } | 416 } |
| 415 | 417 |
| 416 // The logging routines are defined here because some requests are resolved | 418 // The logging routines are defined here because some requests are resolved |
| 417 // without a Request object. | 419 // without a Request object. |
| 418 | 420 |
| 419 // Logs when a request has just been started. | 421 // Logs when a request has just been started. |
| 420 void LogStartRequest(const BoundNetLog& source_net_log, | 422 void LogStartRequest(const BoundNetLog& source_net_log, |
| 421 const HostResolver::RequestInfo& info) { | 423 const HostResolver::RequestInfo& info) { |
| 422 source_net_log.BeginEvent( | 424 source_net_log.BeginEvent( |
| 423 NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, | 425 NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, |
| (...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1330 req->source_net_log().source(), | 1332 req->source_net_log().source(), |
| 1331 priority())); | 1333 priority())); |
| 1332 | 1334 |
| 1333 // TODO(szym): Check if this is still needed. | 1335 // TODO(szym): Check if this is still needed. |
| 1334 if (!req->info().is_speculative()) { | 1336 if (!req->info().is_speculative()) { |
| 1335 had_non_speculative_request_ = true; | 1337 had_non_speculative_request_ = true; |
| 1336 if (proc_task_.get()) | 1338 if (proc_task_.get()) |
| 1337 proc_task_->set_had_non_speculative_request(); | 1339 proc_task_->set_had_non_speculative_request(); |
| 1338 } | 1340 } |
| 1339 | 1341 |
| 1340 requests_.push_back(req.Pass()); | 1342 requests_.push_back(std::move(req)); |
| 1341 | 1343 |
| 1342 UpdatePriority(); | 1344 UpdatePriority(); |
| 1343 } | 1345 } |
| 1344 | 1346 |
| 1345 // Marks |req| as cancelled. If it was the last active Request, also finishes | 1347 // Marks |req| as cancelled. If it was the last active Request, also finishes |
| 1346 // this Job, marking it as cancelled, and deletes it. | 1348 // this Job, marking it as cancelled, and deletes it. |
| 1347 void CancelRequest(Request* req) { | 1349 void CancelRequest(Request* req) { |
| 1348 DCHECK_EQ(key_.hostname, req->info().hostname()); | 1350 DCHECK_EQ(key_.hostname, req->info().hostname()); |
| 1349 DCHECK(!req->was_canceled()); | 1351 DCHECK(!req->was_canceled()); |
| 1350 | 1352 |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1948 } else { | 1950 } else { |
| 1949 job = jobit->second; | 1951 job = jobit->second; |
| 1950 } | 1952 } |
| 1951 | 1953 |
| 1952 // Can't complete synchronously. Create and attach request. | 1954 // Can't complete synchronously. Create and attach request. |
| 1953 scoped_ptr<Request> req(new Request( | 1955 scoped_ptr<Request> req(new Request( |
| 1954 source_net_log, info, priority, callback, addresses)); | 1956 source_net_log, info, priority, callback, addresses)); |
| 1955 if (out_req) | 1957 if (out_req) |
| 1956 *out_req = reinterpret_cast<RequestHandle>(req.get()); | 1958 *out_req = reinterpret_cast<RequestHandle>(req.get()); |
| 1957 | 1959 |
| 1958 job->AddRequest(req.Pass()); | 1960 job->AddRequest(std::move(req)); |
| 1959 // Completion happens during Job::CompleteRequests(). | 1961 // Completion happens during Job::CompleteRequests(). |
| 1960 return ERR_IO_PENDING; | 1962 return ERR_IO_PENDING; |
| 1961 } | 1963 } |
| 1962 | 1964 |
| 1963 int HostResolverImpl::ResolveHelper(const Key& key, | 1965 int HostResolverImpl::ResolveHelper(const Key& key, |
| 1964 const RequestInfo& info, | 1966 const RequestInfo& info, |
| 1965 const IPAddressNumber* ip_number, | 1967 const IPAddressNumber* ip_number, |
| 1966 AddressList* addresses, | 1968 AddressList* addresses, |
| 1967 const BoundNetLog& source_net_log) { | 1969 const BoundNetLog& source_net_log) { |
| 1968 // The result of |getaddrinfo| for empty hosts is inconsistent across systems. | 1970 // The result of |getaddrinfo| for empty hosts is inconsistent across systems. |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2411 AbortDnsTasks(); | 2413 AbortDnsTasks(); |
| 2412 | 2414 |
| 2413 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", false); | 2415 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", false); |
| 2414 UMA_HISTOGRAM_SPARSE_SLOWLY("AsyncDNS.DnsClientDisabledReason", | 2416 UMA_HISTOGRAM_SPARSE_SLOWLY("AsyncDNS.DnsClientDisabledReason", |
| 2415 std::abs(net_error)); | 2417 std::abs(net_error)); |
| 2416 } | 2418 } |
| 2417 | 2419 |
| 2418 void HostResolverImpl::SetDnsClient(scoped_ptr<DnsClient> dns_client) { | 2420 void HostResolverImpl::SetDnsClient(scoped_ptr<DnsClient> dns_client) { |
| 2419 // DnsClient and config must be updated before aborting DnsTasks, since doing | 2421 // DnsClient and config must be updated before aborting DnsTasks, since doing |
| 2420 // so may start new jobs. | 2422 // so may start new jobs. |
| 2421 dns_client_ = dns_client.Pass(); | 2423 dns_client_ = std::move(dns_client); |
| 2422 if (dns_client_ && !dns_client_->GetConfig() && | 2424 if (dns_client_ && !dns_client_->GetConfig() && |
| 2423 num_dns_failures_ < kMaximumDnsFailures) { | 2425 num_dns_failures_ < kMaximumDnsFailures) { |
| 2424 DnsConfig dns_config; | 2426 DnsConfig dns_config; |
| 2425 NetworkChangeNotifier::GetDnsConfig(&dns_config); | 2427 NetworkChangeNotifier::GetDnsConfig(&dns_config); |
| 2426 dns_client_->SetConfig(dns_config); | 2428 dns_client_->SetConfig(dns_config); |
| 2427 num_dns_failures_ = 0; | 2429 num_dns_failures_ = 0; |
| 2428 if (dns_client_->GetConfig()) | 2430 if (dns_client_->GetConfig()) |
| 2429 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); | 2431 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); |
| 2430 } | 2432 } |
| 2431 | 2433 |
| 2432 AbortDnsTasks(); | 2434 AbortDnsTasks(); |
| 2433 } | 2435 } |
| 2434 | 2436 |
| 2435 } // namespace net | 2437 } // namespace net |
| OLD | NEW |