Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / net / dns / dns_config_service_posix.h
blob0db525dfd6f8c716c43632794e1e9f030334542c
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_POSIX_H_
6 #define NET_DNS_DNS_CONFIG_SERVICE_POSIX_H_
8 #if !defined(OS_ANDROID)
9 #include <sys/types.h>
10 #include <netinet/in.h>
11 #include <resolv.h>
12 #endif
14 #include "base/compiler_specific.h"
15 #include "base/files/file_path.h"
16 #include "net/base/net_export.h"
17 #include "net/base/network_change_notifier.h"
18 #include "net/dns/dns_config_service.h"
20 namespace base {
21 class Time;
22 } // namespace base
24 namespace net {
26 // Use DnsConfigService::CreateSystemService to use it outside of tests.
27 namespace internal {
29 // Note: On Android NetworkChangeNotifier::OnNetworkChanged() signals must be
30 // passed in via calls to OnNetworkChanged().
31 class NET_EXPORT_PRIVATE DnsConfigServicePosix : public DnsConfigService {
32 public:
33 DnsConfigServicePosix();
34 ~DnsConfigServicePosix() override;
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
50 void SetDnsConfigForTesting(const DnsConfig* dns_config);
52 protected:
53 // DnsConfigService:
54 void ReadNow() override;
55 bool StartWatching() override;
57 private:
58 friend class DnsConfigServicePosixTest;
59 class Watcher;
60 class ConfigReader;
61 class HostsReader;
63 void OnConfigChanged(bool succeeded);
64 void OnHostsChanged(bool succeeded);
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_;
71 scoped_refptr<ConfigReader> config_reader_;
72 scoped_refptr<HostsReader> hosts_reader_;
73 #if defined(OS_ANDROID)
74 // Has DnsConfigWatcher detected any config changes yet?
75 bool seen_config_change_;
76 #endif
78 DISALLOW_COPY_AND_ASSIGN(DnsConfigServicePosix);
81 enum ConfigParsePosixResult {
82 CONFIG_PARSE_POSIX_OK = 0,
83 CONFIG_PARSE_POSIX_RES_INIT_FAILED,
84 CONFIG_PARSE_POSIX_RES_INIT_UNSET,
85 CONFIG_PARSE_POSIX_BAD_ADDRESS,
86 CONFIG_PARSE_POSIX_BAD_EXT_STRUCT,
87 CONFIG_PARSE_POSIX_NULL_ADDRESS,
88 CONFIG_PARSE_POSIX_NO_NAMESERVERS,
89 CONFIG_PARSE_POSIX_MISSING_OPTIONS,
90 CONFIG_PARSE_POSIX_UNHANDLED_OPTIONS,
91 CONFIG_PARSE_POSIX_NO_DNSINFO,
92 CONFIG_PARSE_POSIX_MAX // Bounding values for enumeration.
95 #if !defined(OS_ANDROID)
96 // Fills in |dns_config| from |res|.
97 ConfigParsePosixResult NET_EXPORT_PRIVATE ConvertResStateToDnsConfig(
98 const struct __res_state& res, DnsConfig* dns_config);
99 #endif
101 } // namespace internal
103 } // namespace net
105 #endif // NET_DNS_DNS_CONFIG_SERVICE_POSIX_H_