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

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
« no previous file with comments | « net/dns/record_parsed.h ('k') | net/dns/record_parsed_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
15 } 18 }
16 19
17 RecordParsed::~RecordParsed() { 20 RecordParsed::~RecordParsed() {
18 } 21 }
19 22
20 // static 23 // static
21 scoped_ptr<const RecordParsed> RecordParsed::CreateFrom( 24 scoped_ptr<const RecordParsed> RecordParsed::CreateFrom(
22 DnsRecordParser* parser) { 25 DnsRecordParser* parser,
26 base::Time time_created) {
23 DnsResourceRecord record; 27 DnsResourceRecord record;
24 scoped_ptr<const RecordRdata> rdata; 28 scoped_ptr<const RecordRdata> rdata;
25 29
26 if (!parser->ReadRecord(&record)) 30 if (!parser->ReadRecord(&record))
27 return scoped_ptr<const RecordParsed>(); 31 return scoped_ptr<const RecordParsed>();
28 32
29 switch (record.type) { 33 switch (record.type) {
30 case ARecordRdata::kType: 34 case ARecordRdata::kType:
31 rdata = ARecordRdata::Create(record.rdata, *parser); 35 rdata = ARecordRdata::Create(record.rdata, *parser);
32 break; 36 break;
37 case AAAARecordRdata::kType:
38 rdata = AAAARecordRdata::Create(record.rdata, *parser);
39 break;
33 case CnameRecordRdata::kType: 40 case CnameRecordRdata::kType:
34 rdata = CnameRecordRdata::Create(record.rdata, *parser); 41 rdata = CnameRecordRdata::Create(record.rdata, *parser);
35 break; 42 break;
36 case PtrRecordRdata::kType: 43 case PtrRecordRdata::kType:
37 rdata = PtrRecordRdata::Create(record.rdata, *parser); 44 rdata = PtrRecordRdata::Create(record.rdata, *parser);
38 break; 45 break;
39 case SrvRecordRdata::kType: 46 case SrvRecordRdata::kType:
40 rdata = SrvRecordRdata::Create(record.rdata, *parser); 47 rdata = SrvRecordRdata::Create(record.rdata, *parser);
41 break; 48 break;
42 case TxtRecordRdata::kType: 49 case TxtRecordRdata::kType:
43 rdata = TxtRecordRdata::Create(record.rdata, *parser); 50 rdata = TxtRecordRdata::Create(record.rdata, *parser);
44 break; 51 break;
45 default: 52 default:
53 LOG(WARNING) << "Unknown RData type for recieved record: " << record.type;
46 return scoped_ptr<const RecordParsed>(); 54 return scoped_ptr<const RecordParsed>();
47 } 55 }
48 56
49 if (!rdata.get()) 57 if (!rdata.get())
50 return scoped_ptr<const RecordParsed>(); 58 return scoped_ptr<const RecordParsed>();
51 59
52 return scoped_ptr<const RecordParsed>(new RecordParsed(record.name, 60 return scoped_ptr<const RecordParsed>(new RecordParsed(record.name,
53 record.type, 61 record.type,
54 record.klass, 62 record.klass,
55 record.ttl, 63 record.ttl,
56 rdata.Pass())); 64 rdata.Pass(),
65 time_created));
66 }
67
68 bool RecordParsed::IsEqual(const RecordParsed* other, bool is_mdns) const {
69 DCHECK(other);
70 uint16 klass = klass_;
71 uint16 other_klass = other->klass_;
72
73 if (is_mdns) {
74 klass &= dns_protocol::kMDnsClassMask;
75 other_klass &= dns_protocol::kMDnsClassMask;
76 }
77
78 return name_ == other->name_ &&
79 klass == other_klass &&
80 type_ == other->type_ &&
81 rdata_->IsEqual(other->rdata_.get());
57 } 82 }
58 } 83 }
OLDNEW
« no previous file with comments | « net/dns/record_parsed.h ('k') | net/dns/record_parsed_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698