Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(585)

Side by Side Diff: net/dns/record_parsed.cc

Issue 14697022: Cache for mDNS records (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@record_parsed_klassbit
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "net/dns/record_parsed.h" 5 #include "net/dns/record_parsed.h"
6 6
7 #include "base/logging.h"
7 #include "net/dns/dns_response.h" 8 #include "net/dns/dns_response.h"
8 #include "net/dns/record_rdata.h" 9 #include "net/dns/record_rdata.h"
9 10
10 namespace net { 11 namespace net {
11 12
12 RecordParsed::RecordParsed(const std::string& name, uint16 type, uint16 klass, 13 RecordParsed::RecordParsed(const std::string& name, uint16 type, uint16 klass,
13 uint32 ttl, scoped_ptr<const RecordRdata> rdata) 14 uint32 ttl, scoped_ptr<const RecordRdata> rdata,
14 : name_(name), type_(type), klass_(klass), ttl_(ttl), rdata_(rdata.Pass()) { 15 base::Time time_created)
16 : name_(name), type_(type), klass_(klass), ttl_(ttl), rdata_(rdata.Pass()),
17 time_created_(time_created) {
18 }
19
20 RecordParsed::RecordParsed(const RecordParsed& other)
21 : name_(other.name_), type_(other.type_), klass_(other.klass_),
22 ttl_(other.ttl_), rdata_(other.rdata_->Copy()),
23 time_created_(other.time_created_) {
15 } 24 }
16 25
17 RecordParsed::~RecordParsed() { 26 RecordParsed::~RecordParsed() {
18 } 27 }
19 28
20 // static 29 // static
21 scoped_ptr<const RecordParsed> RecordParsed::CreateFrom( 30 scoped_ptr<const RecordParsed> RecordParsed::CreateFrom(
22 DnsRecordParser* parser) { 31 DnsRecordParser* parser,
32 base::Time time_created) {
23 DnsResourceRecord record; 33 DnsResourceRecord record;
24 scoped_ptr<const RecordRdata> rdata; 34 scoped_ptr<const RecordRdata> rdata;
25 35
26 if (!parser->ReadRecord(&record)) 36 if (!parser->ReadRecord(&record))
27 return scoped_ptr<const RecordParsed>(); 37 return scoped_ptr<const RecordParsed>();
28 38
29 switch (record.type) { 39 switch (record.type) {
30 case ARecordRdata::kType: 40 case ARecordRdata::kType:
31 rdata = ARecordRdata::Create(record.rdata, *parser); 41 rdata = ARecordRdata::Create(record.rdata, *parser);
32 break; 42 break;
43 case AAAARecordRdata::kType:
44 rdata = AAAARecordRdata::Create(record.rdata, *parser);
45 break;
33 case CnameRecordRdata::kType: 46 case CnameRecordRdata::kType:
34 rdata = CnameRecordRdata::Create(record.rdata, *parser); 47 rdata = CnameRecordRdata::Create(record.rdata, *parser);
35 break; 48 break;
36 case PtrRecordRdata::kType: 49 case PtrRecordRdata::kType:
37 rdata = PtrRecordRdata::Create(record.rdata, *parser); 50 rdata = PtrRecordRdata::Create(record.rdata, *parser);
38 break; 51 break;
39 case SrvRecordRdata::kType: 52 case SrvRecordRdata::kType:
40 rdata = SrvRecordRdata::Create(record.rdata, *parser); 53 rdata = SrvRecordRdata::Create(record.rdata, *parser);
41 break; 54 break;
42 case TxtRecordRdata::kType: 55 case TxtRecordRdata::kType:
43 rdata = TxtRecordRdata::Create(record.rdata, *parser); 56 rdata = TxtRecordRdata::Create(record.rdata, *parser);
44 break; 57 break;
45 default: 58 default:
59 LOG(WARNING) << "Unknown RData type for recieved record: " << record.type;
46 return scoped_ptr<const RecordParsed>(); 60 return scoped_ptr<const RecordParsed>();
47 } 61 }
48 62
49 if (!rdata.get()) 63 if (!rdata.get())
50 return scoped_ptr<const RecordParsed>(); 64 return scoped_ptr<const RecordParsed>();
51 65
52 return scoped_ptr<const RecordParsed>(new RecordParsed(record.name, 66 return scoped_ptr<const RecordParsed>(new RecordParsed(record.name,
53 record.type, 67 record.type,
54 record.klass, 68 record.klass,
55 record.ttl, 69 record.ttl,
56 rdata.Pass())); 70 rdata.Pass(),
71 time_created));
72 }
73
74 bool RecordParsed::IsEqual(const RecordParsed* other, bool is_mdns) const {
75 DCHECK(other);
76 uint16 klass = klass_;
77 uint16 other_klass = other->klass_;
78
79 if (is_mdns) {
80 klass &= dns_protocol::kMDnsClassMask;
81 other_klass &= dns_protocol::kMDnsClassMask;
82 }
83
84 return name_ == other->name_ &&
85 klass == other_klass &&
86 type_ == other->type_ &&
87 rdata_->IsEqual(other->rdata_.get());
57 } 88 }
58 } 89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698