OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NET_DNS_MDNS_CACHE_H_ | |
6 #define NET_DNS_MDNS_CACHE_H_ | |
7 | |
8 #include <map> | |
9 #include <string> | |
10 #include <vector> | |
11 | |
12 #include "base/callback.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/time.h" | |
15 #include "net/base/net_export.h" | |
16 | |
17 /** | |
szym
2013/05/17 05:04:34
Chromium C++ style says use // comments only.
I'd
Noam Samuel
2013/05/17 22:26:05
Done.
| |
18 * mDNS Cache | |
19 * | |
20 * This is a cache of mDNS records. It keeps track of expiration times and is | |
21 * guaranteed not to return expired records. It also has facilities for timely | |
22 * record expiration. | |
23 */ | |
24 | |
25 namespace net { | |
26 | |
27 class ParsedDnsRecord; | |
28 | |
szym
2013/05/17 05:04:34
nit: remove blank line
Noam Samuel
2013/05/17 22:26:05
Done.
| |
29 class RecordParsed; | |
30 | |
31 class NET_EXPORT_PRIVATE MDnsCache { | |
32 public: | |
33 typedef base::Callback<void(const RecordParsed*)> RecordRemovedCallback; | |
34 | |
35 enum UpdateType { | |
36 RecordAdded, | |
37 RecordChanged, | |
38 RecordRemoved, | |
szym
2013/05/17 05:04:34
RecordRemoved is never used. Do you need it?
Noam Samuel
2013/05/17 17:21:02
Hm. I added it here so I could use it to signify u
| |
39 NoChange | |
40 }; | |
41 | |
42 // |record_removed_callback| will be called whenever a record is removed. | |
43 // The calls are done synchronously. | |
szym
2013/05/17 05:04:34
|record_removed_callback| is called in CleanupReco
Noam Samuel
2013/05/17 22:26:05
|record_removed_callback| now passed to CleanupRec
| |
44 explicit MDnsCache(const RecordRemovedCallback& record_removed_callback); | |
45 ~MDnsCache(); | |
46 | |
47 // Return value indicates whether the record was added, changed | |
48 // (existed previously with different value) or not changed (existed | |
49 // previously with same value). | |
50 UpdateType UpdateDnsRecord(scoped_ptr<const RecordParsed> record); | |
51 | |
52 // Return records with type |type| and name |name|. Expired records will not | |
53 // be returned. If |name| is empty, return all records with type |type|. | |
54 void FindDnsRecords(unsigned type, | |
55 const std::string& name, | |
56 std::vector<const RecordParsed*>* records, | |
57 base::Time now); | |
58 | |
59 // Empty the cache, call |record_removed_callback_| for every removed record. | |
szym
2013/05/17 05:04:34
Do you really mean "empty the cache", or is it "re
Noam Samuel
2013/05/17 22:26:05
Done.
| |
60 void CleanupRecords(base::Time now); | |
61 | |
62 // Returns a time less than or equal to the next time a record will expire. | |
63 // Is updated when CleapRecords or UpdateDnsRecord are called. | |
szym
2013/05/17 05:04:34
Fix typo. Should explain returns base::Time() when
Noam Samuel
2013/05/17 22:26:05
Done.
| |
64 base::Time next_expiration() const { return next_expiration_; } | |
65 | |
66 void Clear(); | |
67 | |
68 private: | |
69 // Key type for the record map. It is a 3-tuple of type, name and optional | |
70 // value ordered by type, then name, then optional value. This allows us to | |
71 // query for all records of a certain type and name, while also allowing us | |
72 // to set records of a certain type, name and optionally value as unique. | |
73 class DnsRecordCacheKey { | |
74 public: | |
75 DnsRecordCacheKey(unsigned type, | |
76 const std::string& name, | |
77 const std::string& optional); | |
78 | |
szym
2013/05/17 05:04:34
nit: remove blank
Noam Samuel
2013/05/17 22:26:05
Done.
| |
79 ~DnsRecordCacheKey(); | |
80 bool operator<(const DnsRecordCacheKey& key) const; | |
81 bool operator==(const DnsRecordCacheKey& key) const; | |
82 | |
szym
2013/05/17 05:04:34
I believe this needs explicit copy constructor and
Noam Samuel
2013/05/17 22:26:05
Done.
| |
83 unsigned type() const { return type_; } | |
84 const std::string& name() const { return name_; } | |
85 const std::string& optional() const { return optional_; } | |
86 | |
87 private: | |
88 unsigned type_; | |
89 std::string name_; | |
90 std::string optional_; | |
91 }; | |
92 | |
93 typedef std::map<DnsRecordCacheKey, const RecordParsed*> | |
94 MDnsCacheMap; | |
95 | |
96 // Get the effective expiration of a cache entry, based on its creation time | |
97 // and ttl. Does adjustments so entries with a TTL of zero will have a | |
98 // nonzero ttl, as explained in RFC 6762 Section 10.1. | |
szym
2013/05/17 05:04:34
nit: Use "TTL" consistently (not "ttl").
Noam Samuel
2013/05/17 22:26:05
Done.
| |
99 base::Time GetEffectiveExpiration(const RecordParsed* entry); | |
100 | |
101 // Get optional part of the DNS key for shared records. For example, in PTR | |
102 // records this is the pointed domain, since multiple PTR records may exist | |
103 // for the same name. | |
104 std::string GetOptionalFieldForRecord(const RecordParsed* record); | |
105 | |
106 MDnsCacheMap mdns_cache_; | |
107 | |
108 // next_expiration_ is always guaranteed to be less than or equal to the next | |
szym
2013/05/17 05:04:34
nit: Wrap references to variables in ||.
To avoid
Noam Samuel
2013/05/17 22:26:05
Removed comment here. Better to have comment in pu
| |
109 // expiration. A value of base::Time() implies there is no next expiration | |
110 // (empty cache). | |
111 base::Time next_expiration_; | |
112 | |
113 RecordRemovedCallback record_removed_callback_; | |
szym
2013/05/17 05:04:34
If you keep it and don't intend to change it, make
Noam Samuel
2013/05/17 22:26:05
Removed.
On 2013/05/17 05:04:34, szym wrote:
| |
114 | |
115 DISALLOW_COPY_AND_ASSIGN(MDnsCache); | |
116 }; | |
117 | |
118 } // namespace net | |
119 | |
120 #endif // NET_DNS_MDNS_CACHE_H_ | |
OLD | NEW |