| 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_POSIX_H_ | 5 #ifndef NET_DNS_DNS_CONFIG_SERVICE_POSIX_H_ |
| 6 #define NET_DNS_DNS_CONFIG_SERVICE_POSIX_H_ | 6 #define NET_DNS_DNS_CONFIG_SERVICE_POSIX_H_ |
| 7 | 7 |
| 8 #if !defined(OS_ANDROID) | 8 #if !defined(OS_ANDROID) |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 #include <netinet/in.h> | 10 #include <netinet/in.h> |
| 11 #include <resolv.h> | 11 #include <resolv.h> |
| 12 #endif | 12 #endif |
| 13 | 13 |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/files/file_path.h" |
| 15 #include "net/base/net_export.h" | 16 #include "net/base/net_export.h" |
| 17 #include "net/base/network_change_notifier.h" |
| 16 #include "net/dns/dns_config_service.h" | 18 #include "net/dns/dns_config_service.h" |
| 17 | 19 |
| 20 namespace base { |
| 21 class Time; |
| 22 } // namespace base |
| 23 |
| 18 namespace net { | 24 namespace net { |
| 19 | 25 |
| 20 // Use DnsConfigService::CreateSystemService to use it outside of tests. | 26 // Use DnsConfigService::CreateSystemService to use it outside of tests. |
| 21 namespace internal { | 27 namespace internal { |
| 22 | 28 |
| 29 // Note: On Android NetworkChangeNotifier::OnNetworkChanged() signals must be |
| 30 // passed in via calls to OnNetworkChanged(). |
| 23 class NET_EXPORT_PRIVATE DnsConfigServicePosix : public DnsConfigService { | 31 class NET_EXPORT_PRIVATE DnsConfigServicePosix : public DnsConfigService { |
| 24 public: | 32 public: |
| 25 DnsConfigServicePosix(); | 33 DnsConfigServicePosix(); |
| 26 ~DnsConfigServicePosix() override; | 34 ~DnsConfigServicePosix() override; |
| 27 | 35 |
| 36 #if defined(OS_ANDROID) |
| 37 // Returns whether the DnsConfigServicePosix witnessed a DNS configuration |
| 38 // change since |since_time|. Requires that callers have started listening |
| 39 // for NetworkChangeNotifier::OnNetworkChanged() signals, and passing them in |
| 40 // via OnNetworkChanged(), prior to |since_time|. |
| 41 bool SeenChangeSince(const base::Time& since_time) const; |
| 42 // NetworkChangeNotifier::OnNetworkChanged() signals must be passed |
| 43 // in via calls to OnNetworkChanged(). Allowing external sources of |
| 44 // this signal allows users of DnsConfigServicePosix to start watching for |
| 45 // NetworkChangeNotifier::OnNetworkChanged() signals prior to the |
| 46 // DnsConfigServicePosix even being created. |
| 47 void OnNetworkChanged(NetworkChangeNotifier::ConnectionType type); |
| 48 #endif |
| 49 |
| 50 void SetDnsConfigForTesting(const DnsConfig* dns_config); |
| 51 |
| 28 protected: | 52 protected: |
| 29 // DnsConfigService: | 53 // DnsConfigService: |
| 30 void ReadNow() override; | 54 void ReadNow() override; |
| 31 bool StartWatching() override; | 55 bool StartWatching() override; |
| 32 | 56 |
| 33 private: | 57 private: |
| 58 friend class DnsConfigServicePosixTest; |
| 34 class Watcher; | 59 class Watcher; |
| 35 class ConfigReader; | 60 class ConfigReader; |
| 36 class HostsReader; | 61 class HostsReader; |
| 37 | 62 |
| 38 void OnConfigChanged(bool succeeded); | 63 void OnConfigChanged(bool succeeded); |
| 39 void OnHostsChanged(bool succeeded); | 64 void OnHostsChanged(bool succeeded); |
| 40 | 65 |
| 41 scoped_ptr<Watcher> watcher_; | 66 scoped_ptr<Watcher> watcher_; |
| 67 // Allow a mock hosts file for testing purposes. |
| 68 const base::FilePath::CharType* file_path_hosts_; |
| 69 // Allow a mock DNS server for testing purposes. |
| 70 const DnsConfig* dns_config_for_testing_; |
| 42 scoped_refptr<ConfigReader> config_reader_; | 71 scoped_refptr<ConfigReader> config_reader_; |
| 43 scoped_refptr<HostsReader> hosts_reader_; | 72 scoped_refptr<HostsReader> hosts_reader_; |
| 73 #if defined(OS_ANDROID) |
| 74 // Has DnsConfigWatcher detected any config chagnes yet? |
| 75 bool seen_config_change_; |
| 76 #endif |
| 44 | 77 |
| 45 DISALLOW_COPY_AND_ASSIGN(DnsConfigServicePosix); | 78 DISALLOW_COPY_AND_ASSIGN(DnsConfigServicePosix); |
| 46 }; | 79 }; |
| 47 | 80 |
| 48 enum ConfigParsePosixResult { | 81 enum ConfigParsePosixResult { |
| 49 CONFIG_PARSE_POSIX_OK = 0, | 82 CONFIG_PARSE_POSIX_OK = 0, |
| 50 CONFIG_PARSE_POSIX_RES_INIT_FAILED, | 83 CONFIG_PARSE_POSIX_RES_INIT_FAILED, |
| 51 CONFIG_PARSE_POSIX_RES_INIT_UNSET, | 84 CONFIG_PARSE_POSIX_RES_INIT_UNSET, |
| 52 CONFIG_PARSE_POSIX_BAD_ADDRESS, | 85 CONFIG_PARSE_POSIX_BAD_ADDRESS, |
| 53 CONFIG_PARSE_POSIX_BAD_EXT_STRUCT, | 86 CONFIG_PARSE_POSIX_BAD_EXT_STRUCT, |
| 54 CONFIG_PARSE_POSIX_NULL_ADDRESS, | 87 CONFIG_PARSE_POSIX_NULL_ADDRESS, |
| 55 CONFIG_PARSE_POSIX_NO_NAMESERVERS, | 88 CONFIG_PARSE_POSIX_NO_NAMESERVERS, |
| 56 CONFIG_PARSE_POSIX_MISSING_OPTIONS, | 89 CONFIG_PARSE_POSIX_MISSING_OPTIONS, |
| 57 CONFIG_PARSE_POSIX_UNHANDLED_OPTIONS, | 90 CONFIG_PARSE_POSIX_UNHANDLED_OPTIONS, |
| 58 CONFIG_PARSE_POSIX_NO_DNSINFO, | 91 CONFIG_PARSE_POSIX_NO_DNSINFO, |
| 59 CONFIG_PARSE_POSIX_MAX // Bounding values for enumeration. | 92 CONFIG_PARSE_POSIX_MAX // Bounding values for enumeration. |
| 60 }; | 93 }; |
| 61 | 94 |
| 62 #if !defined(OS_ANDROID) | 95 #if !defined(OS_ANDROID) |
| 63 // Fills in |dns_config| from |res|. | 96 // Fills in |dns_config| from |res|. |
| 64 ConfigParsePosixResult NET_EXPORT_PRIVATE ConvertResStateToDnsConfig( | 97 ConfigParsePosixResult NET_EXPORT_PRIVATE ConvertResStateToDnsConfig( |
| 65 const struct __res_state& res, DnsConfig* dns_config); | 98 const struct __res_state& res, DnsConfig* dns_config); |
| 66 #endif | 99 #endif |
| 67 | 100 |
| 68 } // namespace internal | 101 } // namespace internal |
| 69 | 102 |
| 70 } // namespace net | 103 } // namespace net |
| 71 | 104 |
| 72 #endif // NET_DNS_DNS_CONFIG_SERVICE_POSIX_H_ | 105 #endif // NET_DNS_DNS_CONFIG_SERVICE_POSIX_H_ |
| OLD | NEW |