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

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

Issue 10873018: [net] Move DnsConfigService to NetworkChangeNotifier. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add comment Created 8 years, 3 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
« no previous file with comments | « net/base/network_change_notifier_win.cc ('k') | net/dns/dns_config_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/threading/non_thread_safe.h" 14 #include "base/threading/non_thread_safe.h"
15 #include "base/time.h" 15 #include "base/time.h"
16 #include "base/timer.h" 16 #include "base/timer.h"
17 // Needed on shared build with MSVS2010 to avoid multiple definitions of 17 // Needed on shared build with MSVS2010 to avoid multiple definitions of
18 // std::vector<IPEndPoint>. 18 // std::vector<IPEndPoint>.
19 #include "net/base/address_list.h" 19 #include "net/base/address_list.h"
20 #include "net/base/ip_endpoint.h" // win requires size of IPEndPoint 20 #include "net/base/ip_endpoint.h" // win requires size of IPEndPoint
21 #include "net/base/network_change_notifier.h"
22 #include "net/base/net_export.h" 21 #include "net/base/net_export.h"
23 #include "net/dns/dns_hosts.h" 22 #include "net/dns/dns_hosts.h"
24 23
25 namespace base { 24 namespace base {
26 class Value; 25 class Value;
27 } 26 }
28 27
29 namespace net { 28 namespace net {
30 29
31 // Always use 1 second timeout (followed by binary exponential backoff). 30 // Always use 1 second timeout (followed by binary exponential backoff).
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 // Maximum number of attempts, see res_state.retry. 72 // Maximum number of attempts, see res_state.retry.
74 int attempts; 73 int attempts;
75 // Round robin entries in |nameservers| for subsequent requests. 74 // Round robin entries in |nameservers| for subsequent requests.
76 bool rotate; 75 bool rotate;
77 // Enable EDNS0 extensions. 76 // Enable EDNS0 extensions.
78 bool edns0; 77 bool edns0;
79 }; 78 };
80 79
81 80
82 // Service for reading system DNS settings, on demand or when signalled by 81 // Service for reading system DNS settings, on demand or when signalled by
83 // NetworkChangeNotifier. 82 // internal watchers and NetworkChangeNotifier.
84 class NET_EXPORT_PRIVATE DnsConfigService 83 class NET_EXPORT_PRIVATE DnsConfigService
85 : NON_EXPORTED_BASE(public base::NonThreadSafe), 84 : NON_EXPORTED_BASE(public base::NonThreadSafe) {
86 public NetworkChangeNotifier::DNSObserver {
87 public: 85 public:
88 // Callback interface for the client, called on the same thread as Read() and 86 // Callback interface for the client, called on the same thread as
89 // Watch(). 87 // ReadConfig() and WatchConfig().
90 typedef base::Callback<void(const DnsConfig& config)> CallbackType; 88 typedef base::Callback<void(const DnsConfig& config)> CallbackType;
91 89
92 // Creates the platform-specific DnsConfigService. 90 // Creates the platform-specific DnsConfigService.
93 static scoped_ptr<DnsConfigService> CreateSystemService(); 91 static scoped_ptr<DnsConfigService> CreateSystemService();
94 92
95 DnsConfigService(); 93 DnsConfigService();
96 virtual ~DnsConfigService(); 94 virtual ~DnsConfigService();
97 95
98 // Attempts to read the configuration. Will run |callback| when succeeded. 96 // Attempts to read the configuration. Will run |callback| when succeeded.
99 // Can be called at most once. 97 // Can be called at most once.
100 void Read(const CallbackType& callback); 98 void ReadConfig(const CallbackType& callback);
101 99
102 // Registers for notifications at NetworkChangeNotifier. Will attempt to read 100 // Registers systems watchers. Will attempt to read config after watch starts,
103 // config after watch is started by NetworkChangeNotifier. Will run |callback| 101 // but only if watchers started successfully. Will run |callback| iff config
104 // iff config changes from last call or should be withdrawn. 102 // changes from last call or has to be withdrawn. Can be called at most once.
105 // Can be called at most once. 103 // Might require MessageLoopForIO.
106 virtual void Watch(const CallbackType& callback); 104 void WatchConfig(const CallbackType& callback);
107 105
108 protected: 106 protected:
107 // Immediately attempts to read the current configuration.
108 virtual void ReadNow() = 0;
109 // Registers system watchers. Returns true iff succeeds.
110 virtual bool StartWatching() = 0;
111
109 // Called when the current config (except hosts) has changed. 112 // Called when the current config (except hosts) has changed.
110 void InvalidateConfig(); 113 void InvalidateConfig();
111 // Called when the current hosts have changed. 114 // Called when the current hosts have changed.
112 void InvalidateHosts(); 115 void InvalidateHosts();
113 116
114 // Called with new config. |config|.hosts is ignored. 117 // Called with new config. |config|.hosts is ignored.
115 void OnConfigRead(const DnsConfig& config); 118 void OnConfigRead(const DnsConfig& config);
116 // Called with new hosts. Rest of the config is assumed unchanged. 119 // Called with new hosts. Rest of the config is assumed unchanged.
117 void OnHostsRead(const DnsHosts& hosts); 120 void OnHostsRead(const DnsHosts& hosts);
118 121
119 // NetworkChangeNotifier::DNSObserver: 122 void set_watch_failed(bool value) { watch_failed_ = value; }
120 // Must be defined by implementations.
121 virtual void OnDNSChanged(unsigned detail) OVERRIDE = 0;
122 123
123 private: 124 private:
125 // The timer counts from the last Invalidate* until complete config is read.
124 void StartTimer(); 126 void StartTimer();
125 // Called when the timer expires.
126 void OnTimeout(); 127 void OnTimeout();
127 // Called when the config becomes complete. 128 // Called when the config becomes complete. Stops the timer.
128 void OnCompleteConfig(); 129 void OnCompleteConfig();
129 130
130 CallbackType callback_; 131 CallbackType callback_;
131 132
132 DnsConfig dns_config_; 133 DnsConfig dns_config_;
133 134
135 // True if any of the necessary watchers failed. In that case, the service
136 // will communicate changes via OnTimeout, but will only send empty DnsConfig.
137 bool watch_failed_;
134 // True after On*Read, before Invalidate*. Tells if the config is complete. 138 // True after On*Read, before Invalidate*. Tells if the config is complete.
135 bool have_config_; 139 bool have_config_;
136 bool have_hosts_; 140 bool have_hosts_;
137 // True if receiver needs to be updated when the config becomes complete. 141 // True if receiver needs to be updated when the config becomes complete.
138 bool need_update_; 142 bool need_update_;
139 // True if the last config sent was empty (instead of |dns_config_|). 143 // True if the last config sent was empty (instead of |dns_config_|).
140 // Set when |timer_| expires. 144 // Set when |timer_| expires.
141 bool last_sent_empty_; 145 bool last_sent_empty_;
142 146
143 // Initialized and updated on Invalidate* call. 147 // Initialized and updated on Invalidate* call.
144 base::TimeTicks last_invalidate_config_time_; 148 base::TimeTicks last_invalidate_config_time_;
145 base::TimeTicks last_invalidate_hosts_time_; 149 base::TimeTicks last_invalidate_hosts_time_;
146 // Initialized and updated when |timer_| expires. 150 // Initialized and updated when |timer_| expires.
147 base::TimeTicks last_sent_empty_time_; 151 base::TimeTicks last_sent_empty_time_;
148 152
149 // Started in Invalidate*, cleared in On*Read. 153 // Started in Invalidate*, cleared in On*Read.
150 base::OneShotTimer<DnsConfigService> timer_; 154 base::OneShotTimer<DnsConfigService> timer_;
151 155
152 DISALLOW_COPY_AND_ASSIGN(DnsConfigService); 156 DISALLOW_COPY_AND_ASSIGN(DnsConfigService);
153 }; 157 };
154 158
155 } // namespace net 159 } // namespace net
156 160
157 #endif // NET_DNS_DNS_CONFIG_SERVICE_H_ 161 #endif // NET_DNS_DNS_CONFIG_SERVICE_H_
OLDNEW
« no previous file with comments | « net/base/network_change_notifier_win.cc ('k') | net/dns/dns_config_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698