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

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: remediation to review 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 // TODO(gavinp): Greatly prune the collected codes once we learn which
92 // ares are not sent in practice, to reduce upload size & memory use.
93
94 enum { kHistogramMinHttpResponseCode = 100,
95 kHistogramMaxHttpResponseCode = 599 };
wtc 2011/01/25 18:38:00 This should be formatted as enum { kHistogram
gavinp 2011/01/26 01:42:45 Done.
96
97 std::vector<int> GetAllHttpResponseCodes() {
98 std::vector<int> codes;
99 codes.reserve(
100 kHistogramMaxHttpResponseCode - kHistogramMinHttpResponseCode + 2);
101 codes.push_back(0);
102 for (int i = kHistogramMinHttpResponseCode;
103 i <= kHistogramMaxHttpResponseCode;++i)
wtc 2011/01/25 18:38:00 Document what the 0 status code added on line 101
gavinp 2011/01/26 01:42:45 Done.
gavinp 2011/01/26 01:42:45 Done.
104 codes.push_back(i);
105 return codes;
106 }
107
108 int MapHttpResponseCode(const int code) {
wtc 2011/01/25 18:38:00 Nit: remove the 'const' from the function paramete
gavinp 2011/01/26 01:42:45 Done.
109 if (kHistogramMinHttpResponseCode <= code &&
110 code <= kHistogramMaxHttpResponseCode)
111 return code;
112 return 0;
113 }
114
88 } // namespace 115 } // namespace
89 116
90 struct HttpResponseHeaders::ParsedHeader { 117 struct HttpResponseHeaders::ParsedHeader {
91 // A header "continuation" contains only a subsequent value for the 118 // A header "continuation" contains only a subsequent value for the
92 // preceding header. (Header values are comma separated.) 119 // preceding header. (Header values are comma separated.)
93 bool is_continuation() const { return name_begin == name_end; } 120 bool is_continuation() const { return name_begin == name_end; }
94 121
95 std::string::const_iterator name_begin; 122 std::string::const_iterator name_begin;
96 std::string::const_iterator name_end; 123 std::string::const_iterator name_end;
97 std::string::const_iterator value_begin; 124 std::string::const_iterator value_begin;
98 std::string::const_iterator value_end; 125 std::string::const_iterator value_end;
99 }; 126 };
100 127
101 //----------------------------------------------------------------------------- 128 //-----------------------------------------------------------------------------
102 129
103 HttpResponseHeaders::HttpResponseHeaders(const std::string& raw_input) 130 HttpResponseHeaders::HttpResponseHeaders(const std::string& raw_input)
104 : response_code_(-1) { 131 : response_code_(-1) {
105 Parse(raw_input); 132 Parse(raw_input);
133
134 // The most important thing to do with this histogram is find out the
135 // existence of unusual HTTP response codes. As it happens right now,
136 // there aren't double-constructions of response headers using this
137 // constructor, so our counts should also be accurate, without
138 // instantiating the histogram in two places.
139 UMA_HISTOGRAM_CUSTOM_ENUMERATION("Net.HttpResponseCode",
140 MapHttpResponseCode(response_code_),
141 GetAllHttpResponseCodes());
wtc 2011/01/25 18:38:00 It is wasteful to build the std::vector<int> of co
gavinp 2011/01/26 01:42:45 Added a comment documenting that this is not what'
106 } 142 }
107 143
108 HttpResponseHeaders::HttpResponseHeaders(const Pickle& pickle, void** iter) 144 HttpResponseHeaders::HttpResponseHeaders(const Pickle& pickle, void** iter)
109 : response_code_(-1) { 145 : response_code_(-1) {
110 std::string raw_input; 146 std::string raw_input;
111 if (pickle.ReadString(iter, &raw_input)) 147 if (pickle.ReadString(iter, &raw_input))
112 Parse(raw_input); 148 Parse(raw_input);
113 } 149 }
114 150
115 void HttpResponseHeaders::Persist(Pickle* pickle, PersistOptions options) { 151 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 1243 // We have all the values; let's verify that they make sense for a 206
1208 // response. 1244 // response.
1209 if (*first_byte_position < 0 || *last_byte_position < 0 || 1245 if (*first_byte_position < 0 || *last_byte_position < 0 ||
1210 *instance_length < 0 || *instance_length - 1 < *last_byte_position) 1246 *instance_length < 0 || *instance_length - 1 < *last_byte_position)
1211 return false; 1247 return false;
1212 1248
1213 return true; 1249 return true;
1214 } 1250 }
1215 1251
1216 } // namespace net 1252 } // 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