Chromium Code Reviews| 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 <list> | |
| 9 #include <map> | |
| 10 #include <string> | |
| 11 | |
| 12 #include "base/memory/linked_ptr.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/time.h" | |
| 15 #include "net/base/net_export.h" | |
| 16 | |
| 17 namespace net { | |
| 18 | |
| 19 class ParsedDnsRecord; | |
| 20 | |
| 21 class RecordParsed; | |
| 22 | |
| 23 class NET_EXPORT_PRIVATE MDnsCache { | |
|
szym
2013/05/14 18:14:27
Needs class-level or file-level comment.
Noam Samuel
2013/05/15 00:11:31
Done.
| |
| 24 public: | |
| 25 enum UpdateType { | |
| 26 RecordAdded, | |
| 27 RecordChanged, | |
| 28 RecordRemoved, | |
| 29 NoChange | |
| 30 }; | |
| 31 | |
| 32 class DnsRecordCacheKey { | |
|
szym
2013/05/14 18:14:27
Needs comment here or at the file-level.
Noam Samuel
2013/05/15 00:11:31
Done.
| |
| 33 public: | |
| 34 DnsRecordCacheKey(uint16 type, | |
| 35 const std::string& name, | |
| 36 const std::string& optional); | |
| 37 | |
| 38 ~DnsRecordCacheKey(); | |
| 39 bool operator<(const DnsRecordCacheKey& key) const; | |
| 40 bool operator==(const DnsRecordCacheKey& key) const; | |
| 41 | |
| 42 uint16 type() const { return type_; } | |
| 43 const std::string& name() const { return name_; } | |
| 44 const std::string& optional() const { return optional_; } | |
| 45 | |
| 46 private: | |
| 47 uint16 type_; | |
|
szym
2013/05/14 18:14:27
Does it really need to be uint16? Why not unsigned
Noam Samuel
2013/05/15 00:11:31
Done.
| |
| 48 std::string name_; | |
| 49 std::string optional_; | |
| 50 }; | |
| 51 | |
| 52 class Query { | |
|
szym
2013/05/14 18:14:27
Comment?
It seems to me that this implements the
Noam Samuel
2013/05/14 19:28:01
It's slightly different because it assumes records
Noam Samuel
2013/05/15 00:11:31
Changed querying to remove this class.
| |
| 53 public: | |
| 54 virtual ~Query() {} | |
| 55 | |
| 56 virtual DnsRecordCacheKey GetLowerBoundKey() const = 0; | |
| 57 virtual bool IsMatching(const DnsRecordCacheKey& key) const = 0; | |
| 58 }; | |
| 59 | |
| 60 class TypeOnlyQuery : public MDnsCache::Query { | |
| 61 public: | |
| 62 explicit TypeOnlyQuery(uint16 type); | |
| 63 virtual ~TypeOnlyQuery(); | |
| 64 | |
| 65 virtual DnsRecordCacheKey GetLowerBoundKey() const OVERRIDE; | |
| 66 virtual bool IsMatching(const DnsRecordCacheKey& key) const OVERRIDE; | |
| 67 private: | |
| 68 uint16 type_; | |
| 69 }; | |
| 70 | |
| 71 class TypeNameQuery : public MDnsCache::Query { | |
| 72 public: | |
| 73 TypeNameQuery(uint16 type, const std::string& name); | |
| 74 virtual ~TypeNameQuery(); | |
| 75 | |
| 76 virtual DnsRecordCacheKey GetLowerBoundKey() const OVERRIDE; | |
| 77 virtual bool IsMatching(const DnsRecordCacheKey& key) const OVERRIDE; | |
| 78 private: | |
| 79 uint16 type_; | |
| 80 std::string name_; | |
| 81 }; | |
| 82 | |
| 83 MDnsCache(); | |
| 84 ~MDnsCache(); | |
| 85 | |
| 86 // Update the cache with the new record. Takes ownership of the record. | |
| 87 UpdateType UpdateDnsRecord(const RecordParsed* record); | |
|
szym
2013/05/14 18:14:27
Use scoped_ptr<RecordParsed> instead of the commen
Noam Samuel
2013/05/15 00:11:31
Done.
| |
| 88 | |
| 89 // Return false if nothing has been found. Expired records will not be | |
| 90 // returned. | |
| 91 bool FindDnsRecords(const Query& query, | |
| 92 std::list<const RecordParsed*>* results, | |
|
szym
2013/05/14 18:14:27
If you always return |results| why do you need to
Noam Samuel
2013/05/14 19:28:01
Hm. I think you're right that ideally an iterator
Noam Samuel
2013/05/15 00:11:31
On second thought, writing an iterator will probab
| |
| 93 base::Time now); | |
| 94 | |
| 95 // |records_removed| will be populated with the removed records. Uses | |
| 96 // linked_ptr to signify that the ownership is being transferred to the | |
| 97 // user. | |
| 98 void CleanupRecords( | |
| 99 std::list<linked_ptr<const RecordParsed> >* records_removed, | |
|
szym
2013/05/14 18:14:27
Ditto.
Noam Samuel
2013/05/15 00:11:31
Made irrelevant.
| |
| 100 base::Time now); | |
| 101 | |
| 102 // Returns a time less than or equal to the next time a record will expire. | |
| 103 // Is updated when CleapRecords or UpdateDnsRecord are called. | |
| 104 base::Time GetNextExpiration() const { return next_expiration_; } | |
|
szym
2013/05/14 18:14:27
If it's a simple accessor, code style says it shou
Noam Samuel
2013/05/15 00:11:31
Done.
| |
| 105 | |
| 106 void Clear(); | |
| 107 | |
| 108 private: | |
| 109 base::Time GetEffectiveExpiration(const RecordParsed* entry); | |
|
szym
2013/05/14 18:14:27
Needs comment.
Noam Samuel
2013/05/15 00:11:31
Done.
| |
| 110 std::string GetOptionalFieldForRecord(const RecordParsed* record); | |
|
szym
2013/05/14 18:14:27
Ditto.
Noam Samuel
2013/05/15 00:11:31
Done.
| |
| 111 | |
| 112 typedef std::map<DnsRecordCacheKey, linked_ptr<const RecordParsed> > | |
| 113 MDnsCacheMap; | |
| 114 | |
| 115 MDnsCacheMap mdns_cache_; | |
| 116 | |
| 117 // next_expiration_ is always guaranteed to be less than or equal to the next | |
| 118 // expiration. A value of base::Time() implies there is no next expiration | |
| 119 // (empty cache). | |
| 120 base::Time next_expiration_; | |
| 121 | |
| 122 DISALLOW_COPY_AND_ASSIGN(MDnsCache); | |
| 123 }; | |
| 124 | |
| 125 } // namespace net | |
| 126 | |
| 127 #endif // NET_DNS_MDNS_CACHE_H_ | |
| OLD | NEW |