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

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

Issue 132693025: Add the ability for MDnsListener to actively refresh records (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 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
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);
147 147
148 void NotifyNsecRecord(const RecordParsed* record); 148 void NotifyNsecRecord(const RecordParsed* record);
149 149
150 // Delete and erase the observer list for |key|. Only deletes the observer 150 // Delete and erase the observer list for |key|. Only deletes the observer
151 // list if is empty. 151 // list if is empty.
152 void CleanupObserverList(const ListenerKey& key); 152 void CleanupObserverList(const ListenerKey& key);
153 153
154 ListenerMap listeners_; 154 ListenerMap listeners_;
155 155
156 MDnsClientImpl* client_; 156 MDnsClientImpl* client_;
157 MDnsCache cache_; 157 MDnsCache cache_;
158 158
159 base::CancelableCallback<void()> cleanup_callback_; 159 base::CancelableClosure cleanup_callback_;
160 base::Time scheduled_cleanup_; 160 base::Time scheduled_cleanup_;
161 161
162 scoped_ptr<MDnsConnection> connection_; 162 scoped_ptr<MDnsConnection> connection_;
163 163
164 DISALLOW_COPY_AND_ASSIGN(Core); 164 DISALLOW_COPY_AND_ASSIGN(Core);
165 }; 165 };
166 166
167 MDnsClientImpl(); 167 MDnsClientImpl();
168 virtual ~MDnsClientImpl(); 168 virtual ~MDnsClientImpl();
169 169
(...skipping 27 matching lines...) Expand all
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::CancelableClosure next_refresh_;
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
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698