OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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_CACHE_H_ | 5 #ifndef NET_DNS_MDNS_CACHE_H_ |
6 #define NET_DNS_MDNS_CACHE_H_ | 6 #define NET_DNS_MDNS_CACHE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 21 matching lines...) Expand all Loading... |
32 class Key { | 32 class Key { |
33 public: | 33 public: |
34 Key(unsigned type, const std::string& name, const std::string& optional); | 34 Key(unsigned type, const std::string& name, const std::string& optional); |
35 Key(const Key&); | 35 Key(const Key&); |
36 Key& operator=(const Key&); | 36 Key& operator=(const Key&); |
37 ~Key(); | 37 ~Key(); |
38 bool operator<(const Key& key) const; | 38 bool operator<(const Key& key) const; |
39 bool operator==(const Key& key) const; | 39 bool operator==(const Key& key) const; |
40 | 40 |
41 unsigned type() const { return type_; } | 41 unsigned type() const { return type_; } |
42 const std::string& name() const { return name_; } | 42 const std::string& name() const { return name_; } |
43 const std::string& optional() const { return optional_; } | 43 const std::string& optional() const { return optional_; } |
44 | 44 |
45 // Create the cache key corresponding to |record|. | 45 // Create the cache key corresponding to |record|. |
46 static Key CreateFor(const RecordParsed* record); | 46 static Key CreateFor(const RecordParsed* record); |
| 47 |
47 private: | 48 private: |
48 unsigned type_; | 49 unsigned type_; |
49 std::string name_; | 50 std::string name_; |
50 std::string optional_; | 51 std::string optional_; |
51 }; | 52 }; |
52 | 53 |
53 typedef base::Callback<void(const RecordParsed*)> RecordRemovedCallback; | 54 typedef base::Callback<void(const RecordParsed*)> RecordRemovedCallback; |
54 | 55 |
55 enum UpdateType { | 56 enum UpdateType { RecordAdded, RecordChanged, RecordRemoved, NoChange }; |
56 RecordAdded, | |
57 RecordChanged, | |
58 RecordRemoved, | |
59 NoChange | |
60 }; | |
61 | 57 |
62 MDnsCache(); | 58 MDnsCache(); |
63 ~MDnsCache(); | 59 ~MDnsCache(); |
64 | 60 |
65 // Return value indicates whether the record was added, changed | 61 // Return value indicates whether the record was added, changed |
66 // (existed previously with different value) or not changed (existed | 62 // (existed previously with different value) or not changed (existed |
67 // previously with same value). | 63 // previously with same value). |
68 UpdateType UpdateDnsRecord(scoped_ptr<const RecordParsed> record); | 64 UpdateType UpdateDnsRecord(scoped_ptr<const RecordParsed> record); |
69 | 65 |
70 // Check cache for record with key |key|. Return the record if it exists, or | 66 // Check cache for record with key |key|. Return the record if it exists, or |
(...skipping 27 matching lines...) Expand all Loading... |
98 typedef std::map<Key, const RecordParsed*> RecordMap; | 94 typedef std::map<Key, const RecordParsed*> RecordMap; |
99 | 95 |
100 // Get the effective expiration of a cache entry, based on its creation time | 96 // Get the effective expiration of a cache entry, based on its creation time |
101 // and TTL. Does adjustments so entries with a TTL of zero will have a | 97 // and TTL. Does adjustments so entries with a TTL of zero will have a |
102 // nonzero TTL, as explained in RFC 6762 Section 10.1. | 98 // nonzero TTL, as explained in RFC 6762 Section 10.1. |
103 static base::Time GetEffectiveExpiration(const RecordParsed* entry); | 99 static base::Time GetEffectiveExpiration(const RecordParsed* entry); |
104 | 100 |
105 // Get optional part of the DNS key for shared records. For example, in PTR | 101 // Get optional part of the DNS key for shared records. For example, in PTR |
106 // records this is the pointed domain, since multiple PTR records may exist | 102 // records this is the pointed domain, since multiple PTR records may exist |
107 // for the same name. | 103 // for the same name. |
108 static std::string GetOptionalFieldForRecord( | 104 static std::string GetOptionalFieldForRecord(const RecordParsed* record); |
109 const RecordParsed* record); | |
110 | 105 |
111 RecordMap mdns_cache_; | 106 RecordMap mdns_cache_; |
112 | 107 |
113 base::Time next_expiration_; | 108 base::Time next_expiration_; |
114 | 109 |
115 DISALLOW_COPY_AND_ASSIGN(MDnsCache); | 110 DISALLOW_COPY_AND_ASSIGN(MDnsCache); |
116 }; | 111 }; |
117 | 112 |
118 } // namespace net | 113 } // namespace net |
119 | 114 |
120 #endif // NET_DNS_MDNS_CACHE_H_ | 115 #endif // NET_DNS_MDNS_CACHE_H_ |
OLD | NEW |