Ensure favicon images are correctly used and downloaded when syncing bookmark apps.
[chromium-blink-merge.git] / net / dns / dns_config_service_win.h
blob5b6f22bb7de4b77b545fc22de1f37c3f8fa3bede
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 #ifndef NET_DNS_DNS_CONFIG_SERVICE_WIN_H_
6 #define NET_DNS_DNS_CONFIG_SERVICE_WIN_H_
8 // The sole purpose of dns_config_service_win.h is for unittests so we just
9 // include these headers here.
10 #include <winsock2.h>
11 #include <iphlpapi.h>
13 #include <string>
14 #include <vector>
16 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_ptr.h"
18 #include "base/strings/string16.h"
19 #include "net/base/net_export.h"
20 #include "net/dns/dns_config_service.h"
22 // The general effort of DnsConfigServiceWin is to configure |nameservers| and
23 // |search| in DnsConfig. The settings are stored in the Windows registry, but
24 // to simplify the task we use the IP Helper API wherever possible. That API
25 // yields the complete and ordered |nameservers|, but to determine |search| we
26 // need to use the registry. On Windows 7, WMI does return the correct |search|
27 // but on earlier versions it is insufficient.
29 // Experimental evaluation of Windows behavior suggests that domain parsing is
30 // naive. Domain suffixes in |search| are not validated until they are appended
31 // to the resolved name. We attempt to replicate this behavior.
33 namespace net {
35 namespace internal {
37 // Parses |value| as search list (comma-delimited list of domain names) from
38 // a registry key and stores it in |out|. Returns true on success. Empty
39 // entries (e.g., "chromium.org,,org") terminate the list. Non-ascii hostnames
40 // are converted to punycode.
41 bool NET_EXPORT_PRIVATE ParseSearchList(const base::string16& value,
42 std::vector<std::string>* out);
44 // All relevant settings read from registry and IP Helper. This isolates our
45 // logic from system calls and is exposed for unit tests. Keep it an aggregate
46 // struct for easy initialization.
47 struct NET_EXPORT_PRIVATE DnsSystemSettings {
48 // The |set| flag distinguishes between empty and unset values.
49 struct RegString {
50 bool set;
51 base::string16 value;
54 struct RegDword {
55 bool set;
56 DWORD value;
59 struct DevolutionSetting {
60 // UseDomainNameDevolution
61 RegDword enabled;
62 // DomainNameDevolutionLevel
63 RegDword level;
66 DnsSystemSettings();
67 ~DnsSystemSettings();
69 // Filled in by GetAdapterAddresses. Note that the alternative
70 // GetNetworkParams does not include IPv6 addresses.
71 scoped_ptr<IP_ADAPTER_ADDRESSES, base::FreeDeleter> addresses;
73 // SOFTWARE\Policies\Microsoft\Windows NT\DNSClient\SearchList
74 RegString policy_search_list;
75 // SYSTEM\CurrentControlSet\Tcpip\Parameters\SearchList
76 RegString tcpip_search_list;
77 // SYSTEM\CurrentControlSet\Tcpip\Parameters\Domain
78 RegString tcpip_domain;
79 // SOFTWARE\Policies\Microsoft\System\DNSClient\PrimaryDnsSuffix
80 RegString primary_dns_suffix;
82 // SOFTWARE\Policies\Microsoft\Windows NT\DNSClient
83 DevolutionSetting policy_devolution;
84 // SYSTEM\CurrentControlSet\Dnscache\Parameters
85 DevolutionSetting dnscache_devolution;
86 // SYSTEM\CurrentControlSet\Tcpip\Parameters
87 DevolutionSetting tcpip_devolution;
89 // SOFTWARE\Policies\Microsoft\Windows NT\DNSClient\AppendToMultiLabelName
90 RegDword append_to_multi_label_name;
92 // True when the Name Resolution Policy Table (NRPT) has at least one rule:
93 // SOFTWARE\Policies\Microsoft\Windows NT\DNSClient\DnsPolicyConfig\Rule*
94 bool have_name_resolution_policy;
97 enum ConfigParseWinResult {
98 CONFIG_PARSE_WIN_OK = 0,
99 CONFIG_PARSE_WIN_READ_IPHELPER,
100 CONFIG_PARSE_WIN_READ_POLICY_SEARCHLIST,
101 CONFIG_PARSE_WIN_READ_TCPIP_SEARCHLIST,
102 CONFIG_PARSE_WIN_READ_DOMAIN,
103 CONFIG_PARSE_WIN_READ_POLICY_DEVOLUTION,
104 CONFIG_PARSE_WIN_READ_DNSCACHE_DEVOLUTION,
105 CONFIG_PARSE_WIN_READ_TCPIP_DEVOLUTION,
106 CONFIG_PARSE_WIN_READ_APPEND_MULTILABEL,
107 CONFIG_PARSE_WIN_READ_PRIMARY_SUFFIX,
108 CONFIG_PARSE_WIN_BAD_ADDRESS,
109 CONFIG_PARSE_WIN_NO_NAMESERVERS,
110 CONFIG_PARSE_WIN_UNHANDLED_OPTIONS,
111 CONFIG_PARSE_WIN_MAX // Bounding values for enumeration.
114 // Fills in |dns_config| from |settings|. Exposed for tests.
115 ConfigParseWinResult NET_EXPORT_PRIVATE ConvertSettingsToDnsConfig(
116 const DnsSystemSettings& settings,
117 DnsConfig* dns_config);
119 // Use DnsConfigService::CreateSystemService to use it outside of tests.
120 class NET_EXPORT_PRIVATE DnsConfigServiceWin : public DnsConfigService {
121 public:
122 DnsConfigServiceWin();
123 ~DnsConfigServiceWin() override;
125 private:
126 class Watcher;
127 class ConfigReader;
128 class HostsReader;
130 // DnsConfigService:
131 void ReadNow() override;
132 bool StartWatching() override;
134 void OnConfigChanged(bool succeeded);
135 void OnHostsChanged(bool succeeded);
137 scoped_ptr<Watcher> watcher_;
138 scoped_refptr<ConfigReader> config_reader_;
139 scoped_refptr<HostsReader> hosts_reader_;
141 DISALLOW_COPY_AND_ASSIGN(DnsConfigServiceWin);
144 } // namespace internal
146 } // namespace net
148 #endif // NET_DNS_DNS_CONFIG_SERVICE_WIN_H_