summaryrefslogtreecommitdiffstats
path: root/net/dns
diff options
context:
space:
mode:
authorszym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-12 17:58:18 +0000
committerszym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-12 17:58:18 +0000
commit2ab5c5bf770f10a7f0d39fd8fd44afd4f6e51470 (patch)
treec816a060205947fb7e382c2f2cf254897b1958c2 /net/dns
parentd5a831e998bb4ebe4ae1c0de9385f29c15a73026 (diff)
downloadchromium_src-2ab5c5bf770f10a7f0d39fd8fd44afd4f6e51470.zip
chromium_src-2ab5c5bf770f10a7f0d39fd8fd44afd4f6e51470.tar.gz
chromium_src-2ab5c5bf770f10a7f0d39fd8fd44afd4f6e51470.tar.bz2
[net/dns] Collect histogram on HOSTS file size.
4% of attempts to parse the HOSTS file fail because reading the file fails. This is likely because files above 65kB are rejected. This CL installs the AsyncDNS.HostsSize histogram to measure the observed size of HOSTS file on each call to ParseHostsFile. BUG=137914 Review URL: https://chromiumcodereview.appspot.com/10910229 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156327 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/dns')
-rw-r--r--net/dns/dns_hosts.cc24
1 files changed, 13 insertions, 11 deletions
diff --git a/net/dns/dns_hosts.cc b/net/dns/dns_hosts.cc
index 668d202..66290b4 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) {
- 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);