Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / net / dns / dns_config_service_posix.h
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.
4
5 #ifndef NET_DNS_DNS_CONFIG_SERVICE_POSIX_H_
6 #define NET_DNS_DNS_CONFIG_SERVICE_POSIX_H_
7
8 #if !defined(OS_ANDROID)
9 #include <sys/types.h>
10 #include <netinet/in.h>
11 #include <resolv.h>
12 #endif
13
14 #include "base/compiler_specific.h"
15 #include "net/base/net_export.h"
16 #include "net/dns/dns_config_service.h"
17
18 namespace net {
19
20 // Use DnsConfigService::CreateSystemService to use it outside of tests.
21 namespace internal {
22
23 class NET_EXPORT_PRIVATE DnsConfigServicePosix : public DnsConfigService {
24  public:
25   DnsConfigServicePosix();
26   ~DnsConfigServicePosix() override;
27
28  protected:
29   // DnsConfigService:
30   void ReadNow() override;
31   bool StartWatching() override;
32
33  private:
34   class Watcher;
35   class ConfigReader;
36   class HostsReader;
37
38   void OnConfigChanged(bool succeeded);
39   void OnHostsChanged(bool succeeded);
40
41   scoped_ptr<Watcher> watcher_;
42   scoped_refptr<ConfigReader> config_reader_;
43   scoped_refptr<HostsReader> hosts_reader_;
44
45   DISALLOW_COPY_AND_ASSIGN(DnsConfigServicePosix);
46 };
47
48 enum ConfigParsePosixResult {
49   CONFIG_PARSE_POSIX_OK = 0,
50   CONFIG_PARSE_POSIX_RES_INIT_FAILED,
51   CONFIG_PARSE_POSIX_RES_INIT_UNSET,
52   CONFIG_PARSE_POSIX_BAD_ADDRESS,
53   CONFIG_PARSE_POSIX_BAD_EXT_STRUCT,
54   CONFIG_PARSE_POSIX_NULL_ADDRESS,
55   CONFIG_PARSE_POSIX_NO_NAMESERVERS,
56   CONFIG_PARSE_POSIX_MISSING_OPTIONS,
57   CONFIG_PARSE_POSIX_UNHANDLED_OPTIONS,
58   CONFIG_PARSE_POSIX_NO_DNSINFO,
59   CONFIG_PARSE_POSIX_MAX  // Bounding values for enumeration.
60 };
61
62 #if !defined(OS_ANDROID)
63 // Fills in |dns_config| from |res|.
64 ConfigParsePosixResult NET_EXPORT_PRIVATE ConvertResStateToDnsConfig(
65     const struct __res_state& res, DnsConfig* dns_config);
66 #endif
67
68 }  // namespace internal
69
70 }  // namespace net
71
72 #endif  // NET_DNS_DNS_CONFIG_SERVICE_POSIX_H_