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_H_ | 5 #ifndef NET_DNS_DNS_CONFIG_SERVICE_H_ |
6 #define NET_DNS_DNS_CONFIG_SERVICE_H_ | 6 #define NET_DNS_DNS_CONFIG_SERVICE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/memory/scoped_ptr.h" |
15 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
16 #include "base/threading/non_thread_safe.h" | 17 #include "base/threading/non_thread_safe.h" |
17 #include "base/time.h" | 18 #include "base/time.h" |
18 #include "net/base/ip_endpoint.h" // win requires size of IPEndPoint | 19 #include "net/base/ip_endpoint.h" // win requires size of IPEndPoint |
19 #include "net/base/net_export.h" | 20 #include "net/base/net_export.h" |
20 #include "net/dns/dns_hosts.h" | 21 #include "net/dns/dns_hosts.h" |
21 #include "net/dns/serial_worker.h" | 22 #include "net/dns/serial_worker.h" |
22 | 23 |
23 namespace net { | 24 namespace net { |
24 | 25 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 int attempts; | 58 int attempts; |
58 // Round robin entries in |nameservers| for subsequent requests. | 59 // Round robin entries in |nameservers| for subsequent requests. |
59 bool rotate; | 60 bool rotate; |
60 // Enable EDNS0 extensions. | 61 // Enable EDNS0 extensions. |
61 bool edns0; | 62 bool edns0; |
62 }; | 63 }; |
63 | 64 |
64 | 65 |
65 // Service for watching when the system DNS settings have changed. | 66 // Service for watching when the system DNS settings have changed. |
66 // Depending on the platform, watches files in /etc/ or win registry. | 67 // Depending on the platform, watches files in /etc/ or win registry. |
| 68 // This class also serves as the do-nothing mock implementation. |
67 class NET_EXPORT_PRIVATE DnsConfigService | 69 class NET_EXPORT_PRIVATE DnsConfigService |
68 : NON_EXPORTED_BASE(public base::NonThreadSafe) { | 70 : NON_EXPORTED_BASE(public base::NonThreadSafe) { |
69 public: | 71 public: |
70 // Callback interface for the client. The observer is called on the same | 72 // Callback interface for the client. The observer is called on the same |
71 // thread as Watch(). Observer must outlive the service. | 73 // thread as Watch(). Observer must outlive the service. |
72 class Observer { | 74 class Observer { |
73 public: | 75 public: |
74 virtual ~Observer() {} | 76 virtual ~Observer() {} |
75 | 77 |
76 // Called only when |dns_config| is different from the last call. | 78 // Called only when |dns_config| is different from the last call. |
77 virtual void OnConfigChanged(const DnsConfig& dns_config) = 0; | 79 virtual void OnConfigChanged(const DnsConfig& dns_config) = 0; |
78 }; | 80 }; |
79 | 81 |
80 // Creates the platform-specific DnsConfigService. | 82 // Creates the platform-specific DnsConfigService. |
81 static DnsConfigService* CreateSystemService(); | 83 static scoped_ptr<DnsConfigService> CreateSystemService(); |
82 | 84 |
83 DnsConfigService(); | 85 DnsConfigService(); |
84 virtual ~DnsConfigService(); | 86 virtual ~DnsConfigService(); |
85 | 87 |
86 // Immediately starts watching system configuration for changes and attempts | 88 // Immediately starts watching system configuration for changes and attempts |
87 // to read the configuration. For some platform implementations, the current | 89 // to read the configuration. For some platform implementations, the current |
88 // thread must have an IO loop (for base::files::FilePathWatcher). | 90 // thread must have an IO loop (for base::files::FilePathWatcher). |
89 virtual void Watch() {} | 91 virtual void Watch() {} |
90 | 92 |
91 // If a config is available, |observer| will immediately be called with | 93 // If a config is available, |observer| will immediately be called with |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 // Written in DoRead, read in OnReadFinished, no locking necessary. | 132 // Written in DoRead, read in OnReadFinished, no locking necessary. |
131 DnsHosts dns_hosts_; | 133 DnsHosts dns_hosts_; |
132 bool success_; | 134 bool success_; |
133 | 135 |
134 DISALLOW_COPY_AND_ASSIGN(DnsHostsReader); | 136 DISALLOW_COPY_AND_ASSIGN(DnsHostsReader); |
135 }; | 137 }; |
136 | 138 |
137 } // namespace net | 139 } // namespace net |
138 | 140 |
139 #endif // NET_DNS_DNS_CONFIG_SERVICE_H_ | 141 #endif // NET_DNS_DNS_CONFIG_SERVICE_H_ |
OLD | NEW |