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

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

Issue 1535363003: Switch to standard integer types in net/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stddef Created 5 years 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/dns_hosts.h ('k') | net/dns/dns_protocol.h » ('j') | 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/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/macros.h"
9 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
10 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
11 12
12 using base::StringPiece; 13 using base::StringPiece;
13 14
14 namespace net { 15 namespace net {
15 16
16 namespace { 17 namespace {
17 18
18 // Parses the contents of a hosts file. Returns one token (IP or hostname) at 19 // Parses the contents of a hosts file. Returns one token (IP or hostname) at
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 184
184 ParseHostsWithCommaMode(contents, dns_hosts, comma_mode); 185 ParseHostsWithCommaMode(contents, dns_hosts, comma_mode);
185 } 186 }
186 187
187 bool ParseHostsFile(const base::FilePath& path, DnsHosts* dns_hosts) { 188 bool ParseHostsFile(const base::FilePath& path, DnsHosts* dns_hosts) {
188 dns_hosts->clear(); 189 dns_hosts->clear();
189 // Missing file indicates empty HOSTS. 190 // Missing file indicates empty HOSTS.
190 if (!base::PathExists(path)) 191 if (!base::PathExists(path))
191 return true; 192 return true;
192 193
193 int64 size; 194 int64_t size;
194 if (!base::GetFileSize(path, &size)) 195 if (!base::GetFileSize(path, &size))
195 return false; 196 return false;
196 197
197 UMA_HISTOGRAM_COUNTS("AsyncDNS.HostsSize", 198 UMA_HISTOGRAM_COUNTS("AsyncDNS.HostsSize",
198 static_cast<base::HistogramBase::Sample>(size)); 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_t 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
OLDNEW
« no previous file with comments | « net/dns/dns_hosts.h ('k') | net/dns/dns_protocol.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698