| 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 11 matching lines...) Expand all Loading... |
| 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 virtual ~MDnsSocketFactoryImpl() {}; |
| 30 | 30 |
| 31 virtual void CreateSockets( | 31 virtual void CreateSockets( |
| 32 ScopedVector<DatagramServerSocket>* sockets) OVERRIDE; | 32 ScopedVector<DatagramServerSocket>* sockets) override; |
| 33 | 33 |
| 34 private: | 34 private: |
| 35 DISALLOW_COPY_AND_ASSIGN(MDnsSocketFactoryImpl); | 35 DISALLOW_COPY_AND_ASSIGN(MDnsSocketFactoryImpl); |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 // A connection to the network for multicast DNS clients. It reads data into | 38 // 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. | 39 // DnsResponse objects and alerts the delegate that a packet has been received. |
| 40 class NET_EXPORT_PRIVATE MDnsConnection { | 40 class NET_EXPORT_PRIVATE MDnsConnection { |
| 41 public: | 41 public: |
| 42 class Delegate { | 42 class Delegate { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 | 121 |
| 122 // Add/remove a listener to the list of listeners. | 122 // Add/remove a listener to the list of listeners. |
| 123 void AddListener(MDnsListenerImpl* listener); | 123 void AddListener(MDnsListenerImpl* listener); |
| 124 void RemoveListener(MDnsListenerImpl* listener); | 124 void RemoveListener(MDnsListenerImpl* listener); |
| 125 | 125 |
| 126 // Query the cache for records of a specific type and name. | 126 // Query the cache for records of a specific type and name. |
| 127 void QueryCache(uint16 rrtype, const std::string& name, | 127 void QueryCache(uint16 rrtype, const std::string& name, |
| 128 std::vector<const RecordParsed*>* records) const; | 128 std::vector<const RecordParsed*>* records) const; |
| 129 | 129 |
| 130 // Parse the response and alert relevant listeners. | 130 // Parse the response and alert relevant listeners. |
| 131 virtual void HandlePacket(DnsResponse* response, int bytes_read) OVERRIDE; | 131 virtual void HandlePacket(DnsResponse* response, int bytes_read) override; |
| 132 | 132 |
| 133 virtual void OnConnectionError(int error) OVERRIDE; | 133 virtual void OnConnectionError(int error) override; |
| 134 | 134 |
| 135 private: | 135 private: |
| 136 typedef std::pair<std::string, uint16> ListenerKey; | 136 typedef std::pair<std::string, uint16> ListenerKey; |
| 137 typedef std::map<ListenerKey, ObserverList<MDnsListenerImpl>* > | 137 typedef std::map<ListenerKey, ObserverList<MDnsListenerImpl>* > |
| 138 ListenerMap; | 138 ListenerMap; |
| 139 | 139 |
| 140 // Alert listeners of an update to the cache. | 140 // Alert listeners of an update to the cache. |
| 141 void AlertListeners(MDnsCache::UpdateType update_type, | 141 void AlertListeners(MDnsCache::UpdateType update_type, |
| 142 const ListenerKey& key, const RecordParsed* record); | 142 const ListenerKey& key, const RecordParsed* record); |
| 143 | 143 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 169 DISALLOW_COPY_AND_ASSIGN(Core); | 169 DISALLOW_COPY_AND_ASSIGN(Core); |
| 170 }; | 170 }; |
| 171 | 171 |
| 172 MDnsClientImpl(); | 172 MDnsClientImpl(); |
| 173 virtual ~MDnsClientImpl(); | 173 virtual ~MDnsClientImpl(); |
| 174 | 174 |
| 175 // MDnsClient implementation: | 175 // MDnsClient implementation: |
| 176 virtual scoped_ptr<MDnsListener> CreateListener( | 176 virtual scoped_ptr<MDnsListener> CreateListener( |
| 177 uint16 rrtype, | 177 uint16 rrtype, |
| 178 const std::string& name, | 178 const std::string& name, |
| 179 MDnsListener::Delegate* delegate) OVERRIDE; | 179 MDnsListener::Delegate* delegate) override; |
| 180 | 180 |
| 181 virtual scoped_ptr<MDnsTransaction> CreateTransaction( | 181 virtual scoped_ptr<MDnsTransaction> CreateTransaction( |
| 182 uint16 rrtype, | 182 uint16 rrtype, |
| 183 const std::string& name, | 183 const std::string& name, |
| 184 int flags, | 184 int flags, |
| 185 const MDnsTransaction::ResultCallback& callback) OVERRIDE; | 185 const MDnsTransaction::ResultCallback& callback) override; |
| 186 | 186 |
| 187 virtual bool StartListening(MDnsSocketFactory* socket_factory) OVERRIDE; | 187 virtual bool StartListening(MDnsSocketFactory* socket_factory) override; |
| 188 virtual void StopListening() OVERRIDE; | 188 virtual void StopListening() override; |
| 189 virtual bool IsListening() const OVERRIDE; | 189 virtual bool IsListening() const override; |
| 190 | 190 |
| 191 Core* core() { return core_.get(); } | 191 Core* core() { return core_.get(); } |
| 192 | 192 |
| 193 private: | 193 private: |
| 194 scoped_ptr<Core> core_; | 194 scoped_ptr<Core> core_; |
| 195 | 195 |
| 196 DISALLOW_COPY_AND_ASSIGN(MDnsClientImpl); | 196 DISALLOW_COPY_AND_ASSIGN(MDnsClientImpl); |
| 197 }; | 197 }; |
| 198 | 198 |
| 199 class MDnsListenerImpl : public MDnsListener, | 199 class MDnsListenerImpl : public MDnsListener, |
| 200 public base::SupportsWeakPtr<MDnsListenerImpl> { | 200 public base::SupportsWeakPtr<MDnsListenerImpl> { |
| 201 public: | 201 public: |
| 202 MDnsListenerImpl(uint16 rrtype, | 202 MDnsListenerImpl(uint16 rrtype, |
| 203 const std::string& name, | 203 const std::string& name, |
| 204 MDnsListener::Delegate* delegate, | 204 MDnsListener::Delegate* delegate, |
| 205 MDnsClientImpl* client); | 205 MDnsClientImpl* client); |
| 206 | 206 |
| 207 virtual ~MDnsListenerImpl(); | 207 virtual ~MDnsListenerImpl(); |
| 208 | 208 |
| 209 // MDnsListener implementation: | 209 // MDnsListener implementation: |
| 210 virtual bool Start() OVERRIDE; | 210 virtual bool Start() override; |
| 211 | 211 |
| 212 // Actively refresh any received records. | 212 // Actively refresh any received records. |
| 213 virtual void SetActiveRefresh(bool active_refresh) OVERRIDE; | 213 virtual void SetActiveRefresh(bool active_refresh) override; |
| 214 | 214 |
| 215 virtual const std::string& GetName() const OVERRIDE; | 215 virtual const std::string& GetName() const override; |
| 216 | 216 |
| 217 virtual uint16 GetType() const OVERRIDE; | 217 virtual uint16 GetType() const override; |
| 218 | 218 |
| 219 MDnsListener::Delegate* delegate() { return delegate_; } | 219 MDnsListener::Delegate* delegate() { return delegate_; } |
| 220 | 220 |
| 221 // Alert the delegate of a record update. | 221 // Alert the delegate of a record update. |
| 222 void HandleRecordUpdate(MDnsCache::UpdateType update_type, | 222 void HandleRecordUpdate(MDnsCache::UpdateType update_type, |
| 223 const RecordParsed* record_parsed); | 223 const RecordParsed* record_parsed); |
| 224 | 224 |
| 225 // Alert the delegate of the existence of an Nsec record. | 225 // Alert the delegate of the existence of an Nsec record. |
| 226 void AlertNsecRecord(); | 226 void AlertNsecRecord(); |
| 227 | 227 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 248 public MDnsListener::Delegate { | 248 public MDnsListener::Delegate { |
| 249 public: | 249 public: |
| 250 MDnsTransactionImpl(uint16 rrtype, | 250 MDnsTransactionImpl(uint16 rrtype, |
| 251 const std::string& name, | 251 const std::string& name, |
| 252 int flags, | 252 int flags, |
| 253 const MDnsTransaction::ResultCallback& callback, | 253 const MDnsTransaction::ResultCallback& callback, |
| 254 MDnsClientImpl* client); | 254 MDnsClientImpl* client); |
| 255 virtual ~MDnsTransactionImpl(); | 255 virtual ~MDnsTransactionImpl(); |
| 256 | 256 |
| 257 // MDnsTransaction implementation: | 257 // MDnsTransaction implementation: |
| 258 virtual bool Start() OVERRIDE; | 258 virtual bool Start() override; |
| 259 | 259 |
| 260 virtual const std::string& GetName() const OVERRIDE; | 260 virtual const std::string& GetName() const override; |
| 261 virtual uint16 GetType() const OVERRIDE; | 261 virtual uint16 GetType() const override; |
| 262 | 262 |
| 263 // MDnsListener::Delegate implementation: | 263 // MDnsListener::Delegate implementation: |
| 264 virtual void OnRecordUpdate(MDnsListener::UpdateType update, | 264 virtual void OnRecordUpdate(MDnsListener::UpdateType update, |
| 265 const RecordParsed* record) OVERRIDE; | 265 const RecordParsed* record) override; |
| 266 virtual void OnNsecRecord(const std::string& name, unsigned type) OVERRIDE; | 266 virtual void OnNsecRecord(const std::string& name, unsigned type) override; |
| 267 | 267 |
| 268 virtual void OnCachePurged() OVERRIDE; | 268 virtual void OnCachePurged() override; |
| 269 | 269 |
| 270 private: | 270 private: |
| 271 bool is_active() { return !callback_.is_null(); } | 271 bool is_active() { return !callback_.is_null(); } |
| 272 | 272 |
| 273 void Reset(); | 273 void Reset(); |
| 274 | 274 |
| 275 // Trigger the callback and reset all related variables. | 275 // Trigger the callback and reset all related variables. |
| 276 void TriggerCallback(MDnsTransaction::Result result, | 276 void TriggerCallback(MDnsTransaction::Result result, |
| 277 const RecordParsed* record); | 277 const RecordParsed* record); |
| 278 | 278 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 301 MDnsClientImpl* client_; | 301 MDnsClientImpl* client_; |
| 302 | 302 |
| 303 bool started_; | 303 bool started_; |
| 304 int flags_; | 304 int flags_; |
| 305 | 305 |
| 306 DISALLOW_COPY_AND_ASSIGN(MDnsTransactionImpl); | 306 DISALLOW_COPY_AND_ASSIGN(MDnsTransactionImpl); |
| 307 }; | 307 }; |
| 308 | 308 |
| 309 } // namespace net | 309 } // namespace net |
| 310 #endif // NET_DNS_MDNS_CLIENT_IMPL_H_ | 310 #endif // NET_DNS_MDNS_CLIENT_IMPL_H_ |
| OLD | NEW |