| OLD | NEW |
| 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/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 if (mapped_ip.empty()) | 132 if (mapped_ip.empty()) |
| 133 mapped_ip = ip; | 133 mapped_ip = ip; |
| 134 // else ignore this entry (first hit counts) | 134 // else ignore this entry (first hit counts) |
| 135 } | 135 } |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 | 138 |
| 139 bool ParseHostsFile(const base::FilePath& path, DnsHosts* dns_hosts) { | 139 bool ParseHostsFile(const base::FilePath& path, DnsHosts* dns_hosts) { |
| 140 dns_hosts->clear(); | 140 dns_hosts->clear(); |
| 141 // Missing file indicates empty HOSTS. | 141 // Missing file indicates empty HOSTS. |
| 142 if (!file_util::PathExists(path)) | 142 if (!base::PathExists(path)) |
| 143 return true; | 143 return true; |
| 144 | 144 |
| 145 int64 size; | 145 int64 size; |
| 146 if (!file_util::GetFileSize(path, &size)) | 146 if (!file_util::GetFileSize(path, &size)) |
| 147 return false; | 147 return false; |
| 148 | 148 |
| 149 UMA_HISTOGRAM_COUNTS("AsyncDNS.HostsSize", size); | 149 UMA_HISTOGRAM_COUNTS("AsyncDNS.HostsSize", size); |
| 150 | 150 |
| 151 // Reject HOSTS files larger than |kMaxHostsSize|. | 151 // Reject HOSTS files larger than |kMaxHostsSize|. |
| 152 const int64 kMaxHostsSize = 1 << 16; | 152 const int64 kMaxHostsSize = 1 << 16; |
| 153 if (size > kMaxHostsSize) | 153 if (size > kMaxHostsSize) |
| 154 return false; | 154 return false; |
| 155 | 155 |
| 156 std::string contents; | 156 std::string contents; |
| 157 if (!file_util::ReadFileToString(path, &contents)) | 157 if (!file_util::ReadFileToString(path, &contents)) |
| 158 return false; | 158 return false; |
| 159 | 159 |
| 160 ParseHosts(contents, dns_hosts); | 160 ParseHosts(contents, dns_hosts); |
| 161 return true; | 161 return true; |
| 162 } | 162 } |
| 163 | 163 |
| 164 } // namespace net | 164 } // namespace net |
| 165 | 165 |
| OLD | NEW |