OLD | NEW |
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 #ifndef NET_DNS_DNS_CONFIG_SERVICE_WIN_H_ | 5 #ifndef NET_DNS_DNS_CONFIG_SERVICE_WIN_H_ |
6 #define NET_DNS_DNS_CONFIG_SERVICE_WIN_H_ | 6 #define NET_DNS_DNS_CONFIG_SERVICE_WIN_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 // The sole purpose of dns_config_service_win.h is for unittests so we just | 9 // The sole purpose of dns_config_service_win.h is for unittests so we just |
10 // include these headers here. | 10 // include these headers here. |
(...skipping 15 matching lines...) Expand all Loading... |
26 // yields the complete and ordered |nameservers|, but to determine |search| we | 26 // yields the complete and ordered |nameservers|, but to determine |search| we |
27 // need to use the registry. On Windows 7, WMI does return the correct |search| | 27 // need to use the registry. On Windows 7, WMI does return the correct |search| |
28 // but on earlier versions it is insufficient. | 28 // but on earlier versions it is insufficient. |
29 // | 29 // |
30 // Experimental evaluation of Windows behavior suggests that domain parsing is | 30 // Experimental evaluation of Windows behavior suggests that domain parsing is |
31 // naive. Domain suffixes in |search| are not validated until they are appended | 31 // naive. Domain suffixes in |search| are not validated until they are appended |
32 // to the resolved name. We attempt to replicate this behavior. | 32 // to the resolved name. We attempt to replicate this behavior. |
33 | 33 |
34 namespace net { | 34 namespace net { |
35 | 35 |
36 class FilePathWatcherWrapper; | |
37 | |
38 // Use DnsConfigService::CreateSystemService to use it outside of tests. | |
39 namespace internal { | 36 namespace internal { |
40 | 37 |
41 class NET_EXPORT_PRIVATE DnsConfigServiceWin | 38 // Registry key paths. |
42 : NON_EXPORTED_BASE(public DnsConfigService) { | 39 const wchar_t* const kTcpipPath = |
43 public: | 40 L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters"; |
44 DnsConfigServiceWin(); | 41 const wchar_t* const kTcpip6Path = |
45 virtual ~DnsConfigServiceWin(); | 42 L"SYSTEM\\CurrentControlSet\\Services\\Tcpip6\\Parameters"; |
| 43 const wchar_t* const kDnscachePath = |
| 44 L"SYSTEM\\CurrentControlSet\\Services\\Dnscache\\Parameters"; |
| 45 const wchar_t* const kPolicyPath = |
| 46 L"SOFTWARE\\Policies\\Microsoft\\Windows NT\\DNSClient"; |
46 | 47 |
47 virtual void Watch(const CallbackType& callback) OVERRIDE; | 48 // Returns the path to the HOSTS file. |
| 49 FilePath GetHostsPath(); |
48 | 50 |
49 private: | 51 // Parses |value| as search list (comma-delimited list of domain names) from |
50 class ConfigReader; | 52 // a registry key and stores it in |out|. Returns true on success. Empty |
51 class HostsReader; | 53 // entries (e.g., "chromium.org,,org") terminate the list. Non-ascii hostnames |
52 | 54 // are converted to punycode. |
53 scoped_refptr<ConfigReader> config_reader_; | 55 bool NET_EXPORT_PRIVATE ParseSearchList(const string16& value, |
54 scoped_refptr<HostsReader> hosts_reader_; | 56 std::vector<std::string>* out); |
55 | |
56 DISALLOW_COPY_AND_ASSIGN(DnsConfigServiceWin); | |
57 }; | |
58 | 57 |
59 // All relevant settings read from registry and IP Helper. This isolates our | 58 // All relevant settings read from registry and IP Helper. This isolates our |
60 // logic from system calls and is exposed for unit tests. Keep it an aggregate | 59 // logic from system calls and is exposed for unit tests. Keep it an aggregate |
61 // struct for easy initialization. | 60 // struct for easy initialization. |
62 struct NET_EXPORT_PRIVATE DnsSystemSettings { | 61 struct NET_EXPORT_PRIVATE DnsSystemSettings { |
63 // The |set| flag distinguishes between empty and unset values. | 62 // The |set| flag distinguishes between empty and unset values. |
64 struct RegString { | 63 struct RegString { |
65 bool set; | 64 bool set; |
66 string16 value; | 65 string16 value; |
67 }; | 66 }; |
(...skipping 27 matching lines...) Expand all Loading... |
95 DevolutionSetting policy_devolution; | 94 DevolutionSetting policy_devolution; |
96 // SYSTEM\CurrentControlSet\Dnscache\Parameters | 95 // SYSTEM\CurrentControlSet\Dnscache\Parameters |
97 DevolutionSetting dnscache_devolution; | 96 DevolutionSetting dnscache_devolution; |
98 // SYSTEM\CurrentControlSet\Tcpip\Parameters | 97 // SYSTEM\CurrentControlSet\Tcpip\Parameters |
99 DevolutionSetting tcpip_devolution; | 98 DevolutionSetting tcpip_devolution; |
100 | 99 |
101 // SOFTWARE\Policies\Microsoft\Windows NT\DNSClient\AppendToMultiLabelName | 100 // SOFTWARE\Policies\Microsoft\Windows NT\DNSClient\AppendToMultiLabelName |
102 RegDword append_to_multi_label_name; | 101 RegDword append_to_multi_label_name; |
103 }; | 102 }; |
104 | 103 |
105 // Parses |value| as search list (comma-delimited list of domain names) from | |
106 // a registry key and stores it in |out|. Returns true on success. Empty | |
107 // entries (e.g., "chromium.org,,org") terminate the list. Non-ascii hostnames | |
108 // are converted to punycode. | |
109 bool NET_EXPORT_PRIVATE ParseSearchList(const string16& value, | |
110 std::vector<std::string>* out); | |
111 | |
112 // Fills in |dns_config| from |settings|. Exposed for tests. | 104 // Fills in |dns_config| from |settings|. Exposed for tests. |
113 bool NET_EXPORT_PRIVATE ConvertSettingsToDnsConfig( | 105 bool NET_EXPORT_PRIVATE ConvertSettingsToDnsConfig( |
114 const DnsSystemSettings& settings, DnsConfig* dns_config); | 106 const DnsSystemSettings& settings, |
| 107 DnsConfig* dns_config); |
| 108 |
| 109 // Use DnsConfigService::CreateSystemService to use it outside of tests. |
| 110 class NET_EXPORT_PRIVATE DnsConfigServiceWin |
| 111 : public DnsConfigService, |
| 112 public NetworkChangeNotifier::IPAddressObserver { |
| 113 public: |
| 114 DnsConfigServiceWin(); |
| 115 virtual ~DnsConfigServiceWin(); |
| 116 |
| 117 virtual void Watch(const CallbackType& callback) OVERRIDE; |
| 118 |
| 119 private: |
| 120 class ConfigReader; |
| 121 class HostsReader; |
| 122 |
| 123 // NetworkChangeNotifier::DNSObserver: |
| 124 virtual void OnDNSChanged(unsigned detail) OVERRIDE; |
| 125 |
| 126 // NetworkChangeNotifier::IPAddressObserver: |
| 127 virtual void OnIPAddressChanged() OVERRIDE; |
| 128 |
| 129 scoped_refptr<ConfigReader> config_reader_; |
| 130 scoped_refptr<HostsReader> hosts_reader_; |
| 131 |
| 132 DISALLOW_COPY_AND_ASSIGN(DnsConfigServiceWin); |
| 133 }; |
115 | 134 |
116 } // namespace internal | 135 } // namespace internal |
117 | 136 |
118 } // namespace net | 137 } // namespace net |
119 | 138 |
120 #endif // NET_DNS_DNS_CONFIG_SERVICE_WIN_H_ | 139 #endif // NET_DNS_DNS_CONFIG_SERVICE_WIN_H_ |
121 | 140 |
OLD | NEW |