Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: net/base/host_resolver_impl.cc

Issue 10831277: [net] Change factory methods for HostResolver and HostCache to return a scoped_ptr (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // Limit the size of hostnames that will be resolved to combat issues in 56 // Limit the size of hostnames that will be resolved to combat issues in
57 // some platform's resolvers. 57 // some platform's resolvers.
58 const size_t kMaxHostLength = 4096; 58 const size_t kMaxHostLength = 4096;
59 59
60 // Default TTL for successful resolutions with ProcTask. 60 // Default TTL for successful resolutions with ProcTask.
61 const unsigned kCacheEntryTTLSeconds = 60; 61 const unsigned kCacheEntryTTLSeconds = 60;
62 62
63 // Default TTL for unsuccessful resolutions with ProcTask. 63 // Default TTL for unsuccessful resolutions with ProcTask.
64 const unsigned kNegativeCacheEntryTTLSeconds = 0; 64 const unsigned kNegativeCacheEntryTTLSeconds = 0;
65 65
66 // Maximum of 6 concurrent resolver threads (excluding retries).
67 // Some routers (or resolvers) appear to start to provide host-not-found if
68 // too many simultaneous resolutions are pending. This number needs to be
69 // further optimized, but 8 is what FF currently does. We found some routers
70 // that limit this to 6, so we're temporarily holding it at that level.
71 static const size_t kDefaultMaxProcTasks = 6u;
72
73 // We use a separate histogram name for each platform to facilitate the 66 // We use a separate histogram name for each platform to facilitate the
74 // display of error codes by their symbolic name (since each platform has 67 // display of error codes by their symbolic name (since each platform has
75 // different mappings). 68 // different mappings).
76 const char kOSErrorsForGetAddrinfoHistogramName[] = 69 const char kOSErrorsForGetAddrinfoHistogramName[] =
77 #if defined(OS_WIN) 70 #if defined(OS_WIN)
78 "Net.OSErrorsForGetAddrinfo_Win"; 71 "Net.OSErrorsForGetAddrinfo_Win";
79 #elif defined(OS_MACOSX) 72 #elif defined(OS_MACOSX)
80 "Net.OSErrorsForGetAddrinfo_Mac"; 73 "Net.OSErrorsForGetAddrinfo_Mac";
81 #elif defined(OS_LINUX) 74 #elif defined(OS_LINUX)
82 "Net.OSErrorsForGetAddrinfo_Linux"; 75 "Net.OSErrorsForGetAddrinfo_Linux";
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 if (total_count_ == 0) 389 if (total_count_ == 0)
397 DCHECK_EQ(MINIMUM_PRIORITY, highest_priority_); 390 DCHECK_EQ(MINIMUM_PRIORITY, highest_priority_);
398 } 391 }
399 392
400 private: 393 private:
401 RequestPriority highest_priority_; 394 RequestPriority highest_priority_;
402 size_t total_count_; 395 size_t total_count_;
403 size_t counts_[NUM_PRIORITIES]; 396 size_t counts_[NUM_PRIORITIES];
404 }; 397 };
405 398
406 //----------------------------------------------------------------------------- 399 } // namespace
407
408 HostResolver* CreateHostResolver(size_t max_concurrent_resolves,
409 size_t max_retry_attempts,
410 HostCache* cache,
411 scoped_ptr<DnsClient> dns_client,
412 NetLog* net_log) {
413 if (max_concurrent_resolves == HostResolver::kDefaultParallelism)
414 max_concurrent_resolves = kDefaultMaxProcTasks;
415
416 // TODO(szym): Add experiments with reserved slots for higher priority
417 // requests.
418
419 PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, max_concurrent_resolves);
420
421 HostResolverImpl* resolver = new HostResolverImpl(
422 cache,
423 limits,
424 HostResolverImpl::ProcTaskParams(NULL, max_retry_attempts),
425 dns_client.Pass(),
426 net_log);
427
428 return resolver;
429 }
430
431 } // anonymous namespace
432 400
433 //----------------------------------------------------------------------------- 401 //-----------------------------------------------------------------------------
434 402
435 HostResolver* CreateSystemHostResolver(size_t max_concurrent_resolves,
436 size_t max_retry_attempts,
437 NetLog* net_log) {
438 return CreateHostResolver(max_concurrent_resolves,
439 max_retry_attempts,
440 HostCache::CreateDefaultCache(),
441 scoped_ptr<DnsClient>(NULL),
442 net_log);
443 }
444
445 HostResolver* CreateNonCachingSystemHostResolver(size_t max_concurrent_resolves,
446 size_t max_retry_attempts,
447 NetLog* net_log) {
448 return CreateHostResolver(max_concurrent_resolves,
449 max_retry_attempts,
450 NULL,
451 scoped_ptr<DnsClient>(NULL),
452 net_log);
453 }
454
455 HostResolver* CreateAsyncHostResolver(size_t max_concurrent_resolves,
456 size_t max_retry_attempts,
457 NetLog* net_log) {
458 #if !defined(ENABLE_BUILT_IN_DNS)
459 NOTREACHED();
460 return NULL;
461 #else
462 return CreateHostResolver(max_concurrent_resolves,
463 max_retry_attempts,
464 HostCache::CreateDefaultCache(),
465 DnsClient::CreateClient(net_log),
466 net_log);
467 #endif // !defined(ENABLE_BUILT_IN_DNS)
468 }
469
470 //-----------------------------------------------------------------------------
471
472 // Holds the data for a request that could not be completed synchronously. 403 // Holds the data for a request that could not be completed synchronously.
473 // It is owned by a Job. Canceled Requests are only marked as canceled rather 404 // It is owned by a Job. Canceled Requests are only marked as canceled rather
474 // than removed from the Job's |requests_| list. 405 // than removed from the Job's |requests_| list.
475 class HostResolverImpl::Request { 406 class HostResolverImpl::Request {
476 public: 407 public:
477 Request(const BoundNetLog& source_net_log, 408 Request(const BoundNetLog& source_net_log,
478 const BoundNetLog& request_net_log, 409 const BoundNetLog& request_net_log,
479 const RequestInfo& info, 410 const RequestInfo& info,
480 const CompletionCallback& callback, 411 const CompletionCallback& callback,
481 AddressList* addresses) 412 AddressList* addresses)
(...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1654 size_t max_retry_attempts) 1585 size_t max_retry_attempts)
1655 : resolver_proc(resolver_proc), 1586 : resolver_proc(resolver_proc),
1656 max_retry_attempts(max_retry_attempts), 1587 max_retry_attempts(max_retry_attempts),
1657 unresponsive_delay(base::TimeDelta::FromMilliseconds(6000)), 1588 unresponsive_delay(base::TimeDelta::FromMilliseconds(6000)),
1658 retry_factor(2) { 1589 retry_factor(2) {
1659 } 1590 }
1660 1591
1661 HostResolverImpl::ProcTaskParams::~ProcTaskParams() {} 1592 HostResolverImpl::ProcTaskParams::~ProcTaskParams() {}
1662 1593
1663 HostResolverImpl::HostResolverImpl( 1594 HostResolverImpl::HostResolverImpl(
1664 HostCache* cache, 1595 scoped_ptr<HostCache> cache,
1665 const PrioritizedDispatcher::Limits& job_limits, 1596 const PrioritizedDispatcher::Limits& job_limits,
1666 const ProcTaskParams& proc_params, 1597 const ProcTaskParams& proc_params,
1667 scoped_ptr<DnsClient> dns_client, 1598 scoped_ptr<DnsClient> dns_client,
1668 NetLog* net_log) 1599 NetLog* net_log)
1669 : cache_(cache), 1600 : cache_(cache.Pass()),
1670 dispatcher_(job_limits), 1601 dispatcher_(job_limits),
1671 max_queued_jobs_(job_limits.total_jobs * 100u), 1602 max_queued_jobs_(job_limits.total_jobs * 100u),
1672 proc_params_(proc_params), 1603 proc_params_(proc_params),
1673 default_address_family_(ADDRESS_FAMILY_UNSPECIFIED), 1604 default_address_family_(ADDRESS_FAMILY_UNSPECIFIED),
1674 weak_ptr_factory_(this), 1605 weak_ptr_factory_(this),
1675 dns_client_(dns_client.Pass()), 1606 dns_client_(dns_client.Pass()),
1676 received_dns_config_(false), 1607 received_dns_config_(false),
1677 ipv6_probe_monitoring_(false), 1608 ipv6_probe_monitoring_(false),
1678 additional_resolver_flags_(0), 1609 additional_resolver_flags_(0),
1679 net_log_(net_log) { 1610 net_log_(net_log) {
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
2146 // |this| may be deleted inside AbortAllInProgressJobs(). 2077 // |this| may be deleted inside AbortAllInProgressJobs().
2147 if (self) 2078 if (self)
2148 TryServingAllJobsFromHosts(); 2079 TryServingAllJobsFromHosts();
2149 } 2080 }
2150 2081
2151 bool HostResolverImpl::HaveDnsConfig() const { 2082 bool HostResolverImpl::HaveDnsConfig() const {
2152 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL); 2083 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL);
2153 } 2084 }
2154 2085
2155 } // namespace net 2086 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698