| 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/files/file_util.h" | 7 #include "base/files/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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 bool ParseHostsFile(const base::FilePath& path, DnsHosts* dns_hosts) { | 188 bool ParseHostsFile(const base::FilePath& path, DnsHosts* dns_hosts) { |
| 189 dns_hosts->clear(); | 189 dns_hosts->clear(); |
| 190 // Missing file indicates empty HOSTS. | 190 // Missing file indicates empty HOSTS. |
| 191 if (!base::PathExists(path)) | 191 if (!base::PathExists(path)) |
| 192 return true; | 192 return true; |
| 193 | 193 |
| 194 int64 size; | 194 int64 size; |
| 195 if (!base::GetFileSize(path, &size)) | 195 if (!base::GetFileSize(path, &size)) |
| 196 return false; | 196 return false; |
| 197 | 197 |
| 198 UMA_HISTOGRAM_COUNTS("AsyncDNS.HostsSize", size); | 198 UMA_HISTOGRAM_COUNTS("AsyncDNS.HostsSize", |
| 199 static_cast<base::HistogramBase::Sample>(size)); |
| 199 | 200 |
| 200 // Reject HOSTS files larger than |kMaxHostsSize| bytes. | 201 // Reject HOSTS files larger than |kMaxHostsSize| bytes. |
| 201 const int64 kMaxHostsSize = 1 << 25; // 32MB | 202 const int64 kMaxHostsSize = 1 << 25; // 32MB |
| 202 if (size > kMaxHostsSize) | 203 if (size > kMaxHostsSize) |
| 203 return false; | 204 return false; |
| 204 | 205 |
| 205 std::string contents; | 206 std::string contents; |
| 206 if (!base::ReadFileToString(path, &contents)) | 207 if (!base::ReadFileToString(path, &contents)) |
| 207 return false; | 208 return false; |
| 208 | 209 |
| 209 ParseHosts(contents, dns_hosts); | 210 ParseHosts(contents, dns_hosts); |
| 210 return true; | 211 return true; |
| 211 } | 212 } |
| 212 | 213 |
| 213 } // namespace net | 214 } // namespace net |
| 214 | 215 |
| OLD | NEW |