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

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

Issue 669813003: Update from chromium https://crrev.com/301725/ (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « net/dns/host_resolver_impl_unittest.cc ('k') | net/dns/mdns_client_unittest.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 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>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/cancelable_callback.h" 13 #include "base/cancelable_callback.h"
14 #include "base/memory/scoped_vector.h" 14 #include "base/memory/scoped_vector.h"
15 #include "base/observer_list.h" 15 #include "base/observer_list.h"
16 #include "net/base/io_buffer.h" 16 #include "net/base/io_buffer.h"
17 #include "net/base/ip_endpoint.h" 17 #include "net/base/ip_endpoint.h"
18 #include "net/dns/mdns_cache.h" 18 #include "net/dns/mdns_cache.h"
19 #include "net/dns/mdns_client.h" 19 #include "net/dns/mdns_client.h"
20 #include "net/udp/datagram_server_socket.h" 20 #include "net/udp/datagram_server_socket.h"
21 #include "net/udp/udp_server_socket.h" 21 #include "net/udp/udp_server_socket.h"
22 #include "net/udp/udp_socket.h" 22 #include "net/udp/udp_socket.h"
23 23
24 namespace net { 24 namespace net {
25 25
26 class MDnsSocketFactoryImpl : public MDnsSocketFactory { 26 class MDnsSocketFactoryImpl : public MDnsSocketFactory {
27 public: 27 public:
28 MDnsSocketFactoryImpl() {}; 28 MDnsSocketFactoryImpl() {};
29 virtual ~MDnsSocketFactoryImpl() {}; 29 ~MDnsSocketFactoryImpl() override{};
30 30
31 virtual void CreateSockets( 31 void CreateSockets(ScopedVector<DatagramServerSocket>* sockets) override;
32 ScopedVector<DatagramServerSocket>* sockets) override;
33 32
34 private: 33 private:
35 DISALLOW_COPY_AND_ASSIGN(MDnsSocketFactoryImpl); 34 DISALLOW_COPY_AND_ASSIGN(MDnsSocketFactoryImpl);
36 }; 35 };
37 36
38 // A connection to the network for multicast DNS clients. It reads data into 37 // A connection to the network for multicast DNS clients. It reads data into
39 // DnsResponse objects and alerts the delegate that a packet has been received. 38 // DnsResponse objects and alerts the delegate that a packet has been received.
40 class NET_EXPORT_PRIVATE MDnsConnection { 39 class NET_EXPORT_PRIVATE MDnsConnection {
41 public: 40 public:
42 class Delegate { 41 class Delegate {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 103
105 class NET_EXPORT_PRIVATE MDnsClientImpl : public MDnsClient { 104 class NET_EXPORT_PRIVATE MDnsClientImpl : public MDnsClient {
106 public: 105 public:
107 // The core object exists while the MDnsClient is listening, and is deleted 106 // The core object exists while the MDnsClient is listening, and is deleted
108 // whenever the number of listeners reaches zero. The deletion happens 107 // whenever the number of listeners reaches zero. The deletion happens
109 // asychronously, so destroying the last listener does not immediately 108 // asychronously, so destroying the last listener does not immediately
110 // invalidate the core. 109 // invalidate the core.
111 class Core : public base::SupportsWeakPtr<Core>, MDnsConnection::Delegate { 110 class Core : public base::SupportsWeakPtr<Core>, MDnsConnection::Delegate {
112 public: 111 public:
113 explicit Core(MDnsClientImpl* client); 112 explicit Core(MDnsClientImpl* client);
114 virtual ~Core(); 113 ~Core() override;
115 114
116 // Initialize the core. Returns true on success. 115 // Initialize the core. Returns true on success.
117 bool Init(MDnsSocketFactory* socket_factory); 116 bool Init(MDnsSocketFactory* socket_factory);
118 117
119 // Send a query with a specific rrtype and name. Returns true on success. 118 // Send a query with a specific rrtype and name. Returns true on success.
120 bool SendQuery(uint16 rrtype, std::string name); 119 bool SendQuery(uint16 rrtype, std::string name);
121 120
122 // Add/remove a listener to the list of listeners. 121 // Add/remove a listener to the list of listeners.
123 void AddListener(MDnsListenerImpl* listener); 122 void AddListener(MDnsListenerImpl* listener);
124 void RemoveListener(MDnsListenerImpl* listener); 123 void RemoveListener(MDnsListenerImpl* listener);
125 124
126 // Query the cache for records of a specific type and name. 125 // Query the cache for records of a specific type and name.
127 void QueryCache(uint16 rrtype, const std::string& name, 126 void QueryCache(uint16 rrtype, const std::string& name,
128 std::vector<const RecordParsed*>* records) const; 127 std::vector<const RecordParsed*>* records) const;
129 128
130 // Parse the response and alert relevant listeners. 129 // Parse the response and alert relevant listeners.
131 virtual void HandlePacket(DnsResponse* response, int bytes_read) override; 130 void HandlePacket(DnsResponse* response, int bytes_read) override;
132 131
133 virtual void OnConnectionError(int error) override; 132 void OnConnectionError(int error) override;
134 133
135 private: 134 private:
136 typedef std::pair<std::string, uint16> ListenerKey; 135 typedef std::pair<std::string, uint16> ListenerKey;
137 typedef std::map<ListenerKey, ObserverList<MDnsListenerImpl>* > 136 typedef std::map<ListenerKey, ObserverList<MDnsListenerImpl>* >
138 ListenerMap; 137 ListenerMap;
139 138
140 // Alert listeners of an update to the cache. 139 // Alert listeners of an update to the cache.
141 void AlertListeners(MDnsCache::UpdateType update_type, 140 void AlertListeners(MDnsCache::UpdateType update_type,
142 const ListenerKey& key, const RecordParsed* record); 141 const ListenerKey& key, const RecordParsed* record);
143 142
(...skipping 19 matching lines...) Expand all
163 162
164 base::CancelableClosure cleanup_callback_; 163 base::CancelableClosure cleanup_callback_;
165 base::Time scheduled_cleanup_; 164 base::Time scheduled_cleanup_;
166 165
167 scoped_ptr<MDnsConnection> connection_; 166 scoped_ptr<MDnsConnection> connection_;
168 167
169 DISALLOW_COPY_AND_ASSIGN(Core); 168 DISALLOW_COPY_AND_ASSIGN(Core);
170 }; 169 };
171 170
172 MDnsClientImpl(); 171 MDnsClientImpl();
173 virtual ~MDnsClientImpl(); 172 ~MDnsClientImpl() override;
174 173
175 // MDnsClient implementation: 174 // MDnsClient implementation:
176 virtual scoped_ptr<MDnsListener> CreateListener( 175 scoped_ptr<MDnsListener> CreateListener(
177 uint16 rrtype, 176 uint16 rrtype,
178 const std::string& name, 177 const std::string& name,
179 MDnsListener::Delegate* delegate) override; 178 MDnsListener::Delegate* delegate) override;
180 179
181 virtual scoped_ptr<MDnsTransaction> CreateTransaction( 180 scoped_ptr<MDnsTransaction> CreateTransaction(
182 uint16 rrtype, 181 uint16 rrtype,
183 const std::string& name, 182 const std::string& name,
184 int flags, 183 int flags,
185 const MDnsTransaction::ResultCallback& callback) override; 184 const MDnsTransaction::ResultCallback& callback) override;
186 185
187 virtual bool StartListening(MDnsSocketFactory* socket_factory) override; 186 bool StartListening(MDnsSocketFactory* socket_factory) override;
188 virtual void StopListening() override; 187 void StopListening() override;
189 virtual bool IsListening() const override; 188 bool IsListening() const override;
190 189
191 Core* core() { return core_.get(); } 190 Core* core() { return core_.get(); }
192 191
193 private: 192 private:
194 scoped_ptr<Core> core_; 193 scoped_ptr<Core> core_;
195 194
196 DISALLOW_COPY_AND_ASSIGN(MDnsClientImpl); 195 DISALLOW_COPY_AND_ASSIGN(MDnsClientImpl);
197 }; 196 };
198 197
199 class MDnsListenerImpl : public MDnsListener, 198 class MDnsListenerImpl : public MDnsListener,
200 public base::SupportsWeakPtr<MDnsListenerImpl> { 199 public base::SupportsWeakPtr<MDnsListenerImpl> {
201 public: 200 public:
202 MDnsListenerImpl(uint16 rrtype, 201 MDnsListenerImpl(uint16 rrtype,
203 const std::string& name, 202 const std::string& name,
204 MDnsListener::Delegate* delegate, 203 MDnsListener::Delegate* delegate,
205 MDnsClientImpl* client); 204 MDnsClientImpl* client);
206 205
207 virtual ~MDnsListenerImpl(); 206 ~MDnsListenerImpl() override;
208 207
209 // MDnsListener implementation: 208 // MDnsListener implementation:
210 virtual bool Start() override; 209 bool Start() override;
211 210
212 // Actively refresh any received records. 211 // Actively refresh any received records.
213 virtual void SetActiveRefresh(bool active_refresh) override; 212 void SetActiveRefresh(bool active_refresh) override;
214 213
215 virtual const std::string& GetName() const override; 214 const std::string& GetName() const override;
216 215
217 virtual uint16 GetType() const override; 216 uint16 GetType() const override;
218 217
219 MDnsListener::Delegate* delegate() { return delegate_; } 218 MDnsListener::Delegate* delegate() { return delegate_; }
220 219
221 // Alert the delegate of a record update. 220 // Alert the delegate of a record update.
222 void HandleRecordUpdate(MDnsCache::UpdateType update_type, 221 void HandleRecordUpdate(MDnsCache::UpdateType update_type,
223 const RecordParsed* record_parsed); 222 const RecordParsed* record_parsed);
224 223
225 // Alert the delegate of the existence of an Nsec record. 224 // Alert the delegate of the existence of an Nsec record.
226 void AlertNsecRecord(); 225 void AlertNsecRecord();
227 226
(...skipping 17 matching lines...) Expand all
245 244
246 class MDnsTransactionImpl : public base::SupportsWeakPtr<MDnsTransactionImpl>, 245 class MDnsTransactionImpl : public base::SupportsWeakPtr<MDnsTransactionImpl>,
247 public MDnsTransaction, 246 public MDnsTransaction,
248 public MDnsListener::Delegate { 247 public MDnsListener::Delegate {
249 public: 248 public:
250 MDnsTransactionImpl(uint16 rrtype, 249 MDnsTransactionImpl(uint16 rrtype,
251 const std::string& name, 250 const std::string& name,
252 int flags, 251 int flags,
253 const MDnsTransaction::ResultCallback& callback, 252 const MDnsTransaction::ResultCallback& callback,
254 MDnsClientImpl* client); 253 MDnsClientImpl* client);
255 virtual ~MDnsTransactionImpl(); 254 ~MDnsTransactionImpl() override;
256 255
257 // MDnsTransaction implementation: 256 // MDnsTransaction implementation:
258 virtual bool Start() override; 257 bool Start() override;
259 258
260 virtual const std::string& GetName() const override; 259 const std::string& GetName() const override;
261 virtual uint16 GetType() const override; 260 uint16 GetType() const override;
262 261
263 // MDnsListener::Delegate implementation: 262 // MDnsListener::Delegate implementation:
264 virtual void OnRecordUpdate(MDnsListener::UpdateType update, 263 void OnRecordUpdate(MDnsListener::UpdateType update,
265 const RecordParsed* record) override; 264 const RecordParsed* record) override;
266 virtual void OnNsecRecord(const std::string& name, unsigned type) override; 265 void OnNsecRecord(const std::string& name, unsigned type) override;
267 266
268 virtual void OnCachePurged() override; 267 void OnCachePurged() override;
269 268
270 private: 269 private:
271 bool is_active() { return !callback_.is_null(); } 270 bool is_active() { return !callback_.is_null(); }
272 271
273 void Reset(); 272 void Reset();
274 273
275 // Trigger the callback and reset all related variables. 274 // Trigger the callback and reset all related variables.
276 void TriggerCallback(MDnsTransaction::Result result, 275 void TriggerCallback(MDnsTransaction::Result result,
277 const RecordParsed* record); 276 const RecordParsed* record);
278 277
(...skipping 22 matching lines...) Expand all
301 MDnsClientImpl* client_; 300 MDnsClientImpl* client_;
302 301
303 bool started_; 302 bool started_;
304 int flags_; 303 int flags_;
305 304
306 DISALLOW_COPY_AND_ASSIGN(MDnsTransactionImpl); 305 DISALLOW_COPY_AND_ASSIGN(MDnsTransactionImpl);
307 }; 306 };
308 307
309 } // namespace net 308 } // namespace net
310 #endif // NET_DNS_MDNS_CLIENT_IMPL_H_ 309 #endif // NET_DNS_MDNS_CLIENT_IMPL_H_
OLDNEW
« no previous file with comments | « net/dns/host_resolver_impl_unittest.cc ('k') | net/dns/mdns_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698