Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / net / dns / host_resolver.cc
blobdeacb2d9a62f4a719ef0d56badd2fa26a0e5ea77
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/strings/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 } // namespace
29 PrioritizedDispatcher::Limits HostResolver::Options::GetDispatcherLimits()
30 const {
31 PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, max_concurrent_resolves);
33 // If not using default, do not use the field trial.
34 if (limits.total_jobs != HostResolver::kDefaultParallelism)
35 return limits;
37 // Default, without trial is no reserved slots.
38 limits.total_jobs = kDefaultMaxProcTasks;
40 // Parallelism is determined by the field trial.
41 std::string group = base::FieldTrialList::FindFullName(
42 "HostResolverDispatch");
44 if (group.empty())
45 return limits;
47 // The format of the group name is a list of non-negative integers separated
48 // by ':'. Each of the elements in the list corresponds to an element in
49 // |reserved_slots|, except the last one which is the |total_jobs|.
50 std::vector<base::StringPiece> group_parts = base::SplitStringPiece(
51 group, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
52 if (group_parts.size() != NUM_PRIORITIES + 1) {
53 NOTREACHED();
54 return limits;
57 std::vector<size_t> parsed(group_parts.size());
58 size_t total_reserved_slots = 0;
60 for (size_t i = 0; i < group_parts.size(); ++i) {
61 if (!base::StringToSizeT(group_parts[i], &parsed[i])) {
62 NOTREACHED();
63 return limits;
67 size_t total_jobs = parsed.back();
68 parsed.pop_back();
69 for (size_t i = 0; i < parsed.size(); ++i) {
70 total_reserved_slots += parsed[i];
73 // There must be some unreserved slots available for the all priorities.
74 if (total_reserved_slots > total_jobs ||
75 (total_reserved_slots == total_jobs && parsed[MINIMUM_PRIORITY] == 0)) {
76 NOTREACHED();
77 return limits;
80 limits.total_jobs = total_jobs;
81 limits.reserved_slots = parsed;
82 return limits;
85 HostResolver::Options::Options()
86 : max_concurrent_resolves(kDefaultParallelism),
87 max_retry_attempts(kDefaultRetryAttempts),
88 enable_caching(true) {
91 HostResolver::RequestInfo::RequestInfo(const HostPortPair& host_port_pair)
92 : host_port_pair_(host_port_pair),
93 address_family_(ADDRESS_FAMILY_UNSPECIFIED),
94 host_resolver_flags_(0),
95 allow_cached_response_(true),
96 is_speculative_(false),
97 is_my_ip_address_(false) {}
99 HostResolver::~HostResolver() {
102 void HostResolver::SetDnsClientEnabled(bool enabled) {
105 HostCache* HostResolver::GetHostCache() {
106 return NULL;
109 base::Value* HostResolver::GetDnsConfigAsValue() const {
110 return NULL;
113 // static
114 scoped_ptr<HostResolver> HostResolver::CreateSystemResolver(
115 const Options& options,
116 NetLog* net_log) {
117 return scoped_ptr<HostResolver>(new HostResolverImpl(options, net_log));
120 // static
121 scoped_ptr<HostResolver> HostResolver::CreateDefaultResolver(NetLog* net_log) {
122 return scoped_ptr<HostResolver>(new HostResolverImpl(Options(), net_log));
125 HostResolver::HostResolver() {
128 } // namespace net