Chromium Code Reviews| Index: net/http/http_response_headers.cc |
| diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc |
| index 85df8d5e15f3c390a663dfad6eecb6857564ee59..39954365625a9552bb6b7474532150397c6282ad 100644 |
| --- a/net/http/http_response_headers.cc |
| +++ b/net/http/http_response_headers.cc |
| @@ -12,6 +12,7 @@ |
| #include <algorithm> |
| #include "base/logging.h" |
| +#include "base/metrics/histogram.h" |
| #include "base/pickle.h" |
| #include "base/string_number_conversions.h" |
| #include "base/string_util.h" |
| @@ -85,6 +86,31 @@ bool ShouldUpdateHeader(const std::string::const_iterator& name_begin, |
| return true; |
| } |
| +// Functions for histogram initialization. The code 0 is put in the |
| +// response map to track response codes that are invalid. |
| + |
| +enum { kHistogramMinHttpResponseCode = 100, |
| + kHistogramMaxHttpResponseCode = 599 }; |
|
jar (doing other things)
2011/01/21 20:37:46
This is going to make a slightly large histogram.
gavinp
2011/01/21 21:38:19
I appreciate your point Jim. I do not believe we'
|
| + |
| +std::vector<int> GetAllHttpResponseCodes() { |
| + std::vector<int> codes; |
|
cbentzel
2011/01/21 20:33:25
How expensive is this?
It looks like this fairly
jar (doing other things)
2011/01/21 20:40:36
This is only done during the initialization of the
|
| + codes.reserve( |
| + kHistogramMaxHttpResponseCode - kHistogramMinHttpResponseCode + 2); |
| + codes.push_back(0); |
| + for (int i = kHistogramMinHttpResponseCode; |
| + i <= kHistogramMaxHttpResponseCode;++i) |
| + codes.push_back(i); |
| + return codes; |
| +} |
| + |
| +int MapHttpResponseCode(const int code) { |
| + if (kHistogramMinHttpResponseCode <= code && |
| + code <= kHistogramMaxHttpResponseCode) |
| + return code; |
|
jar (doing other things)
2011/01/21 20:37:46
Probably want something more like
code - kHistog
jar (doing other things)
2011/01/21 20:40:36
<doh> My mistake. Please ignore. The relocation o
|
| + else |
|
jar (doing other things)
2011/01/21 20:37:46
style nit: avoid else clauses when you returned in
gavinp
2011/01/21 21:38:19
Done.
|
| + return 0; |
| +} |
| + |
| } // namespace |
| struct HttpResponseHeaders::ParsedHeader { |
| @@ -103,6 +129,15 @@ struct HttpResponseHeaders::ParsedHeader { |
| HttpResponseHeaders::HttpResponseHeaders(const std::string& raw_input) |
| : response_code_(-1) { |
| Parse(raw_input); |
| + |
| + // The most important thing to do with this histogram is find out the |
| + // existence of unusual HTTP response codes. As it happens right now, |
| + // there aren't double-constructions of response headers using this |
| + // constructor, so our counts should also be accurate, without |
| + // instantiating the histogram in two places. |
| + UMA_HISTOGRAM_CUSTOM_ENUMERATION("Net.HttpResponseCode", |
| + MapHttpResponseCode(response_code_), |
| + GetAllHttpResponseCodes()); |
| } |
| HttpResponseHeaders::HttpResponseHeaders(const Pickle& pickle, void** iter) |