Add signalSyncPoint to the WebGraphicsContext3D command buffer impls.
[chromium-blink-merge.git] / net / dns / host_resolver.cc
blob3b680b7644bf3d404d8576591a2652d8e1146484
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
3 // found in the LICENSE file.
5 #include "net/dns/host_resolver.h"
7 #include "base/logging.h"
8 #include "base/metrics/field_trial.h"
9 #include "base/string_number_conversions.h"
10 #include "base/strings/string_split.h"
11 #include "net/dns/dns_client.h"
12 #include "net/dns/dns_config_service.h"
13 #include "net/dns/host_cache.h"
14 #include "net/dns/host_resolver_impl.h"
16 namespace net {
18 namespace {
20 // Maximum of 6 concurrent resolver threads (excluding retries).
21 // Some routers (or resolvers) appear to start to provide host-not-found if
22 // too many simultaneous resolutions are pending. This number needs to be
23 // further optimized, but 8 is what FF currently does. We found some routers
24 // that limit this to 6, so we're temporarily holding it at that level.
25 const size_t kDefaultMaxProcTasks = 6u;
27 // When configuring from field trial, do not allow
28 const size_t kSaneMaxProcTasks = 20u;
30 PrioritizedDispatcher::Limits GetDispatcherLimits(
31 const HostResolver::Options& options) {
32 PrioritizedDispatcher::Limits limits(NUM_PRIORITIES,
33 options.max_concurrent_resolves);
35 // If not using default, do not use the field trial.
36 if (limits.total_jobs != HostResolver::kDefaultParallelism)
37 return limits;
39 // Default, without trial is no reserved slots.
40 limits.total_jobs = kDefaultMaxProcTasks;
42 // Parallelism is determined by the field trial.
43 std::string group = base::FieldTrialList::FindFullName(
44 "HostResolverDispatch");
46 if (group.empty())
47 return limits;
49 // The format of the group name is a list of non-negative integers separated
50 // by ':'. Each of the elements in the list corresponds to an element in
51 // |reserved_slots|, except the last one which is the |total_jobs|.
53 std::vector<std::string> group_parts;
54 base::SplitString(group, ':', &group_parts);
55 if (group_parts.size() != NUM_PRIORITIES + 1) {
56 NOTREACHED();
57 return limits;
60 std::vector<size_t> parsed(group_parts.size());
61 size_t total_reserved_slots = 0;
63 for (size_t i = 0; i < group_parts.size(); ++i) {
64 if (!base::StringToSizeT(group_parts[i], &parsed[i])) {
65 NOTREACHED();
66 return limits;
70 size_t total_jobs = parsed.back();
71 parsed.pop_back();
72 for (size_t i = 0; i < parsed.size(); ++i) {
73 total_reserved_slots += parsed[i];
76 // There must be some unreserved slots available for the all priorities.
77 if (total_reserved_slots > total_jobs ||
78 (total_reserved_slots == total_jobs && parsed[MINIMUM_PRIORITY] == 0)) {
79 NOTREACHED();
80 return limits;
83 limits.total_jobs = total_jobs;
84 limits.reserved_slots = parsed;
85 return limits;
88 } // namespace
90 HostResolver::Options::Options()
91 : max_concurrent_resolves(kDefaultParallelism),
92 max_retry_attempts(kDefaultRetryAttempts),
93 enable_caching(true) {
96 HostResolver::RequestInfo::RequestInfo(const HostPortPair& host_port_pair)
97 : host_port_pair_(host_port_pair),
98 address_family_(ADDRESS_FAMILY_UNSPECIFIED),
99 host_resolver_flags_(0),
100 allow_cached_response_(true),
101 is_speculative_(false),
102 priority_(MEDIUM) {
105 HostResolver::~HostResolver() {
108 AddressFamily HostResolver::GetDefaultAddressFamily() const {
109 return ADDRESS_FAMILY_UNSPECIFIED;
112 void HostResolver::ProbeIPv6Support() {
115 void HostResolver::SetDnsClientEnabled(bool enabled) {
118 HostCache* HostResolver::GetHostCache() {
119 return NULL;
122 base::Value* HostResolver::GetDnsConfigAsValue() const {
123 return NULL;
126 // static
127 scoped_ptr<HostResolver>
128 HostResolver::CreateSystemResolver(const Options& options, NetLog* net_log) {
129 scoped_ptr<HostCache> cache;
130 if (options.enable_caching)
131 cache = HostCache::CreateDefaultCache();
132 return scoped_ptr<HostResolver>(new HostResolverImpl(
133 cache.Pass(),
134 GetDispatcherLimits(options),
135 HostResolverImpl::ProcTaskParams(NULL, options.max_retry_attempts),
136 net_log));
139 // static
140 scoped_ptr<HostResolver>
141 HostResolver::CreateDefaultResolver(NetLog* net_log) {
142 return CreateSystemResolver(Options(), net_log);
145 HostResolver::HostResolver() {
148 } // namespace net