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

Unified Diff: net/dns/dns_hosts.cc

Issue 10910229: [net/dns] Collect histogram on HOSTS file size. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/dns/dns_hosts.cc
diff --git a/net/dns/dns_hosts.cc b/net/dns/dns_hosts.cc
index 668d20245c0afa938d7a3fc39d5fdd66aea5e658..66290b461bc080aeaa99091e72afccc7a354fccd 100644
--- a/net/dns/dns_hosts.cc
+++ b/net/dns/dns_hosts.cc
@@ -6,6 +6,7 @@
#include "base/file_util.h"
#include "base/logging.h"
+#include "base/metrics/histogram.h"
#include "base/string_tokenizer.h"
#include "base/string_util.h"
@@ -47,24 +48,25 @@ void ParseHosts(const std::string& contents, DnsHosts* dns_hosts) {
}
}
-// Reads the contents of the file at |path| into |str| if the total length is
-// less than |max_size|.
-static bool ReadFile(const FilePath& path, int64 max_size, std::string* str) {
szym 2012/09/12 16:42:35 I removed this function because it doesn't seem to
- int64 size;
- if (!file_util::GetFileSize(path, &size) || size > max_size)
- return false;
- return file_util::ReadFileToString(path, str);
-}
-
bool ParseHostsFile(const FilePath& path, DnsHosts* dns_hosts) {
dns_hosts->clear();
// Missing file indicates empty HOSTS.
if (!file_util::PathExists(path))
return true;
- std::string contents;
+ int64 size;
+ if (!file_util::GetFileSize(path, &size))
+ return false;
+
+ UMA_HISTOGRAM_COUNTS("AsyncDNS.HostsSize", size);
+
+ // Reject HOSTS files larger than |kMaxHostsSize|.
const int64 kMaxHostsSize = 1 << 16;
- if (!ReadFile(path, kMaxHostsSize, &contents))
+ if (size > kMaxHostsSize)
+ return false;
+
+ std::string contents;
+ if (!file_util::ReadFileToString(path, &contents))
return false;
ParseHosts(contents, dns_hosts);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698