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

Side by Side Diff: net/http/http_response_headers.cc

Issue 6317011: Add histogram for HTTP response codes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix lint + range Created 9 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 // The rules for header parsing were borrowed from Firefox: 5 // The rules for header parsing were borrowed from Firefox:
6 // http://lxr.mozilla.org/seamonkey/source/netwerk/protocol/http/src/nsHttpRespo nseHead.cpp 6 // http://lxr.mozilla.org/seamonkey/source/netwerk/protocol/http/src/nsHttpRespo nseHead.cpp
7 // The rules for parsing content-types were also borrowed from Firefox: 7 // The rules for parsing content-types were also borrowed from Firefox:
8 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834 8 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834
9 9
10 #include "net/http/http_response_headers.h" 10 #include "net/http/http_response_headers.h"
11 11
12 #include <algorithm> 12 #include <algorithm>
13 13
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/metrics/histogram.h"
15 #include "base/pickle.h" 16 #include "base/pickle.h"
16 #include "base/string_number_conversions.h" 17 #include "base/string_number_conversions.h"
17 #include "base/string_util.h" 18 #include "base/string_util.h"
18 #include "base/time.h" 19 #include "base/time.h"
19 #include "net/base/escape.h" 20 #include "net/base/escape.h"
20 #include "net/http/http_util.h" 21 #include "net/http/http_util.h"
21 22
22 using base::Time; 23 using base::Time;
23 using base::TimeDelta; 24 using base::TimeDelta;
24 25
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 79
79 bool ShouldUpdateHeader(const std::string::const_iterator& name_begin, 80 bool ShouldUpdateHeader(const std::string::const_iterator& name_begin,
80 const std::string::const_iterator& name_end) { 81 const std::string::const_iterator& name_end) {
81 for (size_t i = 0; i < arraysize(kNonUpdatedHeaders); ++i) { 82 for (size_t i = 0; i < arraysize(kNonUpdatedHeaders); ++i) {
82 if (LowerCaseEqualsASCII(name_begin, name_end, kNonUpdatedHeaders[i])) 83 if (LowerCaseEqualsASCII(name_begin, name_end, kNonUpdatedHeaders[i]))
83 return false; 84 return false;
84 } 85 }
85 return true; 86 return true;
86 } 87 }
87 88
89 // Functions for histogram initialization. The code 0 is put in the
90 // response map to track response codes that are invalid.
91
92 enum { kHistogramMinHttpResponseCode = 100,
93 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'
94
95 std::vector<int> GetAllHttpResponseCodes() {
96 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
97 codes.reserve(
98 kHistogramMaxHttpResponseCode - kHistogramMinHttpResponseCode + 2);
99 codes.push_back(0);
100 for (int i = kHistogramMinHttpResponseCode;
101 i <= kHistogramMaxHttpResponseCode;++i)
102 codes.push_back(i);
103 return codes;
104 }
105
106 int MapHttpResponseCode(const int code) {
107 if (kHistogramMinHttpResponseCode <= code &&
108 code <= kHistogramMaxHttpResponseCode)
109 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
110 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.
111 return 0;
112 }
113
88 } // namespace 114 } // namespace
89 115
90 struct HttpResponseHeaders::ParsedHeader { 116 struct HttpResponseHeaders::ParsedHeader {
91 // A header "continuation" contains only a subsequent value for the 117 // A header "continuation" contains only a subsequent value for the
92 // preceding header. (Header values are comma separated.) 118 // preceding header. (Header values are comma separated.)
93 bool is_continuation() const { return name_begin == name_end; } 119 bool is_continuation() const { return name_begin == name_end; }
94 120
95 std::string::const_iterator name_begin; 121 std::string::const_iterator name_begin;
96 std::string::const_iterator name_end; 122 std::string::const_iterator name_end;
97 std::string::const_iterator value_begin; 123 std::string::const_iterator value_begin;
98 std::string::const_iterator value_end; 124 std::string::const_iterator value_end;
99 }; 125 };
100 126
101 //----------------------------------------------------------------------------- 127 //-----------------------------------------------------------------------------
102 128
103 HttpResponseHeaders::HttpResponseHeaders(const std::string& raw_input) 129 HttpResponseHeaders::HttpResponseHeaders(const std::string& raw_input)
104 : response_code_(-1) { 130 : response_code_(-1) {
105 Parse(raw_input); 131 Parse(raw_input);
132
133 // The most important thing to do with this histogram is find out the
134 // existence of unusual HTTP response codes. As it happens right now,
135 // there aren't double-constructions of response headers using this
136 // constructor, so our counts should also be accurate, without
137 // instantiating the histogram in two places.
138 UMA_HISTOGRAM_CUSTOM_ENUMERATION("Net.HttpResponseCode",
139 MapHttpResponseCode(response_code_),
140 GetAllHttpResponseCodes());
106 } 141 }
107 142
108 HttpResponseHeaders::HttpResponseHeaders(const Pickle& pickle, void** iter) 143 HttpResponseHeaders::HttpResponseHeaders(const Pickle& pickle, void** iter)
109 : response_code_(-1) { 144 : response_code_(-1) {
110 std::string raw_input; 145 std::string raw_input;
111 if (pickle.ReadString(iter, &raw_input)) 146 if (pickle.ReadString(iter, &raw_input))
112 Parse(raw_input); 147 Parse(raw_input);
113 } 148 }
114 149
115 void HttpResponseHeaders::Persist(Pickle* pickle, PersistOptions options) { 150 void HttpResponseHeaders::Persist(Pickle* pickle, PersistOptions options) {
(...skipping 1091 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 // We have all the values; let's verify that they make sense for a 206 1242 // We have all the values; let's verify that they make sense for a 206
1208 // response. 1243 // response.
1209 if (*first_byte_position < 0 || *last_byte_position < 0 || 1244 if (*first_byte_position < 0 || *last_byte_position < 0 ||
1210 *instance_length < 0 || *instance_length - 1 < *last_byte_position) 1245 *instance_length < 0 || *instance_length - 1 < *last_byte_position)
1211 return false; 1246 return false;
1212 1247
1213 return true; 1248 return true;
1214 } 1249 }
1215 1250
1216 } // namespace net 1251 } // namespace net
OLDNEW
« 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