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

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

Issue 2938183003: Make HostCache::RestoreFromListValue() take a const reference (Closed)
Patch Set: auto Created 3 years, 6 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/host_cache.h ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/host_cache.h" 5 #include "net/dns/host_cache.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 23 matching lines...) Expand all
34 // String constants for dictionary keys. 34 // String constants for dictionary keys.
35 const char kHostnameKey[] = "hostname"; 35 const char kHostnameKey[] = "hostname";
36 const char kAddressFamilyKey[] = "address_family"; 36 const char kAddressFamilyKey[] = "address_family";
37 const char kFlagsKey[] = "flags"; 37 const char kFlagsKey[] = "flags";
38 const char kExpirationKey[] = "expiration"; 38 const char kExpirationKey[] = "expiration";
39 const char kTtlKey[] = "ttl"; 39 const char kTtlKey[] = "ttl";
40 const char kNetworkChangesKey[] = "network_changes"; 40 const char kNetworkChangesKey[] = "network_changes";
41 const char kErrorKey[] = "error"; 41 const char kErrorKey[] = "error";
42 const char kAddressesKey[] = "addresses"; 42 const char kAddressesKey[] = "addresses";
43 43
44 bool AddressListFromListValue(base::ListValue* value, AddressList* list) { 44 bool AddressListFromListValue(const base::ListValue* value, AddressList* list) {
45 list->clear(); 45 list->clear();
46 for (base::ListValue::const_iterator it = value->begin(); it != value->end(); 46 for (base::ListValue::const_iterator it = value->begin(); it != value->end();
47 it++) { 47 it++) {
48 IPAddress address; 48 IPAddress address;
49 std::string addr_string; 49 std::string addr_string;
50 if (!it->GetAsString(&addr_string) || 50 if (!it->GetAsString(&addr_string) ||
51 !address.AssignFromIPLiteral(addr_string)) { 51 !address.AssignFromIPLiteral(addr_string)) {
52 return false; 52 return false;
53 } 53 }
54 list->push_back(IPEndPoint(address, 0)); 54 list->push_back(IPEndPoint(address, 0));
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 entry_dict->SetList(kAddressesKey, std::move(addresses_value)); 308 entry_dict->SetList(kAddressesKey, std::move(addresses_value));
309 } 309 }
310 310
311 entry_list->Append(std::move(entry_dict)); 311 entry_list->Append(std::move(entry_dict));
312 } 312 }
313 313
314 return entry_list; 314 return entry_list;
315 } 315 }
316 316
317 // TODO(mgersh): Add histograms to track failures. 317 // TODO(mgersh): Add histograms to track failures.
318 bool HostCache::RestoreFromListValue(base::ListValue& old_cache) { 318 bool HostCache::RestoreFromListValue(const base::ListValue& old_cache) {
319 for (base::ListValue::iterator it = old_cache.begin(); it != old_cache.end(); 319 for (auto it = old_cache.begin(); it != old_cache.end(); it++) {
320 it++) { 320 const base::DictionaryValue* entry_dict;
321 base::DictionaryValue* entry_dict;
322 if (!it->GetAsDictionary(&entry_dict)) 321 if (!it->GetAsDictionary(&entry_dict))
323 return false; 322 return false;
324 323
325 std::string hostname; 324 std::string hostname;
326 int address_family; 325 int address_family;
327 HostResolverFlags flags; 326 HostResolverFlags flags;
328 int error = OK; 327 int error = OK;
329 std::string expiration; 328 std::string expiration;
330 base::ListValue empty_list; 329 base::ListValue empty_list;
331 base::ListValue* addresses_value = &empty_list; 330 const base::ListValue* addresses_value = &empty_list;
332 AddressList address_list; 331 AddressList address_list;
333 332
334 if (!entry_dict->GetString(kHostnameKey, &hostname) || 333 if (!entry_dict->GetString(kHostnameKey, &hostname) ||
335 !entry_dict->GetInteger(kFlagsKey, &flags) || 334 !entry_dict->GetInteger(kFlagsKey, &flags) ||
336 !entry_dict->GetInteger(kAddressFamilyKey, &address_family) || 335 !entry_dict->GetInteger(kAddressFamilyKey, &address_family) ||
337 !entry_dict->GetString(kExpirationKey, &expiration)) { 336 !entry_dict->GetString(kExpirationKey, &expiration)) {
338 return false; 337 return false;
339 } 338 }
340 339
341 // Only one of these fields should be in the dictionary. 340 // Only one of these fields should be in the dictionary.
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 CACHE_HISTOGRAM_TIME("EraseValid.ValidFor", -stale.expired_by); 509 CACHE_HISTOGRAM_TIME("EraseValid.ValidFor", -stale.expired_by);
511 } 510 }
512 } 511 }
513 512
514 void HostCache::RecordEraseAll(EraseReason reason, base::TimeTicks now) { 513 void HostCache::RecordEraseAll(EraseReason reason, base::TimeTicks now) {
515 for (const auto& it : entries_) 514 for (const auto& it : entries_)
516 RecordErase(reason, now, it.second); 515 RecordErase(reason, now, it.second);
517 } 516 }
518 517
519 } // namespace net 518 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/host_cache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698