| 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 #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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 NetLog::LogLevel /* log_level */) { | 322 NetLog::LogLevel /* log_level */) { |
| 323 base::DictionaryValue* dict = new base::DictionaryValue(); | 323 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 324 dict->SetInteger("net_error", net_error); | 324 dict->SetInteger("net_error", net_error); |
| 325 if (dns_error) | 325 if (dns_error) |
| 326 dict->SetInteger("dns_error", dns_error); | 326 dict->SetInteger("dns_error", dns_error); |
| 327 return dict; | 327 return dict; |
| 328 }; | 328 }; |
| 329 | 329 |
| 330 // Creates NetLog parameters containing the information in a RequestInfo object, | 330 // Creates NetLog parameters containing the information in a RequestInfo object, |
| 331 // along with the associated NetLog::Source. | 331 // along with the associated NetLog::Source. |
| 332 base::Value* NetLogRequestInfoCallback(const NetLog::Source& source, | 332 base::Value* NetLogRequestInfoCallback(const HostResolver::RequestInfo* info, |
| 333 const HostResolver::RequestInfo* info, | |
| 334 NetLog::LogLevel /* log_level */) { | 333 NetLog::LogLevel /* log_level */) { |
| 335 base::DictionaryValue* dict = new base::DictionaryValue(); | 334 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 336 source.AddToEventParameters(dict); | |
| 337 | 335 |
| 338 dict->SetString("host", info->host_port_pair().ToString()); | 336 dict->SetString("host", info->host_port_pair().ToString()); |
| 339 dict->SetInteger("address_family", | 337 dict->SetInteger("address_family", |
| 340 static_cast<int>(info->address_family())); | 338 static_cast<int>(info->address_family())); |
| 341 dict->SetBoolean("allow_cached_response", info->allow_cached_response()); | 339 dict->SetBoolean("allow_cached_response", info->allow_cached_response()); |
| 342 dict->SetBoolean("is_speculative", info->is_speculative()); | 340 dict->SetBoolean("is_speculative", info->is_speculative()); |
| 343 return dict; | 341 return dict; |
| 344 } | 342 } |
| 345 | 343 |
| 346 // Creates NetLog parameters for the creation of a HostResolverImpl::Job. | 344 // Creates NetLog parameters for the creation of a HostResolverImpl::Job. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 367 base::Value* NetLogDnsConfigCallback(const DnsConfig* config, | 365 base::Value* NetLogDnsConfigCallback(const DnsConfig* config, |
| 368 NetLog::LogLevel /* log_level */) { | 366 NetLog::LogLevel /* log_level */) { |
| 369 return config->ToValue(); | 367 return config->ToValue(); |
| 370 } | 368 } |
| 371 | 369 |
| 372 // The logging routines are defined here because some requests are resolved | 370 // The logging routines are defined here because some requests are resolved |
| 373 // without a Request object. | 371 // without a Request object. |
| 374 | 372 |
| 375 // Logs when a request has just been started. | 373 // Logs when a request has just been started. |
| 376 void LogStartRequest(const BoundNetLog& source_net_log, | 374 void LogStartRequest(const BoundNetLog& source_net_log, |
| 377 const BoundNetLog& request_net_log, | |
| 378 const HostResolver::RequestInfo& info) { | 375 const HostResolver::RequestInfo& info) { |
| 379 source_net_log.BeginEvent( | 376 source_net_log.BeginEvent( |
| 380 NetLog::TYPE_HOST_RESOLVER_IMPL, | |
| 381 request_net_log.source().ToEventParametersCallback()); | |
| 382 | |
| 383 request_net_log.BeginEvent( | |
| 384 NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, | 377 NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, |
| 385 base::Bind(&NetLogRequestInfoCallback, source_net_log.source(), &info)); | 378 base::Bind(&NetLogRequestInfoCallback, &info)); |
| 386 } | 379 } |
| 387 | 380 |
| 388 // Logs when a request has just completed (before its callback is run). | 381 // Logs when a request has just completed (before its callback is run). |
| 389 void LogFinishRequest(const BoundNetLog& source_net_log, | 382 void LogFinishRequest(const BoundNetLog& source_net_log, |
| 390 const BoundNetLog& request_net_log, | |
| 391 const HostResolver::RequestInfo& info, | 383 const HostResolver::RequestInfo& info, |
| 392 int net_error) { | 384 int net_error) { |
| 393 request_net_log.EndEventWithNetErrorCode( | 385 source_net_log.EndEventWithNetErrorCode( |
| 394 NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, net_error); | 386 NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, net_error); |
| 395 source_net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL); | |
| 396 } | 387 } |
| 397 | 388 |
| 398 // Logs when a request has been cancelled. | 389 // Logs when a request has been cancelled. |
| 399 void LogCancelRequest(const BoundNetLog& source_net_log, | 390 void LogCancelRequest(const BoundNetLog& source_net_log, |
| 400 const BoundNetLog& request_net_log, | |
| 401 const HostResolverImpl::RequestInfo& info) { | 391 const HostResolverImpl::RequestInfo& info) { |
| 402 request_net_log.AddEvent(NetLog::TYPE_CANCELLED); | 392 source_net_log.AddEvent(NetLog::TYPE_CANCELLED); |
| 403 request_net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST); | 393 source_net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST); |
| 404 source_net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL); | |
| 405 } | 394 } |
| 406 | 395 |
| 407 //----------------------------------------------------------------------------- | 396 //----------------------------------------------------------------------------- |
| 408 | 397 |
| 409 // Keeps track of the highest priority. | 398 // Keeps track of the highest priority. |
| 410 class PriorityTracker { | 399 class PriorityTracker { |
| 411 public: | 400 public: |
| 412 explicit PriorityTracker(RequestPriority initial_priority) | 401 explicit PriorityTracker(RequestPriority initial_priority) |
| 413 : highest_priority_(initial_priority), total_count_(0) { | 402 : highest_priority_(initial_priority), total_count_(0) { |
| 414 memset(counts_, 0, sizeof(counts_)); | 403 memset(counts_, 0, sizeof(counts_)); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 //----------------------------------------------------------------------------- | 443 //----------------------------------------------------------------------------- |
| 455 | 444 |
| 456 const unsigned HostResolverImpl::kMaximumDnsFailures = 16; | 445 const unsigned HostResolverImpl::kMaximumDnsFailures = 16; |
| 457 | 446 |
| 458 // Holds the data for a request that could not be completed synchronously. | 447 // Holds the data for a request that could not be completed synchronously. |
| 459 // It is owned by a Job. Canceled Requests are only marked as canceled rather | 448 // It is owned by a Job. Canceled Requests are only marked as canceled rather |
| 460 // than removed from the Job's |requests_| list. | 449 // than removed from the Job's |requests_| list. |
| 461 class HostResolverImpl::Request { | 450 class HostResolverImpl::Request { |
| 462 public: | 451 public: |
| 463 Request(const BoundNetLog& source_net_log, | 452 Request(const BoundNetLog& source_net_log, |
| 464 const BoundNetLog& request_net_log, | |
| 465 const RequestInfo& info, | 453 const RequestInfo& info, |
| 466 RequestPriority priority, | 454 RequestPriority priority, |
| 467 const CompletionCallback& callback, | 455 const CompletionCallback& callback, |
| 468 AddressList* addresses) | 456 AddressList* addresses) |
| 469 : source_net_log_(source_net_log), | 457 : source_net_log_(source_net_log), |
| 470 request_net_log_(request_net_log), | |
| 471 info_(info), | 458 info_(info), |
| 472 priority_(priority), | 459 priority_(priority), |
| 473 job_(NULL), | 460 job_(NULL), |
| 474 callback_(callback), | 461 callback_(callback), |
| 475 addresses_(addresses), | 462 addresses_(addresses), |
| 476 request_time_(base::TimeTicks::Now()) {} | 463 request_time_(base::TimeTicks::Now()) {} |
| 477 | 464 |
| 478 // Mark the request as canceled. | 465 // Mark the request as canceled. |
| 479 void MarkAsCanceled() { | 466 void MarkAsCanceled() { |
| 480 job_ = NULL; | 467 job_ = NULL; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 504 | 491 |
| 505 Job* job() const { | 492 Job* job() const { |
| 506 return job_; | 493 return job_; |
| 507 } | 494 } |
| 508 | 495 |
| 509 // NetLog for the source, passed in HostResolver::Resolve. | 496 // NetLog for the source, passed in HostResolver::Resolve. |
| 510 const BoundNetLog& source_net_log() { | 497 const BoundNetLog& source_net_log() { |
| 511 return source_net_log_; | 498 return source_net_log_; |
| 512 } | 499 } |
| 513 | 500 |
| 514 // NetLog for this request. | |
| 515 const BoundNetLog& request_net_log() { | |
| 516 return request_net_log_; | |
| 517 } | |
| 518 | |
| 519 const RequestInfo& info() const { | 501 const RequestInfo& info() const { |
| 520 return info_; | 502 return info_; |
| 521 } | 503 } |
| 522 | 504 |
| 523 RequestPriority priority() const { return priority_; } | 505 RequestPriority priority() const { return priority_; } |
| 524 | 506 |
| 525 base::TimeTicks request_time() const { return request_time_; } | 507 base::TimeTicks request_time() const { return request_time_; } |
| 526 | 508 |
| 527 private: | 509 private: |
| 528 BoundNetLog source_net_log_; | 510 const BoundNetLog source_net_log_; |
| 529 BoundNetLog request_net_log_; | |
| 530 | 511 |
| 531 // The request info that started the request. | 512 // The request info that started the request. |
| 532 const RequestInfo info_; | 513 const RequestInfo info_; |
| 533 | 514 |
| 534 // TODO(akalin): Support reprioritization. | 515 // TODO(akalin): Support reprioritization. |
| 535 const RequestPriority priority_; | 516 const RequestPriority priority_; |
| 536 | 517 |
| 537 // The resolve job that this request is dependent on. | 518 // The resolve job that this request is dependent on. |
| 538 Job* job_; | 519 Job* job_; |
| 539 | 520 |
| (...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1193 | 1174 |
| 1194 // Aggregates all Requests for the same Key. Dispatched via PriorityDispatch. | 1175 // Aggregates all Requests for the same Key. Dispatched via PriorityDispatch. |
| 1195 class HostResolverImpl::Job : public PrioritizedDispatcher::Job, | 1176 class HostResolverImpl::Job : public PrioritizedDispatcher::Job, |
| 1196 public HostResolverImpl::DnsTask::Delegate { | 1177 public HostResolverImpl::DnsTask::Delegate { |
| 1197 public: | 1178 public: |
| 1198 // Creates new job for |key| where |request_net_log| is bound to the | 1179 // Creates new job for |key| where |request_net_log| is bound to the |
| 1199 // request that spawned it. | 1180 // request that spawned it. |
| 1200 Job(const base::WeakPtr<HostResolverImpl>& resolver, | 1181 Job(const base::WeakPtr<HostResolverImpl>& resolver, |
| 1201 const Key& key, | 1182 const Key& key, |
| 1202 RequestPriority priority, | 1183 RequestPriority priority, |
| 1203 const BoundNetLog& request_net_log) | 1184 const BoundNetLog& source_net_log) |
| 1204 : resolver_(resolver), | 1185 : resolver_(resolver), |
| 1205 key_(key), | 1186 key_(key), |
| 1206 priority_tracker_(priority), | 1187 priority_tracker_(priority), |
| 1207 had_non_speculative_request_(false), | 1188 had_non_speculative_request_(false), |
| 1208 had_dns_config_(false), | 1189 had_dns_config_(false), |
| 1209 num_occupied_job_slots_(0), | 1190 num_occupied_job_slots_(0), |
| 1210 dns_task_error_(OK), | 1191 dns_task_error_(OK), |
| 1211 creation_time_(base::TimeTicks::Now()), | 1192 creation_time_(base::TimeTicks::Now()), |
| 1212 priority_change_time_(creation_time_), | 1193 priority_change_time_(creation_time_), |
| 1213 net_log_(BoundNetLog::Make(request_net_log.net_log(), | 1194 net_log_(BoundNetLog::Make(source_net_log.net_log(), |
| 1214 NetLog::SOURCE_HOST_RESOLVER_IMPL_JOB)) { | 1195 NetLog::SOURCE_HOST_RESOLVER_IMPL_JOB)) { |
| 1215 request_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_CREATE_JOB); | 1196 source_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_CREATE_JOB); |
| 1216 | 1197 |
| 1217 net_log_.BeginEvent( | 1198 net_log_.BeginEvent( |
| 1218 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, | 1199 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, |
| 1219 base::Bind(&NetLogJobCreationCallback, | 1200 base::Bind(&NetLogJobCreationCallback, |
| 1220 request_net_log.source(), | 1201 source_net_log.source(), |
| 1221 &key_.hostname)); | 1202 &key_.hostname)); |
| 1222 } | 1203 } |
| 1223 | 1204 |
| 1224 ~Job() override { | 1205 ~Job() override { |
| 1225 if (is_running()) { | 1206 if (is_running()) { |
| 1226 // |resolver_| was destroyed with this Job still in flight. | 1207 // |resolver_| was destroyed with this Job still in flight. |
| 1227 // Clean-up, record in the log, but don't run any callbacks. | 1208 // Clean-up, record in the log, but don't run any callbacks. |
| 1228 if (is_proc_running()) { | 1209 if (is_proc_running()) { |
| 1229 proc_task_->Cancel(); | 1210 proc_task_->Cancel(); |
| 1230 proc_task_ = NULL; | 1211 proc_task_ = NULL; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1241 } | 1222 } |
| 1242 // else CompleteRequests logged EndEvent. | 1223 // else CompleteRequests logged EndEvent. |
| 1243 | 1224 |
| 1244 // Log any remaining Requests as cancelled. | 1225 // Log any remaining Requests as cancelled. |
| 1245 for (RequestsList::const_iterator it = requests_.begin(); | 1226 for (RequestsList::const_iterator it = requests_.begin(); |
| 1246 it != requests_.end(); ++it) { | 1227 it != requests_.end(); ++it) { |
| 1247 Request* req = *it; | 1228 Request* req = *it; |
| 1248 if (req->was_canceled()) | 1229 if (req->was_canceled()) |
| 1249 continue; | 1230 continue; |
| 1250 DCHECK_EQ(this, req->job()); | 1231 DCHECK_EQ(this, req->job()); |
| 1251 LogCancelRequest(req->source_net_log(), req->request_net_log(), | 1232 LogCancelRequest(req->source_net_log(), req->info()); |
| 1252 req->info()); | |
| 1253 } | 1233 } |
| 1254 } | 1234 } |
| 1255 | 1235 |
| 1256 // Add this job to the dispatcher. If "at_head" is true, adds at the front | 1236 // Add this job to the dispatcher. If "at_head" is true, adds at the front |
| 1257 // of the queue. | 1237 // of the queue. |
| 1258 void Schedule(bool at_head) { | 1238 void Schedule(bool at_head) { |
| 1259 DCHECK(!is_queued()); | 1239 DCHECK(!is_queued()); |
| 1260 PrioritizedDispatcher::Handle handle; | 1240 PrioritizedDispatcher::Handle handle; |
| 1261 if (!at_head) { | 1241 if (!at_head) { |
| 1262 handle = resolver_->dispatcher_->Add(this, priority()); | 1242 handle = resolver_->dispatcher_->Add(this, priority()); |
| 1263 } else { | 1243 } else { |
| 1264 handle = resolver_->dispatcher_->AddAtHead(this, priority()); | 1244 handle = resolver_->dispatcher_->AddAtHead(this, priority()); |
| 1265 } | 1245 } |
| 1266 // The dispatcher could have started |this| in the above call to Add, which | 1246 // The dispatcher could have started |this| in the above call to Add, which |
| 1267 // could have called Schedule again. In that case |handle| will be null, | 1247 // could have called Schedule again. In that case |handle| will be null, |
| 1268 // but |handle_| may have been set by the other nested call to Schedule. | 1248 // but |handle_| may have been set by the other nested call to Schedule. |
| 1269 if (!handle.is_null()) { | 1249 if (!handle.is_null()) { |
| 1270 DCHECK(handle_.is_null()); | 1250 DCHECK(handle_.is_null()); |
| 1271 handle_ = handle; | 1251 handle_ = handle; |
| 1272 } | 1252 } |
| 1273 } | 1253 } |
| 1274 | 1254 |
| 1275 void AddRequest(scoped_ptr<Request> req) { | 1255 void AddRequest(scoped_ptr<Request> req) { |
| 1276 DCHECK_EQ(key_.hostname, req->info().hostname()); | 1256 DCHECK_EQ(key_.hostname, req->info().hostname()); |
| 1277 | 1257 |
| 1278 req->set_job(this); | 1258 req->set_job(this); |
| 1279 priority_tracker_.Add(req->priority()); | 1259 priority_tracker_.Add(req->priority()); |
| 1280 | 1260 |
| 1281 req->request_net_log().AddEvent( | 1261 req->source_net_log().AddEvent( |
| 1282 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_ATTACH, | 1262 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_ATTACH, |
| 1283 net_log_.source().ToEventParametersCallback()); | 1263 net_log_.source().ToEventParametersCallback()); |
| 1284 | 1264 |
| 1285 net_log_.AddEvent( | 1265 net_log_.AddEvent( |
| 1286 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_REQUEST_ATTACH, | 1266 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_REQUEST_ATTACH, |
| 1287 base::Bind(&NetLogJobAttachCallback, | 1267 base::Bind(&NetLogJobAttachCallback, |
| 1288 req->request_net_log().source(), | 1268 req->source_net_log().source(), |
| 1289 priority())); | 1269 priority())); |
| 1290 | 1270 |
| 1291 // TODO(szym): Check if this is still needed. | 1271 // TODO(szym): Check if this is still needed. |
| 1292 if (!req->info().is_speculative()) { | 1272 if (!req->info().is_speculative()) { |
| 1293 had_non_speculative_request_ = true; | 1273 had_non_speculative_request_ = true; |
| 1294 if (proc_task_.get()) | 1274 if (proc_task_.get()) |
| 1295 proc_task_->set_had_non_speculative_request(); | 1275 proc_task_->set_had_non_speculative_request(); |
| 1296 } | 1276 } |
| 1297 | 1277 |
| 1298 requests_.push_back(req.release()); | 1278 requests_.push_back(req.release()); |
| 1299 | 1279 |
| 1300 UpdatePriority(); | 1280 UpdatePriority(); |
| 1301 } | 1281 } |
| 1302 | 1282 |
| 1303 // Marks |req| as cancelled. If it was the last active Request, also finishes | 1283 // Marks |req| as cancelled. If it was the last active Request, also finishes |
| 1304 // this Job, marking it as cancelled, and deletes it. | 1284 // this Job, marking it as cancelled, and deletes it. |
| 1305 void CancelRequest(Request* req) { | 1285 void CancelRequest(Request* req) { |
| 1306 DCHECK_EQ(key_.hostname, req->info().hostname()); | 1286 DCHECK_EQ(key_.hostname, req->info().hostname()); |
| 1307 DCHECK(!req->was_canceled()); | 1287 DCHECK(!req->was_canceled()); |
| 1308 | 1288 |
| 1309 // Don't remove it from |requests_| just mark it canceled. | 1289 // Don't remove it from |requests_| just mark it canceled. |
| 1310 req->MarkAsCanceled(); | 1290 req->MarkAsCanceled(); |
| 1311 LogCancelRequest(req->source_net_log(), req->request_net_log(), | 1291 LogCancelRequest(req->source_net_log(), req->info()); |
| 1312 req->info()); | |
| 1313 | 1292 |
| 1314 priority_tracker_.Remove(req->priority()); | 1293 priority_tracker_.Remove(req->priority()); |
| 1315 net_log_.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_REQUEST_DETACH, | 1294 net_log_.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_REQUEST_DETACH, |
| 1316 base::Bind(&NetLogJobAttachCallback, | 1295 base::Bind(&NetLogJobAttachCallback, |
| 1317 req->request_net_log().source(), | 1296 req->source_net_log().source(), |
| 1318 priority())); | 1297 priority())); |
| 1319 | 1298 |
| 1320 if (num_active_requests() > 0) { | 1299 if (num_active_requests() > 0) { |
| 1321 UpdatePriority(); | 1300 UpdatePriority(); |
| 1322 } else { | 1301 } else { |
| 1323 // If we were called from a Request's callback within CompleteRequests, | 1302 // If we were called from a Request's callback within CompleteRequests, |
| 1324 // that Request could not have been cancelled, so num_active_requests() | 1303 // that Request could not have been cancelled, so num_active_requests() |
| 1325 // could not be 0. Therefore, we are not in CompleteRequests(). | 1304 // could not be 0. Therefore, we are not in CompleteRequests(). |
| 1326 CompleteRequestsWithError(OK /* cancelled */); | 1305 CompleteRequestsWithError(OK /* cancelled */); |
| 1327 } | 1306 } |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1693 // Complete all of the requests that were attached to the job. | 1672 // Complete all of the requests that were attached to the job. |
| 1694 for (RequestsList::const_iterator it = requests_.begin(); | 1673 for (RequestsList::const_iterator it = requests_.begin(); |
| 1695 it != requests_.end(); ++it) { | 1674 it != requests_.end(); ++it) { |
| 1696 Request* req = *it; | 1675 Request* req = *it; |
| 1697 | 1676 |
| 1698 if (req->was_canceled()) | 1677 if (req->was_canceled()) |
| 1699 continue; | 1678 continue; |
| 1700 | 1679 |
| 1701 DCHECK_EQ(this, req->job()); | 1680 DCHECK_EQ(this, req->job()); |
| 1702 // Update the net log and notify registered observers. | 1681 // Update the net log and notify registered observers. |
| 1703 LogFinishRequest(req->source_net_log(), req->request_net_log(), | 1682 LogFinishRequest(req->source_net_log(), req->info(), entry.error); |
| 1704 req->info(), entry.error); | |
| 1705 if (did_complete) { | 1683 if (did_complete) { |
| 1706 // Record effective total time from creation to completion. | 1684 // Record effective total time from creation to completion. |
| 1707 RecordTotalTime(had_dns_config_, req->info().is_speculative(), | 1685 RecordTotalTime(had_dns_config_, req->info().is_speculative(), |
| 1708 base::TimeTicks::Now() - req->request_time()); | 1686 base::TimeTicks::Now() - req->request_time()); |
| 1709 } | 1687 } |
| 1710 req->OnComplete(entry.error, entry.addrlist); | 1688 req->OnComplete(entry.error, entry.addrlist); |
| 1711 | 1689 |
| 1712 // Check if the resolver was destroyed as a result of running the | 1690 // Check if the resolver was destroyed as a result of running the |
| 1713 // callback. If it was, we could continue, but we choose to bail. | 1691 // callback. If it was, we could continue, but we choose to bail. |
| 1714 if (!resolver_.get()) | 1692 if (!resolver_.get()) |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1864 const BoundNetLog& source_net_log) { | 1842 const BoundNetLog& source_net_log) { |
| 1865 DCHECK(addresses); | 1843 DCHECK(addresses); |
| 1866 DCHECK(CalledOnValidThread()); | 1844 DCHECK(CalledOnValidThread()); |
| 1867 DCHECK_EQ(false, callback.is_null()); | 1845 DCHECK_EQ(false, callback.is_null()); |
| 1868 | 1846 |
| 1869 // Check that the caller supplied a valid hostname to resolve. | 1847 // Check that the caller supplied a valid hostname to resolve. |
| 1870 std::string labeled_hostname; | 1848 std::string labeled_hostname; |
| 1871 if (!DNSDomainFromDot(info.hostname(), &labeled_hostname)) | 1849 if (!DNSDomainFromDot(info.hostname(), &labeled_hostname)) |
| 1872 return ERR_NAME_NOT_RESOLVED; | 1850 return ERR_NAME_NOT_RESOLVED; |
| 1873 | 1851 |
| 1874 // Make a log item for the request. | 1852 LogStartRequest(source_net_log, info); |
| 1875 BoundNetLog request_net_log = BoundNetLog::Make(net_log_, | |
| 1876 NetLog::SOURCE_HOST_RESOLVER_IMPL_REQUEST); | |
| 1877 | |
| 1878 LogStartRequest(source_net_log, request_net_log, info); | |
| 1879 | 1853 |
| 1880 // Build a key that identifies the request in the cache and in the | 1854 // Build a key that identifies the request in the cache and in the |
| 1881 // outstanding jobs map. | 1855 // outstanding jobs map. |
| 1882 Key key = GetEffectiveKeyForRequest(info, request_net_log); | 1856 Key key = GetEffectiveKeyForRequest(info, source_net_log); |
| 1883 | 1857 |
| 1884 int rv = ResolveHelper(key, info, addresses, request_net_log); | 1858 int rv = ResolveHelper(key, info, addresses, source_net_log); |
| 1885 if (rv != ERR_DNS_CACHE_MISS) { | 1859 if (rv != ERR_DNS_CACHE_MISS) { |
| 1886 LogFinishRequest(source_net_log, request_net_log, info, rv); | 1860 LogFinishRequest(source_net_log, info, rv); |
| 1887 RecordTotalTime(HaveDnsConfig(), info.is_speculative(), base::TimeDelta()); | 1861 RecordTotalTime(HaveDnsConfig(), info.is_speculative(), base::TimeDelta()); |
| 1888 return rv; | 1862 return rv; |
| 1889 } | 1863 } |
| 1890 | 1864 |
| 1891 // Next we need to attach our request to a "job". This job is responsible for | 1865 // Next we need to attach our request to a "job". This job is responsible for |
| 1892 // calling "getaddrinfo(hostname)" on a worker thread. | 1866 // calling "getaddrinfo(hostname)" on a worker thread. |
| 1893 | 1867 |
| 1894 JobMap::iterator jobit = jobs_.find(key); | 1868 JobMap::iterator jobit = jobs_.find(key); |
| 1895 Job* job; | 1869 Job* job; |
| 1896 if (jobit == jobs_.end()) { | 1870 if (jobit == jobs_.end()) { |
| 1897 job = | 1871 job = |
| 1898 new Job(weak_ptr_factory_.GetWeakPtr(), key, priority, request_net_log); | 1872 new Job(weak_ptr_factory_.GetWeakPtr(), key, priority, source_net_log); |
| 1899 job->Schedule(false); | 1873 job->Schedule(false); |
| 1900 | 1874 |
| 1901 // Check for queue overflow. | 1875 // Check for queue overflow. |
| 1902 if (dispatcher_->num_queued_jobs() > max_queued_jobs_) { | 1876 if (dispatcher_->num_queued_jobs() > max_queued_jobs_) { |
| 1903 Job* evicted = static_cast<Job*>(dispatcher_->EvictOldestLowest()); | 1877 Job* evicted = static_cast<Job*>(dispatcher_->EvictOldestLowest()); |
| 1904 DCHECK(evicted); | 1878 DCHECK(evicted); |
| 1905 evicted->OnEvicted(); // Deletes |evicted|. | 1879 evicted->OnEvicted(); // Deletes |evicted|. |
| 1906 if (evicted == job) { | 1880 if (evicted == job) { |
| 1907 rv = ERR_HOST_RESOLVER_QUEUE_TOO_LARGE; | 1881 rv = ERR_HOST_RESOLVER_QUEUE_TOO_LARGE; |
| 1908 LogFinishRequest(source_net_log, request_net_log, info, rv); | 1882 LogFinishRequest(source_net_log, info, rv); |
| 1909 return rv; | 1883 return rv; |
| 1910 } | 1884 } |
| 1911 } | 1885 } |
| 1912 jobs_.insert(jobit, std::make_pair(key, job)); | 1886 jobs_.insert(jobit, std::make_pair(key, job)); |
| 1913 } else { | 1887 } else { |
| 1914 job = jobit->second; | 1888 job = jobit->second; |
| 1915 } | 1889 } |
| 1916 | 1890 |
| 1917 // Can't complete synchronously. Create and attach request. | 1891 // Can't complete synchronously. Create and attach request. |
| 1918 scoped_ptr<Request> req(new Request( | 1892 scoped_ptr<Request> req(new Request( |
| 1919 source_net_log, request_net_log, info, priority, callback, addresses)); | 1893 source_net_log, info, priority, callback, addresses)); |
| 1920 if (out_req) | 1894 if (out_req) |
| 1921 *out_req = reinterpret_cast<RequestHandle>(req.get()); | 1895 *out_req = reinterpret_cast<RequestHandle>(req.get()); |
| 1922 | 1896 |
| 1923 job->AddRequest(req.Pass()); | 1897 job->AddRequest(req.Pass()); |
| 1924 // Completion happens during Job::CompleteRequests(). | 1898 // Completion happens during Job::CompleteRequests(). |
| 1925 return ERR_IO_PENDING; | 1899 return ERR_IO_PENDING; |
| 1926 } | 1900 } |
| 1927 | 1901 |
| 1928 int HostResolverImpl::ResolveHelper(const Key& key, | 1902 int HostResolverImpl::ResolveHelper(const Key& key, |
| 1929 const RequestInfo& info, | 1903 const RequestInfo& info, |
| 1930 AddressList* addresses, | 1904 AddressList* addresses, |
| 1931 const BoundNetLog& request_net_log) { | 1905 const BoundNetLog& source_net_log) { |
| 1932 // The result of |getaddrinfo| for empty hosts is inconsistent across systems. | 1906 // The result of |getaddrinfo| for empty hosts is inconsistent across systems. |
| 1933 // On Windows it gives the default interface's address, whereas on Linux it | 1907 // On Windows it gives the default interface's address, whereas on Linux it |
| 1934 // gives an error. We will make it fail on all platforms for consistency. | 1908 // gives an error. We will make it fail on all platforms for consistency. |
| 1935 if (info.hostname().empty() || info.hostname().size() > kMaxHostLength) | 1909 if (info.hostname().empty() || info.hostname().size() > kMaxHostLength) |
| 1936 return ERR_NAME_NOT_RESOLVED; | 1910 return ERR_NAME_NOT_RESOLVED; |
| 1937 | 1911 |
| 1938 int net_error = ERR_UNEXPECTED; | 1912 int net_error = ERR_UNEXPECTED; |
| 1939 if (ResolveAsIP(key, info, &net_error, addresses)) | 1913 if (ResolveAsIP(key, info, &net_error, addresses)) |
| 1940 return net_error; | 1914 return net_error; |
| 1941 if (ServeFromCache(key, info, &net_error, addresses)) { | 1915 if (ServeFromCache(key, info, &net_error, addresses)) { |
| 1942 request_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_CACHE_HIT); | 1916 source_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_CACHE_HIT); |
| 1943 return net_error; | 1917 return net_error; |
| 1944 } | 1918 } |
| 1945 // TODO(szym): Do not do this if nsswitch.conf instructs not to. | 1919 // TODO(szym): Do not do this if nsswitch.conf instructs not to. |
| 1946 // http://crbug.com/117655 | 1920 // http://crbug.com/117655 |
| 1947 if (ServeFromHosts(key, info, addresses)) { | 1921 if (ServeFromHosts(key, info, addresses)) { |
| 1948 request_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_HOSTS_HIT); | 1922 source_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_HOSTS_HIT); |
| 1949 return OK; | 1923 return OK; |
| 1950 } | 1924 } |
| 1951 return ERR_DNS_CACHE_MISS; | 1925 return ERR_DNS_CACHE_MISS; |
| 1952 } | 1926 } |
| 1953 | 1927 |
| 1954 int HostResolverImpl::ResolveFromCache(const RequestInfo& info, | 1928 int HostResolverImpl::ResolveFromCache(const RequestInfo& info, |
| 1955 AddressList* addresses, | 1929 AddressList* addresses, |
| 1956 const BoundNetLog& source_net_log) { | 1930 const BoundNetLog& source_net_log) { |
| 1957 DCHECK(CalledOnValidThread()); | 1931 DCHECK(CalledOnValidThread()); |
| 1958 DCHECK(addresses); | 1932 DCHECK(addresses); |
| 1959 | 1933 |
| 1960 // Make a log item for the request. | 1934 // Update the net log and notify registered observers. |
| 1961 BoundNetLog request_net_log = BoundNetLog::Make(net_log_, | 1935 LogStartRequest(source_net_log, info); |
| 1962 NetLog::SOURCE_HOST_RESOLVER_IMPL_REQUEST); | |
| 1963 | 1936 |
| 1964 // Update the net log and notify registered observers. | 1937 Key key = GetEffectiveKeyForRequest(info, source_net_log); |
| 1965 LogStartRequest(source_net_log, request_net_log, info); | |
| 1966 | 1938 |
| 1967 Key key = GetEffectiveKeyForRequest(info, request_net_log); | 1939 int rv = ResolveHelper(key, info, addresses, source_net_log); |
| 1968 | 1940 LogFinishRequest(source_net_log, info, rv); |
| 1969 int rv = ResolveHelper(key, info, addresses, request_net_log); | |
| 1970 LogFinishRequest(source_net_log, request_net_log, info, rv); | |
| 1971 return rv; | 1941 return rv; |
| 1972 } | 1942 } |
| 1973 | 1943 |
| 1974 void HostResolverImpl::CancelRequest(RequestHandle req_handle) { | 1944 void HostResolverImpl::CancelRequest(RequestHandle req_handle) { |
| 1975 DCHECK(CalledOnValidThread()); | 1945 DCHECK(CalledOnValidThread()); |
| 1976 Request* req = reinterpret_cast<Request*>(req_handle); | 1946 Request* req = reinterpret_cast<Request*>(req_handle); |
| 1977 DCHECK(req); | 1947 DCHECK(req); |
| 1978 Job* job = req->job(); | 1948 Job* job = req->job(); |
| 1979 DCHECK(job); | 1949 DCHECK(job); |
| 1980 job->CancelRequest(req); | 1950 job->CancelRequest(req); |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2359 dns_client_->SetConfig(dns_config); | 2329 dns_client_->SetConfig(dns_config); |
| 2360 num_dns_failures_ = 0; | 2330 num_dns_failures_ = 0; |
| 2361 if (dns_client_->GetConfig()) | 2331 if (dns_client_->GetConfig()) |
| 2362 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); | 2332 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); |
| 2363 } | 2333 } |
| 2364 | 2334 |
| 2365 AbortDnsTasks(); | 2335 AbortDnsTasks(); |
| 2366 } | 2336 } |
| 2367 | 2337 |
| 2368 } // namespace net | 2338 } // namespace net |
| OLD | NEW |