| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/browser/net/dns_master.h" | 5 #include "chrome/browser/net/dns_master.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 | 10 |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 // Currently we only add to the domain map :-/ | 353 // Currently we only add to the domain map :-/ |
| 354 | 354 |
| 355 DCHECK(info->HasHostname(hostname)); | 355 DCHECK(info->HasHostname(hostname)); |
| 356 | 356 |
| 357 if (!info->NeedsDnsUpdate(hostname)) { | 357 if (!info->NeedsDnsUpdate(hostname)) { |
| 358 info->DLogResultsStats("DNS PrefetchNotUpdated"); | 358 info->DLogResultsStats("DNS PrefetchNotUpdated"); |
| 359 return NULL; | 359 return NULL; |
| 360 } | 360 } |
| 361 | 361 |
| 362 info->SetQueuedState(motivation); | 362 info->SetQueuedState(motivation); |
| 363 work_queue_.Push(hostname, motivation); | 363 name_buffer_.push(hostname); |
| 364 |
| 364 PreLockedScheduleLookups(); | 365 PreLockedScheduleLookups(); |
| 366 |
| 365 return info; | 367 return info; |
| 366 } | 368 } |
| 367 | 369 |
| 368 void DnsMaster::PreLockedScheduleLookups() { | 370 void DnsMaster::PreLockedScheduleLookups() { |
| 369 while (!work_queue_.IsEmpty() && | 371 while (!name_buffer_.empty() && |
| 370 pending_lookups_.size() < max_concurrent_lookups_) { | 372 pending_lookups_.size() < max_concurrent_lookups_) { |
| 371 const std::string hostname(work_queue_.Pop()); | 373 const std::string hostname(name_buffer_.front()); |
| 374 name_buffer_.pop(); |
| 375 |
| 372 DnsHostInfo* info = &results_[hostname]; | 376 DnsHostInfo* info = &results_[hostname]; |
| 373 DCHECK(info->HasHostname(hostname)); | 377 DCHECK(info->HasHostname(hostname)); |
| 374 info->SetAssignedState(); | 378 info->SetAssignedState(); |
| 375 | 379 |
| 376 if (PreLockedCongestionControlPerformed(info)) { | |
| 377 DCHECK(work_queue_.IsEmpty()); | |
| 378 return; | |
| 379 } | |
| 380 | |
| 381 LookupRequest* request = new LookupRequest(this, hostname); | 380 LookupRequest* request = new LookupRequest(this, hostname); |
| 382 if (request->Start()) { | 381 if (request->Start()) { |
| 383 pending_lookups_.insert(request); | 382 pending_lookups_.insert(request); |
| 384 peak_pending_lookups_ = std::max(peak_pending_lookups_, | 383 peak_pending_lookups_ = std::max(peak_pending_lookups_, |
| 385 pending_lookups_.size()); | 384 pending_lookups_.size()); |
| 386 } else { | 385 } else { |
| 387 NOTREACHED(); | 386 NOTREACHED(); |
| 388 delete request; | 387 delete request; |
| 389 } | 388 } |
| 390 } | 389 } |
| 391 } | 390 } |
| 392 | 391 |
| 393 bool DnsMaster::PreLockedCongestionControlPerformed(DnsHostInfo* info) { | |
| 394 // Note: queue_duration is ONLY valid after we go to assigned state. | |
| 395 // TODO(jar): Tune selection of arbitrary 1 second constant. Add plumbing so | |
| 396 // that this can be set as part of an A/B experiment. | |
| 397 if (info->queue_duration() < base::TimeDelta::FromSeconds(1)) | |
| 398 return false; | |
| 399 // We need to discard all entries in our queue, as we're keeping them waiting | |
| 400 // too long. By doing this, we'll have a chance to quickly service urgent | |
| 401 // resolutions, and not have a bogged down system. | |
| 402 while (true) { | |
| 403 info->RemoveFromQueue(); | |
| 404 if (work_queue_.IsEmpty()) | |
| 405 break; | |
| 406 info = &results_[work_queue_.Pop()]; | |
| 407 info->SetAssignedState(); | |
| 408 } | |
| 409 return true; | |
| 410 } | |
| 411 | |
| 412 void DnsMaster::OnLookupFinished(LookupRequest* request, | 392 void DnsMaster::OnLookupFinished(LookupRequest* request, |
| 413 const std::string& hostname, bool found) { | 393 const std::string& hostname, bool found) { |
| 414 AutoLock auto_lock(lock_); // For map access (changing info values). | 394 AutoLock auto_lock(lock_); // For map access (changing info values). |
| 415 DnsHostInfo* info = &results_[hostname]; | 395 DnsHostInfo* info = &results_[hostname]; |
| 416 DCHECK(info->HasHostname(hostname)); | 396 DCHECK(info->HasHostname(hostname)); |
| 417 if (info->is_marked_to_delete()) { | 397 if (info->is_marked_to_delete()) |
| 418 results_.erase(hostname); | 398 results_.erase(hostname); |
| 419 } else { | 399 else { |
| 420 if (found) | 400 if (found) |
| 421 info->SetFoundState(); | 401 info->SetFoundState(); |
| 422 else | 402 else |
| 423 info->SetNoSuchNameState(); | 403 info->SetNoSuchNameState(); |
| 424 } | 404 } |
| 425 | 405 |
| 426 pending_lookups_.erase(request); | 406 pending_lookups_.erase(request); |
| 427 delete request; | 407 delete request; |
| 428 | 408 |
| 429 PreLockedScheduleLookups(); | 409 PreLockedScheduleLookups(); |
| 430 } | 410 } |
| 431 | 411 |
| 432 void DnsMaster::DiscardAllResults() { | 412 void DnsMaster::DiscardAllResults() { |
| 433 AutoLock auto_lock(lock_); | 413 AutoLock auto_lock(lock_); |
| 434 // Delete anything listed so far in this session that shows in about:dns. | 414 // Delete anything listed so far in this session that shows in about:dns. |
| 435 cache_eviction_map_.clear(); | 415 cache_eviction_map_.clear(); |
| 436 cache_hits_.clear(); | 416 cache_hits_.clear(); |
| 437 referrers_.clear(); | 417 referrers_.clear(); |
| 438 | 418 |
| 439 | 419 |
| 440 // Try to delete anything in our work queue. | 420 // Try to delete anything in our work queue. |
| 441 while (!work_queue_.IsEmpty()) { | 421 while (!name_buffer_.empty()) { |
| 442 // Emulate processing cycle as though host was not found. | 422 // Emulate processing cycle as though host was not found. |
| 443 std::string hostname = work_queue_.Pop(); | 423 std::string hostname = name_buffer_.front(); |
| 424 name_buffer_.pop(); |
| 444 DnsHostInfo* info = &results_[hostname]; | 425 DnsHostInfo* info = &results_[hostname]; |
| 445 DCHECK(info->HasHostname(hostname)); | 426 DCHECK(info->HasHostname(hostname)); |
| 446 info->SetAssignedState(); | 427 info->SetAssignedState(); |
| 447 info->SetNoSuchNameState(); | 428 info->SetNoSuchNameState(); |
| 448 } | 429 } |
| 449 // Now every result_ is either resolved, or is being resolved | 430 // Now every result_ is either resolved, or is being resolved |
| 450 // (see LookupRequest). | 431 // (see LookupRequest). |
| 451 | 432 |
| 452 // Step through result_, recording names of all hosts that can't be erased. | 433 // Step through result_, recording names of all hosts that can't be erased. |
| 453 // We can't erase anything being worked on. | 434 // We can't erase anything being worked on. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 continue; | 490 continue; |
| 510 Value* subresource_list; | 491 Value* subresource_list; |
| 511 if (!motivating_host->Get(1, &subresource_list)) | 492 if (!motivating_host->Get(1, &subresource_list)) |
| 512 continue; | 493 continue; |
| 513 if (motivating_referrer.empty()) | 494 if (motivating_referrer.empty()) |
| 514 continue; | 495 continue; |
| 515 referrers_[motivating_referrer].Deserialize(*subresource_list); | 496 referrers_[motivating_referrer].Deserialize(*subresource_list); |
| 516 } | 497 } |
| 517 } | 498 } |
| 518 | 499 |
| 519 | |
| 520 //------------------------------------------------------------------------------ | |
| 521 | |
| 522 DnsMaster::HostNameQueue::HostNameQueue() { | |
| 523 } | |
| 524 | |
| 525 DnsMaster::HostNameQueue::~HostNameQueue() { | |
| 526 } | |
| 527 | |
| 528 void DnsMaster::HostNameQueue::Push(const std::string& hostname, | |
| 529 DnsHostInfo::ResolutionMotivation motivation) { | |
| 530 switch (motivation) { | |
| 531 case DnsHostInfo::STATIC_REFERAL_MOTIVATED: | |
| 532 case DnsHostInfo::LEARNED_REFERAL_MOTIVATED: | |
| 533 case DnsHostInfo::MOUSE_OVER_MOTIVATED: | |
| 534 rush_queue_.push(hostname); | |
| 535 break; | |
| 536 | |
| 537 default: | |
| 538 background_queue_.push(hostname); | |
| 539 break; | |
| 540 } | |
| 541 } | |
| 542 | |
| 543 bool DnsMaster::HostNameQueue::IsEmpty() const { | |
| 544 return rush_queue_.empty() && background_queue_.empty(); | |
| 545 } | |
| 546 | |
| 547 std::string DnsMaster::HostNameQueue::Pop() { | |
| 548 DCHECK(!IsEmpty()); | |
| 549 if (!rush_queue_.empty()) { | |
| 550 std::string hostname(rush_queue_.front()); | |
| 551 rush_queue_.pop(); | |
| 552 return hostname; | |
| 553 } | |
| 554 std::string hostname(background_queue_.front()); | |
| 555 background_queue_.pop(); | |
| 556 return hostname; | |
| 557 } | |
| 558 | |
| 559 } // namespace chrome_browser_net | 500 } // namespace chrome_browser_net |
| OLD | NEW |