OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_MDNS_CLIENT_IMPL_H_ | 5 #ifndef NET_DNS_MDNS_CLIENT_IMPL_H_ |
6 #define NET_DNS_MDNS_CLIENT_IMPL_H_ | 6 #define NET_DNS_MDNS_CLIENT_IMPL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 virtual void HandlePacket(DnsResponse* response, int bytes_read) OVERRIDE; | 126 virtual void HandlePacket(DnsResponse* response, int bytes_read) OVERRIDE; |
127 | 127 |
128 virtual void OnConnectionError(int error) OVERRIDE; | 128 virtual void OnConnectionError(int error) OVERRIDE; |
129 | 129 |
130 private: | 130 private: |
131 typedef std::pair<std::string, uint16> ListenerKey; | 131 typedef std::pair<std::string, uint16> ListenerKey; |
132 typedef std::map<ListenerKey, ObserverList<MDnsListenerImpl>* > | 132 typedef std::map<ListenerKey, ObserverList<MDnsListenerImpl>* > |
133 ListenerMap; | 133 ListenerMap; |
134 | 134 |
135 // Alert listeners of an update to the cache. | 135 // Alert listeners of an update to the cache. |
136 void AlertListeners(MDnsListener::UpdateType update_type, | 136 void AlertListeners(MDnsCache::UpdateType update_type, |
137 const ListenerKey& key, const RecordParsed* record); | 137 const ListenerKey& key, const RecordParsed* record); |
138 | 138 |
139 // Schedule a cache cleanup to a specific time, cancelling other cleanups. | 139 // Schedule a cache cleanup to a specific time, cancelling other cleanups. |
140 void ScheduleCleanup(base::Time cleanup); | 140 void ScheduleCleanup(base::Time cleanup); |
141 | 141 |
142 // Clean up the cache and schedule a new cleanup. | 142 // Clean up the cache and schedule a new cleanup. |
143 void DoCleanup(); | 143 void DoCleanup(); |
144 | 144 |
145 // Callback for when a record is removed from the cache. | 145 // Callback for when a record is removed from the cache. |
146 void OnRecordRemoved(const RecordParsed* record); | 146 void OnRecordRemoved(const RecordParsed* record); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 MDnsListenerImpl(uint16 rrtype, | 197 MDnsListenerImpl(uint16 rrtype, |
198 const std::string& name, | 198 const std::string& name, |
199 MDnsListener::Delegate* delegate, | 199 MDnsListener::Delegate* delegate, |
200 MDnsClientImpl* client); | 200 MDnsClientImpl* client); |
201 | 201 |
202 virtual ~MDnsListenerImpl(); | 202 virtual ~MDnsListenerImpl(); |
203 | 203 |
204 // MDnsListener implementation: | 204 // MDnsListener implementation: |
205 virtual bool Start() OVERRIDE; | 205 virtual bool Start() OVERRIDE; |
206 | 206 |
207 // Actively refresh any received records. | |
208 virtual void SetActiveRefresh(bool active_refresh) OVERRIDE; | |
209 | |
207 virtual const std::string& GetName() const OVERRIDE; | 210 virtual const std::string& GetName() const OVERRIDE; |
208 | 211 |
209 virtual uint16 GetType() const OVERRIDE; | 212 virtual uint16 GetType() const OVERRIDE; |
210 | 213 |
211 MDnsListener::Delegate* delegate() { return delegate_; } | 214 MDnsListener::Delegate* delegate() { return delegate_; } |
212 | 215 |
213 // Alert the delegate of a record update. | 216 // Alert the delegate of a record update. |
214 void AlertDelegate(MDnsListener::UpdateType update_type, | 217 void HandleRecordUpdate(MDnsCache::UpdateType update_type, |
215 const RecordParsed* record_parsed); | 218 const RecordParsed* record_parsed); |
216 | 219 |
217 // Alert the delegate of the existence of an Nsec record. | 220 // Alert the delegate of the existence of an Nsec record. |
218 void AlertNsecRecord(); | 221 void AlertNsecRecord(); |
219 | 222 |
220 private: | 223 private: |
224 void ScheduleNextRefresh(); | |
225 void DoRefresh(); | |
226 | |
221 uint16 rrtype_; | 227 uint16 rrtype_; |
222 std::string name_; | 228 std::string name_; |
223 MDnsClientImpl* client_; | 229 MDnsClientImpl* client_; |
224 MDnsListener::Delegate* delegate_; | 230 MDnsListener::Delegate* delegate_; |
225 | 231 |
232 base::Time last_update_; | |
233 uint32 ttl_; | |
226 bool started_; | 234 bool started_; |
235 bool active_refresh_; | |
236 | |
237 base::CancelableCallback<void()> next_refresh_; | |
szym
2014/01/23 11:24:03
base::CancelableClosure
Noam Samuel
2014/01/23 17:50:42
Done.
| |
227 DISALLOW_COPY_AND_ASSIGN(MDnsListenerImpl); | 238 DISALLOW_COPY_AND_ASSIGN(MDnsListenerImpl); |
228 }; | 239 }; |
229 | 240 |
230 class MDnsTransactionImpl : public base::SupportsWeakPtr<MDnsTransactionImpl>, | 241 class MDnsTransactionImpl : public base::SupportsWeakPtr<MDnsTransactionImpl>, |
231 public MDnsTransaction, | 242 public MDnsTransaction, |
232 public MDnsListener::Delegate { | 243 public MDnsListener::Delegate { |
233 public: | 244 public: |
234 MDnsTransactionImpl(uint16 rrtype, | 245 MDnsTransactionImpl(uint16 rrtype, |
235 const std::string& name, | 246 const std::string& name, |
236 int flags, | 247 int flags, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 MDnsClientImpl* client_; | 296 MDnsClientImpl* client_; |
286 | 297 |
287 bool started_; | 298 bool started_; |
288 int flags_; | 299 int flags_; |
289 | 300 |
290 DISALLOW_COPY_AND_ASSIGN(MDnsTransactionImpl); | 301 DISALLOW_COPY_AND_ASSIGN(MDnsTransactionImpl); |
291 }; | 302 }; |
292 | 303 |
293 } // namespace net | 304 } // namespace net |
294 #endif // NET_DNS_MDNS_CLIENT_IMPL_H_ | 305 #endif // NET_DNS_MDNS_CLIENT_IMPL_H_ |
OLD | NEW |