diff options
author | noamsml@chromium.org <noamsml@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-19 03:43:31 +0000 |
---|---|---|
committer | noamsml@chromium.org <noamsml@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-19 03:43:31 +0000 |
commit | 5e6f42734932258c9d22ecb3065ff787fd3b7b58 (patch) | |
tree | 305b6b5b4e859e4d32f276e98192b936512c6159 /net/dns/mdns_cache.cc | |
parent | e07f7b7b919c7c54bdc4c7b2433c2b79cefdb986 (diff) | |
download | chromium_src-5e6f42734932258c9d22ecb3065ff787fd3b7b58.zip chromium_src-5e6f42734932258c9d22ecb3065ff787fd3b7b58.tar.gz chromium_src-5e6f42734932258c9d22ecb3065ff787fd3b7b58.tar.bz2 |
MDnsClient: Process all records before alerting listeners
Change the notification structure in the MDnsListener to notify listeners after
the whole packet is processed. This should allow listeners to issue cache
queries for other records in the same packet in a synchronous manner.
In order to not issue invalid notifications in case the packet contains multiple
records that cancel each other out (and thus delete each other), store cache
keys in the list of notifications to send, rather than storing record pointers
directly.
BUG=
TEST=MDnsCacheTest.*,MDnsTest.*
Review URL: https://chromiumcodereview.appspot.com/17379009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207161 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/dns/mdns_cache.cc')
-rw-r--r-- | net/dns/mdns_cache.cc | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/net/dns/mdns_cache.cc b/net/dns/mdns_cache.cc index cb7dc117..f210d0ab 100644 --- a/net/dns/mdns_cache.cc +++ b/net/dns/mdns_cache.cc @@ -59,6 +59,14 @@ bool MDnsCache::Key::operator==(const MDnsCache::Key& key) const { return type_ == key.type_ && name_ == key.name_ && optional_ == key.optional_; } +// static +MDnsCache::Key MDnsCache::Key::CreateFor(const RecordParsed* record) { + return Key(record->type(), + record->name(), + GetOptionalFieldForRecord(record)); +} + + MDnsCache::MDnsCache() { } @@ -71,14 +79,19 @@ void MDnsCache::Clear() { STLDeleteValues(&mdns_cache_); } +const RecordParsed* MDnsCache::LookupKey(const Key& key) { + RecordMap::iterator found = mdns_cache_.find(key); + if (found != mdns_cache_.end()) { + return found->second; + } + return NULL; +} + MDnsCache::UpdateType MDnsCache::UpdateDnsRecord( scoped_ptr<const RecordParsed> record) { UpdateType type = NoChange; - MDnsCache::Key cache_key = MDnsCache::Key( - record->type(), - record->name(), - GetOptionalFieldForRecord(record.get())); + Key cache_key = Key::CreateFor(record.get()); base::Time expiration = GetEffectiveExpiration(record.get()); if (next_expiration_ == base::Time() || expiration < next_expiration_) { @@ -155,8 +168,9 @@ void MDnsCache::FindDnsRecords(unsigned type, } } +// static std::string MDnsCache::GetOptionalFieldForRecord( - const RecordParsed* record) const { + const RecordParsed* record) { switch (record->type()) { case PtrRecordRdata::kType: { const PtrRecordRdata* rdata = record->rdata<PtrRecordRdata>(); @@ -167,7 +181,8 @@ std::string MDnsCache::GetOptionalFieldForRecord( } } -base::Time MDnsCache::GetEffectiveExpiration(const RecordParsed* record) const { +// static +base::Time MDnsCache::GetEffectiveExpiration(const RecordParsed* record) { base::TimeDelta ttl; if (record->ttl()) { |