| 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 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/histogram.h" | 12 #include "base/histogram.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/lock.h" | 14 #include "base/lock.h" |
| 15 #include "base/stats_counters.h" | 15 #include "base/stats_counters.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/time.h" | 17 #include "base/time.h" |
| 18 #include "net/base/address_list.h" | 18 #include "net/base/address_list.h" |
| 19 #include "net/base/completion_callback.h" | 19 #include "net/base/completion_callback.h" |
| 20 #include "net/base/host_resolver.h" | 20 #include "net/base/host_resolver.h" |
| 21 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
| 22 | 22 |
| 23 using base::TimeDelta; |
| 24 |
| 23 namespace chrome_browser_net { | 25 namespace chrome_browser_net { |
| 24 | 26 |
| 25 class DnsMaster::LookupRequest { | 27 class DnsMaster::LookupRequest { |
| 26 public: | 28 public: |
| 27 LookupRequest(DnsMaster* master, | 29 LookupRequest(DnsMaster* master, |
| 28 net::HostResolver* host_resolver, | 30 net::HostResolver* host_resolver, |
| 29 const std::string& hostname) | 31 const std::string& hostname) |
| 30 : ALLOW_THIS_IN_INITIALIZER_LIST( | 32 : ALLOW_THIS_IN_INITIALIZER_LIST( |
| 31 net_callback_(this, &LookupRequest::OnLookupFinished)), | 33 net_callback_(this, &LookupRequest::OnLookupFinished)), |
| 32 master_(master), | 34 master_(master), |
| (...skipping 28 matching lines...) Expand all Loading... |
| 61 | 63 |
| 62 const std::string hostname_; // Hostname to resolve. | 64 const std::string hostname_; // Hostname to resolve. |
| 63 net::SingleRequestHostResolver resolver_; | 65 net::SingleRequestHostResolver resolver_; |
| 64 net::AddressList addresses_; | 66 net::AddressList addresses_; |
| 65 | 67 |
| 66 DISALLOW_COPY_AND_ASSIGN(LookupRequest); | 68 DISALLOW_COPY_AND_ASSIGN(LookupRequest); |
| 67 }; | 69 }; |
| 68 | 70 |
| 69 DnsMaster::DnsMaster(net::HostResolver* host_resolver, | 71 DnsMaster::DnsMaster(net::HostResolver* host_resolver, |
| 70 MessageLoop* host_resolver_loop, | 72 MessageLoop* host_resolver_loop, |
| 73 TimeDelta max_queue_delay, |
| 71 size_t max_concurrent) | 74 size_t max_concurrent) |
| 72 : peak_pending_lookups_(0), | 75 : peak_pending_lookups_(0), |
| 73 shutdown_(false), | 76 shutdown_(false), |
| 74 max_concurrent_lookups_(max_concurrent), | 77 max_concurrent_lookups_(max_concurrent), |
| 78 max_queue_delay_(max_queue_delay), |
| 75 host_resolver_(host_resolver), | 79 host_resolver_(host_resolver), |
| 76 host_resolver_loop_(host_resolver_loop) { | 80 host_resolver_loop_(host_resolver_loop) { |
| 77 } | 81 } |
| 78 | 82 |
| 79 DnsMaster::~DnsMaster() { | 83 DnsMaster::~DnsMaster() { |
| 80 DCHECK(shutdown_); | 84 DCHECK(shutdown_); |
| 81 } | 85 } |
| 82 | 86 |
| 83 void DnsMaster::Shutdown() { | 87 void DnsMaster::Shutdown() { |
| 84 AutoLock auto_lock(lock_); | 88 AutoLock auto_lock(lock_); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 } | 347 } |
| 344 | 348 |
| 345 // Partition the DnsHostInfo's into categories. | 349 // Partition the DnsHostInfo's into categories. |
| 346 for (Snapshot::iterator it(snapshot.begin()); it != snapshot.end(); it++) { | 350 for (Snapshot::iterator it(snapshot.begin()); it != snapshot.end(); it++) { |
| 347 if (it->second.was_nonexistant()) { | 351 if (it->second.was_nonexistant()) { |
| 348 name_not_found.push_back(it->second); | 352 name_not_found.push_back(it->second); |
| 349 continue; | 353 continue; |
| 350 } | 354 } |
| 351 if (!it->second.was_found()) | 355 if (!it->second.was_found()) |
| 352 continue; // Still being processed. | 356 continue; // Still being processed. |
| 353 if (base::TimeDelta() != it->second.benefits_remaining()) { | 357 if (TimeDelta() != it->second.benefits_remaining()) { |
| 354 network_hits.push_back(it->second); // With no benefit yet. | 358 network_hits.push_back(it->second); // With no benefit yet. |
| 355 continue; | 359 continue; |
| 356 } | 360 } |
| 357 if (DnsHostInfo::kMaxNonNetworkDnsLookupDuration > | 361 if (DnsHostInfo::kMaxNonNetworkDnsLookupDuration > |
| 358 it->second.resolve_duration()) { | 362 it->second.resolve_duration()) { |
| 359 already_cached.push_back(it->second); | 363 already_cached.push_back(it->second); |
| 360 continue; | 364 continue; |
| 361 } | 365 } |
| 362 // Remaining case is where prefetch benefit was significant, and was used. | 366 // Remaining case is where prefetch benefit was significant, and was used. |
| 363 // Since we shot those cases as historical hits, we won't bother here. | 367 // Since we shot those cases as historical hits, we won't bother here. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 378 DnsHostInfo::GetHtmlTable(already_cached, | 382 DnsHostInfo::GetHtmlTable(already_cached, |
| 379 "Previously cached resolutions were found for ", brief, output); | 383 "Previously cached resolutions were found for ", brief, output); |
| 380 DnsHostInfo::GetHtmlTable(name_not_found, | 384 DnsHostInfo::GetHtmlTable(name_not_found, |
| 381 "Prefetching DNS records revealed non-existance for ", brief, output); | 385 "Prefetching DNS records revealed non-existance for ", brief, output); |
| 382 } | 386 } |
| 383 | 387 |
| 384 DnsHostInfo* DnsMaster::PreLockedResolve( | 388 DnsHostInfo* DnsMaster::PreLockedResolve( |
| 385 const std::string& hostname, | 389 const std::string& hostname, |
| 386 DnsHostInfo::ResolutionMotivation motivation) { | 390 DnsHostInfo::ResolutionMotivation motivation) { |
| 387 // DCHECK(We have the lock); | 391 // DCHECK(We have the lock); |
| 388 DCHECK(0 != hostname.length()); | 392 DCHECK_NE(0u, hostname.length()); |
| 389 | 393 |
| 390 if (shutdown_) | 394 if (shutdown_) |
| 391 return NULL; | 395 return NULL; |
| 392 | 396 |
| 393 DnsHostInfo* info = &results_[hostname]; | 397 DnsHostInfo* info = &results_[hostname]; |
| 394 info->SetHostname(hostname); // Initialize or DCHECK. | 398 info->SetHostname(hostname); // Initialize or DCHECK. |
| 395 // TODO(jar): I need to discard names that have long since expired. | 399 // TODO(jar): I need to discard names that have long since expired. |
| 396 // Currently we only add to the domain map :-/ | 400 // Currently we only add to the domain map :-/ |
| 397 | 401 |
| 398 DCHECK(info->HasHostname(hostname)); | 402 DCHECK(info->HasHostname(hostname)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 // there was (equivalently) some network error that prevents us from | 441 // there was (equivalently) some network error that prevents us from |
| 438 // finding the name. Status net::OK means it was "found." | 442 // finding the name. Status net::OK means it was "found." |
| 439 PrelockedLookupFinished(request, hostname, status == net::OK); | 443 PrelockedLookupFinished(request, hostname, status == net::OK); |
| 440 delete request; | 444 delete request; |
| 441 } | 445 } |
| 442 } | 446 } |
| 443 } | 447 } |
| 444 | 448 |
| 445 bool DnsMaster::PreLockedCongestionControlPerformed(DnsHostInfo* info) { | 449 bool DnsMaster::PreLockedCongestionControlPerformed(DnsHostInfo* info) { |
| 446 // Note: queue_duration is ONLY valid after we go to assigned state. | 450 // Note: queue_duration is ONLY valid after we go to assigned state. |
| 447 // TODO(jar): Tune selection of arbitrary 1 second constant. Add plumbing so | 451 if (info->queue_duration() < max_queue_delay_) |
| 448 // that this can be set as part of an A/B experiment. | |
| 449 if (info->queue_duration() < base::TimeDelta::FromSeconds(1)) | |
| 450 return false; | 452 return false; |
| 451 // We need to discard all entries in our queue, as we're keeping them waiting | 453 // We need to discard all entries in our queue, as we're keeping them waiting |
| 452 // too long. By doing this, we'll have a chance to quickly service urgent | 454 // too long. By doing this, we'll have a chance to quickly service urgent |
| 453 // resolutions, and not have a bogged down system. | 455 // resolutions, and not have a bogged down system. |
| 454 while (true) { | 456 while (true) { |
| 455 info->RemoveFromQueue(); | 457 info->RemoveFromQueue(); |
| 456 if (work_queue_.IsEmpty()) | 458 if (work_queue_.IsEmpty()) |
| 457 break; | 459 break; |
| 458 info = &results_[work_queue_.Pop()]; | 460 info = &results_[work_queue_.Pop()]; |
| 459 info->SetAssignedState(); | 461 info->SetAssignedState(); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 std::string hostname(rush_queue_.front()); | 611 std::string hostname(rush_queue_.front()); |
| 610 rush_queue_.pop(); | 612 rush_queue_.pop(); |
| 611 return hostname; | 613 return hostname; |
| 612 } | 614 } |
| 613 std::string hostname(background_queue_.front()); | 615 std::string hostname(background_queue_.front()); |
| 614 background_queue_.pop(); | 616 background_queue_.pop(); |
| 615 return hostname; | 617 return hostname; |
| 616 } | 618 } |
| 617 | 619 |
| 618 } // namespace chrome_browser_net | 620 } // namespace chrome_browser_net |
| OLD | NEW |