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 <queue> |
9 #include <string> | 10 #include <string> |
10 #include <utility> | 11 #include <utility> |
11 #include <vector> | 12 #include <vector> |
12 | 13 |
13 #include "base/cancelable_callback.h" | 14 #include "base/cancelable_callback.h" |
14 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
15 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
16 #include "net/base/io_buffer.h" | 17 #include "net/base/io_buffer.h" |
17 #include "net/base/ip_endpoint.h" | 18 #include "net/base/ip_endpoint.h" |
18 #include "net/dns/mdns_cache.h" | 19 #include "net/dns/mdns_cache.h" |
19 #include "net/dns/mdns_client.h" | 20 #include "net/dns/mdns_client.h" |
20 #include "net/udp/datagram_server_socket.h" | 21 #include "net/udp/datagram_server_socket.h" |
21 #include "net/udp/udp_server_socket.h" | 22 #include "net/udp/udp_server_socket.h" |
22 #include "net/udp/udp_socket.h" | 23 #include "net/udp/udp_socket.h" |
23 | 24 |
| 25 namespace base { |
| 26 class Clock; |
| 27 class Timer; |
| 28 } // namespace base |
| 29 |
24 namespace net { | 30 namespace net { |
25 | 31 |
26 class MDnsSocketFactoryImpl : public MDnsSocketFactory { | 32 class MDnsSocketFactoryImpl : public MDnsSocketFactory { |
27 public: | 33 public: |
28 MDnsSocketFactoryImpl() {}; | 34 MDnsSocketFactoryImpl() {} |
29 ~MDnsSocketFactoryImpl() override{}; | 35 ~MDnsSocketFactoryImpl() override{}; |
30 | 36 |
31 void CreateSockets(ScopedVector<DatagramServerSocket>* sockets) override; | 37 void CreateSockets(ScopedVector<DatagramServerSocket>* sockets) override; |
32 | 38 |
33 private: | 39 private: |
34 DISALLOW_COPY_AND_ASSIGN(MDnsSocketFactoryImpl); | 40 DISALLOW_COPY_AND_ASSIGN(MDnsSocketFactoryImpl); |
35 }; | 41 }; |
36 | 42 |
37 // A connection to the network for multicast DNS clients. It reads data into | 43 // A connection to the network for multicast DNS clients. It reads data into |
38 // DnsResponse objects and alerts the delegate that a packet has been received. | 44 // DnsResponse objects and alerts the delegate that a packet has been received. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 // Query the cache for records of a specific type and name. | 131 // Query the cache for records of a specific type and name. |
126 void QueryCache(uint16 rrtype, const std::string& name, | 132 void QueryCache(uint16 rrtype, const std::string& name, |
127 std::vector<const RecordParsed*>* records) const; | 133 std::vector<const RecordParsed*>* records) const; |
128 | 134 |
129 // Parse the response and alert relevant listeners. | 135 // Parse the response and alert relevant listeners. |
130 void HandlePacket(DnsResponse* response, int bytes_read) override; | 136 void HandlePacket(DnsResponse* response, int bytes_read) override; |
131 | 137 |
132 void OnConnectionError(int error) override; | 138 void OnConnectionError(int error) override; |
133 | 139 |
134 private: | 140 private: |
| 141 FRIEND_TEST_ALL_PREFIXES(MDnsTest, CacheCleanupWithShortTTL); |
| 142 |
135 typedef std::pair<std::string, uint16> ListenerKey; | 143 typedef std::pair<std::string, uint16> ListenerKey; |
136 typedef std::map<ListenerKey, ObserverList<MDnsListenerImpl>* > | 144 typedef std::map<ListenerKey, ObserverList<MDnsListenerImpl>* > |
137 ListenerMap; | 145 ListenerMap; |
138 | 146 |
139 // Alert listeners of an update to the cache. | 147 // Alert listeners of an update to the cache. |
140 void AlertListeners(MDnsCache::UpdateType update_type, | 148 void AlertListeners(MDnsCache::UpdateType update_type, |
141 const ListenerKey& key, const RecordParsed* record); | 149 const ListenerKey& key, const RecordParsed* record); |
142 | 150 |
143 // Schedule a cache cleanup to a specific time, cancelling other cleanups. | 151 // Schedule a cache cleanup to a specific time, cancelling other cleanups. |
144 void ScheduleCleanup(base::Time cleanup); | 152 void ScheduleCleanup(base::Time cleanup); |
145 | 153 |
146 // Clean up the cache and schedule a new cleanup. | 154 // Clean up the cache and schedule a new cleanup. |
147 void DoCleanup(); | 155 void DoCleanup(); |
148 | 156 |
149 // Callback for when a record is removed from the cache. | 157 // Callback for when a record is removed from the cache. |
150 void OnRecordRemoved(const RecordParsed* record); | 158 void OnRecordRemoved(const RecordParsed* record); |
151 | 159 |
152 void NotifyNsecRecord(const RecordParsed* record); | 160 void NotifyNsecRecord(const RecordParsed* record); |
153 | 161 |
154 // Delete and erase the observer list for |key|. Only deletes the observer | 162 // Delete and erase the observer list for |key|. Only deletes the observer |
155 // list if is empty. | 163 // list if is empty. |
156 void CleanupObserverList(const ListenerKey& key); | 164 void CleanupObserverList(const ListenerKey& key); |
157 | 165 |
| 166 void set_cleanup_timer_for_test(scoped_ptr<base::Timer> timer); |
| 167 |
| 168 void set_clock_for_test(scoped_ptr<base::Clock> clock); |
| 169 |
158 ListenerMap listeners_; | 170 ListenerMap listeners_; |
159 | 171 |
160 MDnsCache cache_; | 172 MDnsCache cache_; |
161 | 173 |
162 base::CancelableClosure cleanup_callback_; | 174 scoped_ptr<base::Clock> clock_; |
| 175 scoped_ptr<base::Timer> cleanup_timer_; |
163 base::Time scheduled_cleanup_; | 176 base::Time scheduled_cleanup_; |
164 | 177 |
165 scoped_ptr<MDnsConnection> connection_; | 178 scoped_ptr<MDnsConnection> connection_; |
166 | 179 |
167 DISALLOW_COPY_AND_ASSIGN(Core); | 180 DISALLOW_COPY_AND_ASSIGN(Core); |
168 }; | 181 }; |
169 | 182 |
170 MDnsClientImpl(); | 183 MDnsClientImpl(); |
171 ~MDnsClientImpl() override; | 184 ~MDnsClientImpl() override; |
172 | 185 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 MDnsClientImpl* client_; | 312 MDnsClientImpl* client_; |
300 | 313 |
301 bool started_; | 314 bool started_; |
302 int flags_; | 315 int flags_; |
303 | 316 |
304 DISALLOW_COPY_AND_ASSIGN(MDnsTransactionImpl); | 317 DISALLOW_COPY_AND_ASSIGN(MDnsTransactionImpl); |
305 }; | 318 }; |
306 | 319 |
307 } // namespace net | 320 } // namespace net |
308 #endif // NET_DNS_MDNS_CLIENT_IMPL_H_ | 321 #endif // NET_DNS_MDNS_CLIENT_IMPL_H_ |
OLD | NEW |