diff options
author | vitalybuka <vitalybuka@chromium.org> | 2016-01-05 21:25:17 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-06 05:26:02 +0000 |
commit | a97cddb717feb2e775feaf0331ee6fbb307b6469 (patch) | |
tree | 451bf4915833781850338d5b0d9ef021ddaaf78f /net | |
parent | 5de01d904d77ba5e5beaf4776e45e6eecd47a87b (diff) | |
download | chromium_src-a97cddb717feb2e775feaf0331ee6fbb307b6469.zip chromium_src-a97cddb717feb2e775feaf0331ee6fbb307b6469.tar.gz chromium_src-a97cddb717feb2e775feaf0331ee6fbb307b6469.tar.bz2 |
Use scoped_ptr in RecordMap
Use std::map<Key, scoped_ptr<const RecordParsed>> instead of
std::map<Key, const RecordParsed*> RecordMap
Review URL: https://codereview.chromium.org/1556193004
Cr-Commit-Position: refs/heads/master@{#367780}
Diffstat (limited to 'net')
-rw-r--r-- | net/dns/mdns_cache.cc | 36 | ||||
-rw-r--r-- | net/dns/mdns_cache.h | 7 |
2 files changed, 15 insertions, 28 deletions
diff --git a/net/dns/mdns_cache.cc b/net/dns/mdns_cache.cc index a55fdca..2c57828 100644 --- a/net/dns/mdns_cache.cc +++ b/net/dns/mdns_cache.cc @@ -8,7 +8,6 @@ #include <tuple> #include <utility> -#include "base/stl_util.h" #include "base/strings/string_number_conversions.h" #include "net/dns/dns_protocol.h" #include "net/dns/record_parsed.h" @@ -66,20 +65,14 @@ MDnsCache::MDnsCache() { } MDnsCache::~MDnsCache() { - Clear(); -} - -void MDnsCache::Clear() { - next_expiration_ = base::Time(); - 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 found->second.get(); } - return NULL; + return nullptr; } MDnsCache::UpdateType MDnsCache::UpdateDnsRecord( @@ -95,20 +88,18 @@ MDnsCache::UpdateType MDnsCache::UpdateDnsRecord( new_expiration = std::min(new_expiration, next_expiration_); std::pair<RecordMap::iterator, bool> insert_result = - mdns_cache_.insert(std::make_pair(cache_key, (const RecordParsed*)NULL)); + mdns_cache_.insert(std::make_pair(cache_key, nullptr)); UpdateType type = NoChange; if (insert_result.second) { type = RecordAdded; } else { - const RecordParsed* other_record = insert_result.first->second; - - if (record->ttl() != 0 && !record->IsEqual(other_record, true)) { + if (record->ttl() != 0 && + !record->IsEqual(insert_result.first->second.get(), true)) { type = RecordChanged; } - delete other_record; } - insert_result.first->second = record.release(); + insert_result.first->second = std::move(record); next_expiration_ = new_expiration; return type; } @@ -125,10 +116,9 @@ void MDnsCache::CleanupRecords( for (RecordMap::iterator i = mdns_cache_.begin(); i != mdns_cache_.end(); ) { - base::Time expiration = GetEffectiveExpiration(i->second); + base::Time expiration = GetEffectiveExpiration(i->second.get()); if (now >= expiration) { - record_removed_callback.Run(i->second); - delete i->second; + record_removed_callback.Run(i->second.get()); mdns_cache_.erase(i++); } else { if (next_expiration == base::Time() || expiration < next_expiration) { @@ -155,7 +145,7 @@ void MDnsCache::FindDnsRecords(unsigned type, break; } - const RecordParsed* record = i->second; + const RecordParsed* record = i->second.get(); // Records are deleted only upon request. if (now >= GetEffectiveExpiration(record)) continue; @@ -169,17 +159,17 @@ scoped_ptr<const RecordParsed> MDnsCache::RemoveRecord( Key key = Key::CreateFor(record); RecordMap::iterator found = mdns_cache_.find(key); - if (found != mdns_cache_.end() && found->second == record) { + if (found != mdns_cache_.end() && found->second.get() == record) { + scoped_ptr<const RecordParsed> result = std::move(found->second); mdns_cache_.erase(key); - return scoped_ptr<const RecordParsed>(record); + return result; } return scoped_ptr<const RecordParsed>(); } // static -std::string MDnsCache::GetOptionalFieldForRecord( - const RecordParsed* record) { +std::string MDnsCache::GetOptionalFieldForRecord(const RecordParsed* record) { switch (record->type()) { case PtrRecordRdata::kType: { const PtrRecordRdata* rdata = record->rdata<PtrRecordRdata>(); diff --git a/net/dns/mdns_cache.h b/net/dns/mdns_cache.h index e8f9153..38f121a 100644 --- a/net/dns/mdns_cache.h +++ b/net/dns/mdns_cache.h @@ -93,10 +93,8 @@ class NET_EXPORT_PRIVATE MDnsCache { // passed in if it was removed, scoped null otherwise. scoped_ptr<const RecordParsed> RemoveRecord(const RecordParsed* record); - void Clear(); - private: - typedef std::map<Key, const RecordParsed*> RecordMap; + typedef std::map<Key, scoped_ptr<const RecordParsed>> RecordMap; // Get the effective expiration of a cache entry, based on its creation time // and TTL. Does adjustments so entries with a TTL of zero will have a @@ -106,8 +104,7 @@ class NET_EXPORT_PRIVATE MDnsCache { // Get optional part of the DNS key for shared records. For example, in PTR // records this is the pointed domain, since multiple PTR records may exist // for the same name. - static std::string GetOptionalFieldForRecord( - const RecordParsed* record); + static std::string GetOptionalFieldForRecord(const RecordParsed* record); RecordMap mdns_cache_; |