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

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

Issue 18286004: Move PathExists to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
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/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
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
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_index_file_unittest.cc ('k') | net/proxy/proxy_config_service_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698