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

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

Issue 9721002: [net/dns] Removes locking from DnsConfigServiceWin and adds local computer name. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Extract local IP from GetAdapterAddresses. Created 8 years, 9 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) 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/dns_hosts.h" 5 #include "net/dns/dns_hosts.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_tokenizer.h" 9 #include "base/string_tokenizer.h"
10 10
(...skipping 16 matching lines...) Expand all
27 StringTokenizer tokens(part, " \t"); 27 StringTokenizer tokens(part, " \t");
28 28
29 if (tokens.GetNext()) { 29 if (tokens.GetNext()) {
30 IPAddressNumber ip; 30 IPAddressNumber ip;
31 // TODO(szym): handle %iface notation on mac 31 // TODO(szym): handle %iface notation on mac
32 if (!ParseIPLiteralToNumber(tokens.token(), &ip)) 32 if (!ParseIPLiteralToNumber(tokens.token(), &ip))
33 continue; // Ignore malformed lines. 33 continue; // Ignore malformed lines.
34 AddressFamily fam = (ip.size() == 4) ? ADDRESS_FAMILY_IPV4 : 34 AddressFamily fam = (ip.size() == 4) ? ADDRESS_FAMILY_IPV4 :
35 ADDRESS_FAMILY_IPV6; 35 ADDRESS_FAMILY_IPV6;
36 while (tokens.GetNext()) { 36 while (tokens.GetNext()) {
37 // TODO(szym): Normalize name to lowercase. http://crbug.com/118995
37 IPAddressNumber& mapped_ip = hosts[DnsHostsKey(tokens.token(), fam)]; 38 IPAddressNumber& mapped_ip = hosts[DnsHostsKey(tokens.token(), fam)];
38 if (mapped_ip.empty()) 39 if (mapped_ip.empty())
39 mapped_ip = ip; 40 mapped_ip = ip;
40 // else ignore this entry (first hit counts) 41 // else ignore this entry (first hit counts)
41 } 42 }
42 } 43 }
43 } 44 }
44 } 45 }
45 } 46 }
46 47
47 DnsHostsReader::DnsHostsReader(const FilePath& path, 48 DnsHostsReader::DnsHostsReader(const FilePath& path,
48 const CallbackType& callback) 49 const CallbackType& callback)
49 : path_(path), 50 : path_(path),
50 callback_(callback), 51 callback_(callback),
51 success_(false) { 52 success_(false) {
52 DCHECK(!callback.is_null()); 53 DCHECK(!callback.is_null());
53 } 54 }
54 55
56 DnsHostsReader::DnsHostsReader(const FilePath& path)
57 : path_(path),
58 success_(false) {
59 }
60
55 // Reads the contents of the file at |path| into |str| if the total length is 61 // Reads the contents of the file at |path| into |str| if the total length is
56 // less than |max_size|. 62 // less than |max_size|.
57 static bool ReadFile(const FilePath& path, int64 max_size, std::string* str) { 63 static bool ReadFile(const FilePath& path, int64 max_size, std::string* str) {
58 int64 size; 64 int64 size;
59 if (!file_util::GetFileSize(path, &size) || size > max_size) 65 if (!file_util::GetFileSize(path, &size) || size > max_size)
60 return false; 66 return false;
61 return file_util::ReadFileToString(path, str); 67 return file_util::ReadFileToString(path, str);
62 } 68 }
63 69
64 void DnsHostsReader::DoWork() { 70 void DnsHostsReader::DoWork() {
(...skipping 17 matching lines...) Expand all
82 void DnsHostsReader::OnWorkFinished() { 88 void DnsHostsReader::OnWorkFinished() {
83 DCHECK(!IsCancelled()); 89 DCHECK(!IsCancelled());
84 if (success_) 90 if (success_)
85 callback_.Run(dns_hosts_); 91 callback_.Run(dns_hosts_);
86 } 92 }
87 93
88 DnsHostsReader::~DnsHostsReader() {} 94 DnsHostsReader::~DnsHostsReader() {}
89 95
90 } // namespace net 96 } // namespace net
91 97
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698