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

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

Issue 761903003: Update from https://crrev.com/306655 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 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/disk_cache/simple/simple_synchronous_entry.cc ('k') | net/dns/dns_session.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/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
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
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_synchronous_entry.cc ('k') | net/dns/dns_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698