Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: net/dns/dns_config_service.h

Issue 10377092: [net/dns] Isolate DnsConfigWatcher from DnsConfigService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments. Braces. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/threading/non_thread_safe.h" 15 #include "base/threading/non_thread_safe.h"
16 #include "base/time.h" 16 #include "base/time.h"
17 #include "base/timer.h" 17 #include "base/timer.h"
18 // Needed on shared build with MSVS2010 to avoid multiple definitions of 18 // Needed on shared build with MSVS2010 to avoid multiple definitions of
19 // std::vector<IPEndPoint>. 19 // std::vector<IPEndPoint>.
20 #include "net/base/address_list.h" 20 #include "net/base/address_list.h"
21 #include "net/base/ip_endpoint.h" // win requires size of IPEndPoint 21 #include "net/base/ip_endpoint.h" // win requires size of IPEndPoint
22 #include "net/base/network_change_notifier.h"
22 #include "net/base/net_export.h" 23 #include "net/base/net_export.h"
23 #include "net/dns/dns_hosts.h" 24 #include "net/dns/dns_hosts.h"
24 25
25 namespace base { 26 namespace base {
26 class Value; 27 class Value;
27 } 28 }
28 29
29 namespace net { 30 namespace net {
30 31
31 // DnsConfig stores configuration of the system resolver. 32 // DnsConfig stores configuration of the system resolver.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 base::TimeDelta timeout; 69 base::TimeDelta timeout;
69 // Maximum number of attempts, see res_state.retry. 70 // Maximum number of attempts, see res_state.retry.
70 int attempts; 71 int attempts;
71 // Round robin entries in |nameservers| for subsequent requests. 72 // Round robin entries in |nameservers| for subsequent requests.
72 bool rotate; 73 bool rotate;
73 // Enable EDNS0 extensions. 74 // Enable EDNS0 extensions.
74 bool edns0; 75 bool edns0;
75 }; 76 };
76 77
77 78
78 // Service for watching when the system DNS settings have changed. 79 // Service for reading system DNS settings, on demand or when signalled by
79 // Depending on the platform, watches files in /etc/ or Windows registry. 80 // NetworkChangeNotifier.
80 class NET_EXPORT_PRIVATE DnsConfigService 81 class NET_EXPORT_PRIVATE DnsConfigService
81 : NON_EXPORTED_BASE(public base::NonThreadSafe) { 82 : NON_EXPORTED_BASE(public base::NonThreadSafe),
83 public NetworkChangeNotifier::DNSObserver {
82 public: 84 public:
83 // Callback interface for the client, called on the same thread as Watch(). 85 // Callback interface for the client, called on the same thread as Read() and
86 // Watch().
84 typedef base::Callback<void(const DnsConfig& config)> CallbackType; 87 typedef base::Callback<void(const DnsConfig& config)> CallbackType;
85 88
86 // Creates the platform-specific DnsConfigService. 89 // Creates the platform-specific DnsConfigService.
87 static scoped_ptr<DnsConfigService> CreateSystemService(); 90 static scoped_ptr<DnsConfigService> CreateSystemService();
88 91
89 DnsConfigService(); 92 DnsConfigService();
90 virtual ~DnsConfigService(); 93 virtual ~DnsConfigService();
91 94
92 // Immediately starts watching system configuration for changes and attempts 95 // Attempts to read the configuration. Will run |callback| when succeeded.
93 // to read the configuration. For some platform implementations, the current 96 // Can be called at most once.
94 // thread must have an IO loop (for base::files::FilePathWatcher). 97 void Read(const CallbackType& callback);
95 virtual void Watch(const CallbackType& callback) = 0; 98
99 // Registers for notifications at NetworkChangeNotifier. Will attempt to read
100 // config after watch is started by NetworkChangeNotifier. Will run |callback|
101 // iff config changes from last call or should be withdrawn.
102 // Can be called at most once.
103 virtual void Watch(const CallbackType& callback);
96 104
97 protected: 105 protected:
98 friend class DnsHostsReader; 106 friend class DnsHostsReader;
99 107
100 // Called when the current config (except hosts) has changed. 108 // Called when the current config (except hosts) has changed.
101 void InvalidateConfig(); 109 void InvalidateConfig();
102 // Called when the current hosts have changed. 110 // Called when the current hosts have changed.
103 void InvalidateHosts(); 111 void InvalidateHosts();
104 112
105 // Called with new config. |config|.hosts is ignored. 113 // Called with new config. |config|.hosts is ignored.
106 void OnConfigRead(const DnsConfig& config); 114 void OnConfigRead(const DnsConfig& config);
107 // Called with new hosts. Rest of the config is assumed unchanged. 115 // Called with new hosts. Rest of the config is assumed unchanged.
108 void OnHostsRead(const DnsHosts& hosts); 116 void OnHostsRead(const DnsHosts& hosts);
109 117
110 void set_callback(const CallbackType& callback) { 118 // NetworkChangeNotifier::DNSObserver:
111 callback_ = callback; 119 // Must be defined by implementations.
112 } 120 virtual void OnDNSChanged(unsigned detail) OVERRIDE = 0;
113 121
114 private: 122 private:
115 void StartTimer(); 123 void StartTimer();
116 // Called when the timer expires. 124 // Called when the timer expires.
117 void OnTimeout(); 125 void OnTimeout();
118 // Called when the config becomes complete. 126 // Called when the config becomes complete.
119 void OnCompleteConfig(); 127 void OnCompleteConfig();
120 128
121 CallbackType callback_; 129 CallbackType callback_;
122 130
123 DnsConfig dns_config_; 131 DnsConfig dns_config_;
124 132
125 // True after On*Read, before Invalidate*. Tell if the config is complete. 133 // True after On*Read, before Invalidate*. Tells if the config is complete.
126 bool have_config_; 134 bool have_config_;
127 bool have_hosts_; 135 bool have_hosts_;
128 // True if receiver needs to be updated when the config becomes complete. 136 // True if receiver needs to be updated when the config becomes complete.
129 bool need_update_; 137 bool need_update_;
130 138
131 // Started in Invalidate*, cleared in On*Read. 139 // Started in Invalidate*, cleared in On*Read.
132 base::OneShotTimer<DnsConfigService> timer_; 140 base::OneShotTimer<DnsConfigService> timer_;
133 141
134 private: 142 private:
135 DISALLOW_COPY_AND_ASSIGN(DnsConfigService); 143 DISALLOW_COPY_AND_ASSIGN(DnsConfigService);
136 }; 144 };
137 145
138 } // namespace net 146 } // namespace net
139 147
140 #endif // NET_DNS_DNS_CONFIG_SERVICE_H_ 148 #endif // NET_DNS_DNS_CONFIG_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698